summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--amd.html.markdown212
-rw-r--r--bash.html.markdown61
-rw-r--r--c++.html.markdown590
-rw-r--r--c.html.markdown898
-rw-r--r--coffeescript.html.markdown9
-rw-r--r--common-lisp.html.markdown2
-rw-r--r--compojure.html.markdown280
-rw-r--r--csharp.html.markdown10
-rw-r--r--css.html.markdown91
-rw-r--r--de-de/coffeescript-de.html.markdown106
-rw-r--r--de-de/css-de.html.markdown179
-rw-r--r--de-de/go-de.html.markdown318
-rw-r--r--de-de/haskell-de.html.markdown425
-rw-r--r--de-de/javascript-de.html.markdown4
-rw-r--r--de-de/markdown-de.html.markdown256
-rw-r--r--elixir.html.markdown45
-rw-r--r--erlang.html.markdown39
-rw-r--r--es-es/bash-es.html.markdown196
-rw-r--r--es-es/brainfuck-es.html.markdown87
-rw-r--r--es-es/css-es.html.markdown244
-rw-r--r--es-es/go-es.html.markdown2
-rw-r--r--es-es/javascript-es.html.markdown530
-rw-r--r--es-es/json-es.html.markdown59
-rw-r--r--es-es/julia-es.html.markdown5
-rw-r--r--es-es/livescript-es.html.markdown339
-rw-r--r--es-es/markdown-es.html.markdown252
-rw-r--r--es-es/perl-es.html.markdown120
-rw-r--r--es-es/python-es.html.markdown4
-rw-r--r--es-es/python3-es.html.markdown570
-rw-r--r--es-es/whip-es.html.markdown255
-rw-r--r--es-es/xml-es.html.markdown131
-rw-r--r--es-es/yaml-es.html.markdown151
-rw-r--r--fa-ir/javascript.html.markdown4
-rw-r--r--fr-fr/brainfuck-fr.html.markdown87
-rw-r--r--fr-fr/csharp-fr.html.markdown2
-rw-r--r--fr-fr/css-fr.html.markdown221
-rw-r--r--fr-fr/haskell.html.markdown2
-rw-r--r--fr-fr/javascript-fr.html.markdown525
-rw-r--r--fr-fr/lua-fr.html.markdown2
-rw-r--r--fr-fr/markdown.html.markdown288
-rw-r--r--fr-fr/objective-c-fr.html.markdown2
-rw-r--r--fr-fr/ruby-fr.html.markdown4
-rw-r--r--fr-fr/scala.html.markdown457
-rw-r--r--fr-fr/xml-fr.html.markdown128
-rw-r--r--git.html.markdown7
-rw-r--r--go.html.markdown501
-rw-r--r--haml.html.markdown155
-rw-r--r--haskell.html.markdown6
-rw-r--r--ja-jp/bash-jp.html.markdown172
-rw-r--r--ja-jp/r-jp.html.markdown775
-rw-r--r--java.html.markdown4
-rw-r--r--javascript.html.markdown6
-rw-r--r--json.html.markdown12
-rw-r--r--julia.html.markdown11
-rw-r--r--ko-kr/go-kr.html.markdown34
-rw-r--r--ko-kr/javascript-kr.html.markdown4
-rw-r--r--ko-kr/lua-kr.html.markdown2
-rw-r--r--ko-kr/php-kr.html.markdown2
-rw-r--r--ko-kr/racket-kr.html.markdown640
-rw-r--r--lua.html.markdown2
-rw-r--r--markdown.html.markdown254
-rw-r--r--matlab.html.markdown5
-rw-r--r--nim.html.markdown265
-rw-r--r--nl-nl/coffeescript-nl.html.markdown109
-rw-r--r--objective-c.html.markdown2
-rw-r--r--ocaml.html.markdown372
-rw-r--r--paren.html.markdown193
-rw-r--r--perl.html.markdown18
-rw-r--r--perl6.html.markdown1481
-rw-r--r--php.html.markdown2
-rw-r--r--pt-br/c-pt.html.markdown649
-rw-r--r--pt-br/coffeescript-pt.html.markdown106
-rw-r--r--pt-br/git-pt.html.markdown402
-rw-r--r--pt-br/go-pt.html.markdown6
-rw-r--r--pt-br/haskell-pt.html.markdown2
-rw-r--r--pt-br/json-pt.html.markdown62
-rw-r--r--pt-br/markdown-pt.html.markdown251
-rw-r--r--pt-br/php-pt.html.markdown2
-rw-r--r--purescript.html.markdown195
-rw-r--r--python.html.markdown72
-rw-r--r--python3.html.markdown646
-rw-r--r--r.html.markdown525
-rw-r--r--ro-ro/bash-ro.html.markdown42
-rw-r--r--ro-ro/ruby-ro.html.markdown44
-rw-r--r--ru-ru/coffeescript-ru.html.markdown104
-rw-r--r--ru-ru/go-ru.html.markdown44
-rw-r--r--ru-ru/haskell-ru.html.markdown546
-rw-r--r--ru-ru/julia-ru.html.markdown2
-rw-r--r--ru-ru/markdown-ru.html.markdown279
-rw-r--r--ru-ru/objective-c-ru.html.markdown2
-rw-r--r--ru-ru/php-ru.html.markdown2
-rw-r--r--ru-ru/python-ru.html.markdown266
-rw-r--r--ru-ru/python3-ru.html.markdown630
-rw-r--r--ruby-ecosystem.html.markdown67
-rw-r--r--ruby.html.markdown102
-rw-r--r--rust.html.markdown265
-rw-r--r--scala.html.markdown48
-rw-r--r--swift.html.markdown494
-rw-r--r--tmux.html.markdown244
-rw-r--r--tr-tr/objective-c-tr.html.markdown2
-rw-r--r--tr-tr/php-tr.html.markdown2
-rw-r--r--typescript.html.markdown158
-rw-r--r--vi-vn/objective-c-vi.html.markdown2
-rw-r--r--whip.html.markdown20
-rw-r--r--xml.html.markdown21
-rw-r--r--yaml.html.markdown6
-rw-r--r--zh-cn/c-cn.html.markdown4
-rw-r--r--zh-cn/common-lisp-cn.html.markdown2
-rw-r--r--zh-cn/elixir-cn.html.markdown2
-rw-r--r--zh-cn/erlang-cn.html.markdown259
-rw-r--r--zh-cn/go-cn.html.markdown2
-rw-r--r--zh-cn/haskell-cn.html.markdown2
-rw-r--r--zh-cn/javascript-cn.html.markdown4
-rw-r--r--zh-cn/json-cn.html.markdown51
-rw-r--r--zh-cn/julia-cn.html.markdown729
-rw-r--r--zh-cn/livescript-cn.html.markdown322
-rw-r--r--zh-cn/lua-cn.html.markdown3
-rw-r--r--zh-cn/markdown-cn.html.markdown240
-rw-r--r--zh-cn/php-cn.html.markdown2
-rw-r--r--zh-cn/r-cn.html.markdown2
-rw-r--r--zh-cn/ruby-cn.html.markdown2
-rw-r--r--zh-cn/scala-cn.html.markdown4
-rw-r--r--zh-cn/swift-cn.html.markdown227
-rw-r--r--zh-cn/xml-cn.html.markdown127
-rw-r--r--zh-cn/yaml-cn.html.markdown136
125 files changed, 20251 insertions, 1405 deletions
diff --git a/amd.html.markdown b/amd.html.markdown
new file mode 100644
index 00000000..b3237dc7
--- /dev/null
+++ b/amd.html.markdown
@@ -0,0 +1,212 @@
+---
+category: tool
+tool: amd
+contributors:
+ - ["Frederik Ring", "https://github.com/m90"]
+filename: learnamd.js
+---
+
+## Getting Started with AMD
+
+The **Asynchronous Module Definition** API specifies a mechanism for defining
+JavaScript modules such that the module and its dependencies can be asynchronously
+loaded. This is particularly well suited for the browser environment where
+synchronous loading of modules incurs performance, usability, debugging, and
+cross-domain access problems.
+
+### Basic concept
+```javascript
+// The basic AMD API consists of nothing but two methods: `define` and `require`
+// and is all about module definition and consumption:
+// `define(id?, dependencies?, factory)` defines a module
+// `require(dependencies, callback)` imports a set of dependencies and
+// consumes them in the passed callback
+
+// Let's start by using define to define a new named module
+// that has no dependencies. We'll do so by passing a name
+// and a factory function to define:
+define('awesomeAMD', function(){
+ var isAMDAwesome = function(){
+ return true;
+ };
+ // The return value of a module's factory function is
+ // what other modules or require calls will receive when
+ // requiring our `awesomeAMD` module.
+ // The exported value can be anything, (constructor) functions,
+ // objects, primitives, even undefined (although that won't help too much).
+ return isAMDAwesome;
+});
+
+// Now, let's define another module that depends upon our `awesomeAMD` module.
+// Notice that there's an additional argument defining our
+// module's dependencies now:
+define('loudmouth', ['awesomeAMD'], function(awesomeAMD){
+ // dependencies will be passed to the factory's arguments
+ // in the order they are specified
+ var tellEveryone = function(){
+ if (awesomeAMD()){
+ alert('This is sOoOo rad!');
+ } else {
+ alert('Pretty dull, isn\'t it?');
+ }
+ };
+ return tellEveryone;
+});
+
+// As we do know how to use define now, let's use `require` to
+// kick off our program. `require`'s signature is `(arrayOfDependencies, callback)`.
+require(['loudmouth'], function(loudmouth){
+ loudmouth();
+});
+
+// To make this tutorial run code, let's implement a very basic
+// (non-asynchronous) version of AMD right here on the spot:
+function define(name, deps, factory){
+ // notice how modules without dependencies are handled
+ define[name] = require(factory ? deps : [], factory || deps);
+}
+
+function require(deps, callback){
+ var args = [];
+ // first let's retrieve all the dependencies needed
+ // by the require call
+ for (var i = 0; i < deps.length; i++){
+ args[i] = define[deps[i]];
+ }
+ // satisfy all the callback's dependencies
+ return callback.apply(null, args);
+}
+// you can see this code in action here: http://jsfiddle.net/qap949pd/
+```
+
+### Real-world usage with require.js
+
+In contrast to the introductory example, `require.js` (the most popular AMD library) actually implements the **A** in **AMD**, enabling you to load modules and their dependencies asynchronously via XHR:
+
+```javascript
+/* file: app/main.js */
+require(['modules/someClass'], function(SomeClass){
+ // the callback is deferred until the dependency is loaded
+ var thing = new SomeClass();
+});
+console.log('So here we are, waiting!'); // this will run first
+```
+
+By convention, you usually store one module in one file. `require.js` can resolve module names based on file paths, so you don't have to name your modules, but can simply reference them using their location. In the example `someClass` is assumed to be in the `modules` folder, relative to your configuration's `baseUrl`:
+
+* app/
+ * main.js
+ * modules/
+ * someClass.js
+ * someHelpers.js
+ * ...
+ * daos/
+ * things.js
+ * ...
+
+This means we can define `someClass` without specifying a module id:
+
+```javascript
+/* file: app/modules/someClass.js */
+define(['daos/things', 'modules/someHelpers'], function(thingsDao, helpers){
+ // module definition, of course, will also happen asynchronously
+ function SomeClass(){
+ this.method = function(){/**/};
+ // ...
+ }
+ return SomeClass;
+});
+```
+To alter the default path mapping behavior use `requirejs.config(configObj)` in your `main.js`:
+
+```javascript
+/* file: main.js */
+requirejs.config({
+ baseUrl : 'app',
+ paths : {
+ // you can also load modules from other locations
+ jquery : '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min',
+ coolLibFromBower : '../bower_components/cool-lib/coollib'
+ }
+});
+require(['jquery', 'coolLibFromBower', 'modules/someHelpers'], function($, coolLib, helpers){
+ // a `main` file needs to call require at least once,
+ // otherwise no code will ever run
+ coolLib.doFancyStuffWith(helpers.transform($('#foo')));
+});
+```
+`require.js`-based apps will usually have a single entry point (`main.js`) that is passed to the `require.js` script tag as a data-attribute. It will be automatically loaded and executed on pageload:
+
+```html
+<!DOCTYPE html>
+<html>
+<head>
+ <title>A hundred script tags? Never again!</title>
+</head>
+<body>
+ <script src="require.js" data-main="app/main"></script>
+</body>
+</html>
+```
+
+### Optimizing a whole project using r.js
+
+Many people prefer using AMD for sane code organization during development, but still want to ship a single script file in production instead of performing hundreds of XHRs on page load.
+
+`require.js` comes with a script called `r.js` (that you will probably run in node.js, although Rhino is supported too) that can analyse your project's dependency graph, and build a single file containing all your modules (properly named), minified and ready for consumption.
+
+Install it using `npm`:
+```shell
+$ npm install requirejs -g
+```
+
+Now you can feed it with a configuration file:
+```shell
+$ r.js -o app.build.js
+```
+
+For our above example the configuration might look like:
+```javascript
+/* file : app.build.js */
+({
+ name : 'main', // name of the entry point
+ out : 'main-built.js', // name of the file to write the output to
+ baseUrl : 'app',
+ paths : {
+ // `empty:` tells r.js that this should still be loaded from the CDN, using
+ // the location specified in `main.js`
+ jquery : 'empty:',
+ coolLibFromBower : '../bower_components/cool-lib/coollib'
+ }
+})
+```
+
+To use the built file in production, simply swap `data-main`:
+```html
+<script src="require.js" data-main="app/main-built"></script>
+```
+
+An incredibly detailed [overview of build options](https://github.com/jrburke/r.js/blob/master/build/example.build.js) is available in the GitHub repo.
+
+### Topics not covered in this tutorial
+* [Loader plugins / transforms](http://requirejs.org/docs/plugins.html)
+* [CommonJS style loading and exporting](http://requirejs.org/docs/commonjs.html)
+* [Advanced configuration](http://requirejs.org/docs/api.html#config)
+* [Shim configuration (loading non-AMD modules)](http://requirejs.org/docs/api.html#config-shim)
+* [CSS loading and optimizing with require.js](http://requirejs.org/docs/optimization.html#onecss)
+* [Using almond.js for builds](https://github.com/jrburke/almond)
+
+### Further reading:
+
+* [Official Spec](https://github.com/amdjs/amdjs-api/wiki/AMD)
+* [Why AMD?](http://requirejs.org/docs/whyamd.html)
+* [Universal Module Definition](https://github.com/umdjs/umd)
+
+### Implementations:
+
+* [require.js](http://requirejs.org)
+* [dojo toolkit](http://dojotoolkit.org/documentation/tutorials/1.9/modules/)
+* [cujo.js](http://cujojs.com/)
+* [curl.js](https://github.com/cujojs/curl)
+* [lsjs](https://github.com/zazl/lsjs)
+* [mmd](https://github.com/alexlawrence/mmd)
diff --git a/bash.html.markdown b/bash.html.markdown
index d5d08e9d..11c1f3a2 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -6,6 +6,10 @@ contributors:
- ["Darren Lin", "https://github.com/CogBear"]
- ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
- ["Denis Arh", "https://github.com/darh"]
+ - ["akirahirose", "https://twitter.com/akirahirose"]
+ - ["Anton Strömkvist", "http://lutic.org/"]
+ - ["Rahil Momin", "https://github.com/iamrahil"]
+ - ["Gregrory Kielian", "https://github.com/gskielian"]
filename: LearnBash.sh
---
@@ -71,15 +75,26 @@ echo Hello, $NAME!
# use 'man test' for more info about conditionals
if [ $NAME -ne $USER ]
then
- echo "Your name is your username"
-else
echo "Your name isn't your username"
+else
+ echo "Your name is your username"
fi
# There is also conditional execution
echo "Always executed" || echo "Only executed if first command fails"
echo "Always executed" && echo "Only executed if first command does NOT fail"
+# To use && and || with if statements, you need multiple pairs of square brackets:
+if [ $NAME == "Steve" ] && [ $AGE -eq 15 ]
+then
+ echo "This will run if $NAME is Steve AND $AGE is 15."
+fi
+
+if [ $NAME == "Daniya" ] || [ $NAME == "Zach" ]
+then
+ echo "This will run if $NAME is Daniya OR Zach."
+fi
+
# Expressions are denoted with the following format:
echo $(( 10 + 5 ))
@@ -121,14 +136,34 @@ case "$VARIABLE" in
esac
# for loops iterate for as many arguments given:
-# The contents of var $VARIABLE is printed three times.
+# The contents of $VARIABLE is printed three times.
for VARIABLE in {1..3}
do
echo "$VARIABLE"
done
+# Or write it the "traditional for loop" way:
+for ((a=1; a <= 3; a++))
+do
+ echo $a
+done
+
+# They can also be used to act on files..
+# This will run the command 'cat' on file1 and file2
+for VARIABLE in file1 file2
+do
+ cat "$VARIABLE"
+done
+
+# ..or the output from a command
+# This will cat the output from ls.
+for OUTPUT in $(ls)
+do
+ cat "$OUTPUT"
+done
+
# while loop:
-while [true]
+while [ true ]
do
echo "loop body here..."
break
@@ -155,14 +190,22 @@ bar ()
foo "My name is" $NAME
# There are a lot of useful commands you should learn:
-tail -n 10 file.txt
# prints last 10 lines of file.txt
-head -n 10 file.txt
+tail -n 10 file.txt
# prints first 10 lines of file.txt
-sort file.txt
+head -n 10 file.txt
# sort file.txt's lines
-uniq -d file.txt
+sort file.txt
# report or omit repeated lines, with -d it reports them
-cut -d ',' -f 1 file.txt
+uniq -d file.txt
# prints only the first column before the ',' character
+cut -d ',' -f 1 file.txt
+# replaces every occurrence of 'okay' with 'great' in file.txt, (regex compatible)
+sed -i 's/okay/great/g' file.txt
+# print to stdout all lines of file.txt which match some regex, the example prints lines which begin with "foo" and end in "bar"
+grep "^foo.*bar$" file.txt
+# pass the option "-c" to instead print the number of lines matching the regex
+grep -c "^foo.*bar$" file.txt
+# if you literally want to search for the string, and not the regex, use fgrep (or grep -F)
+fgrep "^foo.*bar$" file.txt
```
diff --git a/c++.html.markdown b/c++.html.markdown
new file mode 100644
index 00000000..9f357b08
--- /dev/null
+++ b/c++.html.markdown
@@ -0,0 +1,590 @@
+---
+language: c++
+filename: learncpp.cpp
+contributors:
+ - ["Steven Basart", "http://github.com/xksteven"]
+ - ["Matt Kline", "https://github.com/mrkline"]
+lang: en
+---
+
+C++ is a systems programming language that,
+[according to its inventor Bjarne Stroustrup](http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Keynote),
+was designed to
+
+- be a "better C"
+- support data abstraction
+- support object-oriented programming
+- support generic programming
+
+Though its syntax can be more difficult or complex than newer languages,
+it is widely used because it compiles to native instructions that can be
+directly run by the processor and offers tight control over hardware (like C)
+while offering high-level features such as generics, exceptions, and classes.
+This combination of speed and functionality makes C++
+one of the most widely-used programming languages.
+
+```c++
+//////////////////
+// Comparison to C
+//////////////////
+
+// C++ is _almost_ a superset of C and shares its basic syntax for
+// variable declarations, primitive types, and functions.
+// However, C++ varies in some of the following ways:
+
+// A main() function in C++ should return an int,
+// though void main() is accepted by most compilers (gcc, clang, etc.)
+// This value serves as the program's exit status.
+// See http://en.wikipedia.org/wiki/Exit_status for more information.
+int main(int argc, char** argv)
+{
+ // Command line arguments are passed in by argc and argv in the same way
+ // they are in C.
+ // argc indicates the number of arguments,
+ // and argv is an array of C-style strings (char*)
+ // representing the arguments.
+ // The first argument is the name by which the program was called.
+ // argc and argv can be omitted if you do not care about arguments,
+ // giving the function signature of int main()
+
+ // An exit status of 0 indicates success.
+ return 0;
+}
+
+// In C++, character literals are one byte.
+sizeof('c') == 1
+
+// In C, character literals are the same size as ints.
+sizeof('c') == sizeof(10)
+
+
+// C++ has strict prototyping
+void func(); // function which accepts no arguments
+
+// In C
+void func(); // function which may accept any number of arguments
+
+// Use nullptr instead of NULL in C++
+int* ip = nullptr;
+
+// C standard headers are available in C++,
+// but are prefixed with "c" and have no .h suffix.
+#include <cstdio>
+
+int main()
+{
+ printf("Hello, world!\n");
+ return 0;
+}
+
+///////////////////////
+// Function overloading
+///////////////////////
+
+// C++ supports function overloading
+// provided each function takes different parameters.
+
+void print(char const* myString)
+{
+ printf("String %s\n", myString);
+}
+
+void print(int myInt)
+{
+ printf("My int is %d", myInt);
+}
+
+int main()
+{
+ print("Hello"); // Resolves to void print(const char*)
+ print(15); // Resolves to void print(int)
+}
+
+/////////////////////////////
+// Default function arguments
+/////////////////////////////
+
+// You can provide default arguments for a function
+// if they are not provided by the caller.
+
+void doSomethingWithInts(int a = 1, int b = 4)
+{
+ // Do something with the ints here
+}
+
+int main()
+{
+ doSomethingWithInts(); // a = 1, b = 4
+ doSomethingWithInts(20); // a = 20, b = 4
+ doSomethingWithInts(20, 5); // a = 20, b = 5
+}
+
+// Default arguments must be at the end of the arguments list.
+
+void invalidDeclaration(int a = 1, int b) // Error!
+{
+}
+
+
+/////////////
+// Namespaces
+/////////////
+
+// Namespaces provide separate scopes for variable, function,
+// and other declarations.
+// Namespaces can be nested.
+
+namespace First {
+ namespace Nested {
+ void foo()
+ {
+ printf("This is First::Nested::foo\n");
+ }
+ } // end namespace Nested
+} // end namespace First
+
+namespace Second {
+ void foo()
+ {
+ printf("This is Second::foo\n")
+ }
+}
+
+void foo()
+{
+ printf("This is global foo\n");
+}
+
+int main()
+{
+ // Assume everything is from the namespace "Second"
+ // unless otherwise specified.
+ using namespace Second;
+
+ foo(); // prints "This is Second::foo"
+ First::Nested::foo(); // prints "This is First::Nested::foo"
+ ::foo(); // prints "This is global foo"
+}
+
+///////////////
+// Input/Output
+///////////////
+
+// C++ input and output uses streams
+// cin, cout, and cerr represent stdin, stdout, and stderr.
+// << is the insertion operator and >> is the extraction operator.
+
+#include <iostream> // Include for I/O streams
+
+using namespace std; // Streams are in the std namespace (standard library)
+
+int main()
+{
+ int myInt;
+
+ // Prints to stdout (or terminal/screen)
+ cout << "Enter your favorite number:\n";
+ // Takes in input
+ cin >> myInt;
+
+ // cout can also be formatted
+ cout << "Your favorite number is " << myInt << "\n";
+ // prints "Your favorite number is <myInt>"
+
+ cerr << "Used for error messages";
+}
+
+//////////
+// Strings
+//////////
+
+// Strings in C++ are objects and have many member functions
+#include <string>
+
+using namespace std; // Strings are also in the namespace std (standard library)
+
+string myString = "Hello";
+string myOtherString = " World";
+
+// + is used for concatenation.
+cout << myString + myOtherString; // "Hello World"
+
+cout << myString + " You"; // "Hello You"
+
+// C++ strings are mutable and have value semantics.
+myString.append(" Dog");
+cout << myString; // "Hello Dog"
+
+
+/////////////
+// References
+/////////////
+
+// In addition to pointers like the ones in C,
+// C++ has _references_.
+// These are pointer types that cannot be reassigned once set
+// and cannot be null.
+// They also have the same syntax as the variable itself:
+// No * is needed for dereferencing and
+// & (address of) is not used for assignment.
+
+using namespace std;
+
+string foo = "I am foo";
+string bar = "I am bar";
+
+
+string& fooRef = foo; // This creates a reference to foo.
+fooRef += ". Hi!"; // Modifies foo through the reference
+cout << fooRef; // Prints "I am foo. Hi!"
+
+fooRef = bar; // Error: references cannot be reassigned.
+
+const string& barRef = bar; // Create a const reference to bar.
+// Like C, const values (and pointers and references) cannot be modified.
+barRef += ". Hi!"; // Error, const references cannot be modified.
+
+//////////////////////////////////////////
+// Classes and object-oriented programming
+//////////////////////////////////////////
+
+// First example of classes
+#include <iostream>
+
+// Declare a class.
+// Classes are usually declared in header (.h or .hpp) files.
+class Dog {
+ // Member variables and functions are private by default.
+ std::string name;
+ int weight;
+
+// All members following this are public
+// until "private:" or "protected:" is found.
+public:
+
+ // Default constructor
+ Dog();
+
+ // Member function declarations (implementations to follow)
+ // Note that we use std::string here instead of placing
+ // using namespace std;
+ // above.
+ // Never put a "using namespace" statement in a header.
+ void setName(const std::string& dogsName);
+
+ void setWeight(int dogsWeight);
+
+ // Functions that do not modify the state of the object
+ // should be marked as const.
+ // This allows you to call them if given a const reference to the object.
+ // Also note the functions must be explicitly declared as _virtual_
+ // in order to be overridden in derived classes.
+ // Functions are not virtual by default for performance reasons.
+ virtual void print() const;
+
+ // Functions can also be defined inside the class body.
+ // Functions defined as such are automatically inlined.
+ void bark() const { std::cout << name << " barks!\n" }
+
+ // Along with constructors, C++ provides destructors.
+ // These are called when an object is deleted or falls out of scope.
+ // This enables powerful paradigms such as RAII
+ // (see below)
+ // Destructors must be virtual to allow classes to be derived from this one.
+ virtual ~Dog();
+
+}; // A semicolon must follow the class definition.
+
+// Class member functions are usually implemented in .cpp files.
+void Dog::Dog()
+{
+ std::cout << "A dog has been constructed\n";
+}
+
+// Objects (such as strings) should be passed by reference
+// if you are modifying them or const reference if you are not.
+void Dog::setName(const std::string& dogsName)
+{
+ name = dogsName;
+}
+
+void Dog::setWeight(int dogsWeight)
+{
+ weight = dogsWeight;
+}
+
+// Notice that "virtual" is only needed in the declaration, not the definition.
+void Dog::print() const
+{
+ std::cout << "Dog is " << name << " and weighs " << weight << "kg\n";
+}
+
+void Dog::~Dog()
+{
+ cout << "Goodbye " << name << "\n";
+}
+
+int main() {
+ Dog myDog; // prints "A dog has been constructed"
+ myDog.setName("Barkley");
+ myDog.setWeight(10);
+ myDog.printDog(); // prints "Dog is Barkley and weighs 10 kg"
+ return 0;
+} // prints "Goodbye Barkley"
+
+// Inheritance:
+
+// This class inherits everything public and protected from the Dog class
+class OwnedDog : public Dog {
+
+ void setOwner(const std::string& dogsOwner)
+
+ // Override the behavior of the print function for all OwnedDogs. See
+ // http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Subtyping
+ // for a more general introduction if you are unfamiliar with
+ // subtype polymorphism.
+ // The override keyword is optional but makes sure you are actually
+ // overriding the method in a base class.
+ void print() const override;
+
+private:
+ std::string owner;
+};
+
+// Meanwhile, in the corresponding .cpp file:
+
+void OwnedDog::setOwner(const std::string& dogsOwner)
+{
+ owner = dogsOwner;
+}
+
+void OwnedDog::print() const
+{
+ Dog::print(); // Call the print function in the base Dog class
+ std::cout << "Dog is owned by " << owner << "\n";
+ // Prints "Dog is <name> and weights <weight>"
+ // "Dog is owned by <owner>"
+}
+
+//////////////////////////////////////////
+// Initialization and Operator Overloading
+//////////////////////////////////////////
+
+// In C++ you can overload the behavior of operators such as +, -, *, /, etc.
+// This is done by defining a function which is called
+// whenever the operator is used.
+
+#include <iostream>
+using namespace std;
+
+class Point {
+public:
+ // Member variables can be given default values in this manner.
+ double x = 0;
+ double y = 0;
+
+ // Define a default constructor which does nothing
+ // but initialize the Point to the default value (0, 0)
+ Point() { };
+
+ // The following syntax is known as an initialization list
+ // and is the proper way to initialize class member values
+ Point (double a, double b) :
+ x(a),
+ y(b)
+ { /* Do nothing except initialize the values */ }
+
+ // Overload the + operator.
+ Point operator+(const Point& rhs) const;
+
+ // Overload the += operator
+ Point& operator+=(const Point& rhs);
+
+ // It would also make sense to add the - and -= operators,
+ // but we will skip those for brevity.
+};
+
+Point Point::operator+(const Point& rhs) const
+{
+ // Create a new point that is the sum of this one and rhs.
+ return Point(x + rhs.x, y + rhs.y);
+}
+
+Point& Point::operator+=(const Point& rhs)
+{
+ x += rhs.x;
+ y += rhs.y;
+ return *this;
+}
+
+int main () {
+ Point up (0,1);
+ Point right (1,0);
+ // This calls the Point + operator
+ // Point up calls the + (function) with right as its paramater
+ Point result = up + right;
+ // Prints "Result is upright (1,1)"
+ cout << "Result is upright (" << result.x << ',' << result.y << ")\n";
+ return 0;
+}
+
+/////////////////////
+// Exception Handling
+/////////////////////
+
+// The standard library provides a few exception types
+// (see http://en.cppreference.com/w/cpp/error/exception)
+// but any type can be thrown an as exception
+#include <exception>
+
+// All exceptions thrown inside the _try_ block can be caught by subsequent
+// _catch_ handlers.
+try {
+ // Do not allocate exceptions on the heap using _new_.
+ throw std::exception("A problem occurred");
+}
+// Catch exceptions by const reference if they are objects
+catch (const std::exception& ex)
+{
+ std::cout << ex.what();
+// Catches any exception not caught by previous _catch_ blocks
+} catch (...)
+{
+ std::cout << "Unknown exception caught";
+ throw; // Re-throws the exception
+}
+
+///////
+// RAII
+///////
+
+// RAII stands for Resource Allocation Is Initialization.
+// It is often considered the most powerful paradigm in C++,
+// and is the simple concept that a constructor for an object
+// acquires that object's resources and the destructor releases them.
+
+// To understand how this is useful,
+// consider a function that uses a C file handle:
+void doSomethingWithAFile(const char* filename)
+{
+ // To begin with, assume nothing can fail.
+
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode.
+
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+
+ fclose(fh); // Close the file handle.
+}
+
+// Unfortunately, things are quickly complicated by error handling.
+// Suppose fopen can fail, and that doSomethingWithTheFile and
+// doSomethingElseWithIt return error codes if they fail.
+// (Exceptions are the preferred way of handling failure,
+// but some programmers, especially those with a C background,
+// disagree on the utility of exceptions).
+// We now have to check each call for failure and close the file handle
+// if a problem occurred.
+bool doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode
+ if (fh == nullptr) // The returned pointer is null on failure.
+ reuturn false; // Report that failure to the caller.
+
+ // Assume each function returns false if it failed
+ if (!doSomethingWithTheFile(fh)) {
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return false; // Propagate the error.
+ }
+ if (!doSomethingElseWithIt(fh)) {
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return false; // Propagate the error.
+ }
+
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return true; // Indicate success
+}
+
+// C programmers often clean this up a little bit using goto:
+bool doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r");
+ if (fh == nullptr)
+ reuturn false;
+
+ if (!doSomethingWithTheFile(fh))
+ goto failure;
+
+ if (!doSomethingElseWithIt(fh))
+ goto failure;
+
+ fclose(fh); // Close the file
+ return true; // Indicate success
+
+failure:
+ fclose(fh);
+ return false; // Propagate the error
+}
+
+// If the functions indicate errors using exceptions,
+// things are a little cleaner, but still sub-optimal.
+void doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode
+ if (fh == nullptr)
+ throw std::exception("Could not open the file.");
+
+ try {
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+ }
+ catch (...) {
+ fclose(fh); // Be sure to close the file if an error occurs.
+ throw; // Then re-throw the exception.
+ }
+
+ fclose(fh); // Close the file
+ // Everything succeeded
+}
+
+// Compare this to the use of C++'s file stream class (fstream)
+// fstream uses its destructor to close the file.
+// Recall from above that destructors are automatically called
+// whenver an object falls out of scope.
+void doSomethingWithAFile(const std::string& filename)
+{
+ // ifstream is short for input file stream
+ std::ifstream fh(filename); // Open the file
+
+ // Do things with the file
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+
+} // The file is automatically closed here by the destructor
+
+// This has _massive_ advantages:
+// 1. No matter what happens,
+// the resource (in this case the file handle) will be cleaned up.
+// Once you write the destructor correctly,
+// It is _impossible_ to forget to close the handle and leak the resource.
+// 2. Note that the code is much cleaner.
+// The destructor handles closing the file behind the scenes
+// without you having to worry about it.
+// 3. The code is exception safe.
+// An exception can be thrown anywhere in the function and cleanup
+// will still occur.
+
+// All idiomatic C++ code uses RAII extensively for all resources.
+// Additional examples include
+// - Memory using unique_ptr and shared_ptr
+// - Containers - the standard library linked list,
+// vector (i.e. self-resizing array), hash maps, and so on
+// all automatically destroy their contents when they fall out of scope.
+// - Mutexes using lock_guard and unique_lock
+```
+Futher Reading:
+
+An up-to-date language reference can be found at
+<http://cppreference.com/w/cpp>
+
+Additional resources may be found at <http://cplusplus.com>
diff --git a/c.html.markdown b/c.html.markdown
index 0190125b..6daabe94 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -4,6 +4,8 @@ filename: learnc.c
contributors:
- ["Adam Bard", "http://adambard.com/"]
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
+ - ["Jakub Trzebiatowski", "http://cbs.stgn.pl"]
+ - ["Marco Scannadinari", "https://marcoms.github.io"]
---
@@ -16,16 +18,20 @@ memory management and C will take you as far as you need to go.
```c
// Single-line comments start with // - only available in C99 and later.
-/*
+ /*
Multi-line comments look like this. They work in C89 as well.
-*/
+ */
+
+/*
+Multi-line comments don't nest /* Be careful */ // comment ends on this line...
+*/ // ...not this one!
-// Constants: #define <keyword>
+ // Constants: #define <keyword>
#define DAYS_IN_YEAR 365
-//enumeration constants are also ways to declare constants.
-enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
-// MON gets 2 automatically, TUE gets 3, etc.
+ // Enumeration constants are also ways to declare constants.
+ enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
+// MON gets 2 automatically, TUE gets 3, etc.
// Import headers with #include
#include <stdlib.h>
@@ -34,388 +40,391 @@ enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
// (File names between <angle brackets> are headers from the C standard library.)
// For your own headers, use double quotes instead of angle brackets:
-#include "my_header.h"
+//#include "my_header.h"
// Declare function signatures in advance in a .h file, or at the top of
// your .c file.
-void function_1(char c);
+void function_1();
int function_2(void);
// Must declare a 'function prototype' before main() when functions occur after
// your main() function.
-int add_two_ints(int x1, int x2); // function prototype
+int add_two_ints(int x1, int x2); // function prototype
// Your program's entry point is a function called
// main with an integer return type.
int main() {
- // print output using printf, for "print formatted"
- // %d is an integer, \n is a newline
- printf("%d\n", 0); // => Prints 0
- // All statements must end with a semicolon
-
- ///////////////////////////////////////
- // Types
- ///////////////////////////////////////
-
- // ints are usually 4 bytes
- int x_int = 0;
-
- // shorts are usually 2 bytes
- short x_short = 0;
-
- // chars are guaranteed to be 1 byte
- char x_char = 0;
- char y_char = 'y'; // Char literals are quoted with ''
-
- // longs are often 4 to 8 bytes; long longs are guaranteed to be at least
- // 64 bits
- long x_long = 0;
- long long x_long_long = 0;
-
- // floats are usually 32-bit floating point numbers
- float x_float = 0.0;
-
- // doubles are usually 64-bit floating-point numbers
- double x_double = 0.0;
-
- // Integral types may be unsigned.
- unsigned short ux_short;
- unsigned int ux_int;
- unsigned long long ux_long_long;
-
- // chars inside single quotes are integers in machine's character set.
- '0' // => 48 in the ASCII character set.
- 'A' // => 65 in the ASCII character set.
-
- // sizeof(T) gives you the size of a variable with type T in bytes
- // sizeof(obj) yields the size of the expression (variable, literal, etc.).
- printf("%zu\n", sizeof(int)); // => 4 (on most machines with 4-byte words)
-
-
- // If the argument of the `sizeof` operator is an expression, then its argument
- // is not evaluated (except VLAs (see below)).
- // The value it yields in this case is a compile-time constant.
- int a = 1;
- // size_t is an unsiged integer type of at least 2 bytes used to represent
- // the size of an object.
- size_t size = sizeof(a++); // a++ is not evaluated
- printf("sizeof(a++) = %zu where a = %d\n", size, a);
- // prints "sizeof(a++) = 4 where a = 1" (on a 32-bit architecture)
-
- // Arrays must be initialized with a concrete size.
- char my_char_array[20]; // This array occupies 1 * 20 = 20 bytes
- int my_int_array[20]; // This array occupies 4 * 20 = 80 bytes
- // (assuming 4-byte words)
-
-
- // You can initialize an array to 0 thusly:
- char my_array[20] = {0};
-
- // Indexing an array is like other languages -- or,
- // rather, other languages are like C
- my_array[0]; // => 0
-
- // Arrays are mutable; it's just memory!
- my_array[1] = 2;
- printf("%d\n", my_array[1]); // => 2
-
- // In C99 (and as an optional feature in C11), variable-length arrays (VLAs)
- // can be declared as well. The size of such an array need not be a compile
- // time constant:
- printf("Enter the array size: "); // ask the user for an array size
- char buf[0x100];
- fgets(buf, sizeof buf, stdin);
-
- // strtoul parses a string to an unsigned integer
- size_t size = strtoul(buf, NULL, 10);
- int var_length_array[size]; // declare the VLA
- printf("sizeof array = %zu\n", sizeof var_length_array);
-
- // A possible outcome of this program may be:
- // > Enter the array size: 10
- // > sizeof array = 40
-
- // Strings are just arrays of chars terminated by a NUL (0x00) byte,
- // represented in strings as the special character '\0'.
- // (We don't have to include the NUL byte in string literals; the compiler
- // inserts it at the end of the array for us.)
- char a_string[20] = "This is a string";
- printf("%s\n", a_string); // %s formats a string
-
- printf("%d\n", a_string[16]); // => 0
- // i.e., byte #17 is 0 (as are 18, 19, and 20)
-
- // If we have characters between single quotes, that's a character literal.
- // It's of type `int`, and *not* `char` (for historical reasons).
- int cha = 'a'; // fine
- char chb = 'a'; // fine too (implicit conversion from int to char)
-
- //Multi-dimensional arrays:
- int multi_array[2][5] = {
- {1, 2, 3, 4, 5},
- {6, 7, 8, 9, 0}
- }
- //access elements:
- int array_int = multi_array[0][2]; // => 3
-
- ///////////////////////////////////////
- // Operators
- ///////////////////////////////////////
-
- // Shorthands for multiple declarations:
- int i1 = 1, i2 = 2;
- float f1 = 1.0, f2 = 2.0;
-
- int a, b, c;
- a = b = c = 0;
-
- // Arithmetic is straightforward
- i1 + i2; // => 3
- i2 - i1; // => 1
- i2 * i1; // => 2
- i1 / i2; // => 0 (0.5, but truncated towards 0)
-
- f1 / f2; // => 0.5, plus or minus epsilon
- // Floating-point numbers and calculations are not exact
-
- // Modulo is there as well
- 11 % 3; // => 2
-
- // Comparison operators are probably familiar, but
- // there is no boolean type in c. We use ints instead.
- // (Or _Bool or bool in C99.)
- // 0 is false, anything else is true. (The comparison
- // operators always yield 0 or 1.)
- 3 == 2; // => 0 (false)
- 3 != 2; // => 1 (true)
- 3 > 2; // => 1
- 3 < 2; // => 0
- 2 <= 2; // => 1
- 2 >= 2; // => 1
-
- // C is not Python - comparisons don't chain.
- int a = 1;
- // WRONG:
- int between_0_and_2 = 0 < a < 2;
- // Correct:
- int between_0_and_2 = 0 < a && a < 2;
-
- // Logic works on ints
- !3; // => 0 (Logical not)
- !0; // => 1
- 1 && 1; // => 1 (Logical and)
- 0 && 1; // => 0
- 0 || 1; // => 1 (Logical or)
- 0 || 0; // => 0
-
- //Conditional expression ( ? : )
- int a = 5;
- int b = 10;
- int z;
- z = (a > b) ? a : b; // => 10 "if a > b return a, else return b."
-
- //Increment and decrement operators:
- char *s = "iLoveC"
- int j = 0;
- s[j++]; // => "i". Returns the j-th item of s THEN increments value of j.
- j = 0;
- s[++j]; // => "L". Increments value of j THEN returns j-th value of s.
- // same with j-- and --j
-
- // Bitwise operators!
- ~0x0F; // => 0xF0 (bitwise negation, "1's complement")
- 0x0F & 0xF0; // => 0x00 (bitwise AND)
- 0x0F | 0xF0; // => 0xFF (bitwise OR)
- 0x04 ^ 0x0F; // => 0x0B (bitwise XOR)
- 0x01 << 1; // => 0x02 (bitwise left shift (by 1))
- 0x02 >> 1; // => 0x01 (bitwise right shift (by 1))
-
- // Be careful when shifting signed integers - the following are undefined:
- // - shifting into the sign bit of a signed integer (int a = 1 << 32)
- // - left-shifting a negative number (int a = -1 << 2)
- // - shifting by an offset which is >= the width of the type of the LHS:
- // int a = 1 << 32; // UB if int is 32 bits wide
-
- ///////////////////////////////////////
- // Control Structures
- ///////////////////////////////////////
-
- if (0) {
- printf("I am never run\n");
- } else if (0) {
- printf("I am also never run\n");
- } else {
- printf("I print\n");
- }
-
- // While loops exist
- int ii = 0;
- while (ii < 10) { //ANY value not zero is true.
- printf("%d, ", ii++); // ii++ increments ii AFTER using it's current value.
- } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
-
- printf("\n");
-
- int kk = 0;
- do {
- printf("%d, ", kk);
- } while (++kk < 10); // ++kk increments kk BEFORE using it's current value.
- // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
-
- printf("\n");
-
- // For loops too
- int jj;
- for (jj=0; jj < 10; jj++) {
- printf("%d, ", jj);
- } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
-
- printf("\n");
-
- // *****NOTES*****:
- // Loops and Functions MUST have a body. If no body is needed:
- int i;
- for (i = 0; i <= 5; i++) {
- ; // use semicolon to act as the body (null statement)
- }
-
- // branching with multiple choices: switch()
- switch (some_integral_expression) {
- case 0: // labels need to be integral *constant* epxressions
- do_stuff();
- break; // if you don't break, control flow falls over labels
- case 1:
- do_something_else();
- break;
- default:
- // if `some_integral_expression` didn't match any of the labels
- fputs("error!\n", stderr);
- exit(-1);
- break;
- }
-
-
- ///////////////////////////////////////
- // Typecasting
- ///////////////////////////////////////
-
- // Every value in C has a type, but you can cast one value into another type
- // if you want (with some constraints).
-
- int x_hex = 0x01; // You can assign vars with hex literals
-
- // Casting between types will attempt to preserve their numeric values
- printf("%d\n", x_hex); // => Prints 1
- printf("%d\n", (short) x_hex); // => Prints 1
- printf("%d\n", (char) x_hex); // => Prints 1
-
- // Types will overflow without warning
- printf("%d\n", (unsigned char) 257); // => 1 (Max char = 255 if char is 8 bits long)
-
- // For determining the max value of a `char`, a `signed char` and an `unisigned char`,
- // respectively, use the CHAR_MAX, SCHAR_MAX and UCHAR_MAX macros from <limits.h>
-
- // Integral types can be cast to floating-point types, and vice-versa.
- printf("%f\n", (float)100); // %f formats a float
- printf("%lf\n", (double)100); // %lf formats a double
- printf("%d\n", (char)100.0);
-
- ///////////////////////////////////////
- // Pointers
- ///////////////////////////////////////
-
- // A pointer is a variable declared to store a memory address. Its declaration will
- // also tell you the type of data it points to. You can retrieve the memory address
- // of your variables, then mess with them.
-
- int x = 0;
- printf("%p\n", (void *)&x); // Use & to retrieve the address of a variable
- // (%p formats an object pointer of type void *)
- // => Prints some address in memory;
-
-
- // Pointers start with * in their declaration
- int *px, not_a_pointer; // px is a pointer to an int
- px = &x; // Stores the address of x in px
- printf("%p\n", (void *)px); // => Prints some address in memory
- printf("%zu, %zu\n", sizeof(px), sizeof(not_a_pointer));
- // => Prints "8, 4" on a typical 64-bit system
-
- // To retrieve the value at the address a pointer is pointing to,
- // put * in front to de-reference it.
- // Note: yes, it may be confusing that '*' is used for _both_ declaring a
- // pointer and dereferencing it.
- printf("%d\n", *px); // => Prints 0, the value of x
-
- // You can also change the value the pointer is pointing to.
- // We'll have to wrap the de-reference in parenthesis because
- // ++ has a higher precedence than *.
- (*px)++; // Increment the value px is pointing to by 1
- printf("%d\n", *px); // => Prints 1
- printf("%d\n", x); // => Prints 1
-
- // Arrays are a good way to allocate a contiguous block of memory
- int x_array[20]; //declares array of size 20 (cannot change size)
- int xx;
- for (xx = 0; xx < 20; xx++) {
- x_array[xx] = 20 - xx;
- } // Initialize x_array to 20, 19, 18,... 2, 1
+ // print output using printf, for "print formatted"
+ // %d is an integer, \n is a newline
+ printf("%d\n", 0); // => Prints 0
+ // All statements must end with a semicolon
+
+ ///////////////////////////////////////
+ // Types
+ ///////////////////////////////////////
+
+ // ints are usually 4 bytes
+ int x_int = 0;
+
+ // shorts are usually 2 bytes
+ short x_short = 0;
+
+ // chars are guaranteed to be 1 byte
+ char x_char = 0;
+ char y_char = 'y'; // Char literals are quoted with ''
+
+ // longs are often 4 to 8 bytes; long longs are guaranteed to be at least
+ // 64 bits
+ long x_long = 0;
+ long long x_long_long = 0;
+
+ // floats are usually 32-bit floating point numbers
+ float x_float = 0.0f; // 'f' suffix here denotes floating point literal
+
+ // doubles are usually 64-bit floating-point numbers
+ double x_double = 0.0; // real numbers without any suffix are doubles
+
+ // Integral types may be unsigned.
+ unsigned short ux_short;
+ unsigned int ux_int;
+ unsigned long long ux_long_long;
+
+ // chars inside single quotes are integers in machine's character set.
+ '0'; // => 48 in the ASCII character set.
+ 'A'; // => 65 in the ASCII character set.
+
+ // sizeof(T) gives you the size of a variable with type T in bytes
+ // sizeof(obj) yields the size of the expression (variable, literal, etc.).
+ printf("%zu\n", sizeof(int)); // => 4 (on most machines with 4-byte words)
+
+
+ // If the argument of the `sizeof` operator is an expression, then its argument
+ // is not evaluated (except VLAs (see below)).
+ // The value it yields in this case is a compile-time constant.
+ int a = 1;
+ // size_t is an unsigned integer type of at least 2 bytes used to represent
+ // the size of an object.
+ size_t size = sizeof(a++); // a++ is not evaluated
+ printf("sizeof(a++) = %zu where a = %d\n", size, a);
+ // prints "sizeof(a++) = 4 where a = 1" (on a 32-bit architecture)
+
+ // Arrays must be initialized with a concrete size.
+ char my_char_array[20]; // This array occupies 1 * 20 = 20 bytes
+ int my_int_array[20]; // This array occupies 4 * 20 = 80 bytes
+ // (assuming 4-byte words)
+
+
+ // You can initialize an array to 0 thusly:
+ char my_array[20] = {0};
+
+ // Indexing an array is like other languages -- or,
+ // rather, other languages are like C
+ my_array[0]; // => 0
+
+ // Arrays are mutable; it's just memory!
+ my_array[1] = 2;
+ printf("%d\n", my_array[1]); // => 2
+
+ // In C99 (and as an optional feature in C11), variable-length arrays (VLAs)
+ // can be declared as well. The size of such an array need not be a compile
+ // time constant:
+ printf("Enter the array size: "); // ask the user for an array size
+ char buf[0x100];
+ fgets(buf, sizeof buf, stdin);
+
+ // strtoul parses a string to an unsigned integer
+ size_t size2 = strtoul(buf, NULL, 10);
+ int var_length_array[size2]; // declare the VLA
+ printf("sizeof array = %zu\n", sizeof var_length_array);
+
+ // A possible outcome of this program may be:
+ // > Enter the array size: 10
+ // > sizeof array = 40
+
+ // Strings are just arrays of chars terminated by a NULL (0x00) byte,
+ // represented in strings as the special character '\0'.
+ // (We don't have to include the NULL byte in string literals; the compiler
+ // inserts it at the end of the array for us.)
+ char a_string[20] = "This is a string";
+ printf("%s\n", a_string); // %s formats a string
+
+ printf("%d\n", a_string[16]); // => 0
+ // i.e., byte #17 is 0 (as are 18, 19, and 20)
+
+ // If we have characters between single quotes, that's a character literal.
+ // It's of type `int`, and *not* `char` (for historical reasons).
+ int cha = 'a'; // fine
+ char chb = 'a'; // fine too (implicit conversion from int to char)
+
+ //Multi-dimensional arrays:
+ int multi_array[2][5] = {
+ {1, 2, 3, 4, 5},
+ {6, 7, 8, 9, 0}
+ };
+ //access elements:
+ int array_int = multi_array[0][2]; // => 3
+
+ ///////////////////////////////////////
+ // Operators
+ ///////////////////////////////////////
+
+ // Shorthands for multiple declarations:
+ int i1 = 1, i2 = 2;
+ float f1 = 1.0, f2 = 2.0;
+
+ int b, c;
+ b = c = 0;
+
+ // Arithmetic is straightforward
+ i1 + i2; // => 3
+ i2 - i1; // => 1
+ i2 * i1; // => 2
+ i1 / i2; // => 0 (0.5, but truncated towards 0)
+
+ // You need to cast at least one integer to float to get a floating-point result
+ (float)i1 / i2 // => 0.5f
+ i1 / (double)i2 // => 0.5 // Same with double
+ f1 / f2; // => 0.5, plus or minus epsilon
+ // Floating-point numbers and calculations are not exact
+
+ // Modulo is there as well
+ 11 % 3; // => 2
+
+ // Comparison operators are probably familiar, but
+ // there is no Boolean type in c. We use ints instead.
+ // (Or _Bool or bool in C99.)
+ // 0 is false, anything else is true. (The comparison
+ // operators always yield 0 or 1.)
+ 3 == 2; // => 0 (false)
+ 3 != 2; // => 1 (true)
+ 3 > 2; // => 1
+ 3 < 2; // => 0
+ 2 <= 2; // => 1
+ 2 >= 2; // => 1
+
+ // C is not Python - comparisons don't chain.
+ // Warning: The line below will compile, but it means `(0 < a) < 2`.
+ // This expression is always true, because (0 < a) could be either 1 or 0.
+ // In this case it's 1, because (0 < 1).
+ int between_0_and_2 = 0 < a < 2;
+ // Instead use:
+ int between_0_and_2 = 0 < a && a < 2;
+
+ // Logic works on ints
+ !3; // => 0 (Logical not)
+ !0; // => 1
+ 1 && 1; // => 1 (Logical and)
+ 0 && 1; // => 0
+ 0 || 1; // => 1 (Logical or)
+ 0 || 0; // => 0
+
+ //Conditional expression ( ? : )
+ int e = 5;
+ int f = 10;
+ int z;
+ z = (e > f) ? e : f; // => 10 "if e > f return e, else return f."
+
+ //Increment and decrement operators:
+ char *s = "iLoveC";
+ int j = 0;
+ s[j++]; // => "i". Returns the j-th item of s THEN increments value of j.
+ j = 0;
+ s[++j]; // => "L". Increments value of j THEN returns j-th value of s.
+ // same with j-- and --j
+
+ // Bitwise operators!
+ ~0x0F; // => 0xF0 (bitwise negation, "1's complement")
+ 0x0F & 0xF0; // => 0x00 (bitwise AND)
+ 0x0F | 0xF0; // => 0xFF (bitwise OR)
+ 0x04 ^ 0x0F; // => 0x0B (bitwise XOR)
+ 0x01 << 1; // => 0x02 (bitwise left shift (by 1))
+ 0x02 >> 1; // => 0x01 (bitwise right shift (by 1))
+
+ // Be careful when shifting signed integers - the following are undefined:
+ // - shifting into the sign bit of a signed integer (int a = 1 << 32)
+ // - left-shifting a negative number (int a = -1 << 2)
+ // - shifting by an offset which is >= the width of the type of the LHS:
+ // int a = 1 << 32; // UB if int is 32 bits wide
+
+ ///////////////////////////////////////
+ // Control Structures
+ ///////////////////////////////////////
+
+ if (0) {
+ printf("I am never run\n");
+ } else if (0) {
+ printf("I am also never run\n");
+ } else {
+ printf("I print\n");
+ }
+
+ // While loops exist
+ int ii = 0;
+ while (ii < 10) { //ANY value not zero is true.
+ printf("%d, ", ii++); // ii++ increments ii AFTER using its current value.
+ } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ int kk = 0;
+ do {
+ printf("%d, ", kk);
+ } while (++kk < 10); // ++kk increments kk BEFORE using its current value.
+ // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ // For loops too
+ int jj;
+ for (jj=0; jj < 10; jj++) {
+ printf("%d, ", jj);
+ } // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ // *****NOTES*****:
+ // Loops and Functions MUST have a body. If no body is needed:
+ int i;
+ for (i = 0; i <= 5; i++) {
+ ; // use semicolon to act as the body (null statement)
+ }
+
+ // branching with multiple choices: switch()
+ switch (a) {
+ case 0: // labels need to be integral *constant* expressions
+ printf("Hey, 'a' equals 0!\n");
+ break; // if you don't break, control flow falls over labels
+ case 1:
+ printf("Huh, 'a' equals 1!\n");
+ break;
+ default:
+ // if `some_integral_expression` didn't match any of the labels
+ fputs("error!\n", stderr);
+ exit(-1);
+ break;
+ }
+
+ ///////////////////////////////////////
+ // Typecasting
+ ///////////////////////////////////////
+
+ // Every value in C has a type, but you can cast one value into another type
+ // if you want (with some constraints).
+
+ int x_hex = 0x01; // You can assign vars with hex literals
+
+ // Casting between types will attempt to preserve their numeric values
+ printf("%d\n", x_hex); // => Prints 1
+ printf("%d\n", (short) x_hex); // => Prints 1
+ printf("%d\n", (char) x_hex); // => Prints 1
+
+ // Types will overflow without warning
+ printf("%d\n", (unsigned char) 257); // => 1 (Max char = 255 if char is 8 bits long)
+
+ // For determining the max value of a `char`, a `signed char` and an `unsigned char`,
+ // respectively, use the CHAR_MAX, SCHAR_MAX and UCHAR_MAX macros from <limits.h>
+
+ // Integral types can be cast to floating-point types, and vice-versa.
+ printf("%f\n", (float)100); // %f formats a float
+ printf("%lf\n", (double)100); // %lf formats a double
+ printf("%d\n", (char)100.0);
+
+ ///////////////////////////////////////
+ // Pointers
+ ///////////////////////////////////////
+
+ // A pointer is a variable declared to store a memory address. Its declaration will
+ // also tell you the type of data it points to. You can retrieve the memory address
+ // of your variables, then mess with them.
+
+ int x = 0;
+ printf("%p\n", (void *)&x); // Use & to retrieve the address of a variable
+ // (%p formats an object pointer of type void *)
+ // => Prints some address in memory;
+
+
+ // Pointers start with * in their declaration
+ int *px, not_a_pointer; // px is a pointer to an int
+ px = &x; // Stores the address of x in px
+ printf("%p\n", (void *)px); // => Prints some address in memory
+ printf("%zu, %zu\n", sizeof(px), sizeof(not_a_pointer));
+ // => Prints "8, 4" on a typical 64-bit system
+
+ // To retrieve the value at the address a pointer is pointing to,
+ // put * in front to dereference it.
+ // Note: yes, it may be confusing that '*' is used for _both_ declaring a
+ // pointer and dereferencing it.
+ printf("%d\n", *px); // => Prints 0, the value of x
+
+ // You can also change the value the pointer is pointing to.
+ // We'll have to wrap the dereference in parenthesis because
+ // ++ has a higher precedence than *.
+ (*px)++; // Increment the value px is pointing to by 1
+ printf("%d\n", *px); // => Prints 1
+ printf("%d\n", x); // => Prints 1
+
+ // Arrays are a good way to allocate a contiguous block of memory
+ int x_array[20]; //declares array of size 20 (cannot change size)
+ int xx;
+ for (xx = 0; xx < 20; xx++) {
+ x_array[xx] = 20 - xx;
+ } // Initialize x_array to 20, 19, 18,... 2, 1
// Declare a pointer of type int and initialize it to point to x_array
- int* x_ptr = x_array;
- // x_ptr now points to the first element in the array (the integer 20).
- // This works because arrays often decay into pointers to their first element.
- // For example, when an array is passed to a function or is assigned to a pointer,
- // it decays into (implicitly converted to) a pointer.
- // Exceptions: when the array is the argument of the `&` (address-od) operator:
- int arr[10];
- int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`!
- // It's of type "pointer to array" (of ten `int`s).
- // or when the array is a string literal used for initializing a char array:
- char arr[] = "foobarbazquirk";
- // or when it's the argument of the `sizeof` or `alignof` operator:
- int arr[10];
- int *ptr = arr; // equivalent with int *ptr = &arr[0];
- printf("%zu, %zu\n", sizeof arr, sizeof ptr); // probably prints "40, 4" or "40, 8"
-
-
- // Pointers are incremented and decremented based on their type
- // (this is called pointer arithmetic)
- printf("%d\n", *(x_ptr + 1)); // => Prints 19
- printf("%d\n", x_array[1]); // => Prints 19
-
- // You can also dynamically allocate contiguous blocks of memory with the
- // standard library function malloc, which takes one argument of type size_t
- // representing the number of bytes to allocate (usually from the heap, although this
- // may not be true on e. g. embedded systems - the C standard says nothing about it).
- int *my_ptr = malloc(sizeof(*my_ptr) * 20);
- for (xx = 0; xx < 20; xx++) {
- *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx
- } // Initialize memory to 20, 19, 18, 17... 2, 1 (as ints)
+ int* x_ptr = x_array;
+ // x_ptr now points to the first element in the array (the integer 20).
+ // This works because arrays often decay into pointers to their first element.
+ // For example, when an array is passed to a function or is assigned to a pointer,
+ // it decays into (implicitly converted to) a pointer.
+ // Exceptions: when the array is the argument of the `&` (address-of) operator:
+ int arr[10];
+ int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`!
+ // It's of type "pointer to array" (of ten `int`s).
+ // or when the array is a string literal used for initializing a char array:
+ char otherarr[] = "foobarbazquirk";
+ // or when it's the argument of the `sizeof` or `alignof` operator:
+ int arraythethird[10];
+ int *ptr = arraythethird; // equivalent with int *ptr = &arr[0];
+ printf("%zu, %zu\n", sizeof arraythethird, sizeof ptr); // probably prints "40, 4" or "40, 8"
+
+
+ // Pointers are incremented and decremented based on their type
+ // (this is called pointer arithmetic)
+ printf("%d\n", *(x_ptr + 1)); // => Prints 19
+ printf("%d\n", x_array[1]); // => Prints 19
+
+ // You can also dynamically allocate contiguous blocks of memory with the
+ // standard library function malloc, which takes one argument of type size_t
+ // representing the number of bytes to allocate (usually from the heap, although this
+ // may not be true on e.g. embedded systems - the C standard says nothing about it).
+ int *my_ptr = malloc(sizeof(*my_ptr) * 20);
+ for (xx = 0; xx < 20; xx++) {
+ *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx
+ } // Initialize memory to 20, 19, 18, 17... 2, 1 (as ints)
// Dereferencing memory that you haven't allocated gives
// "unpredictable results" - the program is said to invoke "undefined behavior"
- printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what? It may even crash.
-
- // When you're done with a malloc'd block of memory, you need to free it,
- // or else no one else can use it until your program terminates
- // (this is called a "memory leak"):
- free(my_ptr);
-
- // Strings are arrays of char, but they are usually represented as a
- // pointer-to-char (which is a pointer to the first element of the array).
- // It's good practice to use `const char *' when referring to a string literal,
- // since string literals shall not be modified (i. e. "foo"[0] = 'a' is ILLEGAL.)
- const char *my_str = "This is my very own string literal";
- printf("%c\n", *my_str); // => 'T'
-
- // This is not the case if the string is an array
- // (potentially initialized with a string literal)
- // that resides in writable memory, as in:
- char foo[] = "foo";
- foo[0] = 'a'; // this is legal, foo now contains "aoo"
-
- function_1();
+ printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what? It may even crash.
+
+ // When you're done with a malloc'd block of memory, you need to free it,
+ // or else no one else can use it until your program terminates
+ // (this is called a "memory leak"):
+ free(my_ptr);
+
+ // Strings are arrays of char, but they are usually represented as a
+ // pointer-to-char (which is a pointer to the first element of the array).
+ // It's good practice to use `const char *' when referring to a string literal,
+ // since string literals shall not be modified (i.e. "foo"[0] = 'a' is ILLEGAL.)
+ const char *my_str = "This is my very own string literal";
+ printf("%c\n", *my_str); // => 'T'
+
+ // This is not the case if the string is an array
+ // (potentially initialized with a string literal)
+ // that resides in writable memory, as in:
+ char foo[] = "foo";
+ foo[0] = 'a'; // this is legal, foo now contains "aoo"
+
+ function_1();
} // end main function
///////////////////////////////////////
@@ -427,16 +436,16 @@ int main() {
int add_two_ints(int x1, int x2)
{
- return x1 + x2; // Use return to return a value
+ return x1 + x2; // Use return to return a value
}
/*
-Functions are call by value. When a function is called, the arguments passed to
-the function are copies of the original arguments (except arrays). Anything you
-do to the arguments in the function do not change the value of the original
-argument where the function was called.
+Functions are call by value. When a function is called, the arguments passed to
+≈the function are copies of the original arguments (except arrays). Anything you
+do to the arguments in the function do not change the value of the original
+argument where the function was called.
-Use pointers if you need to edit the original argument values.
+Use pointers if you need to edit the original argument values.
Example: in-place string reversal
*/
@@ -444,14 +453,14 @@ Example: in-place string reversal
// A void function returns no value
void str_reverse(char *str_in)
{
- char tmp;
- int ii = 0;
- size_t len = strlen(str_in); // `strlen()` is part of the c standard library
- for (ii = 0; ii < len / 2; ii++) {
- tmp = str_in[ii];
- str_in[ii] = str_in[len - ii - 1]; // ii-th char from end
- str_in[len - ii - 1] = tmp;
- }
+ char tmp;
+ int ii = 0;
+ size_t len = strlen(str_in); // `strlen()` is part of the c standard library
+ for (ii = 0; ii < len / 2; ii++) {
+ tmp = str_in[ii];
+ str_in[ii] = str_in[len - ii - 1]; // ii-th char from end
+ str_in[len - ii - 1] = tmp;
+ }
}
/*
@@ -463,13 +472,13 @@ printf("%s\n", c); // => ".tset a si sihT"
//if referring to external variables outside function, must use extern keyword.
int i = 0;
void testFunc() {
- extern int i; //i here is now using external variable i
+ extern int i; //i here is now using external variable i
}
//make external variables private to source file with static:
-static int i = 0; //other files using testFunc() cannot access variable i
-void testFunc() {
- extern int i;
+static int j = 0; //other files using testFunc() cannot access variable i
+void testFunc2() {
+ extern int j;
}
//**You may also declare functions as static to make them private**
@@ -486,8 +495,8 @@ my_type my_type_var = 0;
// Structs are just collections of data, the members are allocated sequentially,
// in the order they are written:
struct rectangle {
- int width;
- int height;
+ int width;
+ int height;
};
// It's not generally true that
@@ -497,20 +506,20 @@ struct rectangle {
void function_1()
{
- struct rectangle my_rec;
+ struct rectangle my_rec;
- // Access struct members with .
- my_rec.width = 10;
- my_rec.height = 20;
+ // Access struct members with .
+ my_rec.width = 10;
+ my_rec.height = 20;
- // You can declare pointers to structs
- struct rectangle *my_rec_ptr = &my_rec;
+ // You can declare pointers to structs
+ struct rectangle *my_rec_ptr = &my_rec;
- // Use dereferencing to set struct pointer members...
- (*my_rec_ptr).width = 30;
+ // Use dereferencing to set struct pointer members...
+ (*my_rec_ptr).width = 30;
- // ... or even better: prefer the -> shorthand for the sake of readability
- my_rec_ptr->height = 10; // Same as (*my_rec_ptr).height = 10;
+ // ... or even better: prefer the -> shorthand for the sake of readability
+ my_rec_ptr->height = 10; // Same as (*my_rec_ptr).height = 10;
}
// You can apply a typedef to a struct for convenience
@@ -518,34 +527,34 @@ typedef struct rectangle rect;
int area(rect r)
{
- return r.width * r.height;
+ return r.width * r.height;
}
// if you have large structs, you can pass them "by pointer" to avoid copying
// the whole struct:
-int area(const rect *r)
+int areaptr(const rect *r)
{
- return r->width * r->height;
+ return r->width * r->height;
}
///////////////////////////////////////
-// Function pointers
+// Function pointers
///////////////////////////////////////
/*
-At runtime, functions are located at known memory addresses. Function pointers are
-much like any other pointer (they just store a memory address), but can be used
+At run time, functions are located at known memory addresses. Function pointers are
+much like any other pointer (they just store a memory address), but can be used
to invoke functions directly, and to pass handlers (or callback functions) around.
However, definition syntax may be initially confusing.
Example: use str_reverse from a pointer
*/
void str_reverse_through_pointer(char *str_in) {
- // Define a function pointer variable, named f.
- void (*f)(char *); // Signature should exactly match the target function.
- f = &str_reverse; // Assign the address for the actual function (determined at runtime)
- // f = str_reverse; would work as well - functions decay into pointers, similar to arrays
- (*f)(str_in); // Just calling the function through the pointer
- // f(str_in); // That's an alternative but equally valid syntax for calling it.
+ // Define a function pointer variable, named f.
+ void (*f)(char *); // Signature should exactly match the target function.
+ f = &str_reverse; // Assign the address for the actual function (determined at run time)
+ // f = str_reverse; would work as well - functions decay into pointers, similar to arrays
+ (*f)(str_in); // Just calling the function through the pointer
+ // f(str_in); // That's an alternative but equally valid syntax for calling it.
}
/*
@@ -557,39 +566,40 @@ typedef void (*my_fnp_type)(char *);
// Then used when declaring the actual pointer variable:
// ...
-// my_fnp_type f;
+// my_fnp_type f;
//Special characters:
-'\a' // alert (bell) character
-'\n' // newline character
-'\t' // tab character (left justifies text)
-'\v' // vertical tab
-'\f' // new page (formfeed)
-'\r' // carriage return
-'\b' // backspace character
-'\0' // null character. Usually put at end of strings in C lang.
- // hello\n\0. \0 used by convention to mark end of string.
-'\\' // backslash
-'\?' // question mark
-'\'' // single quote
-'\"' // double quote
-'\xhh' // hexadecimal number. Example: '\xb' = vertical tab character
-'\ooo' // octal number. Example: '\013' = vertical tab character
+/*
+'\a'; // alert (bell) character
+'\n'; // newline character
+'\t'; // tab character (left justifies text)
+'\v'; // vertical tab
+'\f'; // new page (form feed)
+'\r'; // carriage return
+'\b'; // backspace character
+'\0'; // NULL character. Usually put at end of strings in C.
+// hello\n\0. \0 used by convention to mark end of string.
+'\\'; // backslash
+'\?'; // question mark
+'\''; // single quote
+'\"'; // double quote
+'\xhh'; // hexadecimal number. Example: '\xb' = vertical tab character
+'\0oo'; // octal number. Example: '\013' = vertical tab character
//print formatting:
-"%d" // integer
-"%3d" // integer with minimum of length 3 digits (right justifies text)
-"%s" // string
-"%f" // float
-"%ld" // long
-"%3.2f" // minimum 3 digits left and 2 digits right decimal float
-"%7.4s" // (can do with strings too)
-"%c" // char
-"%p" // pointer
-"%x" // hexidecimal
-"%o" // octal
-"%%" // prints %
-
+"%d"; // integer
+"%3d"; // integer with minimum of length 3 digits (right justifies text)
+"%s"; // string
+"%f"; // float
+"%ld"; // long
+"%3.2f"; // minimum 3 digits left and 2 digits right decimal float
+"%7.4s"; // (can do with strings too)
+"%c"; // char
+"%p"; // pointer
+"%x"; // hexadecimal
+"%o"; // octal
+"%%"; // prints %
+*/
///////////////////////////////////////
// Order of Evaluation
///////////////////////////////////////
@@ -628,7 +638,7 @@ If you have a question, read the [compl.lang.c Frequently Asked Questions](http:
It's very important to use proper spacing, indentation and to be consistent with your coding style in general.
Readable code is better than clever code and fast code. For a good, sane coding style to adopt, see the
-[Linux kernel coding stlye](https://www.kernel.org/doc/Documentation/CodingStyle).
+[Linux kernel coding style](https://www.kernel.org/doc/Documentation/CodingStyle).
Other than that, Google is your friend.
diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown
index 4fdf5903..4c080bc6 100644
--- a/coffeescript.html.markdown
+++ b/coffeescript.html.markdown
@@ -11,7 +11,7 @@ As one of the succeeders of JavaScript, CoffeeScript tries its best to output re
See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript.
-``` coffeescript
+```coffeescript
# CoffeeScript is a hipster language.
# It goes with the trends of many modern languages.
# So comments are like Ruby and Python, they use number symbols.
@@ -20,7 +20,7 @@ See also [the CoffeeScript website](http://coffeescript.org/), which has a compl
Block comments are like these, and they translate directly to '/ *'s and '* /'s
for the resulting JavaScript code.
-You should understand most of JavaScript semantices
+You should understand most of JavaScript semantics
before continuing.
###
@@ -95,3 +95,8 @@ eat food for food in foods when food isnt 'chocolate'
# }
#}
```
+
+## Additional resources
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown
index 8de81549..08134e35 100644
--- a/common-lisp.html.markdown
+++ b/common-lisp.html.markdown
@@ -17,7 +17,7 @@ Another popular and recent book is
-```scheme
+```common_lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 0. Syntax
diff --git a/compojure.html.markdown b/compojure.html.markdown
new file mode 100644
index 00000000..36a8d123
--- /dev/null
+++ b/compojure.html.markdown
@@ -0,0 +1,280 @@
+---
+category: tool
+tool: compojure
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+filename: learncompojure.clj
+---
+
+## Getting Started with Compojure
+
+Compojure is a DSL for *quickly* creating *performant* web applications
+in Clojure with minimal effort:
+
+```clojure
+(ns myapp.core
+ (:require [compojure.core :refer :all]
+ [org.httpkit.server :refer [run-server]])) ; httpkit is a server
+
+(defroutes myapp
+ (GET "/" [] "Hello World"))
+
+(defn -main []
+ (run-server myapp {:port 5000}))
+```
+
+**Step 1:** Create a project with [Leiningen](http://leiningen.org/):
+
+```
+lein new myapp
+```
+
+**Step 2:** Put the above code in `src/myapp/core.clj`
+
+**Step 3:** Add some dependencies to `project.clj`:
+
+```
+[compojure "1.1.8"]
+[http-kit "2.1.16"]
+```
+
+**Step 4:** Run:
+
+```
+lein run -m myapp.core
+```
+
+View at: <http://localhost:5000/>
+
+Compojure apps will run on any ring-compatible server, but we recommend
+[http-kit](http://http-kit.org/) for its performance and
+[massive concurrency](http://http-kit.org/600k-concurrent-connection-http-kit.html).
+
+### Routes
+
+In compojure, each route is an HTTP method paired with a URL-matching pattern,
+an argument list, and a body.
+
+```clojure
+(defroutes myapp
+ (GET "/" [] "Show something")
+ (POST "/" [] "Create something")
+ (PUT "/" [] "Replace something")
+ (PATCH "/" [] "Modify Something")
+ (DELETE "/" [] "Annihilate something")
+ (OPTIONS "/" [] "Appease something")
+ (HEAD "/" [] "Preview something"))
+```
+
+Compojure route definitions are just functions which
+[accept request maps and return response maps](https://github.com/mmcgrana/ring/blob/master/SPEC):
+
+```clojure
+(myapp {:uri "/" :request-method :post})
+; => {:status 200
+; :headers {"Content-Type" "text/html; charset=utf-8}
+; :body "Create Something"}
+```
+
+The body may be a function, which must accept the request as a parameter:
+
+```clojure
+(defroutes myapp
+ (GET "/" [] (fn [req] "Do something with req")))
+```
+
+Or, you can just use the request directly:
+
+```clojure
+(defroutes myapp
+ (GET "/" req "Do something with req"))
+```
+
+Route patterns may include named parameters:
+
+```clojure
+(defroutes myapp
+ (GET "/hello/:name" [name] (str "Hello " name)))
+```
+
+You can adjust what each parameter matches by supplying a regex:
+
+```clojure
+(defroutes myapp
+ (GET ["/file/:name.:ext" :name #".*", :ext #".*"] [name ext]
+ (str "File: " name ext)))
+```
+
+### Middleware
+
+Clojure uses [Ring](https://github.com/ring-clojure/ring) for routing.
+Handlers are just functions that accept a request map and return a
+response map (Compojure will turn strings into 200 responses for you).
+
+You can easily write middleware that wraps all or part of your
+application to modify requests or responses:
+
+```clojure
+(defroutes myapp
+ (GET "/" req (str "Hello World v" (:app-version req))))
+
+(defn wrap-version [handler]
+ (fn [request]
+ (handler (assoc request :app-version "1.0.1"))))
+
+(defn -main []
+ (run-server (wrap-version myapp) {:port 5000}))
+```
+
+[Ring-Defaults](https://github.com/ring-clojure/ring-defaults) provides some handy
+middlewares for sites and apis, so add it to your dependencies:
+
+```
+[ring/ring-defaults "0.1.1"]
+```
+
+Then, you can import it in your ns:
+
+```
+(ns myapp.core
+ (:require [compojure.core :refer :all]
+ [ring.middleware.defaults :refer :all]
+ [org.httpkit.server :refer [run-server]]))
+```
+
+And use `wrap-defaults` to add the `site-defaults` middleware to your
+app:
+
+```
+(defn -main []
+ (run-server (wrap-defaults myapp site-defaults) {:port 5000}))
+```
+
+Now, your handlers may utilize query parameters:
+
+```clojure
+(defroutes myapp
+ (GET "/posts" req
+ (let [title (get (:params req) "title")
+ author (get (:params req) "author")]
+ (str "Title: " title ", Author: " author))))
+```
+
+Or, for POST and PUT requests, form parameters as well
+
+```clojure
+(defroutes myapp
+ (POST "/posts" req
+ (let [title (get (:params req) "title")
+ author (get (:params req) "author")]
+ (str "Title: " title ", Author: " author))))
+```
+
+
+### Return values
+
+The return value of a route block determines the response body
+passed on to the HTTP client, or at least the next middleware in the
+ring stack. Most commonly, this is a string, as in the above examples.
+But, you may also return a [response map](https://github.com/mmcgrana/ring/blob/master/SPEC):
+
+```clojure
+(defroutes myapp
+ (GET "/" []
+ {:status 200 :body "Hello World"})
+ (GET "/is-403" []
+ {:status 403 :body ""})
+ (GET "/is-json" []
+ {:status 200 :headers {"Content-Type" "application/json"} :body "{}"}))
+```
+
+### Static Files
+
+To serve up static files, use `compojure.route.resources`.
+Resources will be served from your project's `resources/` folder.
+
+```clojure
+(require '[compojure.route :as route])
+
+(defroutes myapp
+ (GET "/")
+ (route/resources "/")) ; Serve static resources at the root path
+
+(myapp {:uri "/js/script.js" :request-method :get})
+; => Contents of resources/public/js/script.js
+```
+
+### Views / Templates
+
+To use templating with Compojure, you'll need a template library. Here are a few:
+
+#### [Stencil](https://github.com/davidsantiago/stencil)
+
+[Stencil](https://github.com/davidsantiago/stencil) is a [Mustache](http://mustache.github.com/) template library:
+
+```clojure
+(require '[stencil.core :refer [render-string]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-string "Hello {{name}}" {:name name})))
+```
+
+You can easily read in templates from your resources directory. Here's a helper function
+
+```clojure
+(require 'clojure.java.io)
+
+(defn read-template [filename]
+ (slurp (clojure.java.io/resource filename)))
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-string (read-template "templates/hello.html") {:name name})))
+```
+
+#### [Selmer](https://github.com/yogthos/Selmer)
+
+[Selmer](https://github.com/yogthos/Selmer) is a Django and Jinja2-inspired templating language:
+
+```clojure
+(require '[selmer.parser :refer [render-file]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-file "templates/hello.html" {:name name})))
+```
+
+#### [Hiccup](https://github.com/weavejester/hiccup)
+
+[Hiccup](https://github.com/weavejester/hiccup) is a library for representing HTML as Clojure code
+
+```clojure
+(require '[hiccup.core :as hiccup])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (hiccup/html
+ [:html
+ [:body
+ [:h1 {:class "title"}
+ (str "Hello " name)]]])))
+```
+
+#### [Markdown](https://github.com/yogthos/markdown-clj)
+
+[Markdown-clj](https://github.com/yogthos/markdown-clj) is a Markdown implementation.
+
+```clojure
+(require '[markdown.core :refer [md-to-html-string]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (md-to-html-string "## Hello, world")))
+```
+
+Further reading:
+
+* [Official Compojure Documentation](https://github.com/weavejester/compojure/wiki)
+
+* [Clojure for the Brave and True](http://www.braveclojure.com/)
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 81eb467d..f6708590 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -307,7 +307,7 @@ on a new line! ""Wow!"", the masses cried";
// try parse will default to type default on failure
// in this case: 0
int tryInt;
- if (int.TryParse("123", out tryInt)) // Funciton is boolean
+ if (int.TryParse("123", out tryInt)) // Function is boolean
Console.WriteLine(tryInt); // 123
// Convert Integer To String
@@ -367,7 +367,7 @@ on a new line! ""Wow!"", the masses cried";
}
// Methods can have the same name, as long as the signature is unique
- public static void MethodSignature(string maxCount)
+ public static void MethodSignatures(string maxCount)
{
}
@@ -508,7 +508,7 @@ on a new line! ""Wow!"", the masses cried";
// LINQ - maps a store to IQueryable<T> objects, with delayed execution
// e.g. LinqToSql - maps to a database, LinqToXml maps to an xml document
- var db = new BikeRespository();
+ var db = new BikeRepository();
// execution is delayed, which is great when querying a database
var filter = db.Bikes.Where(b => b.HasTassles); // no query run
@@ -767,9 +767,9 @@ on a new line! ""Wow!"", the masses cried";
/// EntityFramework Code First is awesome (similar to Ruby's ActiveRecord, but bidirectional)
/// http://msdn.microsoft.com/en-us/data/jj193542.aspx
/// </summary>
- public class BikeRespository : DbSet
+ public class BikeRepository : DbSet
{
- public BikeRespository()
+ public BikeRepository()
: base()
{
}
diff --git a/css.html.markdown b/css.html.markdown
index cdef50cc..e058d691 100644
--- a/css.html.markdown
+++ b/css.html.markdown
@@ -3,6 +3,7 @@ language: css
contributors:
- ["Mohammad Valipour", "https://github.com/mvalipour"]
- ["Marco Scannadinari", "https://github.com/marcoms"]
+ - ["Geoffrey Liu", "https://github.com/g-liu"]
filename: learncss.css
---
@@ -24,18 +25,19 @@ The main focus of this article is on the syntax and some general tips.
```css
-/* comments appear inside slash-asterisk, just like this line! */
+/* comments appear inside slash-asterisk, just like this line!
+ there are no "one-line comments"; this is the only comment style */
/* ####################
## SELECTORS
- ####################*/
+ #################### */
/* Generally, the primary statement in CSS is very simple */
selector { property: value; /* more properties...*/ }
/* the selector is used to target an element on page.
-You can target all elments on the page! */
+You can target all elments on the page using asterisk! */
* { color:red; }
/*
@@ -62,61 +64,61 @@ div { }
/* or that the attribute has a specific value */
[attr='value'] { font-size:smaller; }
-/* start with a value*/
+/* start with a value (CSS3) */
[attr^='val'] { font-size:smaller; }
-/* or ends with */
+/* or ends with (CSS3) */
[attr$='ue'] { font-size:smaller; }
-/* or even contains a value */
+/* or even contains a value (CSS3) */
[attr~='lu'] { font-size:smaller; }
/* and more importantly you can combine these together -- there shouldn't be
-any spaaace between different parts because that makes it to have another
-meaning.*/
+any space between different parts because that makes it to have another
+meaning. */
div.some-class[attr$='ue'] { }
-/* you can also select an element based on its parent.*/
+/* you can also select an element based on its parent. */
-/*an element which is direct child of an element (selected the same way) */
+/* an element which is direct child of an element (selected the same way) */
div.some-parent > .class-name {}
-/* or any of its parents in the tree */
-/* the following basically means any element that has class "class-name"
-and is child of a div with class name "some-parent" IN ANY DEPTH */
+/* or any of its parents in the tree
+ the following basically means any element that has class "class-name"
+ and is child of a div with class name "some-parent" IN ANY DEPTH */
div.some-parent .class-name {}
/* warning: the same selector wihout spaaace has another meaning.
-can you say what? */
+ can you say what? */
div.some-parent.class-name {}
/* you also might choose to select an element based on its direct
-previous sibling */
+ previous sibling */
.i-am-before + .this-element { }
-/*or any sibling before this */
+/* or any sibling before this */
.i-am-any-before ~ .this-element {}
/* There are some pseudo classes that allows you to select an element
-based on its page behaviour (rather than page structure) */
+ based on its page behaviour (rather than page structure) */
/* for example for when an element is hovered */
-:hover {}
+selector:hover {}
-/* or a visited link*/
-:visited {}
+/* or a visited link */
+selected:visited {}
-/* or not visited link*/
-:link {}
+/* or not visited link */
+selected:link {}
/* or an input element which is focused */
-:focus {}
+selected:focus {}
/* ####################
## PROPERTIES
- ####################*/
+ #################### */
selector {
@@ -126,8 +128,12 @@ selector {
width: 200px; /* in pixels */
font-size: 20pt; /* in points */
width: 5cm; /* in centimeters */
- width: 50mm; /* in millimeters */
- width: 5in; /* in inches */
+ min-width: 50mm; /* in millimeters */
+ max-width: 5in; /* in inches. max-(width|height) */
+ height: 0.2vh; /* times vertical height of browser viewport (CSS3) */
+ width: 0.4vw; /* times horizontal width of browser viewport (CSS3) */
+ min-height: 0.1vmin; /* the lesser of vertical, horizontal dimensions of browser viewport (CSS3) */
+ max-width: 0.3vmax; /* same as above, except the greater of the dimensions (CSS3) */
/* Colors */
background-color: #F6E; /* in short hex */
@@ -135,16 +141,20 @@ selector {
background-color: tomato; /* can be a named color */
background-color: rgb(255, 255, 255); /* in rgb */
background-color: rgb(10%, 20%, 50%); /* in rgb percent */
- background-color: rgba(255, 0, 0, 0.3); /* in semi-transparent rgb */
+ background-color: rgba(255, 0, 0, 0.3); /* in semi-transparent rgb (CSS3) */
+ background-color: transparent; /* see thru */
+ background-color: hsl(0, 100%, 50%); /* hsl format (CSS3). */
+ background-color: hsla(0, 100%, 50%, 0.3); /* Similar to RGBA, specify opacity at end (CSS3) */
+
/* Images */
- background-image: url(/path-to-image/image.jpg);
+ background-image: url(/path-to-image/image.jpg); /* quotes inside url() optional */
/* Fonts */
font-family: Arial;
- font-family: "Courier New"; /* if name has spaaace it appears in double-quote */
- font-family: "Courier New", Trebuchet, Arial; /* if first one was not found
- browser uses the second font, and so forth */
+ font-family: "Courier New"; /* if name has spaaace it appears in single or double quotes */
+ font-family: "Courier New", Trebuchet, Arial, sans-serif; /* if first one was not found
+ browser uses the second font, and so forth */
}
```
@@ -155,17 +165,17 @@ Save any CSS you want in a file with extension `.css`.
```xml
<!-- you need to include the css file in your page's <head>: -->
-<link rel='stylesheet' type='text/css' href='filepath/filename.css' />
+<link rel='stylesheet' type='text/css' href='path/to/style.css' />
<!-- you can also include some CSS inline in your markup. However it is highly
recommended to avoid this. -->
<style>
- selector { property:value; }
+ a { color: purple; }
</style>
<!-- or directly set CSS properties on the element.
This has to be avoided as much as you can. -->
-<div style='property:value;'>
+<div style="border: 1px solid red;">
</div>
```
@@ -207,27 +217,28 @@ The precedence of style is as followed:
Remember, the precedence is for each **property**, not for the entire block.
* `E` has the highest precedence because of the keyword `!important`.
- It is recommended to avoid this unless it is strictly necessary to use.
+ It is recommended to avoid this unless it is strictly necessary to use.
* `F` is next, because it is inline style.
* `A` is next, because it is more "specific" than anything else.
- more specific = more specifiers. here 3 specifiers: 1 tagname `p` +
- class name `class1` + 1 attribute `attr='value'`
+ more specific = more specifiers. here 3 specifiers: 1 tagname `p` +
+ class name `class1` + 1 attribute `attr='value'`
* `C` is next. although it has the same specificness as `B`
- but it appears last.
+ but it appears last.
* Then is `B`
* and lastly is `D`.
## Compatibility
Most of the features in CSS2 (and gradually in CSS3) are compatible across
-all browsers and devices. But it's always vital to have in mind the compatiblity
+all browsers and devices. But it's always vital to have in mind the compatiblity
of what you use in CSS with your target browsers.
[QuirksMode CSS](http://www.quirksmode.org/css/) is one of the best sources for this.
+To run a quick compatibility check, [CanIUse](http://caniuse.com) is a great resource.
+
## Further Reading
* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
* [QuirksMode CSS](http://www.quirksmode.org/css/)
* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
-
diff --git a/de-de/coffeescript-de.html.markdown b/de-de/coffeescript-de.html.markdown
new file mode 100644
index 00000000..98a452ba
--- /dev/null
+++ b/de-de/coffeescript-de.html.markdown
@@ -0,0 +1,106 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["Frederik Ring", "https://github.com/m90"]
+ - ["Philipp Fischbeck", "https://github.com/PFischbeck"]
+filename: coffeescript-de.coffee
+lang: de-de
+---
+
+CoffeeScript ist eine kleine Sprache, die eins zu eins nach JavaScript übersetzt wird - es findet keine Interpretation zur Laufzeit statt.
+Als Nachfolger von JavaScript konzipiert, gibt CoffeeScript sein Bestes, lesbaren, gut formatierten und sauber laufenden JavaScript-Code zu erzeugen, der in jeder JavaScript-Laufzeit einwandfrei funktioniert.
+
+Auf [der CoffeeScript Website](http://coffeescript.org/) gibt es ein ausführliches Tutorial.
+
+``` coffeescript
+# CoffeeScript ist eine dieser Sprachen für "Hipster"
+# und folgt daher vielen Trends und Einflüssen aus modernen Sprachen.
+# Kommentare werden daher wie in Ruby und Python mit Hashes gekennzeichnet
+
+###
+Kommentarblöcke sehen aus wie diese und werden direkt nach '/ *'s und '* /'s
+im erzeugten JavaScript umgewandelt.
+
+Vorweg: bevor du mit CoffeeScript anfängst, solltest du bereits einen guten
+Überblick über die Sprache JavaScript haben.
+###
+
+# Zuweisung:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# Bedingungen:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# Funktionen:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+fill = (container, liquid = "Kaffee") ->
+ "#{container} wird mit #{liquid} gefüllt..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "Kaffee";
+# }
+# return container + " wird mit " + liquid + " gefüllt...";
+#};
+
+# "Ranges":
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# Objekte:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# "Splats":
+race = (winner, runners...) ->
+ print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
+
+# Existenz-Operator:
+alert "Hab ich's nicht gesagt?" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("Hab ich's nicht gesagt?"); }
+
+# Listen-Abstraktion:
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['Brokkoli', 'Spinat', 'Schokolade']
+eat food for food in foods when food isnt 'Schokolade'
+#=>foods = ['Brokkoli', 'Spinat', 'Schokolade'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'Schokolade') {
+# eat(food);
+# }
+#}
+```
+
+## Weiterführende Links
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
diff --git a/de-de/css-de.html.markdown b/de-de/css-de.html.markdown
index 8909b251..23c1df94 100644
--- a/de-de/css-de.html.markdown
+++ b/de-de/css-de.html.markdown
@@ -8,107 +8,106 @@ lang: de-de
filename: learncss-de.css
---
-In den frühen Tagen des Internets gab es keine visuellen Elemente, alles war nur reiner Text. Aber mit der Weiterentwickliung von Browsern wurden auch vollständig visuelle Webseiten zu einem Standard.
-CSS ist die allgemeine Sprache, die dazu da ist, damit man den HTML-Code und die Designelemente von Webseiten (strikt) unterscheiden kann.
+In den frühen Tagen des Internets gab es keine visuellen Elemente, alles war nur reiner Text. Aber mit der Weiterentwicklung von Browsern wurden auch vollständig visuelle Webseiten zu einem Standard.
+Durch Verwendung von CSS lässt sich eine strikte Trennung zwischen HTML-Code und Designelementen erreichen.
-Kurzgefasst, CSS ermöglicht es, verschiedene HTML-Elemente anzuvisieren und ihnen stilistische Eigenschaften zu geben.
+Kurzgefasst, CSS ermöglicht es, verschiedene HTML-Elemente innerhalb eines Dokuments auszuwählen und ihnen visuelle Eigenschaften zu geben.
CSS hat wie jede andere Sprache viele Versionen. Hier fokussieren wir uns auf CSS2.0, welche nicht die neueste, aber die am weitesten verbreitete und unterstützte Version ist.
-**NOTE:** Weil die Ausgabe von CSS visuelle Eigenschaften sind, wirst du wahrscheinlich eine CSS-Sandbox wie [dabblet](http://dabblet.com/) benutzen müssen, um die Sprache richtig zu lernen.
+**HINWEIS:** Weil die Ausgabe von CSS visuelle Eigenschaften sind, wirst du wahrscheinlich eine CSS-Sandbox wie [dabblet](http://dabblet.com/) benutzen müssen, um die Sprache richtig zu lernen.
In diesem Artikel wird am meisten auf generelle Hinweise und die Syntax geachtet.
```css
-/* kommentare werden in sternchen-schrägstrichkombinationen gepackt (genauso wie hier!) */
+/* Kommentare werden in Sternchen-Schrägstrichkombinationen gepackt (genauso wie hier!) */
/* ####################
## SELEKTOREN
####################*/
-/* Eigentlich ist die häufigste Anwendungsweise von CSS sehr simpel */
+/* Eigentlich ist das grundlegende CSS-Statement sehr simpel */
selektor { eigenschaft: wert; /* mehr eigenschaften...*/ }
-/* der selektor wird dazu benutzt, ein element auf der seite anzuvisieren
+/* Der Selektor wird dazu benutzt, ein Element auf der Seite auszuwählen.
-Aber man kann auch alle Elemente auf einer Seite anvisieren! */
+Man kann aber auch alle Elemente auf einer Seite auswählen! */
* { color:red; } /* farbe:rot */
/*
-Wenn wir so ein Element auf einer Seite haben:
+Angenommen wir haben folgendes Element auf einer Seite:
<div class='eine-klasse klasse2' id='eineId' attr='wert' />
*/
-/* kann man es so bei seiner klasse anvisieren */
+/* kann man es so über seine Klasse auswählen */
.eine-klasse { }
-/*oder bei beiden klassen! */
+/* oder über beide Klassen! */
.eine-klasse.klasse2 { }
-/* oder beim namen des tags */
+/* oder über den Namen des Tags */
div { }
-/* oder bei seiner id */
+/* oder über seine Id */
#eineId { }
-/* oder daran, dass es ein Attribut hat! */
+/* oder darüber, dass es ein Attribut hat! */
[attr] { font-size:smaller; }
-/* oder daran, dass das attribut einen bestimmten wert hat*/
+/* oder auch darüber, dass das Attribut einen bestimmten Wert hat */
[attr='wert'] { font-size:smaller; }
-/* beginnt mit einem wert*/
-[attr^='wert'] { font-size:smaller; }
+/* beginnt mit dem übergebenen Wert */
+[attr^='we'] { font-size:smaller; }
-/* oder endet mit */
+/* endet damit */
[attr$='rt'] { font-size:smaller; }
-/* oder sogar nur beinhaltet */
+/* oder beinhaltet einen Teil davon */
[attr~='er'] { font-size:smaller; }
-/* was aber noch wichtiger ist, ist dass man alle diese kombinieren
-kann - man sollte nur mit der leerzeichensetzung vorsichtig sein,
-da es mit einem leerzeichen zwei verschiedene selektoren wären*/
+/* Noch wichtiger ist aber die Möglichkeit, all das miteinander kombinieren
+zu können - man sollte hierbei nur mit der Leerzeichensetzung vorsichtig sein,
+ein Leerzeichen macht es zu zwei verschiedenen Selektoren */
+
div.eine-klasse[attr$='rt'] { } /* so ist es richtig */
-/* man kann auch ein element daran festmachen, wie sich die übergeordneten
-elemente verhalten!*/
+/* Man kann auch ein Element über seine Elternelemente auswählen */
-/*es muss allerdings ein direktes kind sein */
+/* > wählt ein direktes Kind aus */
div.ein-elternteil > .klassen-name {}
-/* oder jeder seiner eltern in der struktur */
-/* das folgende heißt also, dass jedes element mit der klasse 'klassen-name'
-und dem elternteil IN JEDER TIEFE ausgewählt wird */
+/* Mit einem Leerzeichen getrennt kann man alle Elternelemente ansprechen */
+/* Das folgende heißt also, dass jedes Element mit der Klasse 'klassen-name'
+und dem Elternteil IN JEDER TIEFE ausgewählt wird */
div.ein-elternteil .klassen-name {}
-/* achtung: dasselbe ohne das leerzeichen hat eine andere bedeutung,
+/* Achtung: das selbe ohne das Leerzeichen hat eine andere Bedeutung,
kannst du mir sagen, was? */
div.ein-elternteil.klassen-name {}
-/* man kann auch ein element nach seinem direkten vorherigen zwilling
+/* Man kann ein Element auch nach seinem direkten Nachbarelement
auswählen */
.ich-bin-vorher + .dieses-element { }
-/* oder jeden zwilling davor */
+/* Oder über jedes Geschwisterelement davor */
.ich-kann-jeder-davor-sein ~ .dieses-element {}
-/* es gibt ein paar pseudoklassen, die sich basierend auf dem
-seitenverhalten, nämlich nicht auf der seitenstruktur auswählen
-lassen können */
+/* Mit Pseudoklassen lassen sich Elemente anhand ihres momentanen Zustands
+auf der Seite auswählen (anstatt über die Seitenstruktur) */
-/* zum beispiel, wenn über ein element mit dem mauszeiger gefahren wird */
+/* Zum Beispiel, wenn über ein Element mit dem Mauszeiger gefahren wird */
:hover {}
-/* oder einen bereits besuchten link*/
+/* Oder einen bereits besuchten Link*/
:visited {}
-/* oder einen noch nicht besuchten link*/
+/* Oder einen noch nicht besuchten Link*/
:link {}
-/* oder ein eingabeelement, das zurzeit im fokus steht */
+/* Oder ein Eingabeelement, das zurzeit im Fokus steht */
:focus {}
@@ -117,64 +116,64 @@ lassen können */
####################*/
selector {
-
- /* einheiten */
- width: 50%; /* in prozent */
- font-size: 2em; /* mal der derzeitigen schriftgröße */
- width: 200px; /* in pixeln */
- font-size: 20pt; /* in punkten */
- width: 5cm; /* in zentimetern */
- width: 50mm; /* in millimetern */
- width: 5in; /* in zoll */
-
- /* farben */
- background-color: #F6E /* in kurzem hex */
- background-color: #F262E2 /* in langem hex */
- background-color: tomato /* kann auch eine genannte farbe sein */
- background-color: rgb(255, 255, 255) /* in rgb */
- background-color: rgb(10%, 20%, 50%) /* in rgb prozent */
- background-color: rgba(255, 0, 0, 0.3); /* in semi-transparentem rgb */
-
- /* bilder */
+
+ /* Einheiten */
+ width: 50%; /* in Prozent */
+ font-size: 2em; /* mal der derzeitigen Schriftgröße */
+ width: 200px; /* in Pixeln */
+ font-size: 20pt; /* in Punkten */
+ width: 5cm; /* in Zentimetern */
+ width: 50mm; /* in Millimetern */
+ width: 5in; /* in Zoll */
+
+ /* Farben */
+ background-color: #F6E /* in kurzem Hex */
+ background-color: #F262E2 /* in langem Hex */
+ background-color: tomato /* kann auch eine benannte Farbe sein */
+ background-color: rgb(255, 255, 255) /* in RGB */
+ background-color: rgb(10%, 20%, 50%) /* in RGB Prozent */
+ background-color: rgba(255, 0, 0, 0.3); /* in semi-transparentem RGB */
+
+ /* Bilder */
background-image: url(/pfad-zum-bild/image.jpg);
-
- /* schriften */
+
+ /* Schriften */
font-family: Arial;
- font-family: "Courier New"; /* wenn der name ein leerzeichen beinhält, kommt er in
- apostrophe */
- font-family: "Courier New", Trebuchet, Arial; /* wenn der erste nicht gefunden wird, wird
- der zweite benutzt, und so weiter */
+ font-family: "Courier New"; /* wenn der Name ein Leerzeichen beinhält, kommt er in
+ Anführungszeichen */
+ font-family: "Courier New", Trebuchet, Arial; /* wird die erste Schriftart
+ nicht gefunden, wird die zweite benutzt, usw. */
}
```
## Benutzung
-speichere das css, das du benutzen willst mit der endung '.css'.
+Speichere das CSS, das du benutzen willst mit der endung '.css'.
```xml
-<!-- du musst die css-datei im <head>-bereich der seite erwähnen -->
+<!-- du musst die CSS-Datei im <head>-bereich der seite einbinden -->
<link rel='stylesheet' type='text/css' href='filepath/filename.css' />
-<!-- es geht allerdings auch direkt, wobei diese methode nicht
+<!-- Einbindung funktioniert auch inline, wobei diese Methode nicht
empfohlen ist -->
<style>
selector { property:value; }
</style>
-<!-- oder direkt am element (sollte aber gelassen werden) -->
+<!-- Oder direkt auf einem Element (sollte aber vermieden werden) -->
<div style='property:value;'>
</div>
```
-## Wichtigkeit
+## Spezifität
-ein element kann von mehr als einem selektoren angezielt werden.
-und kann auch eine eigenschaft mehr als einmal zugewiesen bekommen.
-in diesen fällen gibt es regeln, die die wichtigkeit von selektoren einführen.
+Ein Element kann natürlich auch von mehr als einer Regel in einem Stylesheet
+angesprochen werdenm und kann eine Eigenschaft auch öfters als einmal zugewiesen
+bekommen. In diesen Fällen gibt es Regeln, die die Spezifität von Selektoren regeln.
-wie haben dieses CSS:
+Wir haben dieses CSS:
```css
/*A*/
@@ -194,34 +193,34 @@ p { property: wert !important; }
```
-und das folgende markup:
+und das folgende Markup:
```xml
<p style='/*F*/ property:value;' class='class1 class2' attr='value'>
</p>
```
-die wichtigkeit der stile ist wie folgt:
-(die wichtigkeit gilt nur für **eigenschaften**, nicht für ganze blöcke)
-
-* `E` hat die größte wichtigkeit wegen dem schlüsselwort `!important`.
- man sollte diese form aber vermeiden.
-* `F` ist als nächstes, da es direkt an dem element definiert ist.
-* `A` ist als nächstes, da es "spezifischer" als alle anderen ist.
- spezifischer = mehr zuweisungen: 1 tagname `p` +
- klassenname `klasse1` + 1 attribut `attr='value'`
-* `C` ist als nächstes obwohl es genau so ist wie `B`
- aber es erscheint als letztes.
-* dann ist `B`
+Die Spezifität der Stile ist wie folgt:
+(die Spezifität gilt nur für **einzelne Eigenschaften**, nicht für ganze Blöcke)
+
+* `E` hat die größte Spezifität wegen dem Schlüsselwort `!important`.
+ man sollte diese Form aber vermeiden.
+* `F` ist als nächstes dran, da es direkt an dem element definiert ist.
+* Dann folgt `A`, da es "spezifischer" als alle anderen ist.
+ spezifischer = mehr Zuweisungen: 1 Tagname `p` +
+ Klassenname `klasse1` + 1 Attribut `attr='value'`
+* `C` kommt als nächstes, obwohl es genau so ist wie `B`,
+ es erscheint aber später im Stylesheet.
+* dann kommt `B`
* und als letztes `D`.
-## Kompabilität
+## Kompatibilität
-die meisten features von CSS sind in allen browsern verfügbar.
-man sollte jedoch immer darauf achten, wenn man etwas mit CSS
-programmiert.
+Die meisten Features von CSS sind in allen Browsern verfügbar. Man sollte
+jedoch immer darauf achten die benutzten Features auf Verfügbarkeit in den
+vom Projekt unterstützten Browser zu überprüfen.
-[QuirksMode CSS](http://www.quirksmode.org/css/) ist eine der besten quellen dafür.
+[QuirksMode CSS](http://www.quirksmode.org/css/) oder [Can I Use](http://caniuse.com/) sind zwei der besten Quellen dafür.
## Weiterlesen
diff --git a/de-de/go-de.html.markdown b/de-de/go-de.html.markdown
new file mode 100644
index 00000000..ca27fdc7
--- /dev/null
+++ b/de-de/go-de.html.markdown
@@ -0,0 +1,318 @@
+---
+language: Go
+filename: learngo-de.go
+contributors:
+ - ["Joseph Adams", "https://github.com/jcla1"]
+lang: de-de
+---
+Go wurde entwickelt um probleme zu lösen. Sie ist zwar nicht der neuste Trend in
+der Informatik, aber sie ist eine der neusten und schnellsten Wege um Aufgabe in
+der realen Welt zu lösen.
+
+Sie hat vertraute Elemente von imperativen Sprachen mit statisher Typisierung
+und kann schnell kompiliert und ausgeführt werden. Verbunden mit leicht zu
+verstehenden Parallelitäts-Konstrukten, um die heute üblichen mehrkern
+Prozessoren optimal nutzen zu können, eignet sich Go äußerst gut für große
+Programmierprojekte.
+
+Außerdem beinhaltet Go eine gut ausgestattete standard bibliothek und hat eine
+aktive community.
+
+```go
+// Einzeiliger Kommentar
+/* Mehr-
+ zeiliger Kommentar */
+
+// Eine jede Quelldatei beginnt mit einer Packet-Klausel.
+// "main" ist ein besonderer Packetname, da er ein ausführbares Programm
+// einleitet, im Gegensatz zu jedem anderen Namen, der eine Bibliothek
+// deklariert.
+package main
+
+// Ein "import" wird verwendet um Packte zu deklarieren, die in dieser
+// Quelldatei Anwendung finden.
+import (
+ "fmt" // Ein Packet in der Go standard Bibliothek
+ "net/http" // Ja, ein Webserver.
+ "strconv" // Zeichenkettenmanipulation
+)
+
+// Es folgt die Definition einer Funktions, in diesem Fall von "main". Auch hier
+// ist der Name wieder besonders. "main" markiert den Eintrittspunkt des
+// Programms. Vergessen Sie nicht die geschweiften Klammern!
+func main() {
+ // Println gibt eine Zeile zu stdout aus.
+ // Der Prefix "fmt" bestimmt das Packet aus welchem die Funktion stammt.
+ fmt.Println("Hello world!")
+
+ // Aufruf einer weiteren Funktion definiert innerhalb dieses Packets.
+ beyondHello()
+}
+
+// Funktionen können Parameter akzeptieren, diese werden in Klammern deklariert,
+// die aber auch bei keinen Parametern erforderlich sind.
+func beyondHello() {
+ var x int // Deklaration einer Variable, muss vor Gebrauch geschehen.
+ x = 3 // Zuweisung eines Werts.
+ // Kurze Deklaration: Benutzen Sie ":=" um die Typisierung automatisch zu
+ // folgern, die Variable zu deklarieren und ihr einen Wert zu zuweisen.
+ y := 4
+
+ // Eine Funktion mit mehreren Rückgabewerten.
+ sum, prod := learnMultiple(x, y)
+
+ fmt.Println("sum:", sum, "prod:", prod) // Simple Ausgabe
+ learnTypes() // In < y Minuten lernen Sie mehr!
+}
+
+// Funktionen können mehrere Parameter und (mehrere!) Rückgabewerte haben.
+func learnMultiple(x, y int) (sum, prod int) {
+ return x + y, x * y // Wiedergabe zweier Werte
+}
+
+// Überblick ueber einige eingebaute Typen und Literale.
+func learnTypes() {
+ // Kurze Deklarationen sind die Norm.
+ s := "Lernen Sie Go!" // Zeichenketten-Typ
+
+ s2 := `Eine "raw" Zeichenkette kann
+Zeilenumbrüche beinhalten.` // Selber Zeichenketten-Typ
+
+ // nicht-ASCII Literal. Go Quelltext ist UTF-8 kompatibel.
+ g := 'Σ' // Ein Runen-Typ, alias int32, gebraucht für unicode code points.
+
+ f := 3.14195 // float64, eine IEEE-754 64-bit Dezimalzahl
+ c := 3 + 4i // complex128, besteht intern aus zwei float64-er
+
+ // "var"-Syntax mit Initalwert
+ var u uint = 7 // Vorzeichenlos, aber die Größe ist implementationsabhängig
+ var pi float32 = 22. / 7
+
+ // Umwandlungs-Syntax mit kurzer Deklaration
+ n := byte('\n') // byte ist ein Alias für uint8
+
+ // Arrays haben bei Kompile-Zeit festgelegte Größen
+ var a4 [4]int // Ein Array mit 4 ints, alle mit Initialwert 0
+ a3 := [...]int{3, 1, 5} // Ein Array mit 4 ints, Initialwerte wie angezeigt
+
+ // "slices" haben eine dynamische Größe. Arrays und Slices haben beide ihre
+ // Vorzüge, aber slices werden viel häufiger verwendet
+ s3 := []int{4, 5, 9} // Vergleichen Sie mit a3, hier: keine Ellipse
+ s4 := make([]int, 4) // Weist Speicher für 4 ints zu, alle mit Initialwert 0
+ var d2 [][]float64 // Nur eine Deklaration, keine Speicherzuweisung
+ bs := []byte("eine slice") // Umwandlungs-Syntax
+
+ p, q := learnMemory() // Deklariert p & q als Zeiger zu einer int.
+ fmt.Println(*p, *q) // Die gibt die zwei Werte aus. "*" für den Zugriff
+
+ // "Maps" sind dynamische Datenstrukturen mit variabler Größe. Sie sind wie
+ // "hashs" oder "dictionaries" aus anderen Sprachen.
+ m := map[string]int{"drei": 3, "vier": 4}
+ m["eins"] = 1
+
+ // Ungebrauchte Variablen sind Fehler in Go
+ // Der Unterstrich wird verwendet um einen Wert zu verwerfen.
+ _, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
+ // Die Ausgabe zählt natürlich auch als Gebrauch
+ fmt.Println(s, c, a4, s3, d2, m)
+
+ learnFlowControl() // Auf zum Kontrollfluss!
+}
+
+// Go ist komplett "garbage collected". Sie unterstützt Zeiger (pointers) aber
+// keine Zeiger-Rechnungen. Fehler können sich durch "nil" einschleichen, jedoch
+// nicht durch erhöhen eines Zeigers.
+func learnMemory() (p, q *int) {
+ // Die bennanten Rückgabewerte p & q sind vom Typ *int
+ p = new(int) // Eingebaute Funktion "new" weist neuen Speicherplatz zu
+ // Der zugewiesene Speicher ist mit 0 initialisiert, p ist nicht länger nil
+ s := make([]int, 20) // So weist man 20 ints nebeneinander (im Speicher) zu
+ s[3] = 7 // Einer von ihnen wird ein Wert zugewiesen
+ r := -2 // Deklaration einer weiteren lokalen Variable
+ return &s[3], &r // & gibt die Addresse einer Variable
+}
+
+func expensiveComputation() int {
+ return 1e6
+}
+
+func learnFlowControl() {
+ // Bedingte Anweisungen verlangen nach geschweiften Klammern, normale
+ // Klammern um die Bedingung werden aber nicht gebraucht.
+ if true {
+ fmt.Println("hab's dir ja gesagt!")
+ }
+ // Die Formattierung ist durch den Befehl "go fmt" standardisiert
+ if false {
+ // nicht hier
+ } else {
+ // sonder hier! spielt die Musik
+ }
+
+ // Benutzen Sie ein "switch" Statement anstatt eine Anreihung von if-s
+ x := 1
+ switch x {
+ case 0:
+ case 1:
+ // Einzelne Fälle fallen nicht zum nächsten durch!
+ case 2:
+ // wird nicht ausgeführt
+ }
+ // Wie bei "if", braucht "for" auch keine Klammern um die Bedingung
+ for x := 0; x < 3; x++ { // ++ ist ein Statement
+ fmt.Println(x, "-te Iteration")
+ }
+ // Ab hier gilt wieder: x == 1
+
+ // For ist die einzige Schleifenform in Go, sie hat aber mehrere Formen:
+ for { // Endloschleife
+ break // nur ein Spaß
+ continue // wird nie ausgeführt
+ }
+
+ // Wie bei for, bedeutet := in einer Bedingten Anweisung zunächst die
+ // Zuweisung und erst dann die Überprüfung der Bedingung.
+ if y := expensiveComputation(); y > x {
+ x = y
+ }
+ // Funktionsliterale sind "closures"
+ xBig := func() bool {
+ return x > 100 // Verweist auf x, deklariert vor dem switch
+ }
+ fmt.Println("xBig:", xBig()) // true (im moment gilt: x == 1e6)
+ x /= 1e5 // dies macht x == 10
+ fmt.Println("xBig:", xBig()) // jetzt: false
+
+ // Wenn Sie's brauchen, werden Sie's lieben!
+ goto love
+love:
+
+ learnInterfaces() // Jetzt zum interessanten Teil!
+}
+
+// Definiere "Stringer" als ein Interface mit einer Methode: String
+type Stringer interface {
+ String() string
+}
+
+// Definiere ein Paar als struct mit zwei Feldern, Integers mit Namen x & y.
+type pair struct {
+ x, y int
+}
+
+// Definiere eine Methode von "pair". Dieser Typ erfüllt jetzt das Stringer interface.
+func (p pair) String() string { // p ist der Empfänger
+ // Sprintf ist eine weitere öffentliche Funktion von fmt.
+ // Der Syntax mit Punkt greift auf die Felder zu.
+ return fmt.Sprintf("(%d, %d)", p.x, p.y)
+}
+
+func learnInterfaces() {
+ // Der Klammer-Syntax ist ein "struct literal". Es ist ein vollkommen
+ // initialisiertes struct. Der := Syntax deklariert und initialisiert p.
+ p := pair{3, 4}
+ fmt.Println(p.String()) // Aufruf der String() Methode von p.
+ var i Stringer // Deklariere i vom Typ: Stringer
+ i = p // Ok, weil p auch vom Typ Stringer ist.
+ // Aufruf der String Methode von i, gleiche Ausgabe wie zuvor.
+ fmt.Println(i.String())
+
+ // Funktionen des fmt-Packets rufen die String() Methode auf um eine
+ // druckbare variante des Empfängers zu erhalten.
+ fmt.Println(p) // gleiche Ausgabe wie zuvor
+ fmt.Println(i) // und wieder die gleiche Ausgabe wie zuvor
+
+ learnErrorHandling()
+}
+
+func learnErrorHandling() {
+ // Das ", ok" Idiom wird häufig verwendet um zu überprüfen ob etwas schief
+ // gegangen ist.
+ m := map[int]string{3: "drei", 4: "vier"}
+ if x, ok := m[1]; !ok { // ok wird false sein, da 1 nicht in der map ist.
+ fmt.Println("keine eins gefunden")
+ } else {
+ fmt.Print(x) // x wäre der Wert, wenn er in der map wäre.
+ }
+ // Ein Fehler-Wert (error value) gibt mehr Informationen über den Grund für
+ // das Problem an.
+ if _, err := strconv.Atoi("nicht-int"); err != nil { // _ verwirft den Wert
+ // Gibt: "strconv.ParseInt: parsing "nicht-int": invalid syntax" aus
+ fmt.Println(err)
+ }
+ // Wir kommen bald nochmal auf Interfaces zurück. Aber inzwischen:
+ learnConcurrency()
+}
+
+// c ist ein Kannal, ein sicheres Kommunikationsmedium.
+func inc(i int, c chan int) {
+ c <- i + 1 // <- ist der "send" Operator, wenn ein Kannal auf der Linken ist
+}
+
+// Wir verwenden "inc" um Zahlen parallel zu erhöhen.
+func learnConcurrency() {
+ // Die selbe "make"-Funktion wie vorhin. Sie initialisiert Speicher für
+ // maps, slices und Kannäle.
+ c := make(chan int)
+ // Starte drei parallele "Goroutines". Die Zahlen werden parallel (concurrently)
+ // erhöht. Alle drei senden ihr Ergebnis in den gleichen Kannal.
+ go inc(0, c) // "go" ist das Statement zum Start einer neuen Goroutine
+ go inc(10, c)
+ go inc(-805, c)
+ // Auslesen und dann Ausgeben der drei berechneten Werte.
+ // Man kann nicht im voraus feststellen in welcher Reihenfolge die Werte
+ // ankommen.
+ fmt.Println(<-c, <-c, <-c) // mit dem Kannal rechts ist <- der Empfangs-Operator
+
+ cs := make(chan string) // ein weiterer Kannal, diesmal für strings
+ cc := make(chan chan string) // ein Kannal für string Kannäle
+
+ // Start einer neuen Goroutine, nur um einen Wert zu senden
+ go func() { c <- 84 }()
+ go func() { cs <- "wortreich" }() // schon wider, diesmal für
+ // "select" hat eine Syntax wie ein switch Statement, aber jeder Fall ist
+ // eine Kannaloperation. Es wählt eine Fall zufällig aus allen die
+ // kommunikationsbereit sind aus.
+ select {
+ case i := <-c: // der empfangene Wert kann einer Variable zugewiesen werden
+ fmt.Printf("es ist ein: %T", i)
+ case <-cs: // oder der Wert kann verworfen werden
+ fmt.Println("es ist eine Zeichenkette!")
+ case <-cc: // leerer Kannal, nicht bereit für den Empfang
+ fmt.Println("wird nicht passieren.")
+ }
+ // Hier wird eine der beiden Goroutines fertig sein, die andere nicht.
+ // Sie wird warten bis der Wert den sie sendet von dem Kannal gelesen wird.
+
+ learnWebProgramming() // Go kann es und Sie hoffentlich auch bald.
+}
+
+// Eine einzige Funktion aus dem http-Packet kann einen Webserver starten.
+func learnWebProgramming() {
+ // Der erste Parameter von "ListenAndServe" ist eine TCP Addresse an die
+ // sich angeschlossen werden soll.
+ // Der zweite Parameter ist ein Interface, speziell: ein http.Handler
+ err := http.ListenAndServe(":8080", pair{})
+ fmt.Println(err) // Fehler sollte man nicht ignorieren!
+}
+
+// Wir lassen "pair" das http.Handler Interface erfüllen indem wir seine einzige
+// Methode implementieren: ServeHTTP
+func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ // Senden von Daten mit einer Methode des http.ResponseWriter
+ w.Write([]byte("Sie habe Go in Y Minuten gelernt!"))
+}
+```
+
+## Weitere Resourcen
+Alles zu Go finden Sie auf der [offiziellen Go Webseite](http://golang.org/).
+Dort können sie der Tutorial folgen, interaktiv Quelltext ausprobieren und viel
+Dokumentation lesen.
+
+Auch zu empfehlen ist die Spezifikation von Go, die nach heutigen Standards sehr
+kurz und auch gut verständlich formuliert ist. Auf der Leseliste von Go-Neulingen
+ist außerdem der Quelltext der [Go standard Bibliothek](http://golang.org/src/pkg/).
+Gut documentiert, demonstriert sie leicht zu verstehendes und im idiomatischen Stil
+verfasstes Go. Erreichbar ist der Quelltext auch durch das Klicken der Funktions-
+Namen in der [offiziellen Dokumentation von Go](http://golang.org/pkg/).
+
diff --git a/de-de/haskell-de.html.markdown b/de-de/haskell-de.html.markdown
new file mode 100644
index 00000000..2c548961
--- /dev/null
+++ b/de-de/haskell-de.html.markdown
@@ -0,0 +1,425 @@
+---
+language: Haskell
+lang: de-de
+contributors:
+ - ["Adit Bhargava", "http://adit.io"]
+translators:
+ - ["Henrik Jürges", "https://github.com/santifa"]
+filename: haskell-de.hs
+
+---
+
+Haskell wurde als praktische und funktionale Sprache entworfen.
+Es ist berühmt für das Schema der Monaden und des Typsystems, aber
+es sticht vor allem die Einfachheit und Eleganz hervor.
+
+```haskell
+-- Einfache Kommentare beginnen mit 2 Bindestriche.
+{- So wird ein Kommentar
+über mehrere Zeilen angelegt.
+-}
+
+----------------------------------------------------
+-- 1. Primitive Datentypen und Operatoren
+----------------------------------------------------
+
+-- Normale Zahlen.
+3 -- 3
+
+-- Einfache Rechenoperationen.
+1 + 1 -- 2
+8 - 1 -- 7
+10 * 2 -- 20
+35 / 5 -- 7.0
+
+-- Die Division ist per se auf Fließkommazahlen.
+35 / 4 -- 8.75
+
+-- Ganzzahlige Division
+35 `div` 4 -- 8
+
+-- Boolesche Werte sind Primitiven.
+True
+False
+
+-- Logik Operationen
+not True -- False
+not False -- True
+1 == 1 -- True
+1 /= 1 -- False
+1 < 10 -- True
+
+-- `not` ist eine Funktion die ein Argument entgegenimmt.
+-- Haskell benötigt keine Klammern um Argumente.
+-- Sie werden einfach aufgelistet: func arg1 arg2 arg3...
+-- Wie man Funktionen definiert kommt weiter unten.
+
+
+-- Strings und Zeichen
+"Das ist ein String."
+'a' -- Zeichen
+'Einfache Anfuehrungszeichen gehen nicht.' -- error!
+
+-- Strings können konkateniert werden.
+"Hello " ++ "world!" -- "Hello world!"
+
+-- Ein String ist eine Liste von Zeichen.
+"Das ist eine String" !! 0 -- 'D'
+
+
+----------------------------------------------------
+-- Listen und Tupel
+----------------------------------------------------
+
+-- Jedes Element einer Liste muss vom gleichen Typ sein.
+-- Zwei gleiche Listen
+[1, 2, 3, 4, 5]
+[1..5]
+
+-- Haskell unterstuetzt unendliche Listen!
+[1..] -- Die Liste aller natuerlichen Zahlen
+
+-- Unendliche Listen funktionieren in Haskell, da es "lazy evaluation"
+-- unterstuetzt. Haskell evaluiert erst etwas, wenn es benötigt wird.
+-- Somit kannst du nach dem 1000. Element fragen und Haskell gibt es dir:
+
+[1..] !! 999 -- 1000
+
+-- Haskell evaluiert nun die ersten 1 - 1000 Elemente, aber der Rest der Liste
+-- bleibt unangetastet. Haskell wird sie solange nicht weiterevalieren
+-- bis es muss.
+
+-- Zwei Listen konkatenieren
+[1..5] ++ [6..10]
+
+-- Ein Element als Head hinzufuegen
+0:[1..5] -- [0, 1, 2, 3, 4, 5]
+
+-- Gibt den 5. Index zurueck
+[0..] !! 5 -- 5
+
+-- Weitere Listenoperationen
+head [1..5] -- 1
+tail [1..5] -- [2, 3, 4, 5]
+init [1..5] -- [1, 2, 3, 4]
+last [1..5] -- 5
+
+-- list comprehensions | Listen erschaffen
+[x*2 | x <- [1..5]] -- [2, 4, 6, 8, 10]
+
+-- Mit Bedingungen
+[x*2 | x <- [1..5], x*2 > 4] -- [6, 8, 10]
+
+-- Tupel haben eine feste Länge, jedes Element darf aber ein anderen Typ haben.
+-- Ein Tupel:
+("haskell", 1)
+
+-- Auf Elemente eines Tupels zugreifen:
+fst ("haskell", 1) -- "haskell"
+snd ("haskell", 1) -- 1
+
+----------------------------------------------------
+-- 3. Funktionen
+----------------------------------------------------
+-- Eine einfache Funktion die zwei Argumente hat.
+add a b = a + b
+
+-- Wenn man ghci (den Haskell Interpreter) benutzt, muss ein `let` davor.
+-- let add a b = a + b
+
+-- Eine Funktion aufrufen
+add 1 2 -- 3
+
+-- Man kann eine Funktion auch Infix verwenden,
+-- wenn man sie mit backticks umgibt
+1 `add` 2 -- 3
+
+-- So sieht die Definition eines eigenen Operators aus.
+-- Also einer Funktion deren Name aus Symbolen besteht.
+-- Die Integer Division:
+(//) a b = a `div` b
+35 // 4 -- 8
+
+-- Guards sind eine einfache Möglichkeit fuer Fallunterscheidungen.
+fib x
+ | x < 2 = x
+ | otherwise = fib (x - 1) + fib (x - 2)
+
+-- Pattern Matching funktioniert ähnlich.
+-- Hier sind drei Definitionen von fib. Haskell wird automatisch
+-- die erste Funktionen nehmen die dem Pattern der Eingabe entspricht.
+fib 1 = 1
+fib 2 = 2
+fib x = fib (x - 1) + fib (x - 2)
+
+-- Pattern matching auf Tupeln:
+foo (x, y) = (x + 1, y + 2)
+
+-- Pattern matching auf Listen.
+-- `x` ist das erste Element der Liste und `xs` der Rest der Liste.
+-- Damit können wir unsere eigene map Funktion bauen:
+myMap func [] = []
+myMap func (x:xs) = func x:(myMap func xs)
+
+-- Anonyme Funktionen (Lambda-Funktionen) werden mit einem
+-- Backslash eingeleitet, gefolgt von allen Argumenten.
+myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7]
+
+-- Fold (`inject` in einigen Sprachen)
+-- Foldl1 bedeutet: fold von links nach rechts und nehme den ersten
+-- Wert der Liste als Basiswert f[r den Akkumulator.
+foldl1 (\acc x -> acc + x) [1..5] -- 15
+
+----------------------------------------------------
+-- 4. Mehr Funktionen
+----------------------------------------------------
+
+-- currying: Wenn man nicht alle Argumente an eine Funktion uebergibt,
+-- so wird sie eine neue Funktion gebildet ("curried").
+-- Es findet eine partielle Applikation statt und die neue Funktion
+-- nimmt die fehlenden Argumente auf.
+
+add a b = a + b
+foo = add 10 -- foo ist nun Funktion die ein Argument nimmt und 10 addiert
+foo 5 -- 15
+
+-- Ein alternativer Weg
+foo = (+10)
+foo 5 -- 15
+
+-- Funktionskomposition
+-- Die (.) Funktion verkettet Funktionen.
+-- Zum Beispiel, die Funktion Foo nimmt ein Argument addiert 10 dazu und
+-- multipliziert dieses Ergebnis mit 5.
+foo = (*5) . (+10)
+
+-- (5 + 10) * 5 = 75
+foo 5 -- 75
+
+
+-- Haskell hat eine Funktion `$`. Diese ändert den Vorrang,
+-- so dass alles links von ihr zuerst berechnet wird und
+-- und dann an die rechte Seite weitergegeben wird.
+-- Mit `.` und `$` kann man sich viele Klammern ersparen.
+
+-- Vorher
+(even (fib 7)) -- true
+
+-- Danach
+even . fib $ 7 -- true
+
+----------------------------------------------------
+-- 5. Typensystem
+----------------------------------------------------
+
+-- Haskell hat ein sehr starkes Typsystem.
+-- Alles hat einen Typ und eine Typsignatur.
+
+-- Einige grundlegende Typen:
+5 :: Integer
+"hello" :: String
+True :: Bool
+
+-- Funktionen haben genauso Typen.
+-- `not` ist Funktion die ein Bool annimmt und ein Bool zurueckgibt:
+-- not :: Bool -> Bool
+
+-- Eine Funktion die zwei Integer Argumente annimmt:
+-- add :: Integer -> Integer -> Integer
+
+-- Es ist guter Stil zu jeder Funktionsdefinition eine
+-- Typdefinition darueber zu schreiben:
+double :: Integer -> Integer
+double x = x * 2
+
+----------------------------------------------------
+-- 6. If-Anweisung und Kontrollstrukturen
+----------------------------------------------------
+
+-- If-Anweisung:
+haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome"
+
+-- If-Anweisungen können auch ueber mehrere Zeilen verteilt sein.
+-- Das Einruecken ist dabei äußerst wichtig.
+haskell = if 1 == 1
+ then "awesome"
+ else "awful"
+
+-- Case-Anweisung: Zum Beispiel "commandline" Argumente parsen.
+case args of
+ "help" -> printHelp
+ "start" -> startProgram
+ _ -> putStrLn "bad args"
+
+-- Haskell nutzt Rekursion anstatt Schleifen.
+-- map wendet eine Funktion auf jedes Element einer Liste an.
+
+map (*2) [1..5] -- [2, 4, 6, 8, 10]
+
+-- So kann man auch eine for-Funktion kreieren.
+for array func = map func array
+
+-- und so benutzt man sie:
+for [0..5] $ \i -> show i
+
+-- wir hätten sie auch so benutzen können:
+for [0..5] show
+
+-- foldl oder foldr reduziren Listen auf einen Wert.
+-- foldl <fn> <initial value> <list>
+foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43
+
+-- die Abarbeitung sieht so aus:
+(2 * (2 * (2 * 4 + 1) + 2) + 3)
+
+-- foldl ist linksseitig und foldr rechtsseitig.
+foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16
+
+-- die Abarbeitung sieht so aus:
+(2 * 3 + (2 * 2 + (2 * 1 + 4)))
+
+----------------------------------------------------
+-- 7. Datentypen
+----------------------------------------------------
+
+-- So kann man seine eigenen Datentypen in Haskell anlegen:
+
+data Color = Red | Blue | Green
+
+-- Nun können wir sie in einer Funktion benutzen.
+
+say :: Color -> String
+say Red = "You are Red!"
+say Blue = "You are Blue!"
+say Green = "You are Green!"
+
+-- Datentypen können auch Parameter aufnehmen:
+
+data Maybe a = Nothing | Just a
+
+-- Diese sind alle vom Typ Maybe:
+Just "hello" -- vom Typ `Maybe String`
+Just 1 -- vom Typ `Maybe Int`
+Nothing -- vom Typ `Maybe a` fuer jedes `a`
+
+----------------------------------------------------
+-- 8. Haskell IO
+----------------------------------------------------
+
+-- IO kann nicht völlig erklärt werden ohne Monaden zu erklären,
+-- aber man kann die grundlegenden Dinge erklären.
+
+-- Wenn eine Haskell Programm ausgefuehrt wird, so wird `main` aufgerufen.
+-- Diese muss etwas vom Typ `IO ()` zurueckgeben. Zum Beispiel:
+
+main :: IO ()
+main = putStrLn $ "Hello, sky! " ++ (say Blue)
+-- putStrLn hat den Typ String -> IO ()
+
+-- Es ist am einfachsten, wenn man sein Programm als Funktion von
+-- String nach String implementiert.
+-- Zum Beispiel die Funktion interact :: (String -> String) -> IO ()
+-- nimmt einen Text, tut etwas damit und gibt diesen wieder aus.
+
+countLines :: String -> String
+countLines = show . length . lines
+
+main' = interact countLines
+
+-- Man kann den Typ `IO ()` als Repräsentation einer Sequenz von
+-- Aktionen sehen, die der Computer abarbeiten muss.
+-- Wie bei einem Programm das in einer Imperativen Sprache geschreiben wurde.
+-- Mit der `do` Notation können Aktionen verbunden werden.
+
+sayHello :: IO ()
+sayHello = do
+ putStrLn "What is your name?"
+ name <- getLine -- eine Zeile wird geholt und
+ -- an die Variable "name" gebunden
+ putStrLn $ "Hello, " ++ name
+
+-- Uebung: Schreibe deine eigene Version von `interact`,
+-- die nur eine Zeile einliest.
+
+-- `sayHello` wird niemals ausgefuehrt, nur `main` wird ausgefuehrt.
+-- Um `sayHello` laufen zulassen kommentiere die Definition von `main`
+-- aus und ersetze sie mit:
+-- main = sayHello
+
+-- Lass uns untersuchen wie `getLine` arbeitet.
+-- Der Typ ist: getLine :: IO String
+-- Man kann sich vorstellen das der Wert vom Typ `IO a` ein
+-- Programm repräsentiert das etwas vom Typ `a` generiert.
+-- Der Wert wird mit `<-` gespeichert und kann wieder benutzt werden.
+-- Wir könne auch eigene Funktionen vom Typ `IO String` definieren:
+
+action :: IO String
+action = do
+ putStrLn "This is a line. Duh"
+ input1 <- getLine
+ input2 <- getLine
+ -- Der Typ von `do` ergibt sich aus der letzten Zeile.
+ -- `return` ist eine Funktion und keine Schluesselwort
+ return (input1 ++ "\n" ++ input2) -- return :: String -> IO String
+
+-- Nun können wir `action` wie `getLine` benutzen:
+
+main'' = do
+ putStrLn "I will echo two lines!"
+ result <- action
+ putStrLn result
+ putStrLn "This was all, folks!"
+
+-- Der Typ `IO` ist ein Beispiel fuer eine Monade.
+-- Haskell benutzt Monaden Seiteneffekte zu kapseln und somit
+-- eine rein funktional Sprache zu sein.
+-- Jede Funktion die mit der Außenwelt interagiert (z.B. IO)
+-- hat den Typ `IO` in seiner Signatur.
+-- Damit kann man zwischen "reinen" Funktionen (interagieren nicht
+-- mit der Außenwelt oder ändern ihren Zustand) und Anderen unterscheiden.
+
+-- Nebenläufigkeit ist in Haskell sehr einfach, da reine Funktionen
+-- leicht nebenläufig arbeiten können.
+
+----------------------------------------------------
+-- 9. Die Haskell REPL
+----------------------------------------------------
+
+-- Starte die REPL mit dem Befehl `ghci`
+-- Nun kann man Haskell Code eingeben.
+-- Alle neuen Werte muessen mit `let` gebunden werden:
+
+let foo = 5
+
+-- `:t` zeigt den Typen von jedem Wert an:
+
+>:t foo
+foo :: Integer
+
+-- Auch jede `IO ()` Funktion kann ausgefuehrt werden.
+
+> sayHello
+What is your name?
+Friend!
+Hello, Friend!
+
+```
+
+Es gibt noch viel mehr in Haskell, wie zum Beispiel Typklassen und Monaden.
+Dies sind die Ideen durch die Haskell Programmierung zum Spaß wird.
+Mit dem folgenden kleinen Beispiel werde ich euch verlassen:
+Quicksort in Haskell:
+
+```haskell
+qsort [] = []
+qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater
+ where lesser = filter (< p) xs
+ greater = filter (>= p) xs
+```
+
+Haskell ist sehr einfach zu installieren.
+Hohl es dir von [hier](http://www.haskell.org/platform/).
+
+Eine sehr viele langsamere Einfuehrung findest du unter:
+[Learn you a Haskell](http://learnyouahaskell.com/) oder
+[Real World Haskell](http://book.realworldhaskell.org/).
diff --git a/de-de/javascript-de.html.markdown b/de-de/javascript-de.html.markdown
index 0418b2b6..38ce28e2 100644
--- a/de-de/javascript-de.html.markdown
+++ b/de-de/javascript-de.html.markdown
@@ -397,8 +397,8 @@ var myNumberObj = new Number(12);
myNumber == myNumberObj; // = true
// Genau genommen: Sie sind nicht exakt äquivalent.
-typeof(myNumber); // = 'number'
-typeof(myNumberObj); // = 'object'
+typeof myNumber; // = 'number'
+typeof myNumberObj; // = 'object'
myNumber === myNumberObj; // = false
if (0){
// Dieser Teil wird nicht ausgeführt, weil 0 'falsy' ist.
diff --git a/de-de/markdown-de.html.markdown b/de-de/markdown-de.html.markdown
new file mode 100644
index 00000000..6a90980b
--- /dev/null
+++ b/de-de/markdown-de.html.markdown
@@ -0,0 +1,256 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators :
+ - ["Frederik Ring", "https://github.com/m90"]
+ - ["Philipp Fischbeck", "https://github.com/PFischbeck"]
+filename: markdown-de.md
+lang: de-de
+---
+
+Markdown wurde im Jahr 2004 von John Gruber kreiert. Ziel ist und war eine
+Syntax, in der sich Dokumente leicht schreiben *und* lesen lassen. Außerdem
+sollte Markdown sich leicht nach HTML (und in andere Formate) konvertieren
+lassen.
+
+```markdown
+<!-- Markdown ist eine Obermenge von HTML - jede valide HTML-Datei ist also
+automatisch valides Markdown - was heisst dass wir jedes HTML-Element (also auch
+Kommentare) in Markdown benutzen können, ohne dass der Parser sie verändert.
+Jedoch kann man innerhalb eines solchen HTML-Elements dann kein Markdown
+mehr verwenden. -->
+
+<!-- Es existieren unterschiedliche Markdown-Parser und -Dialekte, die sich in
+manchen Punkten unterscheiden. Diese Einführung wird versuchen, zu erläutern,
+welche Features überall verfügbar sind, und welche davon parser-spezifisch sind -->
+
+<!-- Überschriften -->
+<!-- HTML-Überschriften <h1> bis <h6> lassen sich einfach durch ein Voranstellen
+der entsprechenden Anzahl an Hashes (#) auszeichnen -->
+# Das ist eine <h1>
+## Das ist eine <h2>
+### Das ist eine <h3>
+#### Das ist eine <h4>
+##### Das ist eine <h5>
+###### Das ist eine <h6>
+
+<!-- Für die Elemente <h1> und <h2> gibt es in Markdown noch Sonderformen -->
+Das ist eine h1
+=============
+
+Das ist eine h2
+-------------
+
+<!-- Einfaches Textstyling -->
+<!-- Jeglicher Text lässt sich mit Markdown leicht als kursiv oder
+auch als fett auszeichnen -->
+
+*Dieser Text ist kursiv.*
+_Genau wie dieser._
+
+**Dieser Text ist fett.**
+__Genau wie dieser.__
+
+***Dieser Text ist beides***
+**_Dieser auch!_**
+*__Und dieser genau so!__*
+
+<!-- In "Github Flavored Markdown", dem von Github verwendeten Dialekt / Parser,
+gibt es auch noch durchgestrichenen Text: -->
+
+~~Dieser Text wird durchgestrichen dargestellt.~~
+
+<!-- Absätze sind eine oder mehrere zusammenhängende Zeilen Text, und werden
+durch eine oder mehrere Leerzeilen voneinander abgesetzt. -->
+
+Das ist ein Absatz. Ich kann immer noch nicht glauben, wie viel Spaß das macht !?!
+
+Jetzt bin ich schon bei Absatz 2.
+Hier ist dann immer noch Absatz 2!
+
+
+Jetzt ist das dann Nummer drei!
+
+<!-- Sollte man jemals ein <br />-Tag einfügen wollen, kann man einen Absatz
+mit zwei oder mehr Leerzeichen beenden, und danach einen neuen Absatz beginnen. -->
+
+Ich höre mit zwei Leerzeichen auf (markiere mich, und du siehst es).
+
+Über mir ist wohl ein <br />!
+
+<!-- Zitate werden ganz einfach mit einem > ausgezeichnet. -->
+
+> Das ist ein Zitat. Du kannst Zeilenumbrüche
+> entweder manuell hinzufügen und ein `>` vor jeder Zeile einfügen, oder du kannst deine Zeilen einfach immer länger und länger werden lassen, die Umbrüche werden dann automatisch erzeugt.
+> Solange sie mit einem `>` beginnen, macht das keinen Unterschied.
+
+> Auch möglich ist es, den Text
+>> mehrstufig einzurücken.
+> Nicht schlecht, oder?
+
+<!-- Listen -->
+<!-- <ul>s können mit Sternen, Pluszeichen oder Minuszeichen erzeugt werden -->
+
+* Punkt auf der Liste
+* Punkt auf der Liste
+* Anderer Punkt auf der Liste
+
+oder
+
++ Punkt auf der Liste
++ Punkt auf der Liste
++ Noch ein Punkt auf der Liste
+
+oder
+
+- Punkt auf der Liste
+- Punkt auf der Liste
+- Ein letzter Punkt auf der Liste
+
+<!-- <ol>s werden mit einer Zahl gefolgt von einem Punkt erzeugt -->
+
+1. Punkt eins
+2. Punkt zwei
+3. Punkt drei
+
+<!-- Auch wenn es keine gute Idee sein mag: du müsstest die einzelnen Punkte
+nicht mal korrekt numerieren -->
+
+1. Punkt eins
+1. Punkt zwei
+1. Punkt drei
+<!-- (Das sieht genau so aus wie das Beispiel eins weiter oben) -->
+
+<!-- Man kann Listen auch verschachteln -->
+
+1. Punkt eins
+2. Punkt zwei
+3. Punkt drei
+ * Unterpunkt
+ * Unterpunkt
+4. Punkt vier
+
+<!-- Code-Blöcke -->
+<!-- Blöcke von Programmcode (also ein <code>-Element) kannst du auszeichnen,
+indem du eine Zeile mit vier Leerzeichen oder einem Tabulator einrückst -->
+
+ Das ist Quellcode
+ Das hier auch
+
+<!-- Der Code kann natürlich auch wiederum eingerückt sein -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Innerhalb normalen Texts kannst du Code mit Backticks ` auszeichnen -->
+
+Hermann hatte nicht die leiseste Ahnung, was dieses `go_to()` bedeuten könnte!
+
+<!-- In "Github Flavored Markdown" gibt es für Code nocheinmal eine
+besondere Syntax -->
+
+\`\`\`ruby <!-- in "echt" musst du die Backslashes entfernen: ```ruby ! -->
+def foobar
+ puts "Hallo Welt!"
+end
+\`\`\` <!-- hier auch keine Backslashes, nur ``` -->
+
+<-- der obige Block muss nicht extra eingerückt werden, außerdem fügt Github
+Syntax-Highlighting für die nach dem ``` angegebene Sprache hinzu -->
+
+<!-- Horizontale Linie (<hr />) -->
+<!-- Trenner lassen sich einfach mit drei (oder mehr) Sternen oder Bindestrichen
+erzeugen (egal ob mit oder ohne Leerzeichen dazwischen)-->
+
+***
+---
+- - -
+****************
+
+<!-- Hyperlinks -->
+<!-- Eines der besten Features von Markdown ist das kinderleichte Erzeugen von
+Hyperlinks: Einfach den Linktext in eckige Klammern [] setzen, gefolgt von
+einer mit runden Klammern () umschlossenen URL. -->
+
+[Klick mich!](http://test.de/)
+
+<!-- Man kann dem Link auch noch ein title-Attribut geben -->
+
+[Klick mich!](http://test.at/ "Link zu Test.at")
+
+<!-- Relative Pfade funktionieren natürlich auch -->
+
+[Zu meiner Musiksammlung](/music/).
+
+<!-- URLs lassen sich auch über Referenzen festlegen -->
+
+[Klick mich][link1], um mehr über mich herauszufinden!
+[Hier kannst du auch mal draufklicken][foobar], wenn es dich interessiert.
+
+[link1]: http://test.de/ "Wahnsinn!"
+[foobar]: http://foobar.ch/ "Erstaunlich!"
+
+<!-- Das title-Attribut wird entweder mit Anführungszeichen oder Klammern
+umschlossen (oder gleich ganz weggelassen). Die Referenzen können an jeder
+Stelle im gesamtem Dokument vorkommen, als ID kann alles verwendet werden, solange
+es dokumentweit eindeutig ist. -->
+
+<!-- Man kann den Linktext auch als implizite Referenz benutzen -->
+
+[Das][] ist ein Link.
+
+[das]: http://dasisteinlink.at/
+
+<!-- Das ist aber eher unüblich. -->
+
+<!-- Bilder -->
+<!-- Bilder funktionieren genau wie Links, nur dass man noch ein Ausrufezeichen
+voranstellt! -->
+
+![Das ist das alt-Attribut für mein Bild](http://imgur.com/myimage.jpg "Hier noch ein title-Attribut")
+
+<!-- Referenzen funktionieren auch hier genau wie erwartet -->
+
+![Das ist das alt-Attribut][meinbild]
+
+[meinbild]: relative/urls/gehen/auch.jpg "hier wäre noch Platz für einen title"
+
+<!-- Bonusfeatures -->
+<!-- Auto-Links -->
+
+<http://testwebseite.de/> ist das selbe wie
+[http://testwebseite.de/](http://testwebseite.de/)
+
+<!-- Automatische Links für E-Mail-Addressen -->
+
+<foo@bar.com>
+
+<!-- Maskieren -->
+
+Ich würde *diesen Teil gerne mit Sternen umschließen*, doch ohne dass er kursiv
+wird. Also mache ich folgendes: \*Ich umschließe diesen Text mit Sternen\*!
+
+<!-- Tabellen -->
+<!-- Tabellen gibt es bis jetzt nur in "Github Flavored Markdown".
+Zudem sind sie ziemlich mühselig, aber wenn du es wirklich wissen willst: -->
+
+| Spalte1 | Spalte2 | Spalte3 |
+| :----------- | :------: | ------------: |
+| linksbündig | mittig | rechtsbündig |
+| blah | blah | blah |
+
+<!-- oder das selbe in grün: -->
+
+Spalte1 | Spalte2 | Spalte3
+:-- | :-: | --:
+Ganz schön hässlich | vielleicht doch lieber | wieder aufhören
+
+<!-- Das war's! -->
+
+```
+
+Mehr Informationen gibt es in [John Gruber's offiziellem Blog-Post](http://daringfireball.net/projects/markdown/syntax)
+und bei Adam Pritchards [grandiosem Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
+Infos zu Github Flavored Markdown [gibt es hier](https://help.github.com/articles/github-flavored-markdown). \ No newline at end of file
diff --git a/elixir.html.markdown b/elixir.html.markdown
index 0892deb7..0a20e3df 100644
--- a/elixir.html.markdown
+++ b/elixir.html.markdown
@@ -2,6 +2,7 @@
language: elixir
contributors:
- ["Joao Marques", "http://github.com/mrshankly"]
+ - ["Dzianis Dashkevich", "https://github.com/dskecse"]
filename: learnelixir.ex
---
@@ -59,7 +60,7 @@ tail #=> [2,3]
# the tuples have different sizes.
# {a, b, c} = {1, 2} #=> ** (MatchError) no match of right hand side value: {1,2}
-# There's also binaries
+# There are also binaries
<<1,2,3>> # binary
# Strings and char lists
@@ -108,7 +109,7 @@ div(10, 2) #=> 5
# To get the division remainder use `rem`
rem(10, 3) #=> 1
-# There's also boolean operators: `or`, `and` and `not`.
+# There are also boolean operators: `or`, `and` and `not`.
# These operators expect a boolean as their first argument.
true and true #=> true
false or true #=> true
@@ -119,7 +120,6 @@ false or true #=> true
1 || true #=> 1
false && 1 #=> false
nil && 20 #=> nil
-
!true #=> false
# For comparisons we have: `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` and `>`
@@ -165,12 +165,12 @@ case {:one, :two} do
{:four, :five} ->
"This won't match"
{:one, x} ->
- "This will match and assign `x` to `:two`"
+ "This will match and bind `x` to `:two`"
_ ->
"This will match any value"
end
-# It's common practice to assign a value to `_` if we don't need it.
+# It's common to bind the value to `_` if we don't need it.
# For example, if only the head of a list matters to us:
[head | _] = [1,2,3]
head #=> 1
@@ -190,7 +190,7 @@ cond do
"But I will"
end
-# It is common to see a last condition equal to `true`, which will always match.
+# It is common to see the last condition equal to `true`, which will always match.
cond do
1 + 1 == 3 ->
"I will never be seen"
@@ -201,7 +201,7 @@ cond do
end
# `try/catch` is used to catch values that are thrown, it also supports an
-# `after` clause that is invoked whether or not a value is catched.
+# `after` clause that is invoked whether or not a value is caught.
try do
throw(:hello)
catch
@@ -301,7 +301,7 @@ end
Recursion.sum_list([1,2,3], 0) #=> 6
# Elixir modules support attributes, there are built-in attributes and you
-# may also add custom attributes.
+# may also add custom ones.
defmodule MyMod do
@moduledoc """
This is a built-in attribute on a example module.
@@ -312,21 +312,24 @@ defmodule MyMod do
end
## ---------------------------
-## -- Records and Exceptions
+## -- Structs and Exceptions
## ---------------------------
-# Records are basically structures that allow you to associate a name with
-# a particular value.
-defrecord Person, name: nil, age: 0, height: 0
+# Structs are extensions on top of maps that bring default values,
+# compile-time guarantees and polymorphism into Elixir.
+defmodule Person do
+ defstruct name: nil, age: 0, height: 0
+end
-joe_info = Person.new(name: "Joe", age: 30, height: 180)
-#=> Person[name: "Joe", age: 30, height: 180]
+joe_info = %Person{ name: "Joe", age: 30, height: 180 }
+#=> %Person{age: 30, height: 180, name: "Joe"}
# Access the value of name
joe_info.name #=> "Joe"
# Update the value of age
-joe_info = joe_info.age(31) #=> Person[name: "Joe", age: 31, height: 180]
+older_joe_info = %{ joe_info | age: 31 }
+#=> %Person{age: 31, height: 180, name: "Joe"}
# The `try` block with the `rescue` keyword is used to handle exceptions
try do
@@ -358,9 +361,9 @@ f = fn -> 2 * 2 end #=> #Function<erl_eval.20.80484245>
spawn(f) #=> #PID<0.40.0>
# `spawn` returns a pid (process identifier), you can use this pid to send
-# messages to the process. To do message passing we use the `<-` operator.
+# messages to the process. To do message passing we use the `send` operator.
# For all of this to be useful we need to be able to receive messages. This is
-# achived with the `receive` mechanism:
+# achieved with the `receive` mechanism:
defmodule Geometry do
def area_loop do
receive do
@@ -378,11 +381,11 @@ end
pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0>
# Send a message to `pid` that will match a pattern in the receive statement
-pid <- {:rectangle, 2, 3}
+send pid, {:rectangle, 2, 3}
#=> Area = 6
# {:rectangle,2,3}
-pid <- {:circle, 2}
+send pid, {:circle, 2}
#=> Area = 12.56000000000000049738
# {:circle,2}
@@ -394,5 +397,7 @@ self() #=> #PID<0.27.0>
* [Getting started guide](http://elixir-lang.org/getting_started/1.html) from [elixir webpage](http://elixir-lang.org)
* [Elixir Documentation](http://elixir-lang.org/docs/master/)
+* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) by Dave Thomas
+* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf)
* ["Learn You Some Erlang for Great Good!"](http://learnyousomeerlang.com/) by Fred Hebert
-* "Programming Erlang: Software for a Concurrent World" by Joe Armstrong
+* ["Programming Erlang: Software for a Concurrent World"](https://pragprog.com/book/jaerlang2/programming-erlang) by Joe Armstrong
diff --git a/erlang.html.markdown b/erlang.html.markdown
index 065219ba..04086aeb 100644
--- a/erlang.html.markdown
+++ b/erlang.html.markdown
@@ -241,6 +241,45 @@ catcher(N) ->
% exception, it is converted into a tuple that describes the error.
catcher(N) -> catch generate_exception(N).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 4. Concurrency
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Erlang relies on the actor model for concurrency. All we need to write
+% concurrent programs in erlang are three primitives: spawning processes,
+% sending messages and receiving messages.
+
+% To start a new process we use the `spawn` function, which takes a function
+% as argument.
+
+F = fun() -> 2 + 2 end. % #Fun<erl_eval.20.67289768>
+spawn(F). % <0.44.0>
+
+% `spawn` returns a pid (process identifier), you can use this pid to send
+% messages to the process. To do message passing we use the `!` operator.
+% For all of this to be useful we need to be able to receive messages. This is
+% achieved with the `receive` mechanism:
+
+-module(calculateGeometry).
+-compile(export_all).
+calculateArea() ->
+ receive
+ {rectangle, W, H} ->
+ W * H;
+ {circle, R} ->
+ 3.14 * R * R;
+ _ ->
+ io:format("We can only calculate area of rectangles or circles.")
+ end.
+
+% Compile the module and create a process that evaluates `calculateArea` in the shell
+c(calculateGeometry).
+CalculateArea = spawn(calculateGeometry, calculateArea, []).
+CalculateArea ! {circle, 2}. % 12.56000000000000049738
+
+% The shell is also a process, you can use `self` to get the current pid
+self(). % <0.41.0>
+
```
## References
diff --git a/es-es/bash-es.html.markdown b/es-es/bash-es.html.markdown
new file mode 100644
index 00000000..fb89b2a0
--- /dev/null
+++ b/es-es/bash-es.html.markdown
@@ -0,0 +1,196 @@
+---
+category: tool
+tool: bash
+contributors:
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Darren Lin", "https://github.com/CogBear"]
+ - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
+ - ["Denis Arh", "https://github.com/darh"]
+ - ["akirahirose", "https://twitter.com/akirahirose"]
+ - ["Anton Strömkvist", "http://lutic.org/"]
+translators:
+ - ["Daniel Zendejas", "https://github.com/danielzendejas"]
+filename: LearnBash-es.sh
+lang: es-es
+---
+
+Tutorial de Shell en español.
+
+Bash es el nombre del shell de unix, el cual también es distribuido como
+el shell del sistema operativo GNU. También es el shell
+por defecto de Linux y Mac OS X. Casi todos los ejemplos abajo pueden
+ser parte de un script shell o ser ejecutados directamente en la terminal.
+
+[Leer más aquí.](http://www.gnu.org/software/bash/manual/bashref.html)
+
+```bash
+#!/bin/bash
+
+# La primera línea del script es el [shebang](http://en.wikipedia.org/wiki/Shebang_(Unix)) que le indica al sistema
+# cómo ejecutar el script.
+# Como te habrás dado cuenta, los comentarios en shell empiezan con #.
+# El shebang también es un comentario.
+
+# Ejemplo sencillo de hola mundo:
+echo ¡Hola mundo!
+
+# Cada comando empieza con una nueva línea, o después de un punto y coma:
+echo 'Esta es la primera línea'; echo 'Esta es la segunda línea'
+
+# Para declarar una variable se hace lo siguiente:
+VARIABLE="Mi string"
+
+# Pero no así:
+VARIABLE = "Mi string"
+
+# Bash decidirá que VARIABLE es un comando a ejecutar, dando un error.
+
+# Usando la variable:
+echo $VARIABLE
+echo "$VARIABLE"
+echo '$VARIABLE'
+
+# Cuando la variable es usada - o asignada, exportada, etcétera - se
+# escribe su nombre sin $. Si se quiere saber el valor de la variables,
+# entonces sí se usa $. Note que ' (comilla simple) no expandirá las
+# variables.
+
+# Sustitución de strings en variables.
+echo ${VARIABLE/Mi/Una}
+# Esto sustituirá la primera cadena "Mi" con "Una".
+
+# Substring de una variable.
+echo ${VARIABLE:0:7}
+# Esto va a regresar sólo los primeros 7 caracteres del valor.
+
+# Valor por defecto de una variable
+echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"}
+# Esto trabaja para null (VARIABLE=), string vacío (VARIABLE=""), }
+# cero (VARIABLE=0) regresa 0
+
+# Variables del sistema:
+# Aquí hay algunas variables incluídas en el sistema:
+echo "El valor de regreso del último programa: $?"
+echo "PID del sistema: $$"
+echo "Número de argumentos: $#"
+echo "Argumentos del script: $@"
+echo "Argumentos del script separados en variables: $1 $2..."
+
+# Para leer un valor del input:
+echo "¿Cuál es tu nombre?"
+read NOMBRE # Note que no necesitamos declarar una variable
+echo ¡Hola, $NOMBRE!
+
+# Tenemos la estructura 'if' usual:
+# use 'man test' para más información sobre condicionales
+if [ $NOMBRE -ne $USER ]
+then
+ echo "Tu nombre es tu usuario."
+else
+ echo "Tu nombre no es tu usuario."
+fi
+
+# También hay ejecuciones condicionadas.
+echo "Siempre ejecutado" || echo "Sólo ejecutado si el primer comando falla"
+echo "Siempre ejecutado" && echo "Sólo ejecutado si el primer comando NO falla"
+
+# Para usar && y || con condicionales, se necesitan
+# múltiples pares de corchetes:
+if [ $NOMBRE == "Steve" ] && [ $EDAD -eq 15 ]
+then
+ echo "Esto correrá si $NOMBRE es Steve Y $EDAD es 15."
+fi
+
+if [ $NOMBRE == "Daniya" ] || [ $NOMBRE == "Zach" ]
+then
+ echo "Esto correrá si $NOMBRE es Daniya O Zach."
+fi
+
+# Las expresiones se denotan con el siguiente formato:
+echo $(( 10 + 5 ))
+
+# A diferencia de otros lenguajes de programación, bash es shell , así que
+# funciona en un contexto de directorio actual. Puedes listar archivos y
+# directorios en un directorio actual con el comando 'ls':
+ls
+
+# Estos comandos tienen opciones que controlan su ejecución:
+ls -l # Lista todos los archivos y directorios en líneas distintas.
+
+# Los resultados del comando anterior pueden ser pasados al siguiente
+# como input. El comando 'grep' filtra el input con los comandos provistos.
+# Así es como podemos listar archivos .txt en el directorio actual:
+ls -l | grep "\.txt"
+
+# Puedes también redireccionar el input y el error lanzado de algún comando.
+python2 hello.py < "input.in"
+python2 hello.py > "output.out"
+python2 hello.py 2> "error.err"
+
+# El error lanzado eliminará el contenido del archivo si es que existe,
+# para después escribir el error. Para que se concatene (en lugar de eliminar)
+# use el comando ">>".
+
+# Los comandos pueden ser sustituidos dentro de otros comandos usando $():
+# El siguiente ejemplo despliega el número de archivos y directorios en el
+# directorio actual.
+echo "Hay $(ls | wc -l) elementos aquí."
+
+# Lo mismo puede ser hecho usando comillas invertidas `` pero no pueden ser
+# anidadas. El método preferido es $().
+echo "Hay `ls | wc -l` elementos aquí."
+
+# Bash usa una estructura de casos similar al switch de Java o C++:
+case "$VARIABLE" in
+ # Lista de patrones que las condiciones deben cumplir:
+ 0) echo "Hay un cero.";;
+ 1) echo "Hay un uno.";;
+ *) echo "No es null.";;
+esac
+
+# Para los ciclos, se usa la estructura 'for'. Cicla para cada argumento dado:
+# El contenido de $VARIABLE se imprime tres veces.
+for VARIABLE in {1..3}
+do
+ echo "$VARIABLE"
+done
+
+# ciclos while:
+while [true]
+do
+ echo "cuerpo del ciclo..."
+ break
+done
+
+# También se pueden definir sub-rutinas (funciones)
+# Definición:
+function miFuncion ()
+{
+ echo "Los argumentos trabajan igual que argumentos de script: $@"
+ echo "Y: $1 $2..."
+ echo "Esto es una función"
+ return 0
+}
+
+# O simplemente:
+miOtraFuncion ()
+{
+ echo "¡Otra forma de declarar funciones!"
+ return 0
+}
+
+# Para llamar a tu función
+foo "Mi nombre es:" $NOMBRE
+
+# Hay muchos comandos útiles que puedes aprender:
+# imprime las últimas 10 líneas del archivo file.txt
+tail -n 10 file.txt
+# imprime las primeras 10 líneas del archivo file.txt
+head -n 10 file.txt
+# ordena las líneas del archivo file.txt
+sort file.txt
+# identifica u omite las líneas repetidas, con -d las reporta
+uniq -d file.txt
+# imprime sólo la primera columna antes de cada ',' en el archivo|
+cut -d ',' -f 1 file.txt
+```
diff --git a/es-es/brainfuck-es.html.markdown b/es-es/brainfuck-es.html.markdown
new file mode 100644
index 00000000..e33d672d
--- /dev/null
+++ b/es-es/brainfuck-es.html.markdown
@@ -0,0 +1,87 @@
+---
+language: brainfuck
+contributors:
+ - ["Prajit Ramachandran", "http://prajitr.github.io/"]
+ - ["Mathias Bynens", "http://mathiasbynens.be/"]
+translators:
+ - ["Daniel Zendejas", "https://github.com/DanielZendejas"]
+lang: es-es
+---
+
+Brainfuck (con mayúscula sólo al inicio de una oración) es un
+lenguaje de programación mínimo, computacionalmente universal
+en tamaño con sólo 8 comandos.
+
+```
+
+Cualquier caracter que no sea "><+-.,[]" (sin incluir las comillas)
+será ignorado.
+
+Brainfuck es representado por un arreglo de 30,000 celdas inicializadas
+en cero y un apuntador en la celda actual.
+
+Existen ocho comandos:
+
++ : Incrementa 1 al valor de la celda actual.
+- : Decrementa 1 al valor de la celda actual.
+> : Mueve el apuntador a la siguiente celda. (a la derecha)
+< : Mueve el apuntador a la celda anterior. (a la izquierda)
+. : Imprime el valor en ASCII de la celda actual (i.e. 65 = 'A')
+, : Lee un caracter como input y lo escribe en la celda actual.
+[ : Si el valor en la celda actual es cero mueve el apuntador
+ hasta el primer ']' que encuentre. Si no es cero sigue a la
+ siguiente instrucción.
+] : Si el valor en la celda actual es cero, entonces sigue con
+ la siguiente instrucción. Si no entonces mueve el apuntador
+ hacia atrás hasta encontrar el primer '['.
+
+[ y ] forman un while. Obviamente, deben estar balanceados.
+
+Ahora unos ejemplos de programas escritos con brainfuck.
+
+++++++ [ > ++++++++++ < - ] > +++++ .
+
+Este programa imprime la letra 'A'. Primero, incrementa la celda #1 a
+6. La celda #1 será usada para hacer los ciclos. Después entra al ciclo
+([) y se mueve a la celda #2 (>). Después incrementa la celda #2 10 veces,
+y se regresa a la celda #1 (<), para después decrementarla en 1 (-).
+Este ciclo ocurre 6 veces (le toma 6 decrementos a la celda #1 volverse 0),
+cuando esto pasa se salta a (]) y continúa.
+
+En este punto estamos en la celda #1, que tiene un valor de 0, mientras
+que la celda #2 tiene un valor de 60. Nos movemos a la celda #2 (>),
+la incrementamos 5 veces para tener un valor de 65 y luego imprimimos
+el valor de la celda #2 (.). 65 es 'A' en ASCII así que la letra 'A'
+se imprime.
+
+, [ > + < - ] > .
+
+Este programa lee un caracter del input y lo copia en la celda #2 (,).
+Después empieza un ciclo. Nos movemos a la celda #2 (>) e incrementamos su
+valor (+). Regresamos a la celda #1 y decrementamos su valor en 1 (-).
+Esto continúa hasta que la celda #1 contenga un cero. Cuando #1 contenga un
+cero la celda #2 tendrá el valor inicial de #1. Como este ciclo siempre
+terminara en la celda #1 nos movemos a la celda #2 e imprimimos (.).
+
+Ten en mente que los espacios son sólo para fines de legibilidad.
+Es lo mismo escribir el ejemplo de arriba que esto:
+,[>+<-]>.
+
+Intenta descrifrar lo que hace este programa:
+
+,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
+
+Este programa toma dos números como input y los multiplica.
+
+Primero recibe dos números del usuario. Luego empieza el ciclo externo,
+condicionado en la celda #1. Luego se mueve a la celda #2, comenzando
+el ciclo interno condicionado en la celda #2 incrementando la celda #3.
+Sin embargo viene un problema: El ciclo interior no funcionará nuevamente
+hasta la próxima vez. Para resolver este problema también incrementamos la
+celda #4 y luego copiamos la celda #4 a la celda #2. La celda #3 contiene
+el resultado.
+```
+Y eso es brainfuck. ¿No tan difícil o sí? Como diversión, puedes escribir
+tu propio intérprete de brainfuck o tu propio programa en brainfuck. El
+intérprete es relativamente sencillo de hacer, pero si eres masoquista,
+intenta construir tu proprio intérprete de brainfuck... en brainfuck.
diff --git a/es-es/css-es.html.markdown b/es-es/css-es.html.markdown
new file mode 100644
index 00000000..31000785
--- /dev/null
+++ b/es-es/css-es.html.markdown
@@ -0,0 +1,244 @@
+---
+language: css
+filename: learncss-es.css
+contributors:
+ - ["Mohammad Valipour", "https://github.com/mvalipour"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["Daniel Zendejas","https://github.com/DanielZendejas"]
+lang: es-es
+---
+
+Tutorial de CSS en español
+
+En los primeros días de la web no había elementos visuales, todo
+era texto plano. Pero después, con el desarrollo de los navegadores,
+las páginas con contenido visual empezaron a ser más comunes.
+CSS es el lenguaje estándar que existe para separar el contenido
+(HTML) y el aspecto visual de las páginas web.
+
+Lo que CSS hace es proveer con una sintaxis que te permite apuntar a distintos
+elementos HTML y asignarles diferentes propiedades visuales.
+
+CSS, como cualquier otro lenguaje, tiene múltiples versiones. Aquí nos enfocamos
+en CSS 2.0. No es la versión más reciente pero sí la más soportada y compatible.
+
+**NOTA:** Como los resultados de CSS son efectos visuales, para aprenderlo,
+necesitarás probar todo tipo de cosas en ambientes como
+[dabblet](http://dabblet.com/). Este artículo se enfoca, principalmente, en
+la sintaxis y consejos generales.
+
+```css
+/* ¡Los comentarios aparecen dentro de diagonal-asterisco, justo como esta línea! */
+
+/* ####################
+ ## SELECTORES
+ ####################*/
+
+/* Generalmente, la sentencia principal en CSS es muy simple. */
+selector { propiedad: valor; /* más propiedades separados por punto y coma...*/ }
+
+/* El selector es usado para apuntar a (seleccionar) un elemento en la página.
+
+¡Puedes apuntar a todos los elementos en la página con el asterisco! */
+* { color:red; }
+
+/*
+Dado un elemento como este en la página:
+
+<div class='una-clase clase2' id='unaId' attr='valor' />
+*/
+
+/* puedes seleccionar el <div> por el nombre de su clase */
+.una-clase { }
+
+/*¡O por sus dos clases! */
+.una-clase.clase2 { }
+
+/* O por el nombre de su elemento */
+div { }
+
+/* O por su Id */
+#unaId { }
+
+/* ¡O por el hecho de que tiene un atributo! */
+[attr] { font-size:smaller; }
+
+/* O por el hecho de que el atributo tiene un valor determinado */
+[attr='valor'] { font-size:smaller; }
+
+/* Empieza con un valor ('val' en este caso)*/
+[attr^='val'] { font-size:smaller; }
+
+/* O termina con un valor ('or' en este caso) */
+[attr$='or'] { font-size:smaller; }
+
+/* O incluso contiene un valor ('lo' en este caso) */
+[attr~='lo'] { font-size:smaller; }
+
+/*Más importante, puedes combinar estos criterios de búsqueda entre sí.
+No debe existir ningún espacio entre estas partes porque hace que el
+significado cambie.*/
+div.una-clase[attr$='or'] { }
+
+/* También puedes seleccionar un elemento HTML basándote en sus padres*/
+
+/* Un elemento que es hijo directo de otro elemento (Seleccionado de la forma que
+vimos anteriormente) */
+
+div.un-padre > .nombre-clase {}
+
+/* O cualquiera de sus ancestros en la jerarquía*/
+/* La siguiente sentencia selecciona a cualquier elemento que tenga una clase
+"nombre-clase" y sea hijo de un div con clase "un-padre" EN CUALQUIER PROFUNDIDAD*/
+div.un-padre .nombre-clase {}
+
+/* advertencia: el mismo selector sin espacio tiene otro significado. ¿Puedes
+identificar la diferencia?*/
+
+/* También puedes seleccionar un elemento basado en su hermano inmediato previo*/
+.yo-estoy-antes + .este-elemento { }
+
+/*o cualquier hermano previo */
+.yo-soy-cualquiera-antes ~ .estes-elemento {}
+
+/* Existen algunas pseudo-clases que permiten seleccionar un elemento
+basado en el comportamiendo de la página (a diferencia de la estructura de
+la página) */
+
+/* Por ejemplo, para cuando pasas el mouse por encima de un elemento */
+:hover {}
+
+/* o una liga visitada*/
+:visited {}
+
+/* o una liga no visitada aún*/
+:link {}
+
+/* o un elemento de un formulario que esté seleccionado */
+:focus {}
+
+
+/* ####################
+ ## PROPIEDADES
+ ####################*/
+
+selector {
+
+ /* Unidades */
+ width: 50%; /* en porcentaje */
+ font-size: 2em; /* dos veces el tamaño de la fuente actual */
+ width: 200px; /* en pixeles */
+ font-size: 20pt; /* en puntos */
+ width: 5cm; /* en centimetros */
+ width: 50mm; /* en milimetros */
+ width: 5in; /* en pulgadas */
+
+ /* Colores */
+ background-color: #F6E; /* en hexadecimal corto */
+ background-color: #F262E2; /* en hexadecimal largo */
+ background-color: tomato; /* puede ser un color con nombre */
+ background-color: rgb(255, 255, 255); /* en rgb */
+ background-color: rgb(10%, 20%, 50%); /* en rgb percent */
+ background-color: rgba(255, 0, 0, 0.3); /* en rgb semi-transparente (con valor alfa)*/
+
+ /* Imagenes */
+ background-image: url(/ruta-a-la-imagen/imagen.jpg);
+
+ /* Fuentes */
+ font-family: Arial;
+ font-family: "Courier New"; /* si el nombre contiene espacios, debe ir entre comillas */
+ font-family: "Courier New", Trebuchet, Arial; /* si la primera fuente no se encontró
+ entonces se busca la seguna, o la tercera, así recursivamente*/
+}
+
+```
+
+## Uso
+
+Guarda cualquier CSS que quieras en un archivo con extensión `.css`.
+
+```xml
+<!-- Necesitas incluir tu archivo CSS en el elemento <head> de tu HTML: -->
+<link rel='stylesheet' type='text/css' href='ruta/archivoDeEstilos.css' />
+
+<!--
+también puedes incluir CSS dentro del archivo HTML. Esta no es una buena práctica
+y debe ser evitada.
+-->
+<style>
+ selector { propiedad:valor; }
+</style>
+
+<!--
+También se pueden aplicar propiedades al elemento directamente.
+Esta práctica también debe ser evitada a toda costa
+-->
+<div style='propiedad:valor;'>
+</div>
+
+```
+
+## Preferencia y orden
+
+Como te habrás dado cuenta un elemento puede ser seleccionado por más
+de un selector. En este caso alguna de las reglas cobra preferencia
+sobre las otras:
+
+Dado el siguiente CSS:
+
+```css
+/*A*/
+p.clase1[attr='valor']
+
+/*B*/
+p.clase1 {}
+
+/*C*/
+p.clase2 {}
+
+/*D*/
+p {}
+
+/*E*/
+p { propiedad: valor !important; }
+
+```
+
+Y el siguiente HTML:
+
+```xml
+<p style='/*F*/ propiedad:valor;' class='clase1 clase2' attr='valor'>
+</p>
+```
+
+El orden respetado es el siguiente:
+Recuerda, la preferencia es por cada **property**, no para el bloque completo.
+
+* `E` tiene la preferencia más elevada gracias a la palabra `!important`.
+ Es recomendado evitar esto a menos que sea estrictamente necesario incluirlo.
+* `F` le sigue, porque es estilo incrustado directamente en el HTML.
+* `A` le sigue, porque es más específico que cualquier otra opción.
+ más específico = más especificadores. Aquí hay tres especificadores: elemento `p` +
+ nombre de la clase `clase1` + un atributo `attr='valor'`
+* `C` le sigue. Aunque tiene el mismo número de especificadores como `B`
+ pero aparece después.
+* Luego va `B`
+* y al final `D`.
+
+## Compatibilidad
+
+La mayoría de las funcionalidades de CSS2 (y gradualmente de CSS3) son compatibles
+en todos los navegadores y dispositivos. Pero siempre es vital tener en mente la
+compatibilidad y disponibilidad del CSS que uses con respecto a los navegadores
+y dispositivos para los que desarrolles.
+
+
+[QuirksMode CSS](http://www.quirksmode.org/css/) es una excelente referencia para esto.
+
+## Referencias
+
+* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
+* [QuirksMode CSS](http://www.quirksmode.org/css/)
+* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
+
diff --git a/es-es/go-es.html.markdown b/es-es/go-es.html.markdown
index e788e810..86de33ec 100644
--- a/es-es/go-es.html.markdown
+++ b/es-es/go-es.html.markdown
@@ -77,7 +77,7 @@ func learnTypes() {
saltos de línea.` // mismo tipo cadena
// Literal no ASCII. Los fuentes de Go son UTF-8.
- g := 'Σ' // Tipo rune, un alias de uint32, alberga un punto unicode.
+ g := 'Σ' // Tipo rune, un alias de int32, alberga un punto unicode.
f := 3.14195 // float64, el estándar IEEE-754 de coma flotante 64-bit.
c := 3 + 4i // complex128, representado internamente por dos float64.
// Sintaxis Var con inicializadores.
diff --git a/es-es/javascript-es.html.markdown b/es-es/javascript-es.html.markdown
new file mode 100644
index 00000000..a1348508
--- /dev/null
+++ b/es-es/javascript-es.html.markdown
@@ -0,0 +1,530 @@
+---
+language: javascript
+contributors:
+ - ["Adam Brenecki", "http://adam.brenecki.id.au"]
+ - ["Ariel Krakowski", "http://www.learneroo.com"]
+translators:
+ - ["Daniel Zendejas","https://github.com/DanielZendejas"]
+filename: javascript-es.js
+lang: es-es
+---
+Tutorial de JavaScript en español.
+
+JavaScript fue creado por Brendan Eich en 1995 mientras trabajaba en Netscape.
+Su intención original era crear un lenguaje simple para sitios web, complementándolo
+con Java para aplicaciones más complejas. Debido a su integracion estrecha con sitios
+web y soporte por defecto de los navegadores modernos se ha vuelto mucho más común
+para front-end que Java.
+
+JavaScript no sólo se limita a los navegadores web:
+* Node.js: Un proyecto que provee con un ambiente para el motor V8 de Google Chrome.
+
+¡La retroalimentación es bienvenida! Puedes encontrarme en:
+[@adambrenecki](https://twitter.com/adambrenecki), o
+[adam@brenecki.id.au](mailto:adam@brenecki.id.au).
+
+```js
+// Los comentarios son como en C. Los comentarios de una sola línea comienzan con //,
+/* y los comentarios multilínea comienzan
+ y terminan con */
+
+// Cada sentencia puede ser terminada con punto y coma ;
+hazAlgo();
+
+// ... aunque no es necesario, ya que el punto y coma se agrega automaticamente
+// cada que se detecta una nueva línea, a excepción de algunos casos.
+hazAlgo()
+
+// Dado que esta práctica puede llevar a resultados inesperados, seguiremos agregando
+// punto y coma en esta guía.
+
+///////////////////////////////////
+// 1. Números, Strings y Operadores
+
+// JavaScript tiene un solo tipo de número (doble de 64-bit IEEE 754).
+// Así como con Lua, no te espantes por la falta de enteros: los dobles tienen 52 bits
+// de mantisa, lo cual es suficiente para guardar enteros de hasta 9✕10¹⁵.
+3; // = 3
+1.5; // = 1.5
+
+// Toda la aritmética básica funciona como uno esperaría.
+1 + 1; // = 2
+8 - 1; // = 7
+10 * 2; // = 20
+35 / 5; // = 7
+
+// Incluyendo divisiones con resultados no enteros.
+5 / 2; // = 2.5
+
+// Las operaciones con bits también funcionan; cuando ejecutas una operación con bits
+// el número flotante se convierte a entero con signo *hasta* 32 bits.
+1 << 2; // = 4
+
+// La jerarquía de las operaciones se aplica con paréntesis.
+(1 + 3) * 2; // = 8
+
+// Hay tres casos especiales de valores con los números:
+Infinity; // por ejemplo: 1/0
+-Infinity; // por ejemplo: -1/0
+NaN; // por ejemplo: 0/0
+
+// También hay booleanos:
+true;
+false;
+
+// Los Strings se pueden crear con ' o ".
+'abc';
+"Hola, mundo";
+
+// La negación se aplica con la expresión !
+!true; // = false
+!false; // = true
+
+// Para comprobar una igualdad se usa ==
+1 == 1; // = true
+2 == 1; // = false
+
+// Para comprobar una desigualdad se usa !=
+1 != 1; // = false
+2 != 1; // = true
+
+// Más comparaciones
+1 < 10; // = true
+1 > 10; // = false
+2 <= 2; // = true
+2 >= 2; // = true
+
+// Los Strings se concatenan con +
+"¡Hola " + "mundo!"; // = "¡Hola mundo!"
+
+// y se comparan con < y con >
+"a" < "b"; // = true
+
+// Los tipos no importan con el operador ==...
+"5" == 5; // = true
+
+// ...a menos que uses ===
+"5" === 5; // = false
+
+// Los Strings funcionan como arreglos de caracteres
+// Puedes accesar a cada caracter con la función charAt()
+"Este es un String".charAt(0); // = 'E'
+
+// ...o puedes usar la función substring() para acceder a pedazos más grandes
+"Hola Mundo".substring(0, 4); // = "Hola"
+
+// length es una propiedad, así que no uses ()
+"Hola".length; // = 4
+
+// También hay null y undefined
+null; // usado para indicar una falta de valor deliberada
+undefined; // usado para indicar que un valor no está presente actualmente
+ // (aunque undefined es un valor en sí mismo)
+
+// false, null, undefined, NaN, 0 y "" es false; todo lo demás es true.
+// Note que 0 is false y "0" es true, a pesar de que 0 == "0".
+// Aunque 0 === "0" sí es false.
+
+///////////////////////////////////
+// 2. Variables, Arreglos y Objetos
+
+// Las variables se declaran con la palabra var. JavaScript cuenta con tipado dinámico,
+// así que no se necesitan aplicar tipos. La asignación se logra con el operador =.
+var miPrimeraVariable = 5;
+
+// si no escribes la palabra var no se marcará ningún error...
+miSegundaVariable = 10;
+
+// ...pero tu variable se declarará en el ámbito global, no en el ámbito
+// en el que se definió.
+
+// Las variables que no están aún asignadas tienen el valor undefined.
+var miTerceraVariable; // = undefined
+
+// Existen atajos para realizar operaciones aritméticas:
+miPrimeraVariable += 5; // equivalente a miPrimeraVariable = miPrimeraVariable + 5;
+ // miPrimeraVariable ahora es 10
+miPrimeraVariable *= 10; // ahora miPrimeraVariable es 100
+
+// Y atajos aún más cortos para sumar y restar 1
+miPrimeraVariable++; // ahora miPrimeraVariable es 101
+miPrimeraVariable--; // de vuelta a 100
+
+// Los arreglos son listas ordenadas de valores, de cualquier tipo.
+var miArreglo = ["Hola", 45, true];
+
+// Los miembros de un arreglo pueden ser accesados con la sintaxis
+// de indices dentro de corchetes [].
+// Los índices empiezan en cero.
+miArreglo[1]; // = 45
+
+// Los arreglos son mutables y pueden cambiar de longitud.
+miArreglo.push("Mundo");
+miArreglo.length; // = 4
+
+// Agregar/Modificar en un determinado índice
+miArreglo[3] = "Hola";
+
+// Los objetos en JavaScript son equivalentes a los 'diccionarios' o 'mapas' en otros
+// lenguajes: una colección de pares llave/valor desordenada.
+var miObjeto = {llave1: "Hola", llave2: "Mundo"};
+
+// Las llaves son strings, pero no se necesitan las comillas si son un identificador
+// válido de JavaScript. Los valores pueden ser de cualquier tipo.
+var miObjeto = {miLlave: "miValor", "mi otra llave": 4};
+
+// Los atributos de los objetos también pueden ser accesadas usando
+// la sintaxis de corchetes,
+miObjeto["mi otra llave"]; // = 4
+
+// ... o usando la sintaxis de punto, dado que la llave es un identificador válido.
+miObjeto.miLlave; // = "miValor"
+
+// Los objetos son mutables; los valores pueden ser cambiados y se pueden
+// agregar nuevas llaves.
+miObjeto.miTerceraLlave = true;
+
+// Si intentas accesar con una llave que aún no está asignada tendrás undefined.
+miObjeto.miCuartaLlave; // = undefined
+
+///////////////////////////////////
+// 3. Lógica y estructura de control
+
+// La sintaxis de esta sección es casi idéntica a la de Java.
+
+// La estructura if funciona de la misma forma.
+var contador = 1;
+if (contador == 3){
+ // evaluar si contador es igual a 3
+} else if (contador == 4){
+ // evaluar si contador es igual a 4
+} else {
+ // evaluar si contador no es igual a 3 ni a 4
+}
+
+// De la misma forma la estructura while.
+while (true){
+ // ¡Loop infinito!
+}
+
+// La estructura Do-while es igual al while, excepto que se ejecuta al menos una vez.
+var input
+do {
+ input = conseguirInput();
+} while (!esValido(input))
+
+// la esctructura for es la misma que la de C y Java:
+// inicialización; condición; iteración.
+for (var i = 0; i < 5; i++){
+ // correrá cinco veces
+}
+
+// && es un "y" lógico, || es un "o" lógico
+var casa = {tamano:"grande",casa:"color"};
+if (casa.tamano == "grande" && casa.color == "azul"){
+ casa.contiene = "oso";
+}
+if (color == "rojo" || color == "azul"){
+ // el color es rojo o azul
+}
+
+// && y || "corto circuito", lo cual es útil para establecer valores por defecto.
+var nombre = otroNombre || "default";
+
+
+// la estructura switch usa === para sus comparaciones
+// usa 'break' para terminar cada caso
+// o los casos después del caso correcto serán ejecutados también.
+calificacion = 'B';
+switch (calificacion) {
+ case 'A':
+ console.log("Excelente trabajo");
+ break;
+ case 'B':
+ console.log("Buen trabajo");
+ break;
+ case 'C':
+ console.log("Puedes hacerlo mejor");
+ break;
+ default:
+ console.log("Muy mal");
+ break;
+}
+
+
+///////////////////////////////////
+// 4. Funciones, ámbitos y closures
+
+// Las funciones en JavaScript son declaradas con la palabra clave "function".
+function miFuncion(miArgumentoString){
+ return miArgumentoString.toUpperCase(); //la funcion toUpperCase() vuelve todo
+ // el String a mayúsculas
+}
+miFuncion("foo"); // = "FOO"
+
+// Note que el valor a ser regresado debe estar en la misma línea que la
+// palabra clave 'return', de otra forma la función siempre regresará 'undefined'
+// debido a la inserción automática de punto y coma.
+function miFuncion()
+{
+ return // <- punto y coma insertado aquí automáticamente
+ {
+ estaEsUna: 'propiedad'
+ }
+}
+miFuncion(); // = undefined al mandar a llamar la función
+
+// Las funciones en JavaScript son de primera clase, así que pueden ser asignadas
+// a variables y pasadas a otras funciones como argumentos - por ejemplo:
+function miFuncion(){
+ // este código será llamado cada cinco segundos
+}
+setTimeout(miFuncion, 5000);
+// Note: setTimeout no es parte de JS, pero lo puedes obtener de los browsers
+// y Node.js.
+
+// Es posible declarar funciones sin nombre - se llaman funciones anónimas
+// y se definen como argumentos de otras funciones.
+setTimeout(function(){
+ // este código se ejecuta cada cinco segundos
+}, 5000);
+
+// JavaScript tiene ámbitos de funciones; las funciones tienen su propio ámbito pero
+// otros bloques no.
+if (true){
+ var i = 5;
+}
+i; // = 5 - en un lenguaje que da ámbitos por bloque esto sería undefined, pero no aquí.
+
+// Este conlleva a un patrón de diseño común llamado "ejecutar funciones anónimas
+//inmediatamente", que preveé variables temporales de fugarse al ámbito global
+(function(){
+ var temporal = 5;
+ // Podemos accesar al ámbito global asignando al 'objeto global', el cual
+ // en un navegador siempre es 'window'. El objeto global puede tener
+ // un nombre diferente en ambientes distintos, por ejemplo Node.js .
+ window.permanente = 10;
+})();
+temporal; // da ReferenceError
+permanente; // = 10
+
+// Una de las características más útiles de JavaScript son los closures.
+// Si una función es definida dentro de otra función, la función interna tiene acceso
+// a todas las variables de la función externa, incluso aunque la función
+// externa ya haya terminado.
+function decirHolaCadaCincoSegundos(nombre){
+ var texto = "¡Hola, " + nombre + "!";
+ // Las funciones internas son puestas en el ámbito local por defecto
+ // como si fueran declaradas con 'var'.
+ function interna(){
+ alert(texto);
+ }
+ setTimeout(interna, 5000);
+ // setTimeout es asíncrono, así que la funcion decirHolaCadaCincoSegundos
+ // terminará inmediatamente, y setTimeout llamará a interna() a los cinco segundos
+ // Como interna está "cerrada dentro de" decirHolaCadaCindoSegundos, interna todavía tiene
+ // acceso a la variable 'texto' cuando es llamada.
+}
+decirHolaCadaCincoSegundos("Adam"); // mostrará una alerta con "¡Hola, Adam!" en 5s
+
+///////////////////////////////////
+// 5. Más sobre objetos; constructores y prototipos
+
+// Los objetos pueden contener funciones.
+var miObjeto = {
+ miFuncion: function(){
+ return "¡Hola Mundo!";
+ }
+};
+miObjeto.miFuncion(); // = "¡Hola Mundo!"
+
+// Cuando las funciones de un objeto son llamadas, pueden accesar a las variables
+// del objeto con la palabra clave 'this'.
+miObjeto = {
+ miString: "¡Hola Mundo!",
+ miFuncion: function(){
+ return this.miString;
+ }
+};
+miObjeto.miFuncion(); // = "¡Hola Mundo!"
+
+// Las funciones de un objeto deben ser llamadas dentro del contexto de ese objeto.
+var miFuncion = myObj.miFuncion;
+miFuncion(); // = undefined
+
+// Una función puede ser asignada al objeto y ganar acceso a él gracias a esto,
+// incluso si no estaba dentro del objeto cuando este se definió.
+var miOtraFuncion = function(){
+ return this.miString.toUpperCase();
+}
+miObjeto.miOtraFuncion = myOtherFunc;
+miObjeto.miOtraFuncion(); // = "¡HOLA MUNDO!"
+
+// Podemos especificar el contexto en el que una función será llamada con los comandos
+// 'call' o 'apply'.
+
+var otraFuncion = function(otroString){
+ return this.miString + otroString;
+}
+otraFuncion.call(miObjeto, " y hola Luna!"); // = "¡Hola Mundo! y hola Luna!"
+
+// 'apply' es casi idéntico, pero recibe un arreglo como argumento.
+
+otraFuncion.apply(miObjeto, [" y hola Sol!"]); // = "¡Hola Mundo! y hola Sol!"
+
+// Esto es útil cuando estás trabajando con una función que acepta una secuencia de
+// argumentos y quieres pasar un arreglo.
+
+Math.min(42, 6, 27); // = 6
+Math.min([42, 6, 27]); // = NaN (uh-oh!)
+Math.min.apply(Math, [42, 6, 27]); // = 6
+
+// Pero 'call' y 'apply' sólo son temporales. Cuando queremos que se quede, usamos bind.
+
+var funcionUnida = otraFuncion.bind(miObjeto);
+funcionUnida(" y hola Saturno!"); // = "¡Hola Mundo! y hola Saturno!"
+
+// Bind también puede ser usada para aplicar parcialmente (curry) una función.
+
+var producto = function(a, b){ return a * b; }
+var porDos = producto.bind(this, 2);
+porDos(8); // = 16
+
+// Cuando llamas a una función con la palabra clave 'new' un nuevo objeto es creado.
+// Se hace disponible a la función. Las funciones diseñadas para ser usadas así se
+// llaman constructores.
+
+var MiConstructor = function(){
+ this.miNumero = 5;
+}
+miNuevoObjeto = new MiConstructor(); // = {miNumero: 5}
+miNuevoObjeto.miNumero; // = 5
+
+// Todos los objetos JavaScript tienen un 'prototipo'. Cuando vas a accesar a una
+// propiedad en un objeto que no existe en el objeto el intérprete buscará en
+// el prototipo.
+
+// Algunas implementaciones de JavaScript te permiten accesar al prototipo de
+// un objeto con la propiedad __proto__. Mientras que esto es útil para explicar
+// prototipos, no es parte del estándar; veremos formas estándar de usar prototipos
+// más adelante.
+
+var miObjeto = {
+ miString: "¡Hola Mundo!"
+};
+var miPrototipo = {
+ sentidoDeLaVida: 42,
+ miFuncion: function(){
+ return this.miString.toLowerCase()
+ }
+};
+
+miObjeto.__proto__ = miPrototipo;
+miObjeto.sentidoDeLaVida; // = 42
+
+// Esto funcionan también para funciones.
+miObjeto.miFuncion(); // = "hello world!"
+
+// Por supuesto, si la propiedad que buscas no está en el prototipo,
+// se buscará en el prototipo del prototipo.
+miPrototipo.__proto__ = {
+ miBoolean: true
+};
+miObjeto.miBoolean; // = true
+
+// Esto no involucra ningún copiado, cada objeto guarda una referencia a su
+// prototipo. Esto significa que podemos alterar el prototipo y nuestros
+// cambios serán reflejados en todos lados.
+miPrototipo.sentidoDeLaVida = 43;
+miObjeto.sentidoDeLaVida; // = 43
+
+// Mencionabamos anteriormente que __proto__ no está estandarizado, y que no
+// existe una forma estándar de accesar al prototipo de un objeto. De todas formas.
+// hay dos formas de crear un nuevo objeto con un prototipo dado.
+
+// El primer método es Object.create, el cual es una adición reciente a JavaScript,
+// y por lo tanto, no disponible para todas las implementaciones aún.
+var miObjeto = Object.create(miPrototipo);
+miObjeto.sentidoDeLaVida; // = 43
+
+// El segundo método, el cual trabaja en todos lados, tiene que ver con los
+// constructores. Los constructores tienen una propiedad llamada prototype.
+// Este NO ES el prototipo de la función constructor; es el prototipo que
+// se le da a los nuevos objetos cuando son creados con la palabra clave
+// new.
+
+MiConstructor.prototype = {
+ miNumero: 5,
+ getMiNumero: function(){
+ return this.miNumero;
+ }
+};
+var miNuevoObjeto2 = new MiConstructor();
+miNuevoObjeto2.getMiNumero(); // = 5
+miNuevoObjeto2.miNumero = 6
+miNuevoObjeto2.getMiNumero(); // = 6
+
+// Los tipos que vienen por defecto en JavaScript (como Strings y números)
+// también tienen constructores que crean objetos equivalentes.
+var miNumero = 12;
+var miNumeroObjeto = new Number(12);
+miNumero == miNumeroObjeto; // = true
+
+// No son exactamente iguales.
+typeof miNumero; // = 'number'
+typeof miNumeroObjeto; // = 'object'
+miNumero === miNumeroObjeyo; // = false
+if (0){
+ // Este código no se ejecutara porque 0 es false.
+}
+if (Number(0)){
+ // Este código sí se ejecutara, puesto que Number(0) es true.
+}
+
+// Aún así, los objetos que envuelven y los prototipos por defecto comparten
+// un prototipo. así que puedes agregar funcionalidades a un string de la
+// siguiente forma:
+String.prototype.primerCaracter = function(){
+ return this.charAt(0);
+}
+"abc".primerCaracter(); // = "a"
+
+// Este hecho se usa normalmente en "polyfilling", lo cual es implementar
+// nuevas funciones a JavaScript en un JavaScript más viejo, así que pueda ser
+// compatible con ambintes más viejos de JavaScript (por ejemplo, navegadores viejos).
+
+// Por ejemplo, mencionabamos que Object.create no está aún disponible en todas
+// las implementaciones, pero podemos hacerlo con polyfill:
+if (Object.create === undefined){ // esta validación sirve para no sobreescribir
+ Object.create = function(proto){
+ // hace un constructor temporal con el prototipo correcto
+ var Constructor = function(){};
+ Constructor.prototype = proto;
+ // y luego lo usamos para hacer un objeto con el prototipo
+ // correcto.
+ return new Constructor();
+ }
+}
+```
+
+## Fuentes y Referencias
+
+La [Red para Desarroladores de Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
+proveé excelente documentación para JavaScript para navegadores. Además, está en formato de wiki,
+por lo que mientras vayas aprendiendo podrás ayudar a los demás con tu experiencia.
+
+MDN [Una re-introducción a JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
+cubre muchos de los conceptos que vimos aquí pero a mayor detalle. Esta guía cubre, más que nada,
+el lenguaje JavaScript solo. Si quieres aprender a cómo usarlo en un ambiente web empieza aprendiendo
+sobre el [DOM](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core)
+
+[Aprende JavaScript con ejemplos y retos](http://www.learneroo.com/modules/64/nodes/350) es una
+variante de esta guía pero con retos.
+
+[Jardín JavaScript](http://bonsaiden.github.io/JavaScript-Garden/) es una guía para todas las
+funciones y características contra-intuitivas del lenguaje.
+
+[JavaScript: La guía definitiva](http://www.amazon.com/gp/product/0596805527/) es una guía clásica / libro de referencia.
+
+Aparte de las contribuciones directas para este artículo, algo del contenido se adaptó
+del tutorial de Python por Louie Dinh en este sitio. y el [Tutorial JS](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) en la Red de Desarrolladores de Mozilla.
diff --git a/es-es/json-es.html.markdown b/es-es/json-es.html.markdown
new file mode 100644
index 00000000..fff678eb
--- /dev/null
+++ b/es-es/json-es.html.markdown
@@ -0,0 +1,59 @@
+---
+language: json
+filename: learnjson-es.json
+contributors:
+ - ["Anna Harren", "https://github.com/iirelu"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["Daniel Zendejas","https://github.com/DanielZendejas"]
+lang: es-es
+---
+
+Siendo JSON un formato de intercambio de infomación tan sencillo, probablemente este será el Learn X in Y más sencillo jamás.
+
+JSON en su forma más pura no tiene comentarios, pero la mayoría de los parseadores aceptarán comentarios de C (//, /\* \*/). De todas formas, para el propóstio de esto todo será JSON 100% válido. Por suerte, habla por sí mismo.
+
+```json
+
+{
+ "llave": "valor",
+
+ "llaves": "siempre debe estar entre comillas (ya sean dobles o simples)",
+ "numeros": 0,
+ "strings": "Høla, múndo. Todo el unicode está permitido, así como \"escapar\".",
+ "soporta booleanos?": true,
+ "vacios": null,
+
+ "numero grande": 1.2e+100,
+
+ "objetos": {
+ "comentario": "La mayoria de tu estructura vendra de objetos.",
+
+ "arreglo": [0, 1, 2, 3, "Los arreglos pueden contener cualquier cosa.", 5],
+
+ "otro objeto": {
+ "comentario": "Estas cosas pueden estar anidadas, muy util."
+ }
+ },
+
+ "tonteria": [
+ {
+ "fuentes de potasio": ["bananas"]
+ },
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, "neo"],
+ [0, 0, 0, 1]
+ ]
+ ],
+
+ "estilo alternativo": {
+ "comentario": "Mira esto!"
+ , "posicion de la coma": "no importa - mientras este antes del valor, entonces sera valido"
+ , "otro comentario": "que lindo"
+ },
+
+ "eso fue rapido": "Y, estas listo. Ahora sabes todo lo que JSON tiene para ofrecer."
+}
+```
diff --git a/es-es/julia-es.html.markdown b/es-es/julia-es.html.markdown
index 41a7c68b..203ee3bb 100644
--- a/es-es/julia-es.html.markdown
+++ b/es-es/julia-es.html.markdown
@@ -1,8 +1,9 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
- - ["Guillermo Garza" ]
+translators:
+ - ["Guillermo Garza", "http://github.com/ggarza"]
filename: learnjulia-es.jl
lang: es-es
---
diff --git a/es-es/livescript-es.html.markdown b/es-es/livescript-es.html.markdown
new file mode 100644
index 00000000..103a3142
--- /dev/null
+++ b/es-es/livescript-es.html.markdown
@@ -0,0 +1,339 @@
+---
+language: LiveScript
+filename: learnLivescript-es.ls
+contributors:
+ - ["Christina Whyte", "http://github.com/kurisuwhyte/"]
+translators:
+ - ["Daniel Zendejas", "http://github.com/DanielZendejas/"]
+lang: es-es
+---
+
+LiveScript es un lenguaje funcional compilado sobre Javascript. Comparte
+la mayoría de la semántica con este mismo lenguaje. Composición de funciones,
+comparación de patrones y muchas otras cosas son las adiciones que hace
+LiveScript. Está inspirado en lenguajes como Haskell, F# y Scala.
+
+Livescript es un bifurcación de [Coco][], que en sí mismo es una bifurcación
+de [CoffeeScript][]. El lenguaje es estable, y una nueva versión está en
+desarrollo activo para traer aún más funciones.
+
+[Coco]: http://satyr.github.io/coco/
+[CoffeeScript]: http://coffeescript.org/
+
+La retroalimentación siempre es bienvenida, así que sientete libre de
+contactarme en [@kurisuwhyte](https://twitter.com/kurisuwhyte) :)
+
+```coffeescript
+# Justo como su primo CoffeeScript, LiveScript usa símbolos de gato para
+# comentarios de una sola línea
+
+/*
+ Comentarios multi-línea son escritos con estilo de C. Usa este estilo si quieres
+ que los comentarios se preserven en el output de Javascript
+ */
+```
+```coffeescript
+# En lo que a la sintaxis se refiere, LiveScript usa indentación para delimitar
+# bloques en lugar de llaves {} y espacios para aplicar funciones, en lugar de
+# paréntesis.
+
+########################################################################
+## 1. Valores básicos
+########################################################################
+
+# La carencia de valor se define con la palabra `void` en lugar de `undefined`
+void # igual que `undefined` pero más seguro (no puede ser sobre escrito)
+
+# Ningún valor válido se representa con Null.
+null
+
+# El valor básico más pequeño es de tipo lógico:
+true
+false
+
+# Y tiene múltiples alias que significan lo mismo:
+on; off
+yes; no
+
+# Luego vienen los números. Estos número con punto flotante tienen la misma
+# precisión que los de JS:
+10
+0.4 # Note que el `0` al inicio es requerido
+
+# Para fines de fácil lectura, puedes usar guiones bajos y sufijos en un
+# número, y estos serán ignorados por el compilador.
+12_344km
+
+# Los Strings son secuencias de caracteres inmutables, como en JS:
+"Christina" # ¡Los apóstrofes están bien!
+"""Strings
+ de muchas
+ líneas
+ están
+ bien
+ también."""
+
+# A veces quieres codificar un palabra clave, la diagonal invertida sirve para esto:
+\keyword # => 'keyword'
+
+
+# Los arreglos son colecciones ordenadas de datos:
+frutas =
+ * \manzana
+ * \naranja
+ * \pera
+
+# Una forma más concisa de representarlos son con corchetes:
+frutas = [ \manzana, \naranja, \pera ]
+
+# Esta es una conveniente de crear listas de Strings, usando
+# espacio en blanco para delimitar los items:
+frutas = <[ manzana naranja pera ]>
+
+# Puedes recuperar un item usando su índice (empezando en 0):
+frutas[0] # => "manzana"
+
+# Los objetos son colecciones de pares llave/valor sin ordenar, entre otras cosas,
+# (detallaremos más al respecto en un momento):
+persona =
+ nombre: "Christina"
+ gusta:
+ * "gatitos"
+ * "otras cosas"
+
+# Otra vez, puedes expresar el objeto con más consistencia con llaves {}:
+persona = {nombre: "Christina", gusta: ["gatitos", "otras cosas"]}
+
+# Puedes conseguir un valor por medio de su llave:
+persona.nombre # => "Christina"
+persona["nombre"] # => "Christina"
+
+
+# Las expresiones regulares tienen la misma sintaxis que en JavaScript:
+expresion-regular = /\s$/
+
+# A excepción de que puedes hacer expresiones de múltiples líneas
+# (los comentarios y espacios se ignoran):
+expresion-regular = //
+ function\s+(.+) # nombre
+ \s* \((.*)\) \s* # argumentos
+ { (.*) } # cuerpo
+ //
+
+
+########################################################################
+## 2. Operaciones básicas
+########################################################################
+
+# Los operadores aritméticos son los mismos que en JavaScript:
+1 + 2 # => 3
+2 - 1 # => 1
+2 * 3 # => 6
+4 / 2 # => 2
+3 % 2 # => 1
+
+
+# Las comparaciones son casi las mismas, excepto `==` que es igual
+# a `===` en. El operador `==` de JS en LiveScript es `~=`, y `===`
+# permite comparaciones entre objetos y arreglos, y también
+# comparasiones más estrictas:
+2 == 2 # => true
+2 == "2" # => false
+2 ~= "2" # => true
+2 === "2" # => false
+
+[1,2,3] == [1,2,3] # => false
+[1,2,3] === [1,2,3] # => true
+
++0 == -0 # => true
++0 === -0 # => false
+
+# Otros operadores relacionales incluyen <, <=, > and >=
+
+# Los valores lógicos pueden ser combinados mediante los operadores
+# lógicos `or`, `and` and `not`:
+true and false # => false
+false or true # => true
+not false # => true
+
+# Las colecciones también tienen algunos operadores adicionales:
+[1, 2] ++ [3, 4] # => [1, 2, 3, 4]
+'a' in <[ a b c ]> # => true
+'nombre' of { nombre: 'Chris' } # => true
+
+
+########################################################################
+## 3. Funciones
+########################################################################
+
+# Como LiveScript es funcional, uno esperaría que las funciones recibirían
+# un buen tratamiento. En LiveScript es más que aparente que las funciones
+# son de primera clase:
+suma = (primerElemento, segundoElemento) -> primerElemento + segundoElemento
+add 1, 2 # => 3
+
+# Las funciones que no reciben argumentos son llamadas rápidamente
+dos = -> 2
+dos!
+
+# LiveScript, al igual que JS, aplica ámbitos (alcance) a sus variables y
+# tiene cierres (closures) también. A diferencia de JavaScript, el operador
+# `=` sirve como declaración y siempre declarará la variable en lado izquierdo.
+
+# El operador `:=` está disponible para *reusar* un nombre del ámbito del padre.
+
+# Puedes acceder a los argumentos de una función para conseguir
+# los datos internos de una estructura de datos rápidamente:
+cola = ([cabeza, ...resto]) -> resto
+cola [1, 2, 3] # => [2, 3]
+
+# También puedes transformar argumentos usando operadores binarios o unarios.
+# Argumentos por defecto también son posibles
+foo = (a = 1, b = 2) -> a + b
+foo! # => 3
+
+# También puedes usarlo para clonar un argumento en particular para evitar efectos
+# secundarios, por ejemplo:
+copiar = (^^objetivo, fuente) ->
+ for k,v of fuente => objetivo[k] = v
+ objetivo
+a = { a: 1 }
+copiar a, { b: 2 } # => { a: 1, b: 2 }
+a # => { a: 1 }
+
+# Una función puede ser abreviada usando una flecha larga en lugar de una corta:
+suma = (primerElemento, segundoElemento) --> primerElemento + segundoElemento
+sumaAbreviada = suma 1
+sumaAbreviada 2 # => 3
+
+# Las funciones obtienen un argumento `it` implícito, incluso si no declaras
+# ningún argument
+identidad = -> it
+identidad 1 # => 1
+
+# Los operadores no son funciones en LiveScript. ¡Pero se pueden convertir fácilmente
+# en una! Presentamos el seccionamiento de operadores:
+dividir-entre-2 = (/ 2)
+[2, 4, 8, 16].map(dividir-entre-2) .reduce (+)
+
+# LiveScript vive de otras cosas aparte de las funciones. Como en cualquier lenguaje
+# funcional obtienes medios para componer (juntar) funciones:
+doble-menos-uno = (- 1) . (* 2)
+
+# A parte de la clásica fórmula matemática `f . g`, también cuentas co los operadores
+# `>>` y `<<`, que describen el flujo de los valores dentro de las funciones:
+double-minus-one = (* 2) >> (- 1)
+double-minus-one = (- 1) << (* 2)
+
+# Hablando del flujo de los valores, LiveScript también tiene los operadores `|>` y `<|`
+# que aplican un valor a una función:
+map = (f, xs) --> xs.map f
+[1 2 3] |> map (* 2) # => [2 4 6]
+
+# También puedes escoger dónde quieres que el valor se posicione, sólo márcalo con un
+# guíon bajo:
+reducir = (f, xs, initial) --> xs.reducir f, initial
+[1 2 3] |> reducir (+), _, 0 # => 6
+
+# El guíon bajo también se usa para apartar lugares para tus argumentos, por ejemplo:
+division = (dividendo,divisor) -> dividendo / divisor
+dividir-entre-2 = division _, 2
+dividir-entre-2 4 # => 2
+
+# Por último, LiveScript tiene back-calls (útiles mecanismos para hacer
+# callbacks.). A pesar de esto deberías intentar formas más funcionales de hacerlo,
+# como Promises:
+leerArchivo = (nombre, f) -> f name
+a <- leerArchivo 'foo'
+b <- leerArchivo 'bar'
+console.log a + b
+
+# Igual a:
+leerArchivo 'foo', (a) -> leerArchivo 'bar', (b) -> console.log a + b
+
+
+########################################################################
+## 4. Patrones, guardias y control de flujo
+########################################################################
+
+# Puedes bifurcar cálculos con la expresión `if...else`:
+x = if n > 0 then \positive else \negative
+
+# En lugar de `then`, puedes usar `=>`
+x = if n > 0 => \positivo
+ else \negativo
+
+# A pesar de esto, a las condiciones complejas es mejor expresarlas con el `switch`:
+y = {}
+x = switch
+ | (typeof y) is \number => \numero
+ | (typeof y) is \string => \string
+ | 'length' of y => \arreglo
+ | otherwise => \objeto # `otherwise` y `_` son lo mismo.
+
+# Los cuerpos de las funciones, declaraciones y asignaciones tienen un `switch` por defecto,
+# así que no necesitas escribirlo nuevamente:
+
+take = (n, [x, ...xs]) -->
+ | n == 0 => []
+ | _ => [x] ++ take (n - 1), xs
+
+
+########################################################################
+## 5. Comprehensions (Auxiliares)
+########################################################################
+
+# Mientras que los auxiliares funcionales (para lidiar con listas y objetos)
+# están en la librería estándar de JavaScript (y complementada con prelude-ls,
+# que es una "librería estándar" de LiveScipt) los "comprehensions" (Auxiliares)
+# usualemente te permiten hacer lo mismo pero más rápido y con una sintaxis más
+# comprehensible (de ahí su nombre en inglés):
+unoAVeinte = [1 to 20]
+pares = [x for x in oneToTwenty when x % 2 == 0]
+
+# `when` y `unless` pueden ser usados como filtros en el auxiliar.
+
+# Los auxiliares para objetos funcionan de la misma forma, excepto que regresa un
+# objeto en lugar de un arreglo:
+copiar = { [k, v] for k, v of source }
+
+
+########################################################################
+## 4. PROGRAMACIÓN ORIENTADA A OBJETOS
+########################################################################
+
+# Mientras que LiveScript es un lenguaje funcional en la mayoría de los
+# aspectos, también brinda ayudas para la programación orientada a objetos.
+# Algunas de estas ayudas son la sintaxis para las clases y un poco de "azucar"
+# para las clases heredada de CoffeeScript:
+class Animal
+ (@nombre, tipo) ->
+ @tipo = tipo
+ action: (accion) -> "*#{@nombre} (un #{@tipo}) #{accion}*"
+
+class Gato extends Animal
+ (@nombre) -> super @nombre, 'gato'
+ ronronear: -> @action 'ronronea'
+
+gatito = new Gato 'Mei'
+gatito.purr! # => "*Mei (un gato) ronronea*"
+
+# A parte del clásico patrón de herencia simple, también puedes proveer
+# cuantas mezclas quieras para una clase. Las mezclas sólo son objetos:
+Abrazable =
+ abrazar: -> @action 'es abrazado'
+
+class GatoAbrazable extends Gato implements Abrazable
+
+gatito = new GatoAbrazable 'Ronroneo'
+gatito.abrazar! # => "*Mei (un gato) es abrazado*"
+```
+
+## Más recursos
+
+Existe mucho más sobre LiveScript, pero esto debe bastar para que empieces.
+El [sitio oficial](http://livescript.net/) tiene mucha información sobre el
+lenguaje, y un compilador en linea para que pruebes cosas inmediatamente.
+
+También querras probar un poco de [prelude.ls](http://gkz.github.io/prelude-ls/),
+y probar el canal `#livescript` en la red Freenode.
diff --git a/es-es/markdown-es.html.markdown b/es-es/markdown-es.html.markdown
new file mode 100644
index 00000000..d90e3eb5
--- /dev/null
+++ b/es-es/markdown-es.html.markdown
@@ -0,0 +1,252 @@
+---
+language: markdown
+filename: markdown-es.md
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators:
+ - ["Daniel Zendejas", "https://github.com/DanielZendejas"]
+lang: es-es
+---
+
+Markdown fue creado por John Gruber en 2004. Su propósito es ser una sintaxis fácil de leer y escribir que se convierta
+fácilmente a HTML (y, actualmente, otros formatos también).
+
+¡Denme todo la retroalimentación que quieran! / ¡Sientanse en la libertad de hacer forks o pull requests!
+
+
+```markdown
+<!-- Markdown está basado en HTML, así que cualquier archivo HTML es Markdown
+válido, eso significa que podemos usar elementos HTML en Markdown como, por
+ejemplo, el comentario y no serán afectados por un parseador Markdown. Aún
+así si creas un elemento HTML en tu archivo Markdown no podrás usar sintaxis
+Markdown dentro de él. -->
+
+<!-- La implementación de Markdown cambia de acuerdo al parseador. Esta
+guía servirá para clarificar cuales características son universales y
+cuales son específicas de cada parseador-->
+
+<!-- Headers -->
+<!-- Puedes crear headers HTML fácilmente precediendo al texto con una serie
+de símbolos de números (#)-->
+
+# Esto es un <h1>
+## Esto es un <h2>
+### Esto es un <h3>
+#### Esto es un <h4>
+##### Esto es un <h5>
+###### Esto es un <h6>
+
+<!-- Markdown también nos proveé con dos alternativas para indicar h1 y h2 -->
+Esto es un h1
+=============
+
+Esto es un h2
+-------------
+
+<!-- Estilos para texto plano -->
+<!-- El texto puede ser fácilmente estilizaedo con italicas, negritas o tachado
+usando markdown -->
+
+*Este texto está en itálicas.*
+_Al igual que este texto._
+
+**Este texto está en negritas.**
+__Al igual que este texto.__
+
+***Este texto tiene ambos estilos.***
+**_Al igual que este!_**
+*__¡Y este!__*
+
+<!-- En Github Flavored Markdown, el cual es usado para mostrar archivos
+Markdown en Github, también tenemos: -->
+
+~~Este texto está tachado.~~
+
+<!-- Los párrafos son una o múltuples líneas de texto adyacentes separadas por
+una o múltiples líneas en blanco-->
+
+Este es un párrafo. Estoy escribiendo un párrafo, ¿No es divertido?
+
+Ahora estoy en el párrafo dos.
+¡Sigo en el párrafo dos!
+
+¡Estoy en el párrafo tres!
+
+<!-- Si en algún momento quieres insertar un break HTML <br />, puedes terminar
+un párrafo con dos o más espacios y luego empieza un párrafo nuevo-->
+
+Termino con dos espacios (selecciona esta línea completa para que los veas).
+
+¡Hay un <br /> arriba de mí!
+
+<!-- Las citas de bloque son fáciles y se pueden hacer con el caracter >. -->
+
+> Esta es una cita de bloque. Puedes
+> envolver tus líneas manualmente y poner un `>` antes de cada línea o puedes dejar que tus líneas sean muy largas y que se envuelvan solas.
+> No hay diferencia, siempre y cuando empiecen con `>`.
+
+> ¿También puedes usar más de un nivel
+>> de indentación?
+> Esto es muy útil ¿No?
+
+<!-- Listas -->
+<!-- Las listas desordenadas se hacen usando asteriscos, símbolos de más,
+ o guiones -->
+
+* Item
+* Item
+* Otro item
+
+o
+
++ Item
++ Item
++ Un item más
+
+o
+
+- Item
+- Item
+- El último item
+
+<!-- Las listas ordenadas se logran con un número seguido de un punto -->
+
+1. Item uno
+2. Item dos
+3. Item tres
+
+<!-- Aunque Markdown mostrará los items correctamente en orden, esto no
+es una buena idea -->
+
+1. Item uno
+1. Item dos
+1. Item tres
+<!-- (Esto muestra lo mismo que el ejemplo de arriba) -->
+
+<!-- También puedes usar sub-listas -->
+
+1. Item uno
+2. Item dos
+3. Item tres
+ * Sub-item
+ * Sub-item
+4. Item cuatro
+
+<!-- Bloques de código -->
+<!-- Puedes indicar un bloque de código (usan los elementos <code>) indentando
+una línea con cuatro espacios o un tab-->
+
+ Esto es código
+ Esto también
+
+<!-- También puedes insertar dos tabs (o cuatro espacios adicionales)
+para indentar dentro del código -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Código dentro de la línea puede ser escrito usando la comilla ` -->
+
+¡John no sabía lo que la función `go_to()` hacía!
+
+<!-- Con Github Flavored Markdown, puedes usar una sintaxis especial para código -->
+
+\`\`\`ruby <!-- quita esas comillas cuando lo hagas, deja sólo ```ruby ! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- aquí también, sin comillas, sólo ``` -->
+
+<!-- El texto de arriba no necesita indentación, aparte Github usará
+resaltará la sintaxis del lenguaje que especifiques después de ``` -->
+
+<!-- Regla horizontal (<hr />) -->
+<!-- Las reglas horizontales se agregan fácilmente con tres o más asteriscos o guiones,
+con o sin espacios. -->
+
+***
+---
+- - -
+****************
+
+<!-- Ligas -->
+<!-- Una de las mejores cosas de Markdown es la facilidad para hacer ligas. Pon
+el texto a mostrar en corchetes [] seguidos por la URL en paréntesis () -->
+
+[¡Haz click!](http://test.com/)
+
+<!-- También puedes agregar el titulo de la liga usando comillas dentro de los paréntesis -->
+
+[¡Haz click!](http://test.com/ "Liga al test.com")
+
+<!-- También funcionan las rutas relativas. -->
+
+[Ir a la música](/music/).
+
+<!-- Markdown también soporta ligas con estilo de referencia -->
+
+¡[Has click a esta liga][liga1] para más información!
+[También mira esta liag][foobar] si quieres.
+
+
+
+
+<!-- El título también puede estar en comillas simples o dentro de paréntesis,
+también se pueden omitir completamente. Las referencias pueden estar en cualquier
+lugar en tu documento y los IDs de referencia pueden ser lo que sea mientras sean únicos. -->
+
+<!-- También hay "nombramiento implicito" el cual te permite usar el texto de la liga como id -->
+
+[Esta][] es una liga.
+
+
+
+<!-- Pero no se usa comúnmente. -->
+
+<!-- Imagenes -->
+<!-- Las imagenes se hacen de la misma forma que las ligas pero con un símbolo de exclamaciónal frente! -->
+
+![Esta es una etiqueta (texto alternativo) para mi imagen](http://imgur.com/myimage.jpg "Un titulo opcional")
+
+<!-- Y el estilo de referencia funciona como se espera -->
+
+![Esta es una etiqueta.][myimage]
+
+
+
+<!-- Misceláneos -->
+<!-- Auto-ligas -->
+
+<http://testwebsite.com/> equivale a
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Auto-ligas para correos electrónicos -->
+
+<foo@bar.com>
+
+<!-- Escapando caracteres -->
+
+Quiero escribir *este texto rodeado por asteriscos* pero no quiero que esté en itálicas,
+así que hago esto: \*Este texto está rodeado de asteriscos\*.
+
+<!-- Tablas -->
+<!-- Las tablas sólo están disponibles en Github Flavored Markdown y son un poco pesadas,
+pero si de verdad las quieres: -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| Izquierda | Centrado | Derecha |
+| blah | blah | blah |
+
+<!-- o, para los mismos resultados -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ugh esto es feo | has que | pare.
+
+<!-- ¡El fin! -->
+
+```
+
+Para más información, mira el post oficial de John Gruber's [aquí](http://daringfireball.net/projects/markdown/syntax) y la gran referencia de Adam Pritchard's [aquí](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
diff --git a/es-es/perl-es.html.markdown b/es-es/perl-es.html.markdown
index 4f0c26c1..644182ff 100644
--- a/es-es/perl-es.html.markdown
+++ b/es-es/perl-es.html.markdown
@@ -7,23 +7,24 @@ contributors:
- ["Korjavin Ivan", "http://github.com/korjavin"]
translators:
- ["Francisco Gomez", "http://github.com/frncscgmz"]
+ - ["Joaquín Ferrero", "http://github.com/joaquinferrero"]
lang: es-es
---
-Perl 5 es un lenguaje de programación altamente capaz, rico en características con mas de 25 años de desarrollo.
+Perl 5 es un lenguaje de programación altamente capaz, rico en características, con más de 25 años de desarrollo.
-Perl 5 corre en mas de 100 plataformas desde portales hasta mainframes y es adecuado para realizar prototipos rápidos hasta desarrollar proyectos a gran escala.
+Perl 5 corre en más de 100 plataformas, desde portátiles hasta ordenadores centrales, y es adecuado para realizar desde prototipos rápidos hasta desarrollar proyectos a gran escala.
```perl
-# Comentarios de una sola linea con un carácter hash.
+# Comentarios de una sola línea con un carácter hash
#### Tipos de variables en Perl
-# Las variables comienzan con el símbolo $.
-# Un nombre de variable valido empieza con una letra o un guión bajo,
-# seguido por cualquier numero de letras, números o guiones bajos.
+# Las variables comienzan con el símbolo $
+# Un nombre de variable válido empieza con una letra o un guión bajo,
+# seguido por cualquier número de letras, números o guiones bajos
-### Perl tiene tres tipos principales de variables: escalares, arreglos y hashes.
+### Perl tiene tres tipos principales de variables: escalares, arreglos y hashes
## Escalares
# Un escalar representa un solo valor:
@@ -31,99 +32,98 @@ my $animal = "camello";
my $respuesta = 42;
# Los valores escalares pueden ser cadenas de caracteres, números enteros o
-# de punto flotante, Perl automáticamente los convertirá como sea requerido.
+# de punto flotante; Perl automáticamente los convertirá como sea requerido
## Arreglos
# Un arreglo representa una lista de valores:
-my @animales = {"camello","llama","buho"};
-my @numeros = {23,42,69};
-my @mixto = {"camello",42,1.23};
-
-
+my @animales = ("camello","llama","buho"};
+my @numeros = (23, 42, 69);
+my @mixto = ("camello", 42, 1.23);
## Hashes
-# Un hash representa un conjunto de pares llave/valor:
-
-my %color_fruta = {"manzana","rojo","banana","amarillo"};
-
-# Puedes usar un espacio en blanco y el operador "=>" para asignarlos mas
-# fácilmente.
+# Un hash representa un conjunto de pares llave/valor:
+my %color_fruta = ("manzana","rojo","banana","amarillo");
+# Puede usar un espacio en blanco y el operador "=>" para asignarlos más fácilmente
my %color_fruta = (
manzana => "rojo",
banana => "amarillo",
- );
-# Los escalares, arreglos y hashes están mas documentados en perldata. (perldoc perldata).
+);
-# Los tipos de datos mas complejos pueden ser construidos utilizando
-# referencias, las cuales te permiten construir listas y hashes dentro
-# de listas y hashes.
+# Los escalares, arreglos y hashes están más documentados en perldata (perldoc perldata)
-#### Estructuras condicionales y de ciclos
+# Los tipos de datos más complejos se pueden construir utilizando
+# referencias, las cuales le permiten construir listas y hashes dentro
+# de listas y hashes
-# Perl tiene la mayoría de las estructuras condicionales y de ciclos mas comunes.
+#### Estructuras condicionales y de ciclos
+# Perl tiene la mayoría de las estructuras condicionales y de ciclos más comunes
if ( $var ) {
- ...
+ ...;
} elsif ( $var eq 'bar' ) {
- ...
+ ...;
} else {
- ...
+ ...;
}
unless ( condicion ) {
- ...
- }
-# Esto es proporcionado como una version mas fácil de leer que "if (!condición)"
+ ...;
+}
-# La post condición al modo Perl
+# Esto se ofrece como una versión más fácil de leer que "if (!condición)"
+
+# La postcondición al modo Perl:
print "Yow!" if $zippy;
print "No tenemos bananas" unless $bananas;
# while
- while ( condicion ) {
- ...
- }
-
+while ( condicion ) {
+ ...;
+}
# for y foreach
for ($i = 0; $i <= $max; $i++) {
- ...
- }
+ ...;
+}
+
+for $i (0 .. $max) {
+ ...;
+}
foreach (@array) {
- print "Este elemento es $_\n";
- }
+ print "Este elemento es $_\n";
+}
#### Expresiones regulares
-# El soporte de expresiones regulares en Perl es muy amplio y profundo, y es
-# sujeto a una extensa documentación en perlrequick, perlretut, entre otros.
+# El soporte de expresiones regulares en Perl es muy amplio y profundo, y
+# está sujeto a una extensa documentación en perlrequick, perlretut, entre otros.
# Sin embargo, resumiendo:
-# Pareo simple
+# Coincidencia simple
if (/foo/) { ... } # verdadero si $_ contiene "foo"
if ($a =~ /foo/) { ... } # verdadero si $a contiene "foo"
# Substitución simple
-$a =~ s/foo/bar/; # remplaza foo con bar en $a
-$a =~ s/foo/bar/g; # remplaza TODAS LAS INSTANCIAS de foo con bar en $a
+$a =~ s/foo/bar/; # remplaza "foo" con "bar" en $a
+$a =~ s/foo/bar/g; # remplaza TODAS LAS INSTANCIAS de "foo" con "bar" en $a
-#### Archivos e I/O
+#### Archivos y E/S
-# Puedes abrir un archivo para obtener datos o escribirlos utilizando la
-# función "open()".
+# Puede abrir un archivo para obtener datos o escribirlos utilizando la
+# función "open()"
open(my $entrada, "<" "entrada.txt") or die "No es posible abrir entrada.txt: $!";
open(my $salida, ">", "salida.txt") or die "No es posible abrir salida.txt: $!";
open(my $log, ">>", "mi.log") or die "No es posible abrir mi.log: $!";
-# Es posible leer desde un gestor de archivo abierto utilizando el operador "<>"
-# operador. En contexto escalar leer una sola linea desde el gestor de
-# archivo, y en contexto de lista leer el archivo completo en donde, asigna
-# cada linea a un elemento de la lista.
+# Es posible leer desde un gestor de archivo abierto utilizando el operador "<>".
+# En contexto escalar, leer una sola línea desde el gestor de archivo, y
+# en contexto de lista, leer el archivo completo en donde asigna
+# cada línea a un elemento de la lista
my $linea = <$entrada>;
my @lineas = <$entrada>;
@@ -131,30 +131,26 @@ my @lineas = <$entrada>;
#### Escribiendo subrutinas
# Escribir subrutinas es fácil:
-
sub logger {
my $mensajelog = shift;
open my $archivolog, ">>", "mi.log" or die "No es posible abrir mi.log: $!";
print $archivolog $mensajelog;
}
-# Ahora podemos utilizar la subrutina al igual que cualquier otra función
-# incorporada:
-
+# Ahora podemos utilizar la subrutina al igual que cualquier otra función incorporada:
logger("Tenemos una subrutina logger!");
-
```
#### Utilizando módulos Perl
-Los módulos en Perl proveen una gama de funciones que te pueden ayudar a evitar reinventar la rueda, estas pueden ser descargadas desde CPAN( http://www.cpan.org/ ). Algunos de los módulos mas populares ya están incluidos con la misma distribución de Perl.
+Los módulos en Perl proveen de una gama de funciones que le pueden ayudar a evitar reinventar la rueda. Éstas se pueden descargar desde CPAN ( http://www.cpan.org/ ). Algunos de los módulos más populares ya están incluidos con la misma distribución de Perl.
-perlfaq contiene preguntas y respuestas relacionadas con muchas tareas comunes, y algunas veces provee sugerencias sobre buenos módulos CPAN para usar.
+perlfaq contiene preguntas y respuestas relacionadas con muchas tareas comunes, y algunas veces provee sugerencias sobre buenos módulos de CPAN que puede usar.
#### Material de Lectura
- [perl-tutorial](http://perl-tutorial.org/)
- - [Aprende en www.perl.com](http://www.perl.org/learn.html)
+ - [Learn Perl](http://www.perl.org/learn.html)
- [perldoc](http://perldoc.perl.org/)
- - y perl incorporado: `perldoc perlintro`
+ - y en su propio perl: `perldoc perlintro`
diff --git a/es-es/python-es.html.markdown b/es-es/python-es.html.markdown
index f92f5cde..f7a0ec02 100644
--- a/es-es/python-es.html.markdown
+++ b/es-es/python-es.html.markdown
@@ -130,7 +130,7 @@ otra_variable # Levanta un error de nombre
# 'if' puede ser usado como una expresión
"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
-# Listas sobre secuencias
+# Listas almacenan secuencias
lista = []
# Puedes empezar con una lista prellenada
otra_lista = [4, 5, 6]
@@ -254,7 +254,7 @@ conjunto_lleno | otro_conjunto #=> {1, 2, 3, 4, 5, 6}
# Haz diferencia de conjuntos con -
{1,2,3,4} - {2,3,5} #=> {1, 4}
-# CHequea la existencia en un conjunto con 'in'
+# Chequea la existencia en un conjunto con 'in'
2 in conjunto_lleno #=> True
10 in conjunto_lleno #=> False
diff --git a/es-es/python3-es.html.markdown b/es-es/python3-es.html.markdown
new file mode 100644
index 00000000..1c69481a
--- /dev/null
+++ b/es-es/python3-es.html.markdown
@@ -0,0 +1,570 @@
+---
+language: python3
+contributors:
+ - ["Louie Dinh", "http://pythonpracticeprojects.com"]
+translators:
+ - ["Camilo Garrido", "http://twitter.com/hirohope"]
+lang: es-es
+filename: learnpython3-es.py
+---
+
+Python fue creado por Guido Van Rossum en el principio de los 90'. Ahora es uno
+de los lenguajes más populares en existencia. Me enamoré de Python por su claridad sintáctica.
+Es básicamente pseudocódigo ejecutable.
+
+¡Comentarios serán muy apreciados! Pueden contactarme en [@louiedinh](http://twitter.com/louiedinh) o louiedinh [at] [servicio de email de google]
+
+Nota: Este artículo aplica a Python 2.7 específicamente, pero debería ser aplicable a Python 2.x. ¡Pronto un recorrido por Python 3!
+
+```python
+
+# Comentarios de una línea comienzan con una almohadilla (o signo gato)
+
+""" Strings multilinea pueden escribirse
+ usando tres "'s, y comunmente son usados
+ como comentarios.
+"""
+
+####################################################
+## 1. Tipos de datos primitivos y operadores.
+####################################################
+
+# Tienes números
+3 #=> 3
+
+# Matemática es lo que esperarías
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+
+# Excepto la división la cual por defecto retorna un número 'float' (número de coma flotante)
+35 / 5 # => 7.0
+
+# Cuando usas un float, los resultados son floats
+3 * 2.0 # => 6.0
+
+# Refuerza la precedencia con paréntesis
+(1 + 3) * 2 # => 8
+
+
+# Valores 'boolean' (booleanos) son primitivos
+True
+False
+
+# Niega con 'not'
+not True # => False
+not False # => True
+
+
+# Igualdad es ==
+1 == 1 # => True
+2 == 1 # => False
+
+# Desigualdad es !=
+1 != 1 # => False
+2 != 1 # => True
+
+# Más comparaciones
+1 < 10 # => True
+1 > 10 # => False
+2 <= 2 # => True
+2 >= 2 # => True
+
+# ¡Las comparaciones pueden ser concatenadas!
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
+
+# Strings se crean con " o '
+"Esto es un string."
+'Esto también es un string'
+
+# ¡Strings también pueden ser sumados!
+"Hola " + "mundo!" #=> "Hola mundo!"
+
+# Un string puede ser tratado como una lista de caracteres
+"Esto es un string"[0] #=> 'E'
+
+# .format puede ser usaro para darle formato a los strings, así:
+"{} pueden ser {}".format("strings", "interpolados")
+
+# Puedes repetir los argumentos de formateo para ahorrar tipeos.
+"{0} sé ligero, {0} sé rápido, {0} brinca sobre la {1}".format("Jack", "vela") #=> "Jack sé ligero, Jack sé rápido, Jack brinca sobre la vela"
+# Puedes usar palabras claves si no quieres contar.
+"{nombre} quiere comer {comida}".format(nombre="Bob", food="lasaña") #=> "Bob quiere comer lasaña"
+
+
+# None es un objeto
+None # => None
+
+# No uses el símbolo de igualdad `==` para comparar objetos con None
+# Usa `is` en lugar de
+"etc" is None #=> False
+None is None #=> True
+
+# None, 0, y strings/listas/diccionarios vacíos(as) todos se evalúan como False.
+# Todos los otros valores son True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Variables y Colecciones
+####################################################
+
+# Python tiene una función para imprimir
+print("Soy Python. Encantado de conocerte")
+
+# No hay necesidad de declarar las variables antes de asignarlas.
+una_variable = 5 # La convención es usar guiones_bajos_con_minúsculas
+una_variable #=> 5
+
+# Acceder a variables no asignadas previamente es una excepción.
+# Ve Control de Flujo para aprender más sobre el manejo de excepciones.
+otra_variable # Levanta un error de nombre
+
+# Listas almacena secuencias
+lista = []
+# Puedes empezar con una lista prellenada
+otra_lista = [4, 5, 6]
+
+# Añadir cosas al final de una lista con 'append'
+lista.append(1) #lista ahora es [1]
+lista.append(2) #lista ahora es [1, 2]
+lista.append(4) #lista ahora es [1, 2, 4]
+lista.append(3) #lista ahora es [1, 2, 4, 3]
+# Remueve del final de la lista con 'pop'
+lista.pop() #=> 3 y lista ahora es [1, 2, 4]
+# Pongámoslo de vuelta
+lista.append(3) # Nuevamente lista ahora es [1, 2, 4, 3].
+
+# Accede a una lista como lo harías con cualquier arreglo
+lista[0] #=> 1
+# Mira el último elemento
+lista[-1] #=> 3
+
+# Mirar fuera de los límites es un error 'IndexError'
+lista[4] # Levanta la excepción IndexError
+
+# Puedes mirar por rango con la sintáxis de trozo.
+# (Es un rango cerrado/abierto para ustedes los matemáticos.)
+lista[1:3] #=> [2, 4]
+# Omite el inicio
+lista[2:] #=> [4, 3]
+# Omite el final
+lista[:3] #=> [1, 2, 4]
+# Selecciona cada dos elementos
+lista[::2] # =>[1, 4]
+# Invierte la lista
+lista[::-1] # => [3, 4, 2, 1]
+# Usa cualquier combinación de estos para crear trozos avanzados
+# lista[inicio:final:pasos]
+
+# Remueve elementos arbitrarios de una lista con 'del'
+del lista[2] # lista ahora es [1, 2, 3]
+
+# Puedes sumar listas
+lista + otra_lista #=> [1, 2, 3, 4, 5, 6] - Nota: lista y otra_lista no se tocan
+
+# Concatenar listas con 'extend'
+lista.extend(otra_lista) # lista ahora es [1, 2, 3, 4, 5, 6]
+
+# Chequea la existencia en una lista con 'in'
+1 in lista #=> True
+
+# Examina el largo de una lista con 'len'
+len(lista) #=> 6
+
+
+# Tuplas son como listas pero son inmutables.
+tupla = (1, 2, 3)
+tupla[0] #=> 1
+tupla[0] = 3 # Levanta un error TypeError
+
+# También puedes hacer todas esas cosas que haces con listas
+len(tupla) #=> 3
+tupla + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tupla[:2] #=> (1, 2)
+2 in tupla #=> True
+
+# Puedes desempacar tuplas (o listas) en variables
+a, b, c = (1, 2, 3) # a ahora es 1, b ahora es 2 y c ahora es 3
+# Tuplas son creadas por defecto si omites los paréntesis
+d, e, f = 4, 5, 6
+# Ahora mira que fácil es intercambiar dos valores
+e, d = d, e # d ahora es 5 y e ahora es 4
+
+
+# Diccionarios almacenan mapeos
+dicc_vacio = {}
+# Aquí está un diccionario prellenado
+dicc_lleno = {"uno": 1, "dos": 2, "tres": 3}
+
+# Busca valores con []
+dicc_lleno["uno"] #=> 1
+
+# Obtén todas las llaves como una lista con 'keys()'. Necesitamos envolver la llamada en 'list()' porque obtenemos un iterable. Hablaremos de eso luego.
+list(dicc_lleno.keys()) #=> ["tres", "dos", "uno"]
+# Nota - El orden de las llaves del diccionario no está garantizada.
+# Tus resultados podrían no ser los mismos del ejemplo.
+
+# Obtén todos los valores como una lista. Nuevamente necesitamos envolverlas en una lista para sacarlas del iterable.
+list(dicc_lleno.values()) #=> [3, 2, 1]
+# Nota - Lo mismo que con las llaves, no se garantiza el orden.
+
+# Chequea la existencia de una llave en el diccionario con 'in'
+"uno" in dicc_lleno #=> True
+1 in dicc_lleno #=> False
+
+# Buscar una llave inexistente deriva en KeyError
+dicc_lleno["cuatro"] # KeyError
+
+# Usa el método 'get' para evitar la excepción KeyError
+dicc_lleno.get("uno") #=> 1
+dicc_lleno.get("cuatro") #=> None
+# El método 'get' soporta un argumento por defecto cuando el valor no existe.
+dicc_lleno.get("uno", 4) #=> 1
+dicc_lleno.get("cuatro", 4) #=> 4
+
+# El método 'setdefault' inserta en un diccionario solo si la llave no está presente
+dicc_lleno.setdefault("cinco", 5) #dicc_lleno["cinco"] es puesto con valor 5
+dicc_lleno.setdefault("cinco", 6) #dicc_lleno["cinco"] todavía es 5
+
+
+# Remueve llaves de un diccionario con 'del'
+del dicc_lleno['uno'] # Remueve la llave 'uno' de dicc_lleno
+
+# Sets (conjuntos) almacenan ... bueno, conjuntos
+conjunto_vacio = set()
+# Inicializar un conjunto con montón de valores. Yeah, se ve un poco como un diccionario. Lo siento.
+un_conjunto = {1,2,2,3,4} # un_conjunto ahora es {1, 2, 3, 4}
+
+# Añade más valores a un conjunto
+conjunto_lleno.add(5) # conjunto_lleno ahora es {1, 2, 3, 4, 5}
+
+# Haz intersección de conjuntos con &
+otro_conjunto = {3, 4, 5, 6}
+conjunto_lleno & otro_conjunto #=> {3, 4, 5}
+
+# Haz unión de conjuntos con |
+conjunto_lleno | otro_conjunto #=> {1, 2, 3, 4, 5, 6}
+
+# Haz diferencia de conjuntos con -
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# Chequea la existencia en un conjunto con 'in'
+2 in conjunto_lleno #=> True
+10 in conjunto_lleno #=> False
+
+
+####################################################
+## 3. Control de Flujo
+####################################################
+
+# Let's just make a variable
+some_var = 5
+
+# Aquí está una declaración de un 'if'. ¡La indentación es significativa en Python!
+# imprime "una_variable es menor que 10"
+if una_variable > 10:
+ print("una_variable es completamente mas grande que 10.")
+elif una_variable < 10: # Este condición 'elif' es opcional.
+ print("una_variable es mas chica que 10.")
+else: # Esto también es opcional.
+ print("una_variable es de hecho 10.")
+
+"""
+For itera sobre listas
+imprime:
+ perro es un mamifero
+ gato es un mamifero
+ raton es un mamifero
+"""
+for animal in ["perro", "gato", "raton"]:
+ # Puedes usar % para interpolar strings formateados
+ print("{} es un mamifero".format(animal))
+
+"""
+`range(número)` retorna una lista de números
+desde cero hasta el número dado
+imprime:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+While itera hasta que una condición no se cumple.
+imprime:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # versión corta de x = x + 1
+
+# Maneja excepciones con un bloque try/except
+try:
+ # Usa raise para levantar un error
+ raise IndexError("Este es un error de indice")
+except IndexError as e:
+ pass # Pass no hace nada. Usualmente harias alguna recuperacion aqui.
+
+# Python oferce una abstracción fundamental llamada Iterable.
+# Un iterable es un objeto que puede ser tratado como una sequencia.
+# El objeto es retornado por la función 'range' es un iterable.
+
+dicc_lleno = {"uno": 1, "dos": 2, "tres": 3}
+nuestro_iterable = dicc_lleno.keys()
+print(nuestro_iterable) #=> range(1,10). Este es un objeto que implementa nuestra interfaz Iterable
+
+Podemos recorrerla.
+for i in nuestro_iterable:
+ print(i) # Imprime uno, dos, tres
+
+# Aunque no podemos selecionar un elemento por su índice.
+nuestro_iterable[1] # Genera un TypeError
+
+# Un iterable es un objeto que sabe como crear un iterador.
+nuestro_iterator = iter(nuestro_iterable)
+
+# Nuestro iterador es un objeto que puede recordar el estado mientras lo recorremos.
+# Obtenemos el siguiente objeto llamando la función __next__.
+nuestro_iterator.__next__() #=> "uno"
+
+# Mantiene el estado mientras llamamos __next__.
+nuestro_iterator.__next__() #=> "dos"
+nuestro_iterator.__next__() #=> "tres"
+
+# Después que el iterador ha retornado todos sus datos, da una excepción StopIterator.
+nuestro_iterator.__next__() # Genera StopIteration
+
+# Puedes obtener todos los elementos de un iterador llamando a list() en el.
+list(dicc_lleno.keys()) #=> Retorna ["uno", "dos", "tres"]
+
+
+
+####################################################
+## 4. Funciones
+####################################################
+
+# Usa 'def' para crear nuevas funciones
+def add(x, y):
+ print("x es {} y y es {}".format(x, y))
+ return x + y # Retorna valores con una la declaración return
+
+# Llamando funciones con parámetros
+add(5, 6) #=> imprime "x es 5 y y es 6" y retorna 11
+
+# Otra forma de llamar funciones es con argumentos de palabras claves
+add(y=6, x=5) # Argumentos de palabra clave pueden ir en cualquier orden.
+
+
+# Puedes definir funciones que tomen un número variable de argumentos
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# Puedes definir funciones que toman un número variable de argumentos
+# de palabras claves
+def keyword_args(**kwargs):
+ return kwargs
+
+# Llamémosla para ver que sucede
+keyword_args(pie="grande", lago="ness") #=> {"pie": "grande", "lago": "ness"}
+
+
+# You can do both at once, if you like# Puedes hacer ambas a la vez si quieres
+def todos_los_argumentos(*args, **kwargs):
+ print args
+ print kwargs
+"""
+todos_los_argumentos(1, 2, a=3, b=4) imprime:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# ¡Cuando llames funciones, puedes hacer lo opuesto a varargs/kwargs!
+# Usa * para expandir tuplas y usa ** para expandir argumentos de palabras claves.
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+todos_los_argumentos(*args) # es equivalente a foo(1, 2, 3, 4)
+todos_los_argumentos(**kwargs) # es equivalente a foo(a=3, b=4)
+todos_los_argumentos(*args, **kwargs) # es equivalente a foo(1, 2, 3, 4, a=3, b=4)
+
+# Python tiene funciones de primera clase
+def crear_suma(x):
+ def suma(y):
+ return x + y
+ return suma
+
+sumar_10 = crear_suma(10)
+sumar_10(3) #=> 13
+
+# También hay funciones anónimas
+(lambda x: x > 2)(3) #=> True
+
+# Hay funciones integradas de orden superior
+map(sumar_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# Podemos usar listas por comprensión para mapeos y filtros agradables
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. Classes
+####################################################
+
+
+# Heredamos de object para obtener una clase.
+class Humano(object):
+
+ # Un atributo de clase es compartido por todas las instancias de esta clase
+ especie = "H. sapiens"
+
+ # Constructor basico
+ def __init__(self, nombre):
+ # Asigna el argumento al atributo nombre de la instancia
+ self.nombre = nombre
+
+ # Un metodo de instancia. Todos los metodos toman self como primer argumento
+ def decir(self, msg):
+ return "%s: %s" % (self.nombre, msg)
+
+ # Un metodo de clase es compartido a través de todas las instancias
+ # Son llamados con la clase como primer argumento
+ @classmethod
+ def get_especie(cls):
+ return cls.especie
+
+ # Un metodo estatico es llamado sin la clase o instancia como referencia
+ @staticmethod
+ def roncar():
+ return "*roncar*"
+
+
+# Instancia una clase
+i = Humano(nombre="Ian")
+print i.decir("hi") # imprime "Ian: hi"
+
+j = Humano("Joel")
+print j.decir("hello") #imprime "Joel: hello"
+
+# Llama nuestro método de clase
+i.get_especie() #=> "H. sapiens"
+
+# Cambia los atributos compartidos
+Humano.especie = "H. neanderthalensis"
+i.get_especie() #=> "H. neanderthalensis"
+j.get_especie() #=> "H. neanderthalensis"
+
+# Llama al método estático
+Humano.roncar() #=> "*roncar*"
+
+
+####################################################
+## 6. Módulos
+####################################################
+
+# Puedes importar módulos
+import math
+print(math.sqrt(16)) #=> 4
+
+# Puedes obtener funciones específicas desde un módulo
+from math import ceil, floor
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7))#=> 3.0
+
+# Puedes importar todas las funciones de un módulo
+# Precaución: Esto no es recomendable
+from math import *
+
+# Puedes acortar los nombres de los módulos
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# Los módulos de Python son sólo archivos ordinarios de Python.
+# Puedes escribir tus propios módulos e importarlos. El nombre del módulo
+# es el mismo del nombre del archivo.
+
+# Puedes encontrar que funciones y atributos definen un módulo.
+import math
+dir(math)
+
+
+####################################################
+## 7. Avanzado
+####################################################
+
+# Los generadores te ayudan a hacer un código perezoso (lazy)
+def duplicar_numeros(iterable):
+ for i in iterable:
+ yield i + i
+
+# Un generador cera valores sobre la marcha.
+# En vez de generar y retornar todos los valores de una vez, crea uno en cada iteración.
+# Esto significa que valores más grandes que 15 no serán procesados en 'duplicar_numeros'.
+# Fíjate que 'range' es un generador. Crear una lista 1-900000000 tomaría mucho tiempo en crearse.
+_rango = range(1, 900000000)
+# Duplicará todos los números hasta que un resultado >= se encuentre.
+for i in duplicar_numeros(_rango):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decoradores
+# en este ejemplo 'pedir' envuelve a 'decir'
+# Pedir llamará a 'decir'. Si decir_por_favor es True entonces cambiará el mensaje a retornar
+from functools import wraps
+
+
+def pedir(_decir):
+ @wraps(_decir)
+ def wrapper(*args, **kwargs):
+ mensaje, decir_por_favor = _decir(*args, **kwargs)
+ if decir_por_favor:
+ return "{} {}".format(mensaje, "¡Por favor! Soy pobre :(")
+ return mensaje
+
+ return wrapper
+
+
+@pedir
+def say(decir_por_favor=False):
+ mensaje = "¿Puedes comprarme una cerveza?"
+ return mensaje, decir_por_favor
+
+
+print(decir()) # ¿Puedes comprarme una cerveza?
+print(decir(decir_por_favor=True)) # ¿Puedes comprarme una cerveza? ¡Por favor! Soy pobre :()
+```
+
+## ¿Listo para más?
+
+### Gratis y en línea
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+* [The Official Docs](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Encuadernados
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/es-es/whip-es.html.markdown b/es-es/whip-es.html.markdown
new file mode 100644
index 00000000..7c2f4bd2
--- /dev/null
+++ b/es-es/whip-es.html.markdown
@@ -0,0 +1,255 @@
+---
+language: whip
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+translators:
+ - ["Daniel Zendejas", "https://github.com/DanielZendejas"]
+author: Tenor Biel
+author_url: http://github.com/L8D
+filename: whip-es.lisp
+lang: es-es
+---
+Tutorial de Whip en español.
+
+Whip es un dialecto de LISP hecho para escribir código y conceptos
+simples. Ha tomado prestado bastante de la sintaxis de Haskell
+(un lenguaje no relacionado).
+
+Esta documentación fue escrita por el creador del lenguaje
+
+```scheme
+; Los comentarios son como en LISP, con punto y coma...
+
+; La mayoría de las sentencias de primer nivel están dentro de
+; "formas". Una forma no es más que cosas dentro de paréntesis
+no_en_la_forma
+(en_la_form)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; 1. Números, Strings y Operadores
+
+;Whip tiene un tipo para números (es el estándar 64-bit IEEE 754 double, de JS)
+3 ; => 3
+1.5 ; => 1.5
+
+; Las funciones son llamadas si son el primer elemento de una forma
+(funcion_llamada argumentos)
+
+; La mayoría de los operadores se hacen con funciones
+; Toda la aritmética básica es bastante estándar
+(+ 1 1) ; => 2
+(- 2 1) ; => 1
+(* 1 2) ; => 2
+(/ 2 1) ; => 2
+; incluso el módulo
+(% 9 4) ; => 1
+; división impar al estilo de JavaScript.
+(/ 5 2) ; => 2.5
+
+; Las formas anidadas funcionan como se espera.
+(* 2 (+ 1 3)) ; => 8
+
+; Hay un tipo booleano.
+true
+false
+
+; Los Strings son creados con comillas dobles ".
+"Hola mundo"
+
+; Los caracteres solos se declaran con comillas simples '.
+'a'
+
+; La negación usa la función 'not'.
+(not true) ; => false
+(not false) ; => true
+
+; La mayoría de las funcions que no vienen de Haskell tienen
+; atajos. La función 'not' también se puede declarar con '!'.
+(! (! true)) ; => true
+
+; La igualdad es `equal` o `=`.
+(= 1 1) ; => true
+(equal 2 1) ; => false
+
+; Por ejemplo, la desigualdad sería combinar la función 'not' con
+; la función de igualdad
+(! (= 2 1)) ; => true
+
+; Más comparaciones
+(< 1 10) ; => true
+(> 1 10) ; => false
+; y su contraparte textual.
+(lesser 1 10) ; => true
+(greater 1 10) ; => false
+
+; Los Strings pueden concatenarse con la función +.
+(+ "Hola " "mundo!") ; => "Hello world!"
+
+; También puedes usar las comparativas de JavaScript
+(< 'a' 'b') ; => true
+; ...y la coerción de tipos
+(= '5' 5)
+
+; La función 'at' o @ accesa a los caracteres dentro de los strings,
+; empezando en 0.
+(at 0 'a') ; => 'a'
+(@ 3 "foobar") ; => 'b'
+
+; También están las variables `null` and `undefined`.
+null; usado para indicar una falta de valor deliberada.
+undefined; usado para indicar un valor que aún no está definido.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; 2. Variables, Listas y Diccionarios
+
+; Las variables son declaradas con las funciones `def` o `let`.
+; Las variables que aún no son asignadas tendrán el valor `undefined`.
+(def mi_variable 5)
+; `def` asignará la variable al contexto global.
+; `let` asignará la variable al contexto local,
+; y tiene una sintaxis distinta.
+(let ((mi_variable 5)) (+ mi_variable 5)) ; => 10
+(+ mi_variable 5) ; = undefined + 5 => undefined
+
+; Las listas son arreglos de valores de cualquier tipo.
+; Básicamente, son formas sin funciones al inicio.
+(1 2 3) ; => [1, 2, 3] (sintaxis JavaScript)
+
+; Los diccionarios son el equivalente en Whip de los 'objetos' de JavaScript,
+; los 'dicts' de Python o los 'hashes' de Ruby: una colección desordenada
+; de pares llave-valor
+{"llave1" "valor1" "llave2" 2 3 3}
+
+; Las llaves son sólo valores, identificadores, números o strings.
+(def mi_diccionario {mi_llave "mi_valor" "mi otra llave" 4})
+; Pero con Whip, los diccionarios son leidos así:
+; "llave" "espacio en blanco" "valor" "espacio en blanco"
+{"llave" "valor"
+"otra llave"
+1234
+}
+
+; Las definiciones de los diccionarios pueden accesarse con la función @
+; (como los strings y las listas)
+(@ "mi otra llave" mi_diccionario) ; => 4
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+; 3. Logica y secuencias de control
+
+; La funcion `if` es bastante simple, aunque distinta que en otros lenguajes.
+(if true "regresa esto si es true" "regresa esto si es false")
+; => "regresa esto si es true"
+
+; Y para el operador ternario `?`
+(? false true false) ; => false
+
+? `both` es un 'y' lógico, mientras que la función `either` es un 'o'.
+(both true true) ; => true
+(both true false) ; => false
+(either true false) ; => true
+(either false false) ; => false
+; Y sus atajos son '&' y '^' respectivamente
+; & => both
+; ^ => either
+(& true true) ; => true
+(^ false true) ; => true
+
+;;;;;;;;;
+; Lambdas
+
+; Las Lambdas en Whip son declaradas con las funciones `lambda` o `->`.
+; Las funciones regulares en realidad sólo son lambdas con nombre.
+(def mi_funcion (-> (x y) (+ (+ x y) 10)))
+; | | | |
+; | | | valor regresado(estas son las variables argumentos)
+; | | argumentos
+; | declaración de lambda
+; |
+; nombre de la lambda
+
+(mi_funcion 10 10) ; = (+ (+ 10 10) 10) => 30
+
+; Obviamente, todas las lambdas por definición son anónimas y
+; técnicamente siempre usadas anónimamente. Redundancia.
+((lambda (x) x) 10) ; => 10
+
+;;;;;;;;;;;;;;;;
+; Comprensiones
+
+; `range` o `..` genera una lista de números que comprende
+; cada entero dentro de los argumentos.
+(range 1 5) ; => (1 2 3 4 5)
+(.. 0 2) ; => (0 1 2)
+
+; `map` aplica su primer argumento (que debe ser una función)
+; al siguiente argumento (que es una lista).
+(map (-> (x) (+ x 1)) (1 2 3)) ; => (2 3 4)
+
+; Reducir
+(reduce + (.. 1 5))
+; equivale a
+((+ (+ (+ 1 2) 3) 4) 5)
+
+; Nota: map y reduce no tienen atajos.
+
+; `slice` o `\` es idéntico a la función .slice() de JavaScript
+; Pero toma la lista del primer argumento, no del último.
+(slice (.. 1 5) 2) ; => (3 4 5)
+(\ (.. 0 100) -5) ; => (96 97 98 99 100)
+
+; `append` o `<<` se explica solo.
+(append 4 (1 2 3)) ; => (1 2 3 4)
+(<< "bar" ("foo")) ; => ("foo" "bar")
+
+; Length se explica solo.
+(length (1 2 3)) ; => 3
+(_ "foobar") ; => 6
+
+;;;;;;;;;;;;;;;
+; Elementos de Haskell
+
+; Primer elemento en una lista
+(head (1 2 3)) ; => 1
+
+; Lista del segundo elemento al último en una lista
+(tail (1 2 3)) ; => (2 3)
+
+; Último elemento en una lista
+(last (1 2 3)) ; => 3
+
+; Contrario a `tail`
+(init (1 2 3)) ; => (1 2)
+
+; Lista del primer elemento al argumento
+(take 1 (1 2 3 4)) ; (1 2)
+
+; Contrario a `take`
+(drop 1 (1 2 3 4)) ; (3 4)
+
+; Valor más pequeño de una lista
+(min (1 2 3 4)) ; 1
+
+; Valor más grande de una lista
+(max (1 2 3 4)) ; 4
+
+; Comprobar que el elemento está en la lista
+(elem 1 (1 2 3)) ; true
+(elem "foo" {"foo" "bar"}) ; true
+(elem "bar" {"foo" "bar"}) ; false
+
+; Invertir el orden de la lista
+(reverse (1 2 3 4)) ; => (4 3 2 1)
+
+; Comprobar si un elemento es par o impar
+(even 1) ; => false
+(odd 1) ; => true
+
+; Separar string en una lista de strings, separados por espacios
+(words "foobar nachos cheese") ; => ("foobar" "nachos" "cheese")
+; Juntar lista de strings.
+(unwords ("foo" "bar")) ; => "foobar"
+(pred 21) ; => 20
+(succ 20) ; => 21
+```
+
+Para más información, revisa el [repositorio](http://github.com/L8D/whip)
diff --git a/es-es/xml-es.html.markdown b/es-es/xml-es.html.markdown
new file mode 100644
index 00000000..2e9326cf
--- /dev/null
+++ b/es-es/xml-es.html.markdown
@@ -0,0 +1,131 @@
+---
+language: xml
+filename: learnxml.xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+translators:
+ - ["Daniel Zendejas", "https://github.com/DanielZendejas"]
+lang: es-es
+---
+XML es un lenguaje diseñado para guardar y transportar datos
+
+A diferencia de HTML, XML no especifica cómo desplegar la información,
+sólo la guarda.
+
+* Sintaxis XML
+
+```xml
+<!-- Los comentarios en XML son de esta forma -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<tiendaDeLibros>
+ <libro categoria="COCINA">
+ <titulo lenguaje="en">Everyday Italian</titulo>
+ <autor>Giada De Laurentiis</autor>
+ <anio>2005</anio>
+ <precio>30.00</precio>
+ </libro>
+ <libro categoria="INFANTES">
+ <titulo lenguaje="en">Harry Potter</titulo>
+ <autor>J K. Rowling</autor>
+ <anio>2005</anio>
+ <precio>29.99</precio>
+ </libro>
+ <libro categoria="WEB">
+ <titulo lenguaje="en">Learning XML</titulo>
+ <autor>Erik T. Ray</autor>
+ <anio>2003</anio>
+ <precio>39.95</precio>
+ </libro>
+</tiendaDeLibros>
+
+<!-- Este es un archivo típico de XML.
+ Empieza con una declaración de metadatos (opcional).
+
+ XML usa una estructura de árbol. El nodo raíz es 'tiendaDeLibros', el cual
+ tiene tres nodos hijos, todos llamados 'libros'.
+ Esos nodos tienen más nodos hijos, y así continúa...
+
+ Los nodos son creados usando tags que abren y cierran, y los hijos
+ son sólo nodos entre estas tags.-->
+
+
+<!-- XML guarda dos tipos de datos:
+ 1 - Atributos -> Son los metadatos de un nodo.
+ Usualmente el parseador XML usa esta información para guardar los datos
+ apropiadamente. Aparecen con el formato (nombre="valor") dentro de la
+ tag que abre.
+ 2 - Elementos -> Ese es el dato puro.
+ Eso es lo que el parseador recuperará del archivo XML.
+ Los elementos aparecen entre las tags que abren y cierran.-->
+
+
+<!-- Debajo, un elemento con dos atributos. -->
+<archivo tipo="gif" id="4293">computer.gif</archivo>
+
+
+```
+
+* Documentos con buen formato x Validación
+
+Un documento XML está bien formado cuando es sintácticamente correcto.
+Aún esto, es posible inyectar más restricciones en el documento,
+usando definiciones de documento, así como DTD o XML Schemas.
+
+Un documento XML que sigue a una definición de documento (un esquema) es
+válida.
+
+Con esta herramienta puedes validar datos XML fuera de la aplicación
+
+```xml
+
+<!-- Debajo puedes encontrar una versión simplificada del documento
+ tiendaDeLibros en adición a la definición DTD.-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "tiendaDeLibros.dtd">
+<tiendaDeLibros>
+ <libro categoriq="COCINA">
+ <titulo>Everyday Italian</titulo>
+ <precio>30.00</precio>
+ </libro>
+</tiendaDeLibros>
+
+<!-- El DTD de este documento podría verse algo así:-->
+
+<!DOCTYPE note
+[
+<!ELEMENT tiendaDeLibros (libro+)>
+<!ELEMENT libro (titulo,precio)>
+<!ATTLIST libro categoria CDATA "Literatura">
+<!ELEMENT titulo (#PCDATA)>
+<!ELEMENT precio (#PCDATA)>
+]>
+
+<!--El DTD empieza con una declaración.
+ Después el nodo raíz es declarado, requiriendo 1 o más nodos 'libro'
+ Cada 'libro' debe contener exactamente un 'titulo' y un 'precio' y
+ un atributo llamado 'categoria', con "Literatura" como su valor
+ default.
+ Los nodos 'titulo' y 'precio' contienen datos de caracteres
+ parseados.
+
+ El DTD puede ser declarado dentro del XML mismo.-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT tiendaDeLibros (libro+)>
+<!ELEMENT libro (titulo,precio)>
+<!ATTLIST libro categoria CDATA "Literatura">
+<!ELEMENT titulo (#PCDATA)>
+<!ELEMENT precio (#PCDATA)>
+]>
+<tiendaDeLibros>
+ <libro categoriq="COCINA">
+ <titulo>Everyday Italian</titulo>
+ <precio>30.00</precio>
+ </libro>
+</tiendaDeLibros>
+```
diff --git a/es-es/yaml-es.html.markdown b/es-es/yaml-es.html.markdown
new file mode 100644
index 00000000..a5157b5d
--- /dev/null
+++ b/es-es/yaml-es.html.markdown
@@ -0,0 +1,151 @@
+---
+language: yaml
+lang: es-es
+filename: learnyaml-es.yaml
+contributors:
+ - ["Adam Brenecki", "https://github.com/adambrenecki"]
+translators:
+ - ["Daniel Zendejas","https://github.com/DanielZendejas"]
+---
+Tutorial de YAML en español.
+
+YAML es un lenguaje de serialización de datos diseñado para ser
+leído y escrito por humanos.
+
+Basa su funcionalidad en JSON, con la adición de líneas nuevas
+e indentación inspirada en Python. A diferencia de Python, YAML
+no permite tabs literales.
+
+```yaml
+# Los comentarios en YAML se ven así.
+
+###################
+# TIPOS ESCALARES #
+###################
+
+# Nuestro objeto raíz (el cual es el mismo a lo largo de todo el
+# documento) será un mapa, equivalente a un diccionario, hash,
+# u objeto en otros lenguajes.
+
+llave: valor
+otra_llave: Otro valor
+un_valor_numerico: 100
+notacion_cientifica: 1e+12
+booleano: true
+valor_nulo: null
+llave con espacios: valor
+# Nótese que los strings no deben estar entre comillas, aunqué también es válido.
+llave: "Un string, entre comillas."
+"Las llaves tambien pueden estar entre comillas.": "valor entre comillas"
+
+# Los strings de líneas múltiples pueden ser escritos
+# como un 'bloque literal' (usando pipes |)
+# o como un 'bloque doblado' (usando >)
+
+bloque_literal: |
+ Este bloque completo de texto será preservado como el valor de la llave
+ 'bloque_literal', incluyendo los saltos de línea.
+
+ Se continúa guardando la literal hasta que se cese la indentación.
+ Cualquier línea que tenga más indentación, mantendrá los espacios dados
+ (por ejemplo, estas líneas se guardarán con cuatro espacios)
+
+nloque_doblado: >
+ De la misma forma que el valor de 'bloque_literal', todas estas
+ líneas se guardarán como una sola literal, pero en esta ocasión todos los
+ saltos de línea serán reemplazados por espacio.
+
+ Las líneas en blanco, como la anterior, son convertidos a un salto de línea.
+
+ Las líneas con mayor indentación guardan sus saltos de línea.
+ Esta literal ocuparán dos líneas.
+
+########################
+# TIPOS DE COLECCIONES #
+########################
+
+# La indentación se usa para anidar.
+un_mapa_indentado:
+ llave: valor
+ otra_llave: otro valor
+ otro_mapa_indentado:
+ llave_interna: valor_interno
+
+# Las llaves de los mapas no deben ser strings necesariamente
+0.25: una llave numérica
+
+# Las llaves también pueden ser objetos de multi línea, usando ? para indicar
+# el inicio de una llave
+? |
+ Esto es una llave
+ que tiene múltiples líneas
+: y este es su valor
+
+# YAML tambien permite colecciones como llaves, pero muchos lenguajes de
+# programación se quejarán.
+
+# Las secuencias (equivalentes a listas o arreglos) se ven así:
+una_secuencia:
+ - Item 1
+ - Item 2
+ - 0.5 # las secuencias pueden tener distintos tipos en su contenido.
+ - Item 4
+ - llave: valor
+ otra_llave: otro_valor
+ -
+ - Esta es una secuencia
+ - ...dentro de otra secuencia
+
+# Dado que todo JSON está incluído dentro de YAML, también puedes escribir
+# mapas con la sintaxis de JSON y secuencias:
+mapa_de_json: {"llave": "valor"}
+secuencia_de_json: [3, 2, 1, "despegue"]
+
+##################################
+# CARACTERÍSTICAS EXTRAS DE YAML #
+##################################
+
+# YAML tiene funciones útiles llamadas 'anchors' (anclas), que te permiten
+# duplicar fácilmente contenido a lo largo de tu documento. En el ejemplo
+# a continuación, ambas llaves tendrán el mismo valor:
+contenido_anclado: &nombre_del_ancla Este string será el valor de las llaves
+otra_ancla: *nombre_del_ancla
+
+# YAML también tiene tags, que puedes usar para declarar tipos explícitamente.
+string_explícito: !!str 0.5
+# Algunos parseadores implementar tags específicas del lenguaje, como el
+# que se muestra a continuación, encargado de manejar números complejos en
+# Python:
+numero_complejo_python: !!python/complex 1+2j
+
+########################
+# TIPOS EXTRAS EN YAML #
+########################
+
+# Stirngs y números no son los únicos escalares que YAML puede entener.
+# YAML también puede parsear fechas en formato ISO .
+fechaHora: 2001-12-15T02:59:43.1Z
+fechaHora_con_espacios: 2001-12-14 21:59:43.10 -5
+fecha: 2002-12-14
+
+# La tag !!binary indica que un string es, en realidad, un blob
+# representado en base-64.
+archivo_gif: !!binary |
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
+
+# YAML también tiene un tipo set, que se ve de la siguiente forma:
+set:
+ ? item1
+ ? item2
+ ? item3
+
+# Al igual que Python, los sets sólo son mapas con valores nulos.
+# El ejemplo de arriba es equivalente a:
+set2:
+ item1: null
+ item2: null
+ item3: null
+```
diff --git a/fa-ir/javascript.html.markdown b/fa-ir/javascript.html.markdown
index 922fe416..5c64d24a 100644
--- a/fa-ir/javascript.html.markdown
+++ b/fa-ir/javascript.html.markdown
@@ -493,8 +493,8 @@ myNumber == myNumberObj; // = true
<p dir='rtl'>به جز این که این سازنده ها دقیقا مانند سازنده های دیگر نیستند.</p>
```js
-typeof(myNumber); // = 'number'
-typeof(myNumberObj); // = 'object'
+typeof myNumber; // = 'number'
+typeof myNumberObj; // = 'object'
myNumber === myNumberObj; // = false
if (0){
// This code won't execute, because 0 is falsy.
diff --git a/fr-fr/brainfuck-fr.html.markdown b/fr-fr/brainfuck-fr.html.markdown
new file mode 100644
index 00000000..3882734d
--- /dev/null
+++ b/fr-fr/brainfuck-fr.html.markdown
@@ -0,0 +1,87 @@
+---
+language: brainfuck
+filename: learnbrainfuck-fr.bf
+contributors:
+ - ["Prajit Ramachandran", "http://prajitr.github.io/"]
+ - ["Mathias Bynens", "http://mathiasbynens.be/"]
+translators:
+ - ["Baptiste Fontaine", "http://bfontaine.net"]
+lang: fr-fr
+---
+
+Brainfuck (sans majuscule à part au début d’une phrase) est un langage
+Turing-complet extrêmement simple avec seulement 8 commandes.
+
+```
+Tout caractère en dehors de "><+-.,[]" (en dehors des guillements) est ignoré.
+
+Brainfuck est représenté par un tableau de 30 000 cellules initialisées à 0 et
+un pointeur de données pointant sur la cellule courante.
+
+Il y a huit commandes :
++ : Incrémente la valeur de la cellule courante de un.
+- : Décrémente la valeur de la cellule courante de un.
+> : Déplace le pointeur de données sur la cellule suivante (à droite).
+< : Déplace le pointeur de données sur la cellule précédente (à gauche).
+. : Affiche la valeur ASCII de la cellule courante (par ex. 65 = 'A').
+, : Lit un caractère et le place dans la cellule courante.
+[ : Si la valeur dans la cellule courante vaut 0, saute au ] correspondant.
+ Sinon, continue avec la commande suivante.
+] : Si la valeur dans la cellule courante vaut 0, continue avec la commande
+ suivante. Sinon, retourne au [ correspondant.
+
+[ et ] forment une boucle « tant que » (« while »). Ils doivent évidemment
+aller par paires.
+
+Regardons quelques programmes simples en brainfuck.
+
+++++++ [ > ++++++++++ < - ] > +++++ .
+
+Ce programme affiche la lettre 'A'. Il commence par incrémenter la première
+cellule à 6. Il entre ensuite dans une boucle et se déplace sur la seconde
+cellule. Il l’incrémente 10 fois, retourne sur la première cellule, et la
+décrémente. Cette boucle est exécutée 6 fois (ce qui correspond aux 6
+décrémentations de la première cellule pour la faire atteindre 0, ce qui fait
+sortir de la boucle).
+
+À ce moment-là, nous sommes sur la première cellule, qui a une valeur de 0,
+tandis que la seconde cellule a une valeur de 60. Nous nous déplaçons sur
+celle-ci, l’incrémentons 5 fois, pour une valeur de 65, et affichons sa valeur.
+En ASCII, 65 correspond à 'A' donc le programme affiche 'A' dans le terminal.
+
+, [ > + < - ] > .
+
+Ce programme lit un caractère sur l’entrée standard et le copie dans la
+première cellule. Il commence ensuite une boucle : il bouge sur la seconde
+cellule, incrémente sa valeur, retourne sur la première et décrémente sa
+valeur. Il continue jusqu’à ce que la valeur de la première cellule soit à 0,
+et que la seconde cellule contienne l’ancienne valeur de la première. Comme
+nous sommes sur la première cellule à la fin de la boucle, il bouge sur la
+seconde et affiche sa valeur en ASCII.
+
+Souvenez-vous que les espaces sont uniquement là pour favoriser la lisibilité,
+vous pourriez tout aussi aisément écrire le programme comme ceci :
+
+,[>+<-]>.
+
+Essayez et devinez ce que ce programme fait :
+
+,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
+
+Ce programme prend deux nombres en entrée, et les multiplie.
+
+Il commence par lire deux entrées, puis commence une boucle externe, qui a une
+condition sur la première cellule. Il bouge ensuite sur la seconde, et commence
+une boucle interne sur celle-ci, en incrémentant la troisième cellule. Il y a
+cependant un problème : à la fin de la boucle interne, la valeur de la seconde
+cellule est à zéro. Dans ce cas, la boucle interne ne fonctionnera pas une
+seconde fois. Pour régler le problème, nous incrémentons aussi la quatrième
+cellule, puis recopions sa valeur dans la seconde cellule.
+À la fin, la troisième cellule contient le résultat de la multiplication.
+```
+
+Et voilà ce qu’est le brainfuck. Pas très dur, hein ? Pour le fun, vous pouvez
+écrire vos propres programmes en brainfuck, ou écrire un interpréteur brainfuck
+dans un autre langage. L’interpréteur est relativement simple à implémenter,
+mais si vous êtes un masochiste, essayez d’écrire un interpréteur brainfuck en…
+brainfuck.
diff --git a/fr-fr/csharp-fr.html.markdown b/fr-fr/csharp-fr.html.markdown
index c1641716..e51eacc8 100644
--- a/fr-fr/csharp-fr.html.markdown
+++ b/fr-fr/csharp-fr.html.markdown
@@ -7,7 +7,7 @@ contributors:
- ["Shaun McCarthy", "http://www.shaunmccarthy.com"]
translators:
- ["Olivier Hoarau", "https://github.com/Olwaro"]
-filename: LearnCSharp.cs
+filename: LearnCSharp-fr.cs
lang: fr-fr
---
diff --git a/fr-fr/css-fr.html.markdown b/fr-fr/css-fr.html.markdown
new file mode 100644
index 00000000..bdab9715
--- /dev/null
+++ b/fr-fr/css-fr.html.markdown
@@ -0,0 +1,221 @@
+---
+language: css
+contributors:
+ - ["Mohammad Valipour", "https://github.com/mvalipour"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["@prrrnd", "https://github.com/prrrnd"]
+lang: fr-fr
+---
+
+Au début du web, il n'y avait pas d'élements visuels, simplement du texte pure. Mais avec le dévelopement des navigateurs,
+des pages avec du contenu visuel sont arrivées.
+CSS est le langage standard qui existe et permet de garder une séparation entre
+le contenu (HTML) et le style d'une page web.
+
+En résumé, CSS fournit une syntaxe qui vous permet de cibler des élements présents
+sur une page HTML afin de leur donner des propriétés visuelles différentes.
+
+Comme tous les autres langages, CSS a plusieurs versions. Ici, nous allons parlons de CSS2.0
+qui n'est pas le plus récent, mais qui reste le plus utilisé et le plus compatible avec les différents navigateur.
+
+**NOTE :** Vous pouvez tester les effets visuels que vous ajoutez au fur et à mesure du tutoriel sur des sites comme [dabblet](http://dabblet.com/) afin de voir les résultats, comprendre, et vous familiariser avec le langage.
+Cet article porte principalement sur la syntaxe et quelques astuces.
+
+
+```css
+/* Les commentaires sont entourés par slash-étoile, comme cette ligne! */
+
+/* ####################
+ ## SÉLECTEURS
+ ####################*/
+
+/* Généralement, la première déclaration en CSS est très simple */
+selecteur { propriete: valeur; /* autres proprietés...*/ }
+
+/* Le sélécteur sert à cibler un élément du HTML
+
+Vous pouvez cibler tous les éléments d'une page! */
+* { color:red; }
+
+/*
+Voici un élément dans notre HTML :
+
+<div class='une-classe classe2' id='unId' attr='valeur' />
+*/
+
+/* Vous pouvez le cibler par une classe */
+.une-classe { }
+
+/* ou par deux */
+.une-classe.classe2 { }
+
+/* ou par son type */
+div { }
+
+/* ou son id */
+#unId { }
+
+/* ou par le fait qu'il a un attribut */
+[attr] { font-size:smaller; }
+
+/* ou que l'attribut a une valeur spécifique */
+[attr='valeur'] { font-size:smaller; }
+
+/* commence avec une valeur */
+[attr^='val'] { font-size:smaller; }
+
+/* termine avec une valeur */
+[attr$='eur'] { font-size:smaller; }
+
+/* contient une valeur */
+[attr~='leu'] { font-size:smaller; }
+
+
+/* Ce qu'il faut bien comprendre, c'est que vous pouvez combiner ceci -- Il ne doit pas y avoir
+d'espaces entre. */
+div.une-classe[attr$='eu'] { }
+
+/* Vous pouvez aussi cibler un élément par son parent. */
+
+/* Un élément qui est en enfant direct */
+div.un-parent > .enfant {}
+
+/* Cela cible aussi les .enfants plus profonds dans la structure HTML */
+div.un-parent .enfants {}
+
+/* Attention : le même sélecteur sans espace a un autre sens. */
+div.un-parent.classe {}
+
+/* Vous pouvez cibler un élément basé sur un enfant de même parent */
+.je-suis-avant + .cet-element { }
+
+/* ou n'importe quel enfant de même parent avec celui ci */
+.je-suis-tout-avant ~ .cet-element {}
+
+/* Il y a des pseudo-classes qui permettent de cibler un élément
+basé sur le comportement, en plus de la structure de la page */
+
+/* élément avec le curseur au-dessus */
+:hover {}
+
+/* lien visité */
+:visited {}
+
+/* lien non visité */
+:link {}
+
+/* élément avec le focus */
+:focus {}
+
+
+/* ####################
+ ## PROPRIÉTÉS
+ ####################*/
+
+selecteur {
+
+ /* Units */
+ width: 50%; /* pourcentage */
+ font-size: 2em; /* taille de la police multipliée par X */
+ width: 200px; /* pixels */
+ font-size: 20pt; /* points */
+ width: 5cm; /* centimetres */
+ width: 50mm; /* millimetres */
+ width: 5in; /* pouces */
+
+ /* Couleurs */
+ background-color: #F6E; /* court hex */
+ background-color: #F262E2; /* long hex */
+ background-color: tomato; /* couleur nommée */
+ background-color: rgb(255, 255, 255); /* rouge, vert, bleu */
+ background-color: rgb(10%, 20%, 50%); /* rouge, vert, bleu en pourcent */
+ background-color: rgba(255, 0, 0, 0.3); /* rouge, vert, bleu avec transparence */
+
+ /* Images */
+ background-image: url(/chemin-vers-image/image.jpg);
+
+ /* Polices */
+ font-family: Arial;
+ font-family: "Courier New"; /* Si espace, entre guillemets */
+ font-family: "Courier New", Trebuchet, Arial; /* Si la première n'est pas trouvée, la deuxième est utilisée, etc... */
+}
+
+```
+
+## Utilisation
+
+Le CSS s'écrit dans des fichiers `.css`.
+
+```xml
+<!-- Vous devez inclure le CSS dans la balise <head> : -->
+<link rel='stylesheet' type='text/css' href='chemin/style.css' />
+
+<!-- Vous pouvez inclure du CSS dans le HTML directement, mais ce n'est vraiment pas recommandé. -->
+<style>
+ selecteur { propriete:valeur; }
+</style>
+
+<!-- ou directement sur l'élément HTML.
+PS : à ne pas faire. -->
+<div style='propriete:valeur;'>
+</div>
+
+```
+
+## Priorités
+
+Comme on vient de le voir, un élément peut être ciblé par plus qu'un seul sélecteur
+et une même propriété peut être définie plusieurs fois.
+Dans ces cas, une des propriétés devient prioritaire.
+
+Voici du code CSS :
+
+```css
+/*A*/
+p.classe1[attr='valeur']
+
+/*B*/
+p.classe1 {}
+
+/*C*/
+p.classe2 {}
+
+/*D*/
+p {}
+
+/*E*/
+p { propriete: valeur !important; }
+
+```
+
+et le code HTML:
+
+```xml
+<p style='/*F*/ propriete:valeur;' class='classe1 classe2' attr='valeur'>
+</p>
+```
+
+Les priorités de style sont :
+Attention, les priorités s'appliquent aux **propriétés**, pas aux blocs entiers.
+
+* `E` a la priorité grâce à `!important`.
+* `F` vient ensuite, car le code se trouve directement dans le HTML.
+* `A` vient ensuite, car il est le plus spécifique.
+ plus spécifique veut dire, celui qui cible le plus l'élément
+* `C` vient ensuite. Il est aussi spécifique que `B`, mais est écrit après.
+* Puis `B`
+* Et enfin `D`.
+
+## Compatibilité
+
+La plupart des fonctionnalités de CSS2 (et de plus en plus CSS3) sont compatibles
+avec tous les navigateurs. Mais il est important de vérifier la compatibilité.
+
+[QuirksMode CSS](http://www.quirksmode.org/css/) est une très bonne source pour cela.
+
+## En savoir plus (en anglais)
+
+* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
+* [QuirksMode CSS](http://www.quirksmode.org/css/)
+* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
diff --git a/fr-fr/haskell.html.markdown b/fr-fr/haskell.html.markdown
index 989db1d5..d9d3151f 100644
--- a/fr-fr/haskell.html.markdown
+++ b/fr-fr/haskell.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
translators:
diff --git a/fr-fr/javascript-fr.html.markdown b/fr-fr/javascript-fr.html.markdown
new file mode 100644
index 00000000..2e18d0be
--- /dev/null
+++ b/fr-fr/javascript-fr.html.markdown
@@ -0,0 +1,525 @@
+---
+language: javascript
+contributors:
+ - ['Adam Brenecki', 'http://adam.brenecki.id.au']
+ - ['Ariel Krakowski', 'http://www.learneroo.com']
+filename: javascript-fr.js
+translators:
+ - ['@nbrugneaux', 'https://nicolasbrugneaux.me']
+lang: fr-fr
+---
+
+JavaScript a été créé par Brendan Eich, travaillant alors a Netscape, en 1995.
+Le langage avait à l'origine pour but d'être un langage de scripting simple
+pour les sites web, complétant le Java (à ne pas confondre avec JavaScript)
+pour des applications web complexes. Mais son intégration très proche et
+simple des pages web, ainsi que le support natif des navigateurs a rendu
+le JavaScript incontournable aujourd'hui tant bien dans le front-end que
+dans le back-end.
+
+En effet, le JavaScript n'est plus uniquement limité aux navigateurs, grâce à
+Node.JS, un projet qui offre un environnement indépendant dans lequel un
+interpréteur Javascript, basé sur le célèbre moteur V8 de Google Chrome,
+peut être utilisé directement côté serveur pour exécuter des programmes écrits
+en JavaScript.
+
+```js
+// Les commentaires sont comme en C. Les commentaires mono-ligne commencent par 2 slashs,
+/* et les commentaires sur plusieurs lignes commencent avec slash-étoile
+ et finissent avec étoile-slash */
+
+// Toutes les expressions peuvent finir par ;
+doStuff();
+
+// ... mais n'en n'ont pas forcément besoin, les point-virgules sont ajoutés
+// lors de l’interprétation aux sauts de ligne, sauf exceptions
+doStuff()
+
+// Parce que ces cas peuvent produire des effets inattendus, nous utiliserons
+// des point-virgules dans ce guide.
+
+
+///////////////////////////////////
+// 1. Nombres, Chaines de caractères et Opérateurs
+
+// JavaScript a un seul type de nombre (qui est un 64-bit IEEE 754 double (décimaux))
+// Comme avec le Lua, ne paniquez pas à cause du manque d'int (entiers) : les
+// doubles ont un mantisse de 52 bits, ce qui est assez pour stocker des int jusqu'à
+// 9 x 10¹⁵ exactement.
+3; // = 3
+1.5; // = 1.5
+
+// L'arithmétique de base fonctionne comme vous vous y attendriez
+1 + 1; // = 2
+8 - 1; // = 7
+10 * 2; // = 20
+35 / 5; // = 7
+
+// Ainsi que les divisions non-entières
+5 / 2; // = 2.5
+
+// Les opérations bits à bits fonctionnent aussi, quand vous effectuez une opération
+// bits à bits, votre nombre décimal est converti en entier *jusqu'à* 32 bits.
+1 << 2; // = 4
+
+// Comme en mathématiques, la priorité est donnée aux parenthèses.
+(1 + 3) * 2; // = 8
+
+// Il existe 3 valeurs spéciales pour les nombres:
+Infinity; // le résultat de 1/0 par exemple
+-Infinity; // le résultat de -1/0 par exemple
+NaN; // le résultat de 0/0 par exemple
+
+// Il existe également le type booléen.
+true; // vrai
+false; // faux
+
+// Les chaines de caractères (strings) sont créees avec " ou ' indifféremment, la seule
+// raison de choisir l'un ou l'autre est la cohérence dans votre code.
+"abc";
+'Hello, world';
+
+// La négation utilise le symbole !
+!true; // = false
+!false; // = true
+
+// L'égalité est === ou ==
+// === compare la valeur exacte 2 === '2' // = false
+// == convertit la valeur pour comparer 2 === '2' // = true
+// En général, il vaut mieux utiliser === pour ne pas faire d'erreur.
+1 === 1; // = true
+2 === 1; // = false
+
+// L'inégalité est !== ou !=, basé sur le même principe qu'avant.
+1 !== 1; // = false
+2 !== 1; // = true
+
+// Plus de comparaisons :
+1 < 10; // = true
+1 > 10; // = false
+2 <= 2; // = true
+2 >= 2; // = true
+
+// Les chaines de caractères se concatènent avec +
+'Hello ' + 'world!'; // = 'Hello world!'
+
+// et peuvent être comparées alphabétiquement avec < et >
+'a' < 'b'; // = true
+
+// Vous pouvez accéder les caractères dans une string avec charAt
+'This is a string'.charAt(0); // = 'T'
+
+// ... ou utiliser substring pour avoir un plus gros morceau
+'Hello world'.substring(0, 5); // = 'Hello'
+
+// la longueur, length, est une propriété, donc n'utilisez pas de ()
+'Hello'.length; // = 5
+
+// Il y a également null et undefined
+null; // utilisé pour une non-valeur
+undefined; // utilisé pour une valeur actuellement non présente (cependant,
+ // undefined est aussi une valeur valide)
+
+// false, null, undefined, NaN, 0 and '' sont 'presque-faux' (falsy), tout le reste
+// est 'presque-vrai' (truthy)
+// Notez que 0 est falsy mais '0' est truthy, alors même que 0 == '0' (mais 0 !== '0')
+
+
+///////////////////////////////////
+// 2. Variables, Tableaux et Objets
+
+// Les variables sont déclarées avec le mot clé var. Le typage en JavaScript est
+// dynamique, donc pas besoin de spécifier le type. L'assignement utilise un seul =.
+var someVar = 5;
+
+// si vous oubliez le mot clé var, vous n'aurez pas d'erreur (sauf en mode strict)
+someOtherVar = 10;
+
+// ... mais la variable aura une portée globale (plus communément trouvé en tant
+// que "global scope" en anglais), et non pas une portée limitée à la fonction
+// dans laquelle vous l'aviez définie.
+
+// Les variables déclarées et non assignées sont undefined par défaut
+var someThirdVar;
+var someThirdVar = undefined;
+
+// ... sont deux déclarations identiques.
+
+// Il y a des raccourcis pour les opérations mathématiques:
+someVar += 5; // équivalent pour someVar = someVar + 5;
+someVar *= 10; // de même, someVar = someVar * 100;
+someVar++; // = someVar += 1;
+someVar--; // = someVar -= 1;
+
+// Les tableaux (Arrays) sont des listes ordonnées de valeurs, de tous types.
+var myArray = ['Hello', 45, true];
+
+// Leurs membres peuvent être accédés en utilisant les crochets
+// Les indices commencent à 0.
+myArray[1]; // = 45
+
+// Les tableaux sont modifiables, ainsi que leurs longueurs
+myArray.push( 'World' );
+myArray.length; // = 4
+
+// Ajout/Modification à un index spécifique
+myArray[3] = 'Hello';
+
+// Les objets JavaScript sont appelés 'dictionnaires' ou 'maps' dans certains autres
+// langages : ils sont une liste non-ordonnée de paires clé-valeur.
+var myObj = {key1: 'Hello', key2: 'World'};
+
+// Les clés sont des strings, mais les ' ou " sont optionels si elles sont des
+// noms valides en JavaScript. Les valeurs peuvent être de n'importe quel type.
+var myObj = {myKey: 'myValue', 'my other key': 4};
+
+// Les attributs d'objets peuvent être accédés avec les crochets
+myObj['my other key']; // = 4
+
+// .. ou avec un point si la clé est un identifiant valide.
+myObj.myKey; // = 'myValue'
+
+// Les objets sont eux aussi modifiables.
+myObj.myThirdKey = true;
+
+// Si vous essayez d'accéder à une valeur non-définie, vous obtiendrez undefined
+myObj.myFourthKey; // = undefined
+
+
+///////////////////////////////////
+// 3. Logique et structures de contrôle
+
+// Les si (if) fonctionnent comme vous vous y attendez.
+var count = 1;
+if (count === 3) {
+ // seulement quand count est 3
+}
+else if (count === 4) {
+ // uniquement quand count est 4
+}
+else {
+ // le reste du temps, si ni 3, ni 4.
+}
+
+// De même pour while.
+while (true) {
+ // Une boucle infinie !
+}
+
+// Les boucles do-while sont pareilles, mais sont exécutées au moins une fois.
+var input
+do {
+ input = getInput();
+} while (!isValid(input))
+
+// La boucle for est la même qu'en C ou en Java:
+// initialisation; condition pour continuer; itération
+for (var i = 0; i < 5; i++){
+ // sera exécutée 5 fois
+}
+
+// && est le "et" logique, || est le "ou" logique
+if (house.size === 'big' && house.colour === 'blue'){
+ house.contains = 'bear';
+}
+if (colour === 'red' || colour === 'blue'){
+ // colour est soit 'red' soit 'blue'
+}
+
+// Les raccourcis && et || sont pratiques pour instancier des valeurs par defaut.
+var name = otherName || 'default';
+
+// Ceci est l'équivalent de
+var name = otherName;
+if (!name){
+ name = 'default';
+}
+
+// Le switch vérifie les égalités avec ===
+// utilisez un "break" à la fin de chaque cas
+// ou les cas suivants seront eux aussi exécutés
+grade = 'B';
+switch (grade) {
+ case 'A':
+ console.log('Great job');
+ break;
+ case 'B':
+ console.log('OK job');
+ break;
+ case 'C':
+ console.log('You can do better');
+ break;
+ default:
+ console.log('Oy vey');
+ break;
+}
+
+
+///////////////////////////////////
+// 4. Fonctions, Scope (Environnement) et Closures
+
+// Les fonctions sont déclarées avec le mot clé function
+function myFunction(thing){
+ return thing.toUpperCase();
+}
+myFunction('foo'); // = 'FOO'
+
+// Les fonctions JavaScript sont des objets de première classe, donc peuvent
+// être réassignées à d'autres variables et passées en tant que paramètres pour
+// d'autres fonctions
+function myFunction(){
+ // ce code s'exécutera dans 5 secondes
+}
+setTimeout(myFunction, 5000);
+// Note: setTimeout ne fait pas parti du langage, mais les navigateurs ainsi
+// que Node.js le rendent disponible
+
+// Les fonctions n'ont pas nécessairement besoin d'un nom, elles peuvent être
+// anonymes
+setTimeout(function(){
+ // ce code s'exécutera dans 5 secondes
+}, 5000);
+
+// Le Javascript crée uniquement un scope, une portée d'action limitée, pour
+// les fonctions, et pas dans les autres blocs.
+if (true){
+ var i = 5;
+}
+i; // = 5 - et non undefined comme vous pourriez vous y attendre
+
+// Cela a mené à un style commun de fonctions anonymes immédiatement exécutée;
+// ou "immediately-executing anonymous functions"
+(function(){
+ var temporary = 5;
+ // Nous pouvons accéder au scope global en assignant à l'objet global,
+ // qui dans les navigateurs est "window". Il est différent dans Node.js,
+ // le scope global sera en fait local au module dans lequel vous
+ // vous trouvez. http://nodejs.org/api/globals.html
+ window.permanent = 10;
+})();
+// Cela permet de ne pas avoir de fuites de variables qui polluent
+// l’environnement global.
+temporary; // raises ReferenceError
+permanent; // = 10
+
+// Une des fonctionnalités les plus puissantes de Javascript est le système de
+// closures. Si une fonction est définie dans une autre fonction, alors la
+// fonction interne aura accès aux variables de la fonction parente, même si
+// celle-ci a déjà finie son exécution.
+function sayHelloInFiveSeconds(name){
+ var prompt = 'Hello, ' + name + '!';
+ // Fonction interne
+ function inner(){
+ alert(prompt);
+ }
+ setTimeout(inner, 5000);
+ // setTimeout is asynchrone, donc la fonction sayHelloInFiveSeconds quittera
+ // immédiatement, et setTimeout appelera inner après.
+}
+sayHelloInFiveSeconds('Adam'); // ouvre un popup avec 'Hello, Adam!' dans 5sec
+
+
+///////////////////////////////////
+// 5. Encore plus à propos des Objets; Constructeurs and Prototypes
+
+// Les objets peuvent contenir des fonctions.
+var myObj = {
+ myFunc: function(){
+ return 'Hello world!';
+ }
+};
+myObj.myFunc(); // = 'Hello world!'
+
+// Lorsqu'une fonction attachée à un objet est appelée, elle peut accéder à
+// l'objet avec le mot clé this.
+myObj = {
+ myString: 'Hello world!',
+ myFunc: function(){
+ return this.myString;
+ }
+};
+myObj.myFunc(); // = 'Hello world!'
+
+// La valeur de "this" change de par l'endroit où la fonction est appelée, et
+// non de l'endroit où elle est définie. Donc elle ne fonctionnera pas si elle
+// est appelée hors du contexte l'objet.
+var myFunc = myObj.myFunc;
+myFunc(); // = undefined
+
+// A l'inverse, une fonction peut être attachée à un objet et y gagner l'accès
+// au travers de "this"
+var myOtherFunc = function(){
+ return this.myString.toUpperCase();
+}
+
+myObj.myOtherFunc = myOtherFunc;
+myObj.myOtherFunc(); // = 'HELLO WORLD!'
+
+// Le contexte correspond à la valeur de "this".
+// Nous pouvons aussi spécifier un contexte, forcer la valeur de "this,
+// pour une fonction quand elle est appelée grâce à "call" ou "apply".
+var anotherFunc = function(s){
+ return this.myString + s;
+}
+anotherFunc.call(myObj, ' And Hello Moon!'); // = 'Hello World! And Hello Moon!'
+
+// 'apply' est presque identique, mais prend un tableau comme liste d’arguments.
+
+anotherFunc.apply(myObj, [' And Hello Sun!']); // = 'Hello World! And Hello Sun!'
+
+Math.min(42, 6, 27); // = 6
+Math.min([42, 6, 27]); // = NaN (uh-oh!)
+Math.min.apply(Math, [42, 6, 27]); // = 6
+
+// Mais, "call" and "apply" fonctionnenent uniquement au moment de l'appel de la
+// fonction. Pour lier le contexte de façon permanente, nous pouvons utiliser
+// "bind" pour garder une référence à la fonction avec ce "this".
+var boundFunc = anotherFunc.bind(myObj);
+boundFunc(' And Hello Saturn!'); // = 'Hello World! And Hello Saturn!'
+
+// "bind" peut aussi être utilisé pour créer une application partielle de la
+// fonction (curry)
+var product = function(a, b){ return a * b; }
+var doubler = product.bind(this, 2);
+doubler(8); // = 16
+
+// Lorsque vous appelez une fonction avec le mot clé "new", un nouvel objet est
+// crée et mis à disposition de la fonction via "this". Ces fonctions sont
+// communément appelées constructeurs.
+var MyConstructor = function(){
+ this.myNumber = 5;
+}
+myNewObj = new MyConstructor(); // = {myNumber: 5}
+myNewObj.myNumber; // = 5
+
+// Chaque objet en Javascript a un "prototype". Quand vous essayez d'accéder à
+// une propriété que l'objet n'a pas, l'interpréteur va regarder son prototype.
+
+// Quelques implémentations de JS vous laissent accéder au prototype avec la
+// propriété "magique" __proto__. Ceci peut être utile, mais n'est pas standard
+// et ne fonctionne pas dans certains des navigateurs actuels.
+var myObj = {
+ myString: 'Hello world!'
+};
+var myPrototype = {
+ meaningOfLife: 42,
+ myFunc: function(){
+ return this.myString.toLowerCase()
+ }
+};
+
+myObj.__proto__ = myPrototype;
+myObj.meaningOfLife; // = 42
+myObj.myFunc(); // = 'hello world!'
+
+myPrototype.__proto__ = {
+ myBoolean: true
+};
+myObj.myBoolean; // = true
+
+
+// Pour obtenir le prototype il existe également Object.getPrototypeOf
+Object.getPrototypeOf( myObj ) // = {meaningOfLife: 42, myFunc: function}
+
+// Il n'y a pas de copie ici. Chacun des objets stocke une référence à son
+// prototype. Cela veut dire que l'on peut le modifier et cela se répercutera
+// partout.
+myPrototype.meaningOfLife = 43;
+myObj.meaningOfLife; // = 43
+
+// L'inverse n'est cependant pas vrai. Changer la propriété d'un objet ne change
+// pas la chaine prototypale.
+myObj.meaningOfLife = 42;
+myPrototype.meaningOfLife; // = 43
+
+// Comme précédemment dit, __proto__ n'est pas standard et ne devrait pas être
+// utilisé. Il y a deux autres moyen de créer un nouvel objet avec un prototype
+// donné.
+
+// Le premier est Object.create, mais c'est assez récent et risque de ne pas
+// fonctionner dans tous les navigateurs.
+var myObj = Object.create(myPrototype);
+myObj.meaningOfLife; // = 43
+
+// Le deuxième moyen, qui marche partout, fonctionne avec les constructeurs.
+// Les constructeurs ont un propriété appelée prototype. Ce n'est *pas* le
+// prototype du constructeur de la fonction elle-même, c'est le prototype que
+// les nouveaux objets crées grâce à ce constructeur avec "new" auront.
+MyConstructor.prototype = {
+ myNumber: 5,
+ getMyNumber: function(){
+ return this.myNumber;
+ }
+};
+var myNewObj2 = new MyConstructor();
+myNewObj2.getMyNumber(); // = 5
+myNewObj2.myNumber = 6
+myNewObj2.getMyNumber(); // = 6
+
+// Les types pré-définis tels que les strings ou nombres ont aussi des
+// constructeurs
+var myNumber = 12;
+var myNumberObj = new Number(12);
+myNumber == myNumberObj; // = true
+
+// ... mais ils ne sont pas exactement équivalent.
+typeof myNumber; // = 'number'
+typeof myNumberObj; // = 'object'
+myNumber === myNumberObj; // = false
+if (0){
+ // 0 est falsy, le code ne fonctionnera pas.
+}
+if (Number(0)){
+ // Parce que Number(0) est truthy, le code fonctionnera
+}
+
+// Cependant, vous pouvez ajouter des fonctionnalités aux types de bases grâce à
+// cette particularité.
+String.prototype.firstCharacter = function(){
+ return this.charAt(0);
+}
+'abc'.firstCharacter(); // = 'a'
+
+// C'est très souvent utilisé pour le "polyfilling", qui implémente des nouvelles
+// fonctionnalités de JavaScript dans de plus anciens environnements, tels que
+// les vieux navigateurs.
+
+//Par exemple, Object.create est assez récent, mais peut être implémenté grâce à
+// ce polyfill
+if (Object.create === undefined){ // pour ne pas reécrire si la fonction existe déjà
+ Object.create = function(proto){
+ // on crée un constructeur temporaire avec le bon prototype
+ var Constructor = function(){};
+ Constructor.prototype = proto;
+ // puis on utilise "new" pour créer un object avec ce même prototype
+ return new Constructor();
+ }
+}
+```
+
+## Pour aller plus loin (en anglais)
+
+The [Mozilla Developer
+Network](https://developer.mozilla.org/fr-FR/docs/Web/JavaScript) expose une
+excellente documentation pour le Javascript dans les navigateurs. Et contient
+également un wiki pour s'entraider.
+
+MDN's [A re-introduction to
+JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
+recouvre les principaux sujets vus ici. Le guide est délibérément uniquement
+à propos du JavaScript, et ne parle pas des navigateurs; pour cela, dirigez vous
+plutôt ici :
+[Document Object
+Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core)
+
+[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) quelques challenges.
+
+[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth
+un guide pour vous éviter les faux-amis dans le JavaScript.
+
+[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) un classique. A lire.
+
+En addition aux contributeurs de cet article, du contenu provient du
+"Python tutorial" de Louie Dinh, et de [JS
+Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
+sur le réseau Mozilla.
diff --git a/fr-fr/lua-fr.html.markdown b/fr-fr/lua-fr.html.markdown
index 922d6ebc..b4e2a161 100644
--- a/fr-fr/lua-fr.html.markdown
+++ b/fr-fr/lua-fr.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
filename: learnlua-fr.lua
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
diff --git a/fr-fr/markdown.html.markdown b/fr-fr/markdown.html.markdown
new file mode 100644
index 00000000..e3ac5a92
--- /dev/null
+++ b/fr-fr/markdown.html.markdown
@@ -0,0 +1,288 @@
+---
+language: markdown
+contributors:
+- ["Andrei Curelaru", "http://www.infinidad.fr"]
+filename: markdown.md
+---
+
+Markdown a été créé par Jhon Gruber en 2004. Il se veut être d'une syntaxe
+facile à lire et à écrire, aisément convertible en HTML
+ (et beaucoup d'autres formats aussi à présent).
+
+Faites moi autant de retours que vous voulez! Sentez vous libre de "forker"
+et envoyer des pull request!
+
+
+```markdown
+<!-- Markdown est une sorte de cousin du HTML, si bien que tout document HTML
+est un document Markdown valide. Autrement dit, vous pouvez utiliser des
+balises HTML dans un fichier Markdown, comme la balise commentaire dans
+laquelle nous sommes à présent, car celle-ci ne sera pas affectée par
+le parser( analyseur syntaxique ) Markdown. -->
+
+<!-- Toutefois, si vous voulez créer un élément HTML dans un fichier Markdown,
+ vous ne pourrez pas utiliser du Markdown à l'intérieur de ce dernier. -->
+
+<!-- Le Markdown est implémenté de différentes manières, selon le parser.
+Ce guide va alors tenter de trier les fonctionnalités universelles de celles
+spécifiques à un parser. -->
+
+<!-- Headers ( En-têtes ) -->
+<!-- Vous pouvez facilement créer des éléments HTML <h1> à <h6> en précédant
+ le texte de votre futur titre par un ou plusieurs dièses ( # ), de un à six,
+ selon le niveau de titre souhaité. -->
+# Ceci est un <h1>
+## Ceci est un <h2>
+### Ceci est un <h3>
+#### Ceci est un <h4>
+##### Ceci est un <h5>
+###### Ceci est un <h6>
+
+<!--
+Markdown fournit également une façon alternative de marquer les h1 et h2
+-->
+
+Ceci est un h1
+=============
+
+Ceci est un h2
+-------------
+
+<!-- Styles basiques pour du texte -->
+<!-- On peut facilement rendre un texte "gras" ou "italique" en Markdown -->
+
+*Ce texte est en italique.*
+_Celui-ci aussi._
+
+**Ce texte est en gras.**
+__Celui-là aussi.__
+
+***Ce texte a les deux styles.***
+**_Pareil ici_**
+*__Et là!__*
+
+<!-- Dans le "Github Flavored Markdown", utilisé pour interpréter le Markdown
+sur Github, on a également le strikethrough ( texte barré ) : -->
+
+~~Ce texte est barré avec strikethrough.~~
+
+<!-- Les Paragraphes sont représentés par une ou plusieurs lignes de texte
+séparées par une ou plusieurs lignes vides. -->
+
+Ceci est un paragraphe. Là, je suis dans un paragraphe, facile non?
+
+Maintenant je suis dans le paragraphe 2.
+Je suis toujours dans le paragraphe 2!
+
+
+Puis là, eh oui, le paragraphe 3!
+
+<!--
+Si jamais vous souhaitez insérer une balise HTML <br />, vous pouvez ajouter
+un ou plusieurs espaces à la fin de votre paragraphe, et en commencer
+un nouveau.
+-->
+
+J'ai deux espaces vides à la fin (sélectionnez moi pour les voir).
+
+Bigre, il y a un <br /> au dessus de moi!
+
+<!-- Les 'Blocs de Citations' sont générés aisément, grâce au caractère > -->
+
+> Ceci est une superbe citation. Vous pouvez même
+> revenir à la ligne quand ça vous chante, et placer un `>`
+> devant chaque bout de ligne faisant partie
+> de la citation.
+> La taille ne compte pas^^ tant que chaque ligne commence par un `>`.
+
+> Vous pouvez aussi utiliser plus d'un niveau
+>> d'imbrication!
+> Classe et facile, pas vrai?
+
+<!-- les Listes -->
+<!-- les Listes non ordonnées sont marquées par des asterisques,
+signes plus ou signes moins. -->
+
+* Item
+* Item
+* Un autre item
+
+ou
+
++ Item
++ Item
++ Encore un item
+
+ou
+
+- Item
+- Item
+- Un dernier item
+
+<!-- les Listes Ordonnées sont générées via un nombre suivi d'un point -->
+
+1. Item un
+2. Item deux
+3. Item trois
+
+<!-- Vous pouvez même vous passer de tout numéroter, et Markdown générera
+les bons chiffres. Ceci dit, cette variante perd en clarté.-->
+
+1. Item un
+1. Item deux
+1. Item trois
+<!-- ( cette liste sera interprétée de la même façon que celle au dessus ) -->
+
+<!-- Vous pouvez également utiliser des sous-listes -->
+
+1. Item un
+2. Item deux
+3. Item trois
+* Sub-item
+* Sub-item
+4. Item quatre
+
+<!-- Il y a même des "listes de Taches". Elles génèrent des champs HTML
+de type checkbox. -->
+
+Les [ ] ci dessous, n'ayant pas de [ x ],
+deviendront des cases à cocher HTML non-cochées.
+
+- [ ] Première tache à réaliser.
+- [ ] Une autre chose à faire.
+La case suivante sera une case à cocher HTML cochée.
+- [x] Ça ... c'est fait!
+
+<!-- les Blocs de Code -->
+<!-- Pour marquer du texte comme étant du code, il suffit de commencer
+chaque ligne en tapant 4 espaces (ou un Tab) -->
+
+ echo "Ça, c'est du Code!";
+ var Ça = "aussi !";
+
+<!-- L'indentation par tab ou série de quatre espaces
+fonctionne aussi à l'intérieur du bloc de code -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Des bouts de code en mode 'inline' s'ajoutent en les entourant de ` -->
+
+La fonction `run()` ne vous oblige pas à aller courir!
+
+<!-- Via Github Flavored Markdown, vous pouvez utiliser
+des syntaxes spécifiques -->
+
+\`\`\`ruby
+<!-- mais enlevez les backslashes quand vous faites ça,
+gardez juste ```ruby ( ou nom de la synatxe correspondant à votre code )-->
+def foobar
+puts "Hello world!"
+end
+\`\`\` <!-- pareil, pas de backslashes, juste ``` en guise de fin -->
+
+<-- Pas besoin d'indentation pour le code juste au dessus, de plus, Github
+va utiliser une coloration syntaxique pour le langage indiqué après les ``` -->
+
+<!-- Ligne Horizontale (<hr />) -->
+<!-- Pour en insérer une, utilisez trois ou plusieurs astérisques ou tirets,
+avec ou sans espaces entre chaque un. -->
+
+***
+---
+- - -
+****************
+
+<!-- Liens -->
+<!-- Une des fonctionnalités sympathiques du Markdown est la facilité
+d'ajouter des liens. Le texte du lien entre [ ], l'url entre ( ),
+et voilà l'travail.
+-->
+
+[Clic moi!](http://test.com/)
+
+<!--
+Pour ajouter un attribut Title, collez le entre guillemets, avec le lien.
+-->
+
+[Clic moi!](http://test.com/ "Lien vers Test.com")
+
+<!-- les Liens Relatifs marchent aussi -->
+
+[En avant la musique](/music/).
+
+<!-- Les liens façon "références" sont eux aussi disponibles en Markdown -->
+
+[Cliquez ici][link1] pour plus d'information!
+[Regardez aussi par ici][foobar] si vous voulez.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- Le titre peut aussi être entouré de guillemets simples,
+entre parenthèses ou absent. Les références peuvent être placées
+un peu où vous voulez dans le document, et les identifiants
+(link1, foobar, ...) quoi que ce soit tant qu'ils sont uniques -->
+
+<!-- Il y a également le "nommage implicite" qui transforme le texte du lien
+ en identifiant -->
+
+[Ceci][] est un lien.
+
+[ceci]: http://ceciestunlien.com/
+
+<!-- mais ce n'est pas beaucoup utilisé. -->
+
+<!-- Images -->
+<!-- Pour les images, la syntaxe est identique aux liens, sauf que précédée
+ d'un point d'exclamation! -->
+
+![Attribut ALT de l'image](http://imgur.com/monimage.jpg "Titre optionnel")
+
+<!-- Là aussi, on peut utiliser le mode "références" -->
+
+![Ceci est l'attribut ALT de l'image][monimage]
+
+[monimage]: relative/urls/cool/image.jpg "si vous voulez un titre, c'est ici."
+
+<!-- Divers -->
+<!-- Liens Automatiques -->
+
+<http://testwebsite.com/> est équivalent à :
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Liens Automatiques pour emails -->
+
+<foo@bar.com>
+
+<!-- Escaping -->
+Il suffit de précéder les caractères spécifiques à ignorer par des backslash \
+
+Pour taper *ce texte* entouré d'astérisques mais pas en italique :
+Tapez \*ce texte\*.
+
+<!-- Tableaux -->
+<!-- les Tableaux ne sont disponibles que dans le Github Flavored Markdown
+ et c'est ce n'est pas super agréable d'utilisation.
+ Mais si vous en avez besoin :
+ -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| Alignement Gauche | Centé | Alignement Droite |
+| bla | bla | bla |
+
+<!-- ou bien, pour un résultat équivalent : -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ough que c'est moche | svp | arrêtez
+
+<!-- Fin! -->
+
+```
+
+Pour plus d'information :
+ consultez [ici](http://daringfireball.net/projects/markdown/syntax) le post officiel de Jhon Gruber à propos de la syntaxe,
+ et [là](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) la superbe cheatsheet de Adam Pritchard. \ No newline at end of file
diff --git a/fr-fr/objective-c-fr.html.markdown b/fr-fr/objective-c-fr.html.markdown
index b98d161e..69f4d8f9 100644
--- a/fr-fr/objective-c-fr.html.markdown
+++ b/fr-fr/objective-c-fr.html.markdown
@@ -14,7 +14,7 @@ lang: fr-fr
L'Objective-C est un langage de programmation orienté objet réflexif principalement utilisé par Apple pour les systèmes d'exploitations Mac OS X et iOS et leurs frameworks respectifs, Cocoa et Cocoa Touch.
-```cpp
+```objective_c
// Les commentaires sur une seule ligne commencent par //
/*
diff --git a/fr-fr/ruby-fr.html.markdown b/fr-fr/ruby-fr.html.markdown
index 3060bd75..75c8d0d3 100644
--- a/fr-fr/ruby-fr.html.markdown
+++ b/fr-fr/ruby-fr.html.markdown
@@ -336,8 +336,8 @@ class Humain
puts "#{msg}"
end
- def species
- @@species
+ def espece
+ @@espece
end
end
diff --git a/fr-fr/scala.html.markdown b/fr-fr/scala.html.markdown
new file mode 100644
index 00000000..a43edf16
--- /dev/null
+++ b/fr-fr/scala.html.markdown
@@ -0,0 +1,457 @@
+---
+language: Scala
+contributors:
+ - ["George Petrov", "http://github.com/petrovg"]
+ - ["Dominic Bou-Samra", "http://dbousamra.github.com"]
+translators:
+ - ["Anne-Catherine Dehier", "https://github.com/spellart"]
+filename: learnscala-fr.scala
+lang: fr-fr
+---
+
+### Scala - le langage évolutif
+
+```scala
+
+/*
+ Pour vous préparer :
+
+ 1) (Téléchargez Scala)[http://www.scala-lang.org/downloads]
+ 2) Dézippez/décompressez dans votre endroit préféré
+ et ajoutez le chemin du sous-répertoire bin au chemin du système
+ 3) Commencez un REPL de Scala en tapant juste scala. Vous devriez voir le prompteur :
+
+ scala>
+
+ C'est ce qu'on appelle un REPL (Read-Eval-Print-Loop), c'est une interface de programmation interactive.
+ Vous pouvez y exécuter des commandes.
+ Allons-y :
+*/
+
+println(10) // affiche l'integer 10
+
+println("Boo!") // affiche avec retour à la ligne la chaîne de caractère Boo!
+
+
+// Quelques basiques
+
+// Imprimer et forcer une nouvelle ligne à la prochaine impression
+println("Hello world!")
+// Imprimer sans forcer une nouvelle ligne à la prochaine impression
+print("Hello world")
+
+// Pour déclarer des valeurs on utilise var ou val
+// Les déclarations val sont immuables, tandis que les var sont muables.
+// L'immuabilité est une bonne chose.
+
+val x = 10 // x vaut maintenant 10
+x = 20 // erreur : réaffectation à val
+var x = 10
+x = 20 // x vaut maintenant 20
+
+// Les commentaires d'une ligne commencent par deux slashs
+
+/*
+Les commentaires multilignes ressemblent à ça.
+*/
+
+// les valeurs booléennes
+true
+false
+
+// Les opérateurs booléens
+!true // false
+!false // true
+true == false // false
+10 > 5 // true
+
+// Les opérateurs mathématiques sont habituels
+1 + 1 // 2
+2 - 1 // 1
+5 * 3 // 15
+6 / 2 // 3
+
+
+// Le REPL donne le type et la valeur du résultat quand vous évaluez une commande
+
+1 + 7
+
+/* Les lignes ci-dessous donnent les résultats :
+
+ scala> 1 + 7
+ res29: Int = 8
+
+ Ça signifie que le résultat de l'évaluation 1 + 7 est un objet de
+ type Int avec une valeur de 8
+
+ 1+7 donnera le même résultat
+*/
+
+
+// Tout est un objet, même une fonction. Tapez ceci dans le REPL :
+
+7 // donne res30: Int = 7 (res30 est seulement un nom de variable généré pour le résultat)
+
+
+// La ligne suivante est une fonction qui prend un Int et retourne son carré
+(x:Int) => x * x
+
+
+// On peut assigner cette fonction à un identifieur comme ceci :
+val sq = (x:Int) => x * x
+
+/* La ligne suivante nous dit :
+
+ sq: Int => Int = <function1>
+
+ Ce qui signifie que cette fois-ci nous avons donné un nom explicite à la valeur.
+ sq est une fonction qui prend un Int et retourne un Int.
+
+
+ sq peut être exécutée comme ci-dessous :
+*/
+
+sq(10) // donne comme résultat : res33: Int = 100.
+
+
+// les deux-points définissent explicitement le type de la valeur,
+// dans ce cas une fonction qui prend un Int et retourne un Int.
+val add10: Int => Int = _ + 10
+
+// Scala autorise des méthodes et des fonctions à retourner
+// ou prendre comme paramètres des autres fonctions ou méthodes
+
+
+List(1, 2, 3) map add10 // List(11, 12, 13) - add10 est appliqué à chaque éléments
+
+
+// Les fonctions anonymes peuvent être utilisées à la place des fonctions nommées :
+List(1, 2, 3) map (x => x + 10)
+
+
+
+
+// Le tiret du bas peut être utilisé si la fonction anonyme ne prend qu'un paramètre.
+// Il se comporte comme une variable
+List(1, 2, 3) map (_ + 10)
+
+
+
+// Si le bloc et la fonction anonyme prennent tous les deux un seul argument,
+// vous pouvez omettre le tiret du bas
+List("Dom", "Bob", "Natalia") foreach println
+
+
+
+// Les structures de données
+
+val a = Array(1, 2, 3, 5, 8, 13)
+a(0)
+a(3)
+a(21) // Lance une exception
+
+val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo")
+m("fork")
+m("spoon")
+m("bottle") // Lance une exception
+
+val safeM = m.withDefaultValue("no lo se")
+safeM("bottle")
+
+val s = Set(1, 3, 7)
+s(0)
+s(1)
+
+/* Jetez un oeil sur la documentation de map ici -
+ * http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map
+ */
+
+
+// Tuples
+
+(1, 2)
+
+(4, 3, 2)
+
+(1, 2, "three")
+
+(a, 2, "three")
+
+// Exemple d'utilisation
+val divideInts = (x:Int, y:Int) => (x / y, x % y)
+
+
+divideInts(10,3) // La fonction divideInts donne le résultat et le reste de la division
+
+// Pour accéder à un élément d'un tuple, utilisez _._n
+// où n est l'index de base 1 de l'élément
+val d = divideInts(10,3)
+
+d._1
+
+d._2
+
+
+
+// Des combinaisons
+
+s.map(sq)
+
+val sSquared = s. map(sq)
+
+sSquared.filter(_ < 10)
+
+sSquared.reduce (_+_)
+
+
+
+// La fonction filter prend un prédicat (une fonction de type A -> Booléen) et
+// sélectionne tous les éléments qui satisfont ce prédicat
+List(1, 2, 3) filter (_ > 2) // List(3)
+List(
+ Person(name = "Dom", age = 23),
+ Person(name = "Bob", age = 30)
+).filter(_.age > 25) // List(Person("Bob", 30))
+
+
+
+// Scala a une méthode foreach définie pour certaines collections
+// qui prend en argument une fonction renvoyant Unit (une méthode void)
+aListOfNumbers foreach (x => println(x))
+aListOfNumbers foreach println
+
+
+
+
+// Compréhensions de listes
+
+for { n <- s } yield sq(n)
+
+val nSquared2 = for { n <- s } yield sq(n)
+
+for { n <- nSquared2 if n < 10 } yield n
+
+for { n <- s; nSquared = n * n if nSquared < 10} yield nSquared
+
+
+
+/* Les exemples précédents ne sont pas des boucles for. La sémantique des boucles for
+ est "répète", alors qu'une for-compréhension définit une relation
+ entre deux ensembles de données. */
+
+
+
+// Boucles et itération
+
+1 to 5
+val r = 1 to 5
+r.foreach( println )
+
+r foreach println
+// NB: Scala est vraiment tolérant par rapport aux points et aux parenthèses en étudiant les roles séparément.
+// Ça aide pour écrire des DSL ou des API qui se lisent comme en anglais.
+
+
+(5 to 1 by -1) foreach ( println )
+
+// Une boucle while
+var i = 0
+while (i < 10) { println("i " + i); i+=1 }
+
+while (i < 10) { println("i " + i); i+=1 } // Oui, encore. Qu'est-ce qui s'est passé ? Pourquoi ?
+
+
+
+
+
+
+i // Montre la valeur de i. Notez que while est une boucle au sens classique.
+ // Il exécute séquentiellement pendant que la variable de boucle change.
+ // While est très rapide,
+ // mais utiliser des combinateurs et des compréhensions comme ci-dessus est plus
+ // facile pour comprendre et pour faire la parallélisation
+
+// La boucle do while
+do {
+ println("x is still less then 10");
+ x += 1
+} while (x < 10)
+
+
+// La récursivité est un moyen idiomatique de faire une chose répétitive en Scala.
+// Les fonctions récursives ont besoin d'un type de retour explicite,
+// le compilateur ne peut pas le déduire.
+// Ici c'est Unit.
+def showNumbersInRange(a:Int, b:Int):Unit = {
+ print(a)
+ if (a < b)
+ showNumbersInRange(a + 1, b)
+}
+
+
+
+// Structures de contrôle
+
+val x = 10
+
+if (x == 1) println("yeah")
+if (x == 10) println("yeah")
+if (x == 11) println("yeah")
+if (x == 11) println ("yeah") else println("nay")
+
+println(if (x == 10) "yeah" else "nope")
+val text = if (x == 10) "yeah" else "nope"
+
+var i = 0
+while (i < 10) { println("i " + i); i+=1 }
+
+
+
+// Les caractéristiques "Orienté Objet"
+
+// Création d'une classe Dog
+class Dog {
+ // Une méthode appelée bark qui retourne une chaîne de caractère
+ def bark: String = {
+ // le corps de la méthode
+ "Woof, woof!"
+ }
+}
+
+
+// Les classes peuvent contenir presque n'importe quelle autre construction, incluant d'autres classes,
+// des fonctions, des méthodes, des objets, des classes case, des traits, etc ...
+
+
+
+// Les classes case
+
+case class Person(name:String, phoneNumber:String)
+
+Person("George", "1234") == Person("Kate", "1236")
+
+
+
+
+// Correspondances de motifs
+
+val me = Person("George", "1234")
+
+me match { case Person(name, number) => {
+ "We matched someone : " + name + ", phone : " + number }}
+
+me match { case Person(name, number) => "Match : " + name; case _ => "Hm..." }
+
+me match { case Person("George", number) => "Match"; case _ => "Hm..." }
+
+me match { case Person("Kate", number) => "Match"; case _ => "Hm..." }
+
+me match { case Person("Kate", _) => "Girl"; case Person("George", _) => "Boy" }
+
+val kate = Person("Kate", "1234")
+
+kate match { case Person("Kate", _) => "Girl"; case Person("George", _) => "Boy" }
+
+
+
+// Expressions régulières
+
+val email = "(.*)@(.*)".r // On fait une Regex en invoquant r sur la chaîne de caractère
+
+val email(user, domain) = "henry@zkpr.com"
+
+"mrbean@pyahoo.com" match {
+ case email(name, domain) => "I know your name, " + name
+}
+
+
+
+// Les chaînes de caractères
+
+"Les chaînes de caractères Scala sont entourées de doubles guillements"
+'a' // Un caractère de Scala
+'Les simples guillemets n'existent pas en Scala // Erreur
+"Les chaînes de caractères possèdent les méthodes usuelles de Java".length
+"Il y a aussi quelques méthodes extra de Scala.".reverse
+
+// Voir également : scala.collection.immutable.StringOps
+
+println("ABCDEF".length)
+println("ABCDEF".substring(2, 6))
+println("ABCDEF".replace("C", "3"))
+
+val n = 45
+println(s"We have $n apples")
+
+val a = Array(11, 9, 6)
+println(s"My second daughter is ${a(2-1)} years old")
+
+// Certains caractères ont besoin d'être "échappés",
+// ex un guillemet à l'intérieur d'une chaîne de caractères :
+val a = "They stood outside the \"Rose and Crown\""
+
+// Les triples guillemets permettent d'écrire des chaînes de caractères
+// sur plusieurs lignes et peuvent contenir des guillemets
+
+val html = """<form id="daform">
+ <p>Press belo', Joe</p>
+ | <input type="submit">
+ </form>"""
+
+
+
+// Structure et organisation d'une application
+
+// Importer des chaînes de caratères
+import scala.collection.immutable.List
+
+// Importer tous les sous-paquets
+import scala.collection.immutable._
+
+// Importer plusieurs classes en une seule instruction
+import scala.collection.immutable.{List, Map}
+
+// Renommer un import en utilisant '=>'
+import scala.collection.immutable.{ List => ImmutableList }
+
+// Importer toutes les classes, à l'exception de certaines.
+// La ligne suivante exclut Map et Set :
+import scala.collection.immutable.{Map => _, Set => _, _}
+
+// Le point d'entrée du programme est défini dans un fichier scala
+// utilisant un objet, avec une simple méthode main :
+object Application {
+ def main(args: Array[String]): Unit = {
+ // Votre code ici.
+ }
+}
+
+// Les fichiers peuvent contenir plusieurs classes et plusieurs objets.
+// On les compile avec scalac
+
+
+
+
+// Entrée et Sortie
+
+// Pour lire un fichier ligne par ligne
+import scala.io.Source
+for(line <- Source.fromFile("myfile.txt").getLines())
+ println(line)
+
+// On utilise le PrintWriter de Java pour écrire un fichier
+
+
+```
+
+## Autres ressources
+
+[Scala for the impatient](http://horstmann.com/scala/)
+
+[Twitter Scala school](http://twitter.github.io/scala_school/)
+
+[The scala documentation](http://docs.scala-lang.org/)
+
+[Try Scala in your browser](http://scalatutorials.com/tour/)
+
+Rejoindre le [Scala user group](https://groups.google.com/forum/#!forum/scala-user)
diff --git a/fr-fr/xml-fr.html.markdown b/fr-fr/xml-fr.html.markdown
new file mode 100644
index 00000000..ed5f55ff
--- /dev/null
+++ b/fr-fr/xml-fr.html.markdown
@@ -0,0 +1,128 @@
+---
+language: xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+translators:
+ - ["Geoffrey Liu", "https://github.com/g-liu"]
+filename: learnxml-fr.xml
+lang: fr-fr
+---
+
+XML est un langage de balisage conçu pour stocker et transporter les informations.
+
+Contrairement à HTML, XML ne spécifie pas comment afficher ou formater les informations, juste comment les porter.
+
+* La syntaxe XML
+
+```xml
+<!-- Les commentaires en XML ressemblent ceci -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<librairie>
+ <livre categorie="CUISINE">
+ <titre lang="en">Everyday Italian</titre>
+ <auteur>Giada De Laurentiis</auteur>
+ <an>2005</an>
+ <prix>30.00</prix>
+ </livre>
+ <livre categorie="ENFANTS">
+ <titre lang="en">Harry Potter</titre>
+ <auteur>J. K. Rowling</auteur>
+ <an>2005</an>
+ <prix>29.99</prix>
+ </livre>
+ <livre categorie="WEB">
+ <titre lang="en">Learning XML</titre>
+ <auteur>Erik T. Ray</auteur>
+ <an>2003</an>
+ <prix>39.95</prix>
+ </livre>
+</librairie>
+
+<!-- Ce qui suit est un fichier XML typique.
+ Il commence par une déclaration, qui informe certaines métadonnées (en option).
+
+XML utilise une structure arborescente. Ci-dessus, le nœud racine est «librairie», qui a
+   trois nœuds enfants, qui sont appelés «livres». Ces nœuds ont plus de nœuds enfants, et ainsi de suite ...
+
+On crée les nœuds avec des balises d'ouverture / fermeture, et les enfants sont les nœuds juste entre
+   les balises d'ouverture et de fermeture. -->
+
+
+<!-- XML porte deux types d'informations:
+ 1 - Les attributs -> les métadonnées sur un nœud.
+ Habituellement, l'analyseur XML utilise cette information pour bien stocker les données.
+ 2 - Les éléments -> les informations pures.
+ C'est ce que l'analyseur retrouvera du fichier XML.
+ Les éléments apparaissent entre les balises d'ouverture et de fermeture, sans parenthèses. -->
+
+
+<!-- Ci-dessous, un élément avec deux attributs -->
+<fichier type="gif" id="4293">ordinateur.gif</fichier>
+
+
+```
+
+* Un document bien formaté & le validation
+
+Un document XML est bien formaté s'il est syntaxiquement correct.
+Cependant, il est possible d'injecter plus de contraintes dans le document,
+en utilisant les définitions de documents, tels que les schémas DTD et XML.
+
+Un document XML qui suit une définition de document est dit valide,
+en ce qui concerne ce document.
+
+Avec cet outil, vous pouvez vérifier les données XML en dehors de la logique de l'application.
+
+```xml
+
+<!-- Ci-dessous, vous pouvez voir une version simplifiée du document de librairie,
+   avec l'addition de définition DTD. -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "Librairie.dtd">
+<librairie>
+ <livre categorie="CUISINE">
+ <titre>Everyday Italian</titre>
+ <prix>30.00</prix>
+ </livre>
+</librairie>
+
+<!-- Cette DTD pourrait être quelque chose comme: -->
+
+<!DOCTYPE note
+[
+<!ELEMENT librairie (livre+)>
+<!ELEMENT livre (titre,prix)>
+<!ATTLIST livre categorie CDATA "Littérature">
+<!ELEMENT titre (#PCDATA)>
+<!ELEMENT prix (#PCDATA)>
+]>
+
+<!-- La DTD commence par une déclaration.
+   Après, le nœud racine est déclaré, qui exige un ou plusieurs nœuds enfants.
+   Chaque «livre» doit contenir exactement un «titre» et «prix» et un attribut
+   appelé «catégorie», avec «littérature» comme valeur par défaut.
+   Les nœuds de «titre» et «prix» contiennent des informations de caractère analysés
+ (Anglais: «parsed character data») -->
+
+<!-- La DTD pourrait être déclarée dans le fichier XML lui-même -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT librairie (livre+)>
+<!ELEMENT livre (titre,prix)>
+<!ATTLIST livre categorie CDATA "Littérature">
+<!ELEMENT titre (#PCDATA)>
+<!ELEMENT prix (#PCDATA)>
+]>
+
+<librairie>
+ <livre categorie="CUISINE">
+ <titre>Everyday Italian</titre>
+ <prix>30.00</prix>
+ </livre>
+</librairie>
+```
diff --git a/git.html.markdown b/git.html.markdown
index 4b5e466e..618d1906 100644
--- a/git.html.markdown
+++ b/git.html.markdown
@@ -327,6 +327,11 @@ Push and merge changes from a branch to a remote & branch.
# git push <remote> <branch>
# git push => implicitly defaults to => git push origin master
$ git push origin master
+
+# To link up current local branch with a remote branch, add -u flag:
+$ git push -u origin master
+# Now, anytime you want to push from that same local branch, use shortcut:
+$ git push
```
### rebase (caution)
@@ -390,3 +395,5 @@ $ git rm /pather/to/the/file/HelloWorld.c
* [SalesForce Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)
* [GitGuys](http://www.gitguys.com/)
+
+* [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html) \ No newline at end of file
diff --git a/go.html.markdown b/go.html.markdown
index fa4c8d0b..17f10bd9 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -8,9 +8,11 @@ contributors:
- ["Christopher Bess", "https://github.com/cbess"]
- ["Jesse Johnson", "https://github.com/holocronweaver"]
- ["Quint Guvernator", "https://github.com/qguv"]
+ - ["Jose Donizetti", "https://github.com/josedonizetti"]
+ - ["Alexej Friesen", "https://github.com/heyalexej"]
---
-Go was created out of the need to get work done. It's not the latest trend
+Go was created out of the need to get work done. It's not the latest trend
in computer science, but it is the newest fastest way to solve real-world
problems.
@@ -24,7 +26,7 @@ Go comes with a great standard library and an enthusiastic community.
```go
// Single line comment
/* Multi-
- line comment */
+ line comment */
// A package clause starts every source file.
// Main is a special name declaring an executable rather than a library.
@@ -32,286 +34,362 @@ package main
// Import declaration declares library packages referenced in this file.
import (
- "fmt" // A package in the Go standard library.
- "net/http" // Yes, a web server!
- "strconv" // String conversions.
- m "math" // Math library with local alias m.
+ "fmt" // A package in the Go standard library.
+ "io/ioutil" // Implements some I/O utility functions.
+ m "math" // Math library with local alias m.
+ "net/http" // Yes, a web server!
+ "strconv" // String conversions.
)
-// A function definition. Main is special. It is the entry point for the
-// executable program. Love it or hate it, Go uses brace brackets.
+// A function definition. Main is special. It is the entry point for the
+// executable program. Love it or hate it, Go uses brace brackets.
func main() {
- // Println outputs a line to stdout.
- // Qualify it with the package name, fmt.
- fmt.Println("Hello world!")
+ // Println outputs a line to stdout.
+ // Qualify it with the package name, fmt.
+ fmt.Println("Hello world!")
- // Call another function within this package.
- beyondHello()
+ // Call another function within this package.
+ beyondHello()
}
// Functions have parameters in parentheses.
// If there are no parameters, empty parentheses are still required.
func beyondHello() {
- var x int // Variable declaration. Variables must be declared before use.
- x = 3 // Variable assignment.
- // "Short" declarations use := to infer the type, declare, and assign.
- y := 4
- sum, prod := learnMultiple(x, y) // Function returns two values.
- fmt.Println("sum:", sum, "prod:", prod) // Simple output.
- learnTypes() // < y minutes, learn more!
+ var x int // Variable declaration. Variables must be declared before use.
+ x = 3 // Variable assignment.
+ // "Short" declarations use := to infer the type, declare, and assign.
+ y := 4
+ sum, prod := learnMultiple(x, y) // Function returns two values.
+ fmt.Println("sum:", sum, "prod:", prod) // Simple output.
+ learnTypes() // < y minutes, learn more!
}
// Functions can have parameters and (multiple!) return values.
func learnMultiple(x, y int) (sum, prod int) {
- return x + y, x * y // Return two values.
+ return x + y, x * y // Return two values.
}
// Some built-in types and literals.
func learnTypes() {
- // Short declaration usually gives you what you want.
- s := "Learn Go!" // string type.
+ // Short declaration usually gives you what you want.
+ str := "Learn Go!" // string type.
- s2 := `A "raw" string literal
+ s2 := `A "raw" string literal
can include line breaks.` // Same string type.
- // Non-ASCII literal. Go source is UTF-8.
- g := 'Σ' // rune type, an alias for uint32, holds a unicode code point.
-
- f := 3.14195 // float64, an IEEE-754 64-bit floating point number.
- c := 3 + 4i // complex128, represented internally with two float64's.
-
- // Var syntax with an initializers.
- var u uint = 7 // Unsigned, but implementation dependent size as with int.
- var pi float32 = 22. / 7
-
- // Conversion syntax with a short declaration.
- n := byte('\n') // byte is an alias for uint8.
-
- // Arrays have size fixed at compile time.
- var a4 [4]int // An array of 4 ints, initialized to all 0.
- a3 := [...]int{3, 1, 5} // An array of 3 ints, initialized as shown.
-
- // Slices have dynamic size. Arrays and slices each have advantages
- // but use cases for slices are much more common.
- s3 := []int{4, 5, 9} // Compare to a3. No ellipsis here.
- s4 := make([]int, 4) // Allocates slice of 4 ints, initialized to all 0.
- var d2 [][]float64 // Declaration only, nothing allocated here.
- bs := []byte("a slice") // Type conversion syntax.
-
- p, q := learnMemory() // Declares p, q to be type pointer to int.
- fmt.Println(*p, *q) // * follows a pointer. This prints two ints.
-
- // Maps are a dynamically growable associative array type, like the
- // hash or dictionary types of some other languages.
- m := map[string]int{"three": 3, "four": 4}
- m["one"] = 1
-
- // Unused variables are an error in Go.
- // The underbar lets you "use" a variable but discard its value.
- _, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
- // Output of course counts as using a variable.
- fmt.Println(s, c, a4, s3, d2, m)
+ // Non-ASCII literal. Go source is UTF-8.
+ g := 'Σ' // rune type, an alias for int32, holds a unicode code point.
+
+ f := 3.14195 // float64, an IEEE-754 64-bit floating point number.
+ c := 3 + 4i // complex128, represented internally with two float64's.
+
+ // Var syntax with an initializers.
+ var u uint = 7 // Unsigned, but implementation dependent size as with int.
+ var pi float32 = 22. / 7
+
+ // Conversion syntax with a short declaration.
+ n := byte('\n') // byte is an alias for uint8.
+
+ // Arrays have size fixed at compile time.
+ var a4 [4]int // An array of 4 ints, initialized to all 0.
+ a3 := [...]int{3, 1, 5} // An array initialized with a fixed size of three
+ // elements, with values 3, 1, and 5.
+
+ // Slices have dynamic size. Arrays and slices each have advantages
+ // but use cases for slices are much more common.
+ s3 := []int{4, 5, 9} // Compare to a3. No ellipsis here.
+ s4 := make([]int, 4) // Allocates slice of 4 ints, initialized to all 0.
+ var d2 [][]float64 // Declaration only, nothing allocated here.
+ bs := []byte("a slice") // Type conversion syntax.
+
+ // Because they are dynamic, slices can be appended to on-demand.
+ // To append elements to a slice, built-in append() function is used.
+ // First argument is a slice to which we are appending. Commonly,
+ // the array variable is updated in place, as in example below.
+ s := []int{1, 2, 3} // Result is a slice of length 3.
+ s = append(s, 4, 5, 6) // Added 3 elements. Slice now has length of 6.
+ fmt.Println(s) // Updated slice is now [1 2 3 4 5 6]
+ // To append another slice, instead of list of atomic elements we can
+ // pass a reference to a slice or a slice literal like this, with a
+ // trailing elipsis, meaning take a slice and unpack its elements,
+ // appending them to slice s.
+ s = append(s, []int{7, 8, 9}...) // Second argument is a slice literal.
+ fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9]
+
+ p, q := learnMemory() // Declares p, q to be type pointer to int.
+ fmt.Println(*p, *q) // * follows a pointer. This prints two ints.
+
+ // Maps are a dynamically growable associative array type, like the
+ // hash or dictionary types of some other languages.
+ m := map[string]int{"three": 3, "four": 4}
+ m["one"] = 1
+
+ // Unused variables are an error in Go.
+ // The underbar lets you "use" a variable but discard its value.
+ _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs
+ // Output of course counts as using a variable.
+ fmt.Println(s, c, a4, s3, d2, m)
+
+ learnFlowControl() // Back in the flow.
+}
- learnFlowControl() // Back in the flow.
+// It is possible, unlike in many other languages for functions in go
+// to have named return values.
+// Assigning a name to the type being returned in the function declaration line
+// allows us to easily return from multiple points in a function as well as to
+// only use the return keyword, without anything further.
+func learnNamedReturns(x, y int) (z int) {
+ z = x * y
+ return // z is implicit here, because we named it earlier.
}
-// Go is fully garbage collected. It has pointers but no pointer arithmetic.
+// Go is fully garbage collected. It has pointers but no pointer arithmetic.
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
func learnMemory() (p, q *int) {
- // Named return values p and q have type pointer to int.
- p = new(int) // Built-in function new allocates memory.
- // The allocated int is initialized to 0, p is no longer nil.
- s := make([]int, 20) // Allocate 20 ints as a single block of memory.
- s[3] = 7 // Assign one of them.
- r := -2 // Declare another local variable.
- return &s[3], &r // & takes the address of an object.
+ // Named return values p and q have type pointer to int.
+ p = new(int) // Built-in function new allocates memory.
+ // The allocated int is initialized to 0, p is no longer nil.
+ s := make([]int, 20) // Allocate 20 ints as a single block of memory.
+ s[3] = 7 // Assign one of them.
+ r := -2 // Declare another local variable.
+ return &s[3], &r // & takes the address of an object.
}
func expensiveComputation() float64 {
- return m.Exp(10)
+ return m.Exp(10)
}
func learnFlowControl() {
- // If statements require brace brackets, and do not require parens.
- if true {
- fmt.Println("told ya")
- }
- // Formatting is standardized by the command line command "go fmt."
- if false {
- // Pout.
- } else {
- // Gloat.
- }
- // Use switch in preference to chained if statements.
- x := 42.0
- switch x {
- case 0:
- case 1:
- case 42:
- // Cases don't "fall through".
- case 43:
- // Unreached.
- }
- // Like if, for doesn't use parens either.
- // Variables declared in for and if are local to their scope.
- for x := 0; x < 3; x++ { // ++ is a statement.
- fmt.Println("iteration", x)
- }
- // x == 42 here.
-
- // For is the only loop statement in Go, but it has alternate forms.
- for { // Infinite loop.
- break // Just kidding.
- continue // Unreached.
- }
- // As with for, := in an if statement means to declare and assign y first,
- // then test y > x.
- if y := expensiveComputation(); y > x {
- x = y
- }
- // Function literals are closures.
- xBig := func() bool {
- return x > 10000 // References x declared above switch statement.
- }
- fmt.Println("xBig:", xBig()) // true (we last assigned e^10 to x).
- x = 1.3e3 // This makes x == 1300
- fmt.Println("xBig:", xBig()) // false now.
-
- // When you need it, you'll love it.
- goto love
+ // If statements require brace brackets, and do not require parens.
+ if true {
+ fmt.Println("told ya")
+ }
+ // Formatting is standardized by the command line command "go fmt."
+ if false {
+ // Pout.
+ } else {
+ // Gloat.
+ }
+ // Use switch in preference to chained if statements.
+ x := 42.0
+ switch x {
+ case 0:
+ case 1:
+ case 42:
+ // Cases don't "fall through".
+ case 43:
+ // Unreached.
+ }
+ // Like if, for doesn't use parens either.
+ // Variables declared in for and if are local to their scope.
+ for x := 0; x < 3; x++ { // ++ is a statement.
+ fmt.Println("iteration", x)
+ }
+ // x == 42 here.
+
+ // For is the only loop statement in Go, but it has alternate forms.
+ for { // Infinite loop.
+ break // Just kidding.
+ continue // Unreached.
+ }
+
+ // You can use range to iterate over an array, a slice, a string, a map, or a channel.
+ // range returns one (channel) or two values (array, slice, string and map).
+ for key, value := range map[string]int{"one": 1, "two": 2, "three": 3} {
+ // for each pair in the map, print key and value
+ fmt.Printf("key=%s, value=%d\n", key, value)
+ }
+
+ // As with for, := in an if statement means to declare and assign
+ // y first, then test y > x.
+ if y := expensiveComputation(); y > x {
+ x = y
+ }
+ // Function literals are closures.
+ xBig := func() bool {
+ return x > 10000 // References x declared above switch statement.
+ }
+ fmt.Println("xBig:", xBig()) // true (we last assigned e^10 to x).
+ x = 1.3e3 // This makes x == 1300
+ fmt.Println("xBig:", xBig()) // false now.
+
+ // What's more is function literals may be defined and called inline,
+ // acting as an argument to function, as long as:
+ // a) function literal is called immediately (),
+ // b) result type matches expected type of argument.
+ fmt.Println("Add + double two numbers: ",
+ func(a, b int) int {
+ return (a + b) * 2
+ }(10, 2)) // Called with args 10 and 2
+ // => Add + double two numbers: 24
+
+ // When you need it, you'll love it.
+ goto love
love:
- learnDefer() // A quick detour to an important keyword.
- learnInterfaces() // Good stuff coming up!
+ learnFunctionFactory() // func returning func is fun(3)(3)
+ learnDefer() // A quick detour to an important keyword.
+ learnInterfaces() // Good stuff coming up!
+}
+
+func learnFunctionFactory() {
+ // Next two are equivalent, with second being more practical
+ fmt.Println(sentenceFactory("summer")("A beautiful", "day!"))
+
+ d := sentenceFactory("summer")
+ fmt.Println(d("A beautiful", "day!"))
+ fmt.Println(d("A lazy", "afternoon!"))
+}
+
+// Decorators are common in other languages. Same can be done in Go
+// with function literals that accept arguments.
+func sentenceFactory(mystring string) func(before, after string) string {
+ return func(before, after string) string {
+ return fmt.Sprintf("%s %s %s", before, mystring, after) // new string
+ }
}
func learnDefer() (ok bool) {
- // Deferred statements are executed just before the function returns.
- defer fmt.Println("deferred statements execute in reverse (LIFO) order.")
- defer fmt.Println("\nThis line is being printed first because")
- // Defer is commonly used to close a file, so the function closing the file
- // stays close to the function opening the file
- return true
+ // Deferred statements are executed just before the function returns.
+ defer fmt.Println("deferred statements execute in reverse (LIFO) order.")
+ defer fmt.Println("\nThis line is being printed first because")
+ // Defer is commonly used to close a file, so the function closing the
+ // file stays close to the function opening the file.
+ return true
}
// Define Stringer as an interface type with one method, String.
type Stringer interface {
- String() string
+ String() string
}
// Define pair as a struct with two fields, ints named x and y.
type pair struct {
- x, y int
+ x, y int
}
-// Define a method on type pair. Pair now implements Stringer.
+// Define a method on type pair. Pair now implements Stringer.
func (p pair) String() string { // p is called the "receiver"
- // Sprintf is another public function in package fmt.
- // Dot syntax references fields of p.
- return fmt.Sprintf("(%d, %d)", p.x, p.y)
+ // Sprintf is another public function in package fmt.
+ // Dot syntax references fields of p.
+ return fmt.Sprintf("(%d, %d)", p.x, p.y)
}
func learnInterfaces() {
- // Brace syntax is a "struct literal." It evaluates to an initialized
- // struct. The := syntax declares and initializes p to this struct.
- p := pair{3, 4}
- fmt.Println(p.String()) // Call String method of p, of type pair.
- var i Stringer // Declare i of interface type Stringer.
- i = p // Valid because pair implements Stringer
- // Call String method of i, of type Stringer. Output same as above.
- fmt.Println(i.String())
-
- // Functions in the fmt package call the String method to ask an object
- // for a printable representation of itself.
- fmt.Println(p) // Output same as above. Println calls String method.
- fmt.Println(i) // Output same as above.
-
- learnVariadicParams("great", "learning", "here!")
+ // Brace syntax is a "struct literal". It evaluates to an initialized
+ // struct. The := syntax declares and initializes p to this struct.
+ p := pair{3, 4}
+ fmt.Println(p.String()) // Call String method of p, of type pair.
+ var i Stringer // Declare i of interface type Stringer.
+ i = p // Valid because pair implements Stringer
+ // Call String method of i, of type Stringer. Output same as above.
+ fmt.Println(i.String())
+
+ // Functions in the fmt package call the String method to ask an object
+ // for a printable representation of itself.
+ fmt.Println(p) // Output same as above. Println calls String method.
+ fmt.Println(i) // Output same as above.
+
+ learnVariadicParams("great", "learning", "here!")
}
// Functions can have variadic parameters.
func learnVariadicParams(myStrings ...interface{}) {
- // Iterate each value of the variadic.
- for _, param := range myStrings {
- fmt.Println("param:", param)
- }
+ // Iterate each value of the variadic.
+ // The underbar here is ignoring the index argument of the array.
+ for _, param := range myStrings {
+ fmt.Println("param:", param)
+ }
- // Pass variadic value as a variadic parameter.
- fmt.Println("params:", fmt.Sprintln(myStrings...))
+ // Pass variadic value as a variadic parameter.
+ fmt.Println("params:", fmt.Sprintln(myStrings...))
- learnErrorHandling()
+ learnErrorHandling()
}
func learnErrorHandling() {
- // ", ok" idiom used to tell if something worked or not.
- m := map[int]string{3: "three", 4: "four"}
- if x, ok := m[1]; !ok { // ok will be false because 1 is not in the map.
- fmt.Println("no one there")
- } else {
- fmt.Print(x) // x would be the value, if it were in the map.
- }
- // An error value communicates not just "ok" but more about the problem.
- if _, err := strconv.Atoi("non-int"); err != nil { // _ discards value
- // prints 'strconv.ParseInt: parsing "non-int": invalid syntax'
- fmt.Println(err)
- }
- // We'll revisit interfaces a little later. Meanwhile,
- learnConcurrency()
+ // ", ok" idiom used to tell if something worked or not.
+ m := map[int]string{3: "three", 4: "four"}
+ if x, ok := m[1]; !ok { // ok will be false because 1 is not in the map.
+ fmt.Println("no one there")
+ } else {
+ fmt.Print(x) // x would be the value, if it were in the map.
+ }
+ // An error value communicates not just "ok" but more about the problem.
+ if _, err := strconv.Atoi("non-int"); err != nil { // _ discards value
+ // prints 'strconv.ParseInt: parsing "non-int": invalid syntax'
+ fmt.Println(err)
+ }
+ // We'll revisit interfaces a little later. Meanwhile,
+ learnConcurrency()
}
// c is a channel, a concurrency-safe communication object.
func inc(i int, c chan int) {
- c <- i + 1 // <- is the "send" operator when a channel appears on the left.
+ c <- i + 1 // <- is the "send" operator when a channel appears on the left.
}
// We'll use inc to increment some numbers concurrently.
func learnConcurrency() {
- // Same make function used earlier to make a slice. Make allocates and
- // initializes slices, maps, and channels.
- c := make(chan int)
- // Start three concurrent goroutines. Numbers will be incremented
- // concurrently, perhaps in parallel if the machine is capable and
- // properly configured. All three send to the same channel.
- go inc(0, c) // go is a statement that starts a new goroutine.
- go inc(10, c)
- go inc(-805, c)
- // Read three results from the channel and print them out.
- // There is no telling in what order the results will arrive!
- fmt.Println(<-c, <-c, <-c) // channel on right, <- is "receive" operator.
-
- cs := make(chan string) // Another channel, this one handles strings.
- ccs := make(chan chan string) // A channel of string channels.
- go func() { c <- 84 }() // Start a new goroutine just to send a value.
- go func() { cs <- "wordy" }() // Again, for cs this time.
- // Select has syntax like a switch statement but each case involves
- // a channel operation. It selects a case at random out of the cases
- // that are ready to communicate.
- select {
- case i := <-c: // The value received can be assigned to a variable,
- fmt.Printf("it's a %T", i)
- case <-cs: // or the value received can be discarded.
- fmt.Println("it's a string")
- case <-ccs: // Empty channel, not ready for communication.
- fmt.Println("didn't happen.")
- }
- // At this point a value was taken from either c or cs. One of the two
- // goroutines started above has completed, the other will remain blocked.
-
- learnWebProgramming() // Go does it. You want to do it too.
+ // Same make function used earlier to make a slice. Make allocates and
+ // initializes slices, maps, and channels.
+ c := make(chan int)
+ // Start three concurrent goroutines. Numbers will be incremented
+ // concurrently, perhaps in parallel if the machine is capable and
+ // properly configured. All three send to the same channel.
+ go inc(0, c) // go is a statement that starts a new goroutine.
+ go inc(10, c)
+ go inc(-805, c)
+ // Read three results from the channel and print them out.
+ // There is no telling in what order the results will arrive!
+ fmt.Println(<-c, <-c, <-c) // channel on right, <- is "receive" operator.
+
+ cs := make(chan string) // Another channel, this one handles strings.
+ ccs := make(chan chan string) // A channel of string channels.
+ go func() { c <- 84 }() // Start a new goroutine just to send a value.
+ go func() { cs <- "wordy" }() // Again, for cs this time.
+ // Select has syntax like a switch statement but each case involves
+ // a channel operation. It selects a case at random out of the cases
+ // that are ready to communicate.
+ select {
+ case i := <-c: // The value received can be assigned to a variable,
+ fmt.Printf("it's a %T", i)
+ case <-cs: // or the value received can be discarded.
+ fmt.Println("it's a string")
+ case <-ccs: // Empty channel, not ready for communication.
+ fmt.Println("didn't happen.")
+ }
+ // At this point a value was taken from either c or cs. One of the two
+ // goroutines started above has completed, the other will remain blocked.
+
+ learnWebProgramming() // Go does it. You want to do it too.
}
// A single function from package http starts a web server.
func learnWebProgramming() {
- // First parameter of ListenAndServe is TCP address to listen to.
- // Second parameter is an interface, specifically http.Handler.
- err := http.ListenAndServe(":8080", pair{})
- fmt.Println(err) // don't ignore errors
+
+ // First parameter of ListenAndServe is TCP address to listen to.
+ // Second parameter is an interface, specifically http.Handler.
+ go func() {
+ err := http.ListenAndServe(":8080", pair{})
+ fmt.Println(err) // don't ignore errors
+ }()
+
+ requestServer()
}
// Make pair an http.Handler by implementing its only method, ServeHTTP.
func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- // Serve data with a method of http.ResponseWriter.
- w.Write([]byte("You learned Go in Y minutes!"))
+ // Serve data with a method of http.ResponseWriter.
+ w.Write([]byte("You learned Go in Y minutes!"))
+}
+
+func requestServer() {
+ resp, err := http.Get("http://localhost:8080")
+ fmt.Println(err)
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ fmt.Printf("\nWebserver said: `%s`", string(body))
}
```
@@ -320,12 +398,15 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
The root of all things Go is the [official Go web site](http://golang.org/).
There you can follow the tutorial, play interactively, and read lots.
-The language definition itself is highly recommended. It's easy to read
+The language definition itself is highly recommended. It's easy to read
and amazingly short (as language definitions go these days.)
+You can play around with the code on [Go playground](https://play.golang.org/p/tnWMjr16Mm). Try to change it and run it from your browser! Note that you can use [https://play.golang.org](https://play.golang.org) as a [REPL](https://en.wikipedia.org/wiki/Read-eval-print_loop) to test things and code in your browser, without even installing Go.
+
On the reading list for students of Go is the [source code to the standard
-library](http://golang.org/src/pkg/). Comprehensively documented, it
+library](http://golang.org/src/pkg/). Comprehensively documented, it
demonstrates the best of readable and understandable Go, Go style, and Go
-idioms. Or you can click on a function name in [the
+idioms. Or you can click on a function name in [the
documentation](http://golang.org/pkg/) and the source code comes up!
+Another great resource to learn Go is [Go by example](https://gobyexample.com/).
diff --git a/haml.html.markdown b/haml.html.markdown
new file mode 100644
index 00000000..aed3dcae
--- /dev/null
+++ b/haml.html.markdown
@@ -0,0 +1,155 @@
+---
+language: haml
+filename: learnhaml.haml
+contributors:
+ - ["Simon Neveu", "https://github.com/sneveu"]
+---
+
+Haml is a markup language predominantly used with Ruby that cleanly and simply describes the HTML of any web document without the use of inline code. It is a popular alternative to using Rails templating language (.erb) and allows you to embed Ruby code into your markup.
+
+It aims to reduce repetition in your markup by closing tags for you based on the structure of the indents in your code. The result is markup that is well-structured, DRY, logical, and easier to read.
+
+You can also use Haml on a project independent of Ruby, by installing the Haml gem on your machine and using the command line to convert it to html.
+
+$ haml input_file.haml output_file.html
+
+
+```haml
+/ -------------------------------------------
+/ Indenting
+/ -------------------------------------------
+
+/
+ Because of the importance indentation has on how your code is rendered, the
+ indents should be consistent throughout the document. Any differences in
+ indentation will throw an error. It's common-practice to use two spaces,
+ but it's really up to you, as long as they're constant.
+
+
+/ -------------------------------------------
+/ Comments
+/ -------------------------------------------
+
+/ This is what a comment looks like in Haml.
+
+/
+ To write a multi line comment, indent your commented code to be
+ wrapped by the forward slash
+
+-# This is a silent comment, which means it wont be rendered into the doc at all
+
+
+/ -------------------------------------------
+/ Html elements
+/ -------------------------------------------
+
+/ To write your tags, use the percent sign followed by the name of the tag
+%body
+ %header
+ %nav
+
+/ Notice no closing tags. The above code would output
+ <body>
+ <header>
+ <nav></nav>
+ </header>
+ </body>
+
+/ The div tag is the default element, so they can be written simply like this
+.foo
+
+/ To add content to a tag, add the text directly after the declaration
+%h1 Headline copy
+
+/ To write multiline content, nest it instead
+%p
+ This is a lot of content that we could probably split onto two
+ separate lines.
+
+/
+ You can escape html by using the ampersand and equals sign ( &= ). This
+ converts html-sensitive characters (&, /, :) into their html encoded
+ equivalents. For example
+
+%p
+ &= "Yes & yes"
+
+/ would output 'Yes &amp; yes'
+
+/ You can unescape html by using the bang and equals sign ( != )
+%p
+ != "This is how you write a paragraph tag <p></p>"
+
+/ which would output 'This is how you write a paragraph tag <p></p>'
+
+/ CSS classes can be added to your tags either by chaining .classnames to the tag
+%div.foo.bar
+
+/ or as part of a Ruby hash
+%div{:class => 'foo bar'}
+
+/ Attributes for any tag can be added in the hash
+%a{:href => '#', :class => 'bar', :title => 'Bar'}
+
+/ For boolean attributes assign the value 'true'
+%input{:selected => true}
+
+/ To write data-attributes, use the :data key with its value as another hash
+%div{:data => {:attribute => 'foo'}}
+
+
+/ -------------------------------------------
+/ Inserting Ruby
+/ -------------------------------------------
+
+/
+ To output a Ruby value as the contents of a tag, use an equals sign followed
+ by the Ruby code
+
+%h1= book.name
+
+%p
+ = book.author
+ = book.publisher
+
+
+/ To run some Ruby code without rendering it to the html, use a hyphen instead
+- books = ['book 1', 'book 2', 'book 3']
+
+/ Allowing you to do all sorts of awesome, like Ruby blocks
+- books.shuffle.each_with_index do |book, index|
+ %h1= book
+
+ if book do
+ %p This is a book
+
+/
+ Again, no need to add the closing tags to the block, even for the Ruby.
+ Indentation will take care of that for you.
+
+
+/ -------------------------------------------
+/ Inline Ruby / Ruby interpolation
+/ -------------------------------------------
+
+/ Include a Ruby variable in a line of plain text using #{}
+%p Your highest scoring game is #{best_game}
+
+
+/ -------------------------------------------
+/ Filters
+/ -------------------------------------------
+
+/
+ Use the colon to define Haml filters, one example of a filter you can
+ use is :javascript, which can be used for writing inline js
+
+:javascript
+ console.log('This is inline <script>');
+
+```
+
+## Additional resources
+
+- [What is HAML?](http://haml.info/) - A good introduction that does a much better job of explaining the benefits of using HAML.
+- [Official Docs](http://haml.info/docs/yardoc/file.REFERENCE.html) - If you'd like to go a little deeper.
diff --git a/haskell.html.markdown b/haskell.html.markdown
index e0489710..2785405c 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
---
@@ -171,8 +171,8 @@ foldl1 (\acc x -> acc + x) [1..5] -- 15
-- 4. More functions
----------------------------------------------------
--- currying: if you don't pass in all the arguments to a function,
--- it gets "curried". That means it returns a function that takes the
+-- partial application: if you don't pass in all the arguments to a function,
+-- it gets "partially applied". That means it returns a function that takes the
-- rest of the arguments.
add a b = a + b
diff --git a/ja-jp/bash-jp.html.markdown b/ja-jp/bash-jp.html.markdown
new file mode 100644
index 00000000..88e5ff1c
--- /dev/null
+++ b/ja-jp/bash-jp.html.markdown
@@ -0,0 +1,172 @@
+---
+category: tool
+tool: bash
+contributors:
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Darren Lin", "https://github.com/CogBear"]
+ - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
+ - ["Denis Arh", "https://github.com/darh"]
+translators:
+ - ["akirahirose", "https://twitter.com/akirahirose"]
+filename: LearnBash-jp.sh
+lang: ja-jp
+---
+
+Bash はunixシェルの1つです。GNUオペレーションシステムのシェルとして配布されています。
+LinuxやMac OS Xの、デフォルトシェルにもなっています。
+以下にある例は、ほぼ全部シェルスクリプトの一部として使えます。また、一部はそのままシェルから実行できます。
+
+[ちゃんとした説明は、こちらをどうぞ](http://www.gnu.org/software/bash/manual/bashref.html)
+
+```bash
+#!/bin/bash
+# 最初の行はShebang(シェバング、シバン)というもので、システムに対して何を使って実行するのかを教えるためのものです
+# ちゃんとした説明、こちらをどうぞ: http://en.wikipedia.org/wiki/Shebang_(Unix)
+# 既にお気づきのように、コメント行は#で始まります. Shebangもコメントです
+
+# まずは Hello world です
+echo Hello world!
+
+# コマンド毎に改行を入れるか、セミコロンで区切ります
+echo 'This is the first line'; echo 'This is the second line'
+
+# 変数の宣言はこのようにやります
+VARIABLE="Some string"
+
+# が、以下のようにやってはダメです
+VARIABLE = "Some string"
+# このように(空白を入れて)書くと、Bash はVARIABLEを実行するべきコマンドとみなし、実行します。
+# そして、VARIABLEというコマンドはない(はずな)ので、エラーになります
+
+
+# 変数の使い方
+echo $VARIABLE
+echo "$VARIABLE"
+echo '$VARIABLE'
+# 変数の値(中身)を使わず、変数名だけを使うとき(代入するときや渡すときなど)は、$なしで変数名を書いてください
+# 変数の値(中身)を使うときは、$をつけます
+# 上記例の最後にある、' (シングルクォート) で囲んだ場合は、変数の値は表示されません!
+
+# 変数値の文字列置換
+echo ${VARIABLE/Some/A}
+# 最初に出てくる "Some" を "A" で置換します
+
+# 変数値の一部を取り出します
+echo ${VARIABLE:0:7}
+# 最初の7文字だけを取り出します
+
+# デフォルトの変数値設定(訳注:シェル実行時に引数で変数値を設定できるが、設定しなかった場合の値を指定できる)
+echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"}
+# 上記は、FOO番目の引数がnullだったとき(FOO番目=)や、空文字が指定されたとき(FOO番目="")に、変数に0を入れます
+# ( 当然ですが、引数に0を指定したとき(FOO番目=0) も、0は入ります)
+
+# 組込み変数
+# 以下のような便利な組込み変数があります
+echo "Last program return value: $?"
+echo "Script's PID: $$"
+echo "Number of arguments: $#"
+echo "Scripts arguments: $@"
+echo "Scripts arguments seperated in different variables: $1 $2..."
+
+# 入力値の読み込み
+echo "What's your name?"
+read NAME # 新しく変数を宣言する必要はないことに注意
+echo Hello, $NAME!
+
+# 普通のif文も使えます
+# 利用できる判定条件については、'man test' で参照してください
+if [ $NAME -ne $USER ]
+then
+ echo "Your name is your username"
+else
+ echo "Your name isn't your username"
+fi
+
+# 他にも、条件判定ができます
+echo "Always executed" || echo "Only executed if first command fails"
+echo "Always executed" && echo "Only executed if first command does NOT fail"
+
+# 数式は以下のように書きます
+echo $(( 10 + 5 ))
+
+# 他のプログラム言語とは違ってbashはシェルなので、現在いるディレクトリ位置が異なると、異なる結果になります
+# lsコマンドで、現在いるディレクトリにあるファイルと、ディレクトリのリストが取得できます
+ls
+
+# これらのコマンドには、実行オプションがいろいろあります
+ls -l # ファイルとディレクトリのリストを行に分けて表示します
+
+# あるコマンド実行による返値を、次のコマンドの入力値としてつかえます
+# 例えばですが、lsコマンドの返値を、grepコマンドによって指定したルールに基づいてフィルタできます。
+# 以下は、現在いるディレクトリにある、.txtファイルのリストを表示する例です
+ls -l | grep "\.txt"
+
+# コマンドに対する入力元や出力先、またエラー出力先などを変更できます
+python2 hello.py < "input.in"
+python2 hello.py > "output.out"
+python2 hello.py 2> "error.err"
+# 出力先として指定したファイルが既に存在する場合は、上書きされます
+# もしもファイルに追記したい場合は、代わりに">>" を使ってください
+
+# コマンド文中で、$()内に別コマンドを入れると、その別コマンドの返値をコマンド文の一部として使う事ができます
+# 次のコマンドは、現在いるディレクトリにあるファイルの数を表示します
+echo "There are $(ls | wc -l) items here."
+
+# バッククォート(backticks) `` でも同じことができますが、入れ子にはできません
+# そのため、$()がお勧めです
+echo "There are `ls | wc -l` items here."
+
+# BashはJavaやC++のように、case文による分岐ができます
+case "$VARIABLE" in
+ #分岐条件として使いたいパターンを並べてください
+ 0) echo "There is a zero.";;
+ 1) echo "There is a one.";;
+ *) echo "It is not null.";;
+esac
+
+# 指定した回数、処理を繰り返し
+# 変数の値 $VARIABLE が3回表示されます
+for VARIABLE in {1..3}
+do
+ echo "$VARIABLE"
+done
+
+# while ループです
+while [true]
+do
+ echo "loop body here..."
+ break
+done
+
+# 関数の定義もできます
+function foo ()
+{
+ echo "Arguments work just like script arguments: $@"
+ echo "And: $1 $2..."
+ echo "This is a function"
+ return 0
+}
+
+# 以下のように、もっと簡単な書き方もあります
+bar ()
+{
+ echo "Another way to declare functions!"
+ return 0
+}
+
+# 自作関数を呼びます
+foo "My name is" $NAME
+
+# 他にもいろいろと、知っておくと便利なコマンドがあります
+# file.txtの最後10行を表示します
+tail -n 10 file.txt
+# file.txtの最初10行を表示します
+head -n 10 file.txt
+# file.txt's の行を並び替えます
+sort file.txt
+# 重複している行を表示するか、削除できます。-dオプションをつけると、表示します
+uniq -d file.txt
+# 1行ごとに、','が最初に出てくる前の部分を表示します
+cut -d ',' -f 1 file.txt
+
+```
diff --git a/ja-jp/r-jp.html.markdown b/ja-jp/r-jp.html.markdown
new file mode 100644
index 00000000..a8dd7c9c
--- /dev/null
+++ b/ja-jp/r-jp.html.markdown
@@ -0,0 +1,775 @@
+---
+language: R
+contributors:
+ - ["e99n09", "http://github.com/e99n09"]
+ - ["isomorphismes", "http://twitter.com/isomorphisms"]
+translators:
+ - ["akirahirose", "https://twitter.com/akirahirose"]
+filename: learnr-jp.r
+lang: ja-jp
+---
+
+
+R は統計計算用の言語です。
+データの取得やクリーニング、統計処理やグラフ作成をするために便利な、たくさんのライブラリがあります。また、LaTeX文書からRコマンドを呼び出すこともできます
+
+
+```r
+# コメント行は、#で開始します
+
+
+# 複数行をまとめてコメントにすることはできないので、
+# コメントを複数の行に分けたい場合、このように、単に毎行をコメントにしてください
+
+
+# WindowsやMacでは、 COMMAND-ENTERで、コマンドを1行実行できます
+
+
+
+
+
+
+#############################################################################
+# プログラミングがわからなくとも使えるコマンド類
+#############################################################################
+
+
+# この節では、プログラミングがわからなくとも使える便利なRコマンドを紹介します
+# 全てを理解できなくとも、まずはやってみましょう!
+
+
+data() # 既にロードされているデータを閲覧します
+data(rivers) # "北米にある大きな川の長さ"データを取得します
+ls() # "rivers" がワークスペースに表示されました
+head(rivers) # データの先頭部分です
+# 735 320 325 392 524 450
+
+
+length(rivers) # 何本の川がデータにある?
+# 141
+summary(rivers) # 統計的に要約するとどうなる?
+# Min. 1st Qu. Median Mean 3rd Qu. Max.
+# 135.0 310.0 425.0 591.2 680.0 3710.0
+
+
+# 茎葉図(ヒストグラムに似た図)を描く
+stem(rivers)
+
+
+# The decimal point is 2 digit(s) to the right of the |
+#
+# 0 | 4
+# 2 | 011223334555566667778888899900001111223333344455555666688888999
+# 4 | 111222333445566779001233344567
+# 6 | 000112233578012234468
+# 8 | 045790018
+# 10 | 04507
+# 12 | 1471
+# 14 | 56
+# 16 | 7
+# 18 | 9
+# 20 |
+# 22 | 25
+# 24 | 3
+# 26 |
+# 28 |
+# 30 |
+# 32 |
+# 34 |
+# 36 | 1
+
+
+stem(log(rivers)) # このデータは、正規分布でも対数正規分布でもないので、注意!
+# 特に正規分布原理主義のみなさん
+
+
+# The decimal point is 1 digit(s) to the left of the |
+#
+# 48 | 1
+# 50 |
+# 52 | 15578
+# 54 | 44571222466689
+# 56 | 023334677000124455789
+# 58 | 00122366666999933445777
+# 60 | 122445567800133459
+# 62 | 112666799035
+# 64 | 00011334581257889
+# 66 | 003683579
+# 68 | 0019156
+# 70 | 079357
+# 72 | 89
+# 74 | 84
+# 76 | 56
+# 78 | 4
+# 80 |
+# 82 | 2
+
+
+# ヒストグラム作成
+hist(rivers, col="#333333", border="white", breaks=25) # これらのパラメータをつかいます
+hist(log(rivers), col="#333333", border="white", breaks=25) # いろいろな使い方ができます
+
+
+# 別のロード済データでやってみましょう。Rには、いろいろなデータがロードされています。
+data(discoveries)
+plot(discoveries, col="#333333", lwd=3, xlab="Year",
+ main="Number of important discoveries per year")
+plot(discoveries, col="#333333", lwd=3, type = "h", xlab="Year",
+ main="Number of important discoveries per year")
+
+
+# 年次のソートだけではなく、
+# 標準的な並べ替えもできます
+sort(discoveries)
+# [1] 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
+# [26] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3
+# [51] 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4
+# [76] 4 4 4 4 5 5 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 8 9 10 12
+
+
+stem(discoveries, scale=2)
+#
+# The decimal point is at the |
+#
+# 0 | 000000000
+# 1 | 000000000000
+# 2 | 00000000000000000000000000
+# 3 | 00000000000000000000
+# 4 | 000000000000
+# 5 | 0000000
+# 6 | 000000
+# 7 | 0000
+# 8 | 0
+# 9 | 0
+# 10 | 0
+# 11 |
+# 12 | 0
+
+
+max(discoveries)
+# 12
+summary(discoveries)
+# Min. 1st Qu. Median Mean 3rd Qu. Max.
+# 0.0 2.0 3.0 3.1 4.0 12.0
+
+
+# サイコロを振ります
+round(runif(7, min=.5, max=6.5))
+# 1 4 6 1 4 6 4
+# 私と同じrandom.seed(31337)を使わない限りは、別の値になります
+
+
+# ガウス分布を9回生成します
+rnorm(9)
+# [1] 0.07528471 1.03499859 1.34809556 -0.82356087 0.61638975 -1.88757271
+# [7] -0.59975593 0.57629164 1.08455362
+
+
+
+
+
+
+##################################################
+# データ型と基本計算
+##################################################
+
+
+# ここからは、プログラミングをつかうチュートリアルです
+# この節ではRで重要なデータ型(データクラス)の、整数型、数字型、文字型、論理型と因子(ファクター)型をつかいます
+# 他にもいろいろありますが、これらの必要最小限なものから始めましょう
+
+
+# 整数型
+# 整数型はLで指定します
+5L # 5
+class(5L) # "integer"
+# (?class を実行すると、class()関数について、さらなる情報が得られます)
+# Rでは、この5Lのような1つの値は、長さ1のベクトルとして扱われます
+length(5L) # 1
+# 整数型のベクトルはこのようにつくります
+c(4L, 5L, 8L, 3L) # 4 5 8 3
+length(c(4L, 5L, 8L, 3L)) # 4
+class(c(4L, 5L, 8L, 3L)) # "integer"
+
+
+# 数字型
+# 倍精度浮動小数点数です
+5 # 5
+class(5) # "numeric"
+# しつこいですが、すべてはベクトルです
+# 1つ以上の要素がある数字のベクトルも、作ることができます
+c(3,3,3,2,2,1) # 3 3 3 2 2 1
+# 指数表記もできます
+5e4 # 50000
+6.02e23 # アボガドロ数
+1.6e-35 # プランク長
+# 無限大、無限小もつかえます
+class(Inf) # "numeric"
+class(-Inf) # "numeric"
+# 例のように、"Inf"を使ってください。integrate( dnorm(x), 3, Inf);
+# Z-スコア表が必要なくなります
+
+
+# 基本的な計算
+# 数を計算できます
+# 整数と整数以外の数字を両方使った計算をすると、結果は整数以外の数字になります
+10L + 66L # 76 # 整数足す整数は整数
+53.2 - 4 # 49.2 # 整数引く数字は数字
+2.0 * 2L # 4 # 数字かける整数は数字
+3L / 4 # 0.75 # 整数割る数字は数字
+3 %% 2 # 1 # 二つの数字を割った余りは数字
+# 不正な計算は "not-a-number"になります
+0 / 0 # NaN
+class(NaN) # "numeric"
+# 長さが1より大きなベクター同士の計算もできます
+# どちらかが長い場合、短い方は何度も繰り返して使われます
+c(1,2,3) + c(1,2,3) # 2 4 6
+
+# 文字
+# Rでは、文字列と文字に区別がありません
+"Horatio" # "Horatio"
+class("Horatio") # "character"
+class('H') # "character"
+# 上記は両方とも、長さ1のベクターです
+# 以下は、より長い場合です
+c('alef', 'bet', 'gimmel', 'dalet', 'he')
+# =>
+# "alef" "bet" "gimmel" "dalet" "he"
+length(c("Call","me","Ishmael")) # 3
+# 正規表現処理を文字ベクターに適用できます
+substr("Fortuna multis dat nimis, nulli satis.", 9, 15) # "multis "
+gsub('u', 'ø', "Fortuna multis dat nimis, nulli satis.") # "Fortøna møltis dat nimis, nølli satis."
+# Rはいくつかの文字ベクターを組み込みで持っています
+letters
+# =>
+# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
+# [20] "t" "u" "v" "w" "x" "y" "z"
+month.abb # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
+
+
+# 論理
+# Rでは、Booleanは論理(logical)型です
+class(TRUE) # "logical"
+class(FALSE) # "logical"
+# 以下は比較演算子の例です
+TRUE == TRUE # TRUE
+TRUE == FALSE # FALSE
+FALSE != FALSE # FALSE
+FALSE != TRUE # TRUE
+# 無いデータ (NA) も論理型です
+class(NA) # "logical"
+# 以下のようにすると、複数の要素を持つ、論理型ベクターが返ります
+c('Z', 'o', 'r', 'r', 'o') == "Zorro" # FALSE FALSE FALSE FALSE FALSE
+c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
+
+
+# 因子(ファクター)
+# 因子型は、カテゴリカルデータ用の型です
+# 因子には、子供の学年のように順序がつけられるものか、性別のように順序がないものがあります
+factor(c("female", "female", "male", "NA", "female"))
+# female female male NA female
+# Levels: female male NA
+# "levels" は、カテゴリカルデータがとりうる値を返します
+levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male" "NA"
+# 因子ベクターの長さが1ならば、そのlevelも1です
+length(factor("male")) # 1
+length(levels(factor("male"))) # 1
+# 因子型は、この後で紹介するデータフレーム(というデータ型)内で、よくみられます
+data(infert) # "Infertility after Spontaneous and Induced Abortion"
+levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
+
+
+# NULL
+# "NULL" は特殊な型なのですが、ベクターを空にするときに使います
+class(NULL) # NULL
+parakeet
+# =>
+# [1] "beak" "feathers" "wings" "eyes"
+parakeet <- NULL
+parakeet
+# =>
+# NULL
+
+
+# 型の強制
+# 型の強制とは、ある値を、強制的に別の型として利用する事です
+as.character(c(6, 8)) # "6" "8"
+as.logical(c(1,0,1,1)) # TRUE FALSE TRUE TRUE
+# さまざまな要素が入っているベクターに対して型の強制を行うと、おかしなことになります
+c(TRUE, 4) # 1 4
+c("dog", TRUE, 4) # "dog" "TRUE" "4"
+as.numeric("Bilbo")
+# =>
+# [1] NA
+# Warning message:
+# NAs introduced by coercion
+
+
+# 追記: ここで紹介したのは、基本的な型だけです
+# 実際には、日付(dates)や時系列(time series)など、いろいろな型があります
+
+
+
+
+
+
+##################################################
+# 変数、ループ、もし/ほかに(if/else)
+##################################################
+
+
+# 変数は、ある値を後で使うために入れておく、箱のようなものです
+# 箱に入れることを、変数に値を代入する、といいます
+# 変数を使うと、ループや関数、if/else 分岐を利用できます
+
+
+# 変数
+# 代入する方法はいろいろあります
+x = 5 # これはできます
+y <- "1" # これがおすすめです
+TRUE -> z # これも使えますが、ちょっとわかりにくいですね
+
+
+# ループ
+# forでループできます
+for (i in 1:4) {
+ print(i)
+}
+# whileでループできます
+a <- 10
+while (a > 4) {
+ cat(a, "...", sep = "")
+ a <- a - 1
+}
+# Rでは、forやwhileは遅いことを覚えておいてください
+# ベクターを丸ごと処理する(つまり、行全体や、列全体を指定して処理する)か、
+# 後述する、apply()系の関数を使うのが、速度的にはお勧めです
+
+
+# IF/ELSE
+# ごく普通のif文です
+if (4 > 3) {
+ print("4 is greater than 3")
+} else {
+ print("4 is not greater than 3")
+}
+# =>
+# [1] "4 is greater than 3"
+
+
+# 関数
+# 以下のように定義します
+jiggle <- function(x) {
+ x = x + rnorm(1, sd=.1) #すこしだけ(制御された)ノイズを入れます
+ return(x)
+}
+# 他の関数と同じように、呼びます
+jiggle(5) # 5±ε. set.seed(2716057)をすると、jiggle(5)==5.005043
+
+
+
+
+
+
+###########################################################################
+# データ構造: ベクター、行列、データフレーム、配列
+###########################################################################
+
+
+# 1次元
+
+
+# まずは基本からです。ご存じベクターからです
+vec <- c(8, 9, 10, 11)
+vec # 8 9 10 11
+# 特定の要素を、[角括弧]による指定で取り出せます
+# (Rでは、最初の要素は1番目と数えます)
+vec[1] # 8
+letters[18] # "r"
+LETTERS[13] # "M"
+month.name[9] # "September"
+c(6, 8, 7, 5, 3, 0, 9)[3] # 7
+# 特定のルールに当てはまる要素を見つけることもできます
+which(vec %% 2 == 0) # 1 3
+# 最初か最後の数個を取り出すこともできます
+head(vec, 1) # 8
+tail(vec, 2) # 10 11
+# ある値がベクターにあるかどうかをみることができます
+any(vec == 10) # TRUE
+# ベクターの数より大きなインデックスを指定すると、NAが返ります
+vec[6] # NA
+# ベクターの長さは、length()で取得できます
+length(vec) # 4
+# ベクター全体、または1部に対して、操作ができます
+vec * 4 # 16 20 24 28
+vec[2:3] * 5 # 25 30
+any(vec[2:3] == 8) # FALSE
+# R には、ベクターにある値を要約するための様々な関数があります
+mean(vec) # 9.5
+var(vec) # 1.666667
+sd(vec) # 1.290994
+max(vec) # 11
+min(vec) # 8
+sum(vec) # 38
+# 他にも、ベクター関連ではいろいろな関数があります。以下はベクターをつくるための方法です
+5:15 # 5 6 7 8 9 10 11 12 13 14 15
+seq(from=0, to=31337, by=1337)
+# =>
+# [1] 0 1337 2674 4011 5348 6685 8022 9359 10696 12033 13370 14707
+# [13] 16044 17381 18718 20055 21392 22729 24066 25403 26740 28077 29414 30751
+
+
+# 2次元配列 (すべての値が同じ型の場合)
+
+
+# 同じ型の値が含まれる2次元配列は、このように作れます
+mat <- matrix(nrow = 3, ncol = 2, c(1,2,3,4,5,6))
+mat
+# =>
+# [,1] [,2]
+# [1,] 1 4
+# [2,] 2 5
+# [3,] 3 6
+# ベクターとは違い、2次元配列の型名は"matrix"です。
+class(mat) # => "matrix"
+# 最初の行
+mat[1,] # 1 4
+# 最初の列に対する操作
+3 * mat[,1] # 3 6 9
+# 特定のセルを取り出し
+mat[3,2] # 6
+
+
+# 2次元配列全体を転置します
+t(mat)
+# =>
+# [,1] [,2] [,3]
+# [1,] 1 2 3
+# [2,] 4 5 6
+
+
+# 2次元配列の積
+mat %*% t(mat)
+# =>
+# [,1] [,2] [,3]
+# [1,] 17 22 27
+# [2,] 22 29 36
+# [3,] 27 36 45
+
+
+# cbind() は、複数のベクターを、別々の列に並べて2次元配列を作ります
+mat2 <- cbind(1:4, c("dog", "cat", "bird", "dog"))
+mat2
+# =>
+# [,1] [,2]
+# [1,] "1" "dog"
+# [2,] "2" "cat"
+# [3,] "3" "bird"
+# [4,] "4" "dog"
+class(mat2) # matrix
+# ここでいま1度、2次元配列内の型について注意してください!
+# 2次元配列にある値は、すべて同じ型にする必要があります。そのため、すべて文字型に変換されています
+c(class(mat2[,1]), class(mat2[,2]))
+
+
+# rbind() は、複数のベクターを、別々の行に並べて2次元配列を作ります
+mat3 <- rbind(c(1,2,4,5), c(6,7,0,4))
+mat3
+# =>
+# [,1] [,2] [,3] [,4]
+# [1,] 1 2 4 5
+# [2,] 6 7 0 4
+# 全ての値は同じ型になります。上記例は幸い、強制変換がされないものでした
+
+
+# 2次元配列 (いろいろな型を含む場合)
+
+
+# 異なる型の値を含む配列をつくりたい場合、データフレームを使ってください
+# データフレームは、統計処理を行うプログラムをする際にとても便利です
+# Pythonでも、 "pandas"というパッケージにて、似たものが利用可能です
+
+
+students <- data.frame(c("Cedric","Fred","George","Cho","Draco","Ginny"),
+ c(3,2,2,1,0,-1),
+ c("H", "G", "G", "R", "S", "G"))
+names(students) <- c("name", "year", "house") #カラム名
+class(students) # "data.frame"
+students
+# =>
+# name year house
+# 1 Cedric 3 H
+# 2 Fred 2 G
+# 3 George 2 G
+# 4 Cho 1 R
+# 5 Draco 0 S
+# 6 Ginny -1 G
+class(students$year) # "numeric"
+class(students[,3]) # "factor"
+# 行と列の数をみます
+nrow(students) # 6
+ncol(students) # 3
+dim(students) # 6 3
+# このdata.frame() 関数は、デフォルトでは文字列ベクターを因子ベクターに変換します
+# stringsAsFactors = FALSE に設定してからデータフレームを作成すると、変換されません
+?data.frame
+
+
+# データフレームの1部を取り出すには、いろいろな(変な)、似たような方法があります
+students$year # 3 2 2 1 0 -1
+students[,2] # 3 2 2 1 0 -1
+students[,"year"] # 3 2 2 1 0 -1
+
+
+# データフレームの拡張版が、データテーブルです。
+# 大きなデータやパネルデータ、データセットの結合が必要な場合には、データテーブルを使うべきです。
+# 以下に駆け足で説明します
+install.packages("data.table") # CRANからパッケージをダウンロードします
+require(data.table) # ロードします
+students <- as.data.table(students)
+students # 若干異なる出力がされることに注意
+# =>
+# name year house
+# 1: Cedric 3 H
+# 2: Fred 2 G
+# 3: George 2 G
+# 4: Cho 1 R
+# 5: Draco 0 S
+# 6: Ginny -1 G
+students[name=="Ginny"] # name == "Ginny"の行を取り出します
+# =>
+# name year house
+# 1: Ginny -1 G
+students[year==2] # year == 2の行を取り出します
+# =>
+# name year house
+# 1: Fred 2 G
+# 2: George 2 G
+# データテーブルは、二つのデータセットを結合するのにも便利です
+# 結合用に、生徒データが入った別のデータテーブルをつくります
+founders <- data.table(house=c("G","H","R","S"),
+ founder=c("Godric","Helga","Rowena","Salazar"))
+founders
+# =>
+# house founder
+# 1: G Godric
+# 2: H Helga
+# 3: R Rowena
+# 4: S Salazar
+setkey(students, house)
+setkey(founders, house)
+students <- founders[students] # 二つのデータテーブルを、"house"をキーとして結合します
+setnames(students, c("house","houseFounderName","studentName","year"))
+students[,order(c("name","year","house","houseFounderName")), with=F]
+# =>
+# studentName year house houseFounderName
+# 1: Fred 2 G Godric
+# 2: George 2 G Godric
+# 3: Ginny -1 G Godric
+# 4: Cedric 3 H Helga
+# 5: Cho 1 R Rowena
+# 6: Draco 0 S Salazar
+
+
+# データテーブルは、要約を作るのも簡単です
+students[,sum(year),by=house]
+# =>
+# house V1
+# 1: G 3
+# 2: H 3
+# 3: R 1
+# 4: S 0
+
+
+# データフレームやデータテーブルから列を消したい場合は、NULL値を代入します
+students$houseFounderName <- NULL
+students
+# =>
+# studentName year house
+# 1: Fred 2 G
+# 2: George 2 G
+# 3: Ginny -1 G
+# 4: Cedric 3 H
+# 5: Cho 1 R
+# 6: Draco 0 S
+
+
+# データテーブルから行を消す場合は、以下のように除く行を指定すればできます
+students[studentName != "Draco"]
+# =>
+# house studentName year
+# 1: G Fred 2
+# 2: G George 2
+# 3: G Ginny -1
+# 4: H Cedric 3
+# 5: R Cho 1
+# データフレームの場合も同様です
+students <- as.data.frame(students)
+students[students$house != "G",]
+# =>
+# house houseFounderName studentName year
+# 4 H Helga Cedric 3
+# 5 R Rowena Cho 1
+# 6 S Salazar Draco 0
+
+
+# 多次元 (すべての値が同じ型の場合)
+
+
+# 配列を並べて、N次元の表を作ります
+# 配列なので、すべての値は同じ型にする必要があります
+# ちなみに、以下のようにすれば2次元配列・2次元表も作成可能です
+array(c(c(1,2,4,5),c(8,9,3,6)), dim=c(2,4))
+# =>
+# [,1] [,2] [,3] [,4]
+# [1,] 1 4 8 3
+# [2,] 2 5 9 6
+# 2次元配列を並べて、3次元配列を作ることもできます
+array(c(c(c(2,300,4),c(8,9,0)),c(c(5,60,0),c(66,7,847))), dim=c(3,2,2))
+# =>
+# , , 1
+#
+# [,1] [,2]
+# [1,] 2 8
+# [2,] 300 9
+# [3,] 4 0
+#
+# , , 2
+#
+# [,1] [,2]
+# [1,] 5 66
+# [2,] 60 7
+# [3,] 0 847
+
+
+# リスト(多次元、不完全または複数の型が使われているもの)
+
+
+# ついにRのリストです
+list1 <- list(time = 1:40)
+list1$price = c(rnorm(40,.5*list1$time,4)) # random
+list1
+# リストの要素は以下のようにして取得できます
+list1$time # ある方法
+list1[["time"]] # 別の方法
+list1[[1]] # また別の方法
+# =>
+# [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
+# [34] 34 35 36 37 38 39 40
+# 他のベクターと同じく、1部を取り出すことができます
+list1$price[4]
+
+
+# リストは、Rで1番効率的なデータ型ではありません
+# 特別な理由がない限りは、リストの代わりにデータフレームを使うべきです
+# リストは、線形回帰関数の返値として、しばしば使われています
+
+
+##################################################
+# apply() 系の関数
+##################################################
+
+
+# matは覚えていますよね?
+mat
+# =>
+# [,1] [,2]
+# [1,] 1 4
+# [2,] 2 5
+# [3,] 3 6
+# apply(X, MARGIN, FUN) は、行列Xの行(MARGIN=1で指定)または列(MARGIN=2で指定)に対して、関数FUNを実行します
+# Rで、このように指定してXの全行または全列に関数を実行するのは、forやwhileループを使うよりも、遥かに速いです
+apply(mat, MAR = 2, jiggle)
+# =>
+# [,1] [,2]
+# [1,] 3 15
+# [2,] 7 19
+# [3,] 11 23
+# 他にも便利な関数があります。?lapply, ?sapply で確認してみてください
+
+
+# apply()系関数の使い方は、ちょっとややこしいです(みんなそう思ってます)。なので、あまり怖がりすぎないでください
+
+
+# plyr パッケージは、*apply() 系の関数を置き換えて(さらに改善して)いこうとしています
+install.packages("plyr")
+require(plyr)
+?plyr
+
+
+
+
+
+
+#########################
+# データロード
+#########################
+
+
+# "pets.csv"は、インターネット上に置いてあるファイルです
+# (しかし、自分のPCにあるのと同じぐらい簡単に扱う事ができます)
+pets <- read.csv("http://learnxinyminutes.com/docs/pets.csv")
+pets
+head(pets, 2) # 最初の2行
+tail(pets, 1) # 最後の行
+
+
+# データフレームか行列をcsvファイルとして保存します
+write.csv(pets, "pets2.csv") # 新しくcsvファイルを作ります
+# ワーキングディレクトリを、setwd()で設定します。 ワーキングディレクトリは getwd()で確認可能です
+
+
+# ?read.csv や ?write.csv を入力すると、よりたくさんの情報を確認できます
+
+
+
+
+
+
+#########################
+# プロット
+#########################
+
+
+# Rに組込まれているプロット関数をつかいます
+# 散布図!
+plot(list1$time, list1$price, main = "fake data")
+# 回帰図!
+linearModel <- lm(price ~ time, data = list1)
+linearModel # outputs result of regression
+# 回帰直線を既存の図上に引きます
+abline(linearModel, col = "red")
+# いろいろな散布図をつくって、確認できます
+plot(linearModel)
+# ヒストグラム!
+hist(rpois(n = 10000, lambda = 5), col = "thistle")
+# 棒グラフ!
+barplot(c(1,4,5,1,2), names.arg = c("red","blue","purple","green","yellow"))
+
+
+# GGPLOT2
+# 上記の組込み関数を使うよりも、もっときれいな図を描くこともできます
+# ggplot2 パッケージを使って、より多くのよい図を描いてみましょう
+install.packages("ggplot2")
+require(ggplot2)
+?ggplot2
+pp <- ggplot(students, aes(x=house))
+pp + geom_histogram()
+ll <- as.data.table(list1)
+pp <- ggplot(ll, aes(x=time,price))
+pp + geom_point()
+# ggplot2 には、素晴らしい関連ドキュメントがそろっています (http://docs.ggplot2.org/current/)
+
+
+
+
+
+
+```
+
+
+## Rの入手方法
+
+
+* RとR GUIはこちら [http://www.r-project.org/](http://www.r-project.org/)
+* [RStudio](http://www.rstudio.com/ide/) 別のGUI
diff --git a/java.html.markdown b/java.html.markdown
index 50875491..dffc3828 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -101,9 +101,9 @@ public class LearnJava {
// Arrays
//The array size must be decided upon instantiation
- //The following formats work for declaring an arrow
+ //The following formats work for declaring an array
//<datatype> [] <var name> = new <datatype>[<array size>];
- //<datetype> <var name>[] = new <datatype>[<array size>];
+ //<datatype> <var name>[] = new <datatype>[<array size>];
int [] intArray = new int[10];
String [] stringArray = new String[1];
boolean boolArray [] = new boolean[100];
diff --git a/javascript.html.markdown b/javascript.html.markdown
index f190ff98..cc210c4a 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -7,7 +7,7 @@ filename: javascript.js
---
JavaScript was created by Netscape's Brendan Eich in 1995. It was originally
-intended as a simpler scripting language for websites, complimenting the use of
+intended as a simpler scripting language for websites, complementing the use of
Java for more complex web applications, but its tight integration with Web pages
and built-in support in browsers has caused it to become far more common than
Java in web frontends.
@@ -462,8 +462,8 @@ var myNumberObj = new Number(12);
myNumber == myNumberObj; // = true
// Except, they aren't exactly equivalent.
-typeof(myNumber); // = 'number'
-typeof(myNumberObj); // = 'object'
+typeof myNumber; // = 'number'
+typeof myNumberObj; // = 'object'
myNumber === myNumberObj; // = false
if (0){
// This code won't execute, because 0 is falsy.
diff --git a/json.html.markdown b/json.html.markdown
index f86f0ae9..f5287138 100644
--- a/json.html.markdown
+++ b/json.html.markdown
@@ -3,6 +3,7 @@ language: json
filename: learnjson.json
contributors:
- ["Anna Harren", "https://github.com/iirelu"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
---
As JSON is an extremely simple data-interchange format, this is most likely going
@@ -14,6 +15,9 @@ going to be 100% valid JSON. Luckily, it kind of speaks for itself.
```json
{
+ "key": "value",
+
+ "keys": "must always be enclosed in double quotes",
"numbers": 0,
"strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
"has bools?": true,
@@ -42,7 +46,13 @@ going to be 100% valid JSON. Luckily, it kind of speaks for itself.
[0, 0, 0, 1]
]
],
+
+ "alternative style": {
+ "comment": "check this out!"
+ , "comma position": "doesn't matter - as long as its before the value, then its valid"
+ , "another comment": "how nice"
+ },
- "that was short": "And, you're done. You know know everything JSON has to offer."
+ "that was short": "And, you're done. You now know everything JSON has to offer."
}
```
diff --git a/julia.html.markdown b/julia.html.markdown
index 15b4be90..3a52018c 100644
--- a/julia.html.markdown
+++ b/julia.html.markdown
@@ -1,5 +1,5 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
filename: learnjulia.jl
@@ -12,7 +12,7 @@ This is based on the current development version of Julia, as of October 18th, 2
```ruby
-# Single line comments start with a number symbol.
+# Single line comments start with a hash (pound) symbol.
#= Multiline comments can be written
by putting '#=' before the text and '=#'
after the text. They can also be nested.
@@ -125,8 +125,9 @@ SomeOtherVar123! = 6 # => 6
# A note on naming conventions in Julia:
#
-# * Names of variables are in lower case, with word separation indicated by
-# underscores ('\_').
+# * Word separation can be indicated by underscores ('_'), but use of
+# underscores is discouraged unless the name would be hard to read
+# otherwise.
#
# * Names of Types begin with a capital letter and word separation is shown
# with CamelCase instead of underscores.
@@ -500,7 +501,7 @@ typeof(DataType) # => DataType
# Users can define types
# They are like records or structs in other languages.
-# New types are defined used the `type` keyword.
+# New types are defined using the `type` keyword.
# type Name
# field::OptionalType
diff --git a/ko-kr/go-kr.html.markdown b/ko-kr/go-kr.html.markdown
index e6ebe097..3012c04f 100644
--- a/ko-kr/go-kr.html.markdown
+++ b/ko-kr/go-kr.html.markdown
@@ -5,8 +5,12 @@ language: Go
filename: learngo-kr.go
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["Christopher Bess", "https://github.com/cbess"]
+ - ["Jesse Johnson", "https://github.com/holocronweaver"]
+ - ["Quint Guvernator", "https://github.com/qguv"]
translators:
- ["Jongmin Kim", "http://github.com/atomaths"]
+ - ["Peter Lee", "http://github.com/ins429"]
lang: ko-kr
---
@@ -75,7 +79,7 @@ func learnTypes() {
개행을 포함할 수 있다.` // 같은 string 타입
// non-ASCII 리터럴. Go 소스는 UTF-8로 작성해야 한다.
- g := 'Σ' // 유니코드 코드 포인트를 담고 있고, uint32 타입의 가칭(alias)인 rune 타입
+ g := 'Σ' // 유니코드 코드 포인트를 담고 있고, int32 타입의 가칭(alias)인 rune 타입
f := 3.14195 // float64, an IEEE-754 64-bit 부동소수 타입
c := 3 + 4i // complex128, 내부적으로는 두 개의 float64 타입으로 표현됨
@@ -184,9 +188,20 @@ func learnFlowControl() {
goto love
love:
+ learnDefer() // defer에 대해
learnInterfaces() // 곧이어서 좋은 기능에 대한 설명이 나올 거다.
}
+func learnDefer() (ok bool) {
+ // deferred statements are executed just before the function returns.
+ // 연기된(deferred) 구문은 함수가 리턴하기 직전에 실행된다.
+ defer fmt.Println("deferred statements execute in reverse (LIFO) order.") // 연기된 구문은 LIFO순으로 실행된다.
+ defer fmt.Println("\nThis line is being printed first because") // 이 줄이 먼저 실행된다.
+ // defer는 주로 파일을 닫는데 사용된다.
+ // 파일을 닫는함수를 파일을 여는함수에 가까이 둘수 있다.
+ return true
+}
+
// String 이라는 메서드 하나를 가진 Stringer 라는 인터페이스 타입을 정의하자.
type Stringer interface {
String() string
@@ -220,6 +235,21 @@ func learnInterfaces() {
fmt.Println(p) // 결과는 위와 같다. Println은 String 메서드를 호출한다.
fmt.Println(i) // 결과는 위와 같다.
+ learnVariadicParams("great", "learning", "here!")
+}
+
+// 함수는 가변 인수(variadic) 파라미터를 가질수 있다.
+func learnVariadicParams(myStrings ...interface{}) {
+ // 가변 인수를 차례로 반복한다.
+ // 여기서 언더바(언더스코어, `_`)는 배열의 인덱스 인수를 무시한다.
+ // The underbar here is ignoring the index argument of the array.
+ for _, param := range myStrings {
+ fmt.Println("param:", param)
+ }
+
+ // 가변 인수 값을 가변인수 파라미터로 보내기.
+ fmt.Println("params:", fmt.Sprintln(myStrings...))
+
learnErrorHandling()
}
@@ -312,3 +342,5 @@ Go 소스코드에 대해 좀더 알아보고 싶다면 [Go 표준 라이브러
분석해보기 바란다. 이해하기 쉽게 문서화되어 있고, Go 스타일 그리고 Go에서의
관례 배우기에 가장 좋은 방법일 것이다. 또는 [문서](http://golang.org/pkg/) 안에서
함수 이름 하나를 클릭해보면 소스코드를 브라우저에서 살펴볼 수도 있다.
+
+Go를 배울수 있는 또하나의 좋은 방법은 [Go by example](https://gobyexample.com/).
diff --git a/ko-kr/javascript-kr.html.markdown b/ko-kr/javascript-kr.html.markdown
index f651fbe7..4ca3bb5c 100644
--- a/ko-kr/javascript-kr.html.markdown
+++ b/ko-kr/javascript-kr.html.markdown
@@ -381,8 +381,8 @@ var myNumberObj = new Number(12)
myNumber == myNumberObj // = true
// 하지만 정확히 같지는 않습니다.
-typeof(myNumber) // = 'number'
-typeof(myNumberObj) // = 'object'
+typeof myNumber // = 'number'
+typeof myNumberObj // = 'object'
myNumber === myNumberObj // = false
if (0){
// 0은 거짓이라서 이 코드는 실행되지 않습니다.
diff --git a/ko-kr/lua-kr.html.markdown b/ko-kr/lua-kr.html.markdown
index 850587a0..b4a018ef 100644
--- a/ko-kr/lua-kr.html.markdown
+++ b/ko-kr/lua-kr.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
category: language
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
diff --git a/ko-kr/php-kr.html.markdown b/ko-kr/php-kr.html.markdown
index 80f324f3..1f53221f 100644
--- a/ko-kr/php-kr.html.markdown
+++ b/ko-kr/php-kr.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
category: language
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
diff --git a/ko-kr/racket-kr.html.markdown b/ko-kr/racket-kr.html.markdown
new file mode 100644
index 00000000..8d830279
--- /dev/null
+++ b/ko-kr/racket-kr.html.markdown
@@ -0,0 +1,640 @@
+---
+
+language: racket
+filename: learnracket-kr.rkt
+contributors:
+ - ["th3rac25", "https://github.com/voila"]
+ - ["Eli Barzilay", "https://github.com/elibarzilay"]
+ - ["Gustavo Schmidt", "https://github.com/gustavoschmidt"]
+ - ["Duong H. Nguyen", "https://github.com/cmpitg"]
+translators:
+ - ["KIM Taegyoon", "https://github.com/kimtg"]
+lang: ko-kr
+---
+
+Racket 은 Lisp/Scheme 계열의 일반 목적의, 다중 패러다임 프로그래밍 언어이다.
+
+```racket
+#lang racket ; 우리가 사용하는 언어를 정의한다.
+
+;;; 주석
+
+;; 한 줄 주석은 세미콜론으로 시작한다.
+
+#| 블록 주석
+ 은 여러 줄에 걸칠 수 있으며...
+ #|
+ 중첩될 수 있다!
+ |#
+|#
+
+;; S-expression 주석은 아래 식을 버리므로,
+;; 디버깅할 때 식을 주석화할 때 유용하다.
+#; (이 식은 버려짐)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 1. 근본 자료형과 연산자
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 숫자
+9999999999999999999999 ; 정수
+#b111 ; 이진수 => 7
+#o111 ; 팔진수 => 73
+#x111 ; 16진수 => 273
+3.14 ; 실수
+6.02e+23
+1/2 ; 분수
+1+2i ; 복소수
+
+;; 함수 적용은 이렇게 쓴다: (f x y z ...)
+;; 여기에서 f는 함수이고 x, y, z는 피연산자이다.
+;; 글자 그대로의 데이터 리스트를 만들고 싶다면 평가를 막기 위해 '를 쓰시오.
+'(+ 1 2) ; => (+ 1 2)
+;; 이제, 산술 연산 몇 개
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(expt 2 3) ; => 8
+(quotient 5 2) ; => 2
+(remainder 5 2) ; => 1
+(/ 35 5) ; => 7
+(/ 1 3) ; => 1/3
+(exact->inexact 1/3) ; => 0.3333333333333333
+(+ 1+2i 2-3i) ; => 3-1i
+
+;;; 불린
+#t ; 참
+#f ; 거짓 -- #f가 아닌 것은 참
+(not #t) ; => #f
+(and 0 #f (error "doesn't get here")) ; => #f
+(or #f 0 (error "doesn't get here")) ; => 0
+
+;;; 문자
+#\A ; => #\A
+#\λ ; => #\λ
+#\u03BB ; => #\λ
+
+;;; 문자열은 고정 길이의 문자 배열이다.
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; 백슬래시는 탈출 문자이다.
+"Foo\tbar\41\x21\u0021\a\r\n" ; C 탈출 문자, 유니코드 포함
+"λx:(μα.α→α).xx" ; 유니코드 문자 포함 가능
+
+;; 문자열은 붙여질 수 있다!
+(string-append "Hello " "world!") ; => "Hello world!"
+
+;; 문자열은 문자의 리스트처럼 취급될 수 있다.
+(string-ref "Apple" 0) ; => #\A
+
+;; format은 문자열을 형식화하기 위해 사용된다:
+(format "~a can be ~a" "strings" "formatted")
+
+;; 인쇄는 쉽다.
+(printf "I'm Racket. Nice to meet you!\n")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. 변수
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; define으로 변수를 만든다.
+;; 변수명으로 다음 문자를 사용할 수 없다: ()[]{}",'`;#|\
+(define some-var 5)
+some-var ; => 5
+
+;; 유니코드 문자도 사용 가능하다.
+(define ⊆ subset?)
+(⊆ (set 3 2) (set 1 2 3)) ; => #t
+
+;; 앞에서 정의되지 않은 변수에 접근하면 예외가 발생한다.
+; x ; => x: undefined ...
+
+;; 지역 변수: `me'는 (let ...) 안에서만 "Bob"이다.
+(let ([me "Bob"])
+ "Alice"
+ me) ; => "Bob"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 구조체(Struct)와 모음(Collection)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 구조체
+(struct dog (name breed age))
+(define my-pet
+ (dog "lassie" "collie" 5))
+my-pet ; => #<dog>
+(dog? my-pet) ; => #t
+(dog-name my-pet) ; => "lassie"
+
+;;; 쌍 (불변)
+;; `cons'는 쌍을 만들고, `car'와 `cdr'는 첫번째와
+;; 두번째 원소를 추출한다.
+(cons 1 2) ; => '(1 . 2)
+(car (cons 1 2)) ; => 1
+(cdr (cons 1 2)) ; => 2
+
+;;; 리스트
+
+;; 리스트는 연결-리스트 데이터 구조이며, `cons' 쌍으로 만들어지며
+;; `null' (또는 '()) 로 리스트의 끝을 표시한다.
+(cons 1 (cons 2 (cons 3 null))) ; => '(1 2 3)
+;; `list'는 편리한 가변인자 리스트 생성자이다.
+(list 1 2 3) ; => '(1 2 3)
+;; 글자 그대로의 리스트 값에는 인용부호를 쓴다.
+'(1 2 3) ; => '(1 2 3)
+
+;; 리스트의 앞에 항목을 추가하기 위하여 `cons'를 사용한다.
+(cons 4 '(1 2 3)) ; => '(4 1 2 3)
+
+;; 리스트들을 붙이기 위해 `append'를 사용한다.
+(append '(1 2) '(3 4)) ; => '(1 2 3 4)
+
+;; 리스트는 매우 기본적인 자료형이기 때문에, 리스트에 대해 적용되는 많은 기능들이 있다.
+;; 예를 들어:
+(map add1 '(1 2 3)) ; => '(2 3 4)
+(map + '(1 2 3) '(10 20 30)) ; => '(11 22 33)
+(filter even? '(1 2 3 4)) ; => '(2 4)
+(count even? '(1 2 3 4)) ; => 2
+(take '(1 2 3 4) 2) ; => '(1 2)
+(drop '(1 2 3 4) 2) ; => '(3 4)
+
+;;; 벡터
+
+;; 벡터는 고정 길이의 배열이다.
+#(1 2 3) ; => '#(1 2 3)
+
+;; `vector-append'를 사용하여 벡터들을 붙인다.
+(vector-append #(1 2 3) #(4 5 6)) ; => #(1 2 3 4 5 6)
+
+;;; 집합
+
+;; 리스트로부터 집합 만들기
+(list->set '(1 2 3 1 2 3 3 2 1 3 2 1)) ; => (set 1 2 3)
+
+;; 원소를 추가하려면 `set-add'를 사용한다.
+;; (함수적: 확장된 집합을 반환하며, 원래의 입력을 변경하지 않는다.)
+(set-add (set 1 2 3) 4) ; => (set 1 2 3 4)
+
+;; 원소를 삭제하려면 `set-remove'
+(set-remove (set 1 2 3) 1) ; => (set 2 3)
+
+;; 존재 여부를 조사하려면 `set-member?'
+(set-member? (set 1 2 3) 1) ; => #t
+(set-member? (set 1 2 3) 4) ; => #f
+
+;;; 해시
+
+;; 불변의 해시 테이블을 만든다. (가변 예제는 아래에)
+(define m (hash 'a 1 'b 2 'c 3))
+
+;; 값 꺼내기
+(hash-ref m 'a) ; => 1
+
+;; 없는 값을 꺼내는 것은 예외를 발생시킨다.
+; (hash-ref m 'd) => no value found
+
+;; 키가 없을 때 반환할 기본값을 지정할 수 있다.
+(hash-ref m 'd 0) ; => 0
+
+;; `hash-set'을 사용하여 불변의 해시 테이블을 확장
+;; (원래 것을 변경하지 않고 확장된 해시를 반환한다.)
+(define m2 (hash-set m 'd 4))
+m2 ; => '#hash((b . 2) (a . 1) (d . 4) (c . 3))
+
+;; 이 해시들은 불변이라는 점을 기억하시오!
+m ; => '#hash((b . 2) (a . 1) (c . 3)) <-- no `d'
+
+;; `hash-remove'로 키를 삭제 (이것도 함수적)
+(hash-remove m 'a) ; => '#hash((b . 2) (c . 3))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 함수
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; `lambda'로 함수를 만든다.
+;; 함수는 항상 마지막 식을 반환한다.
+(lambda () "Hello World") ; => #<procedure>
+;; 유니코드 `λ'도 사용 가능
+(λ () "Hello World") ; => same function
+
+;; 모든 함수를 호출할 때는 괄호를 쓴다, lambda 식도 포함하여.
+((lambda () "Hello World")) ; => "Hello World"
+((λ () "Hello World")) ; => "Hello World"
+
+;; 변수에 함수를 할당
+(define hello-world (lambda () "Hello World"))
+(hello-world) ; => "Hello World"
+
+;; 문법적 설탕을 사용하여 함수 정의를 더 짧게할 수 있다:
+(define (hello-world2) "Hello World")
+
+;; 위에서 ()는 함수의 인자 리스트이다.
+(define hello
+ (lambda (name)
+ (string-append "Hello " name)))
+(hello "Steve") ; => "Hello Steve"
+;; ... 또는, 설탕 친 정의로:
+(define (hello2 name)
+ (string-append "Hello " name))
+
+;; 가변인자 함수에는 `case-lambda'를 사용한다.
+(define hello3
+ (case-lambda
+ [() "Hello World"]
+ [(name) (string-append "Hello " name)]))
+(hello3 "Jake") ; => "Hello Jake"
+(hello3) ; => "Hello World"
+;; ... 또는 선택적 인자에 기본값 지정
+(define (hello4 [name "World"])
+ (string-append "Hello " name))
+
+;; 함수는 추가 인자를 리스트에 포장할 수 있다.
+(define (count-args . args)
+ (format "You passed ~a args: ~a" (length args) args))
+(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)"
+;; ... 설탕 안 친 `lambda' 형식으로는:
+(define count-args2
+ (lambda args
+ (format "You passed ~a args: ~a" (length args) args)))
+
+;; 일반 인자와 포장된 인자를 섞을 수 있다.
+(define (hello-count name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args)))
+(hello-count "Finn" 1 2 3)
+; => "Hello Finn, you passed 3 extra args"
+;; ... 설탕 안 친 것:
+(define hello-count2
+ (lambda (name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args))))
+
+;; 키워드 인자
+(define (hello-k #:name [name "World"] #:greeting [g "Hello"] . args)
+ (format "~a ~a, ~a extra args" g name (length args)))
+(hello-k) ; => "Hello World, 0 extra args"
+(hello-k 1 2 3) ; => "Hello World, 3 extra args"
+(hello-k #:greeting "Hi") ; => "Hi World, 0 extra args"
+(hello-k #:name "Finn" #:greeting "Hey") ; => "Hey Finn, 0 extra args"
+(hello-k 1 2 3 #:greeting "Hi" #:name "Finn" 4 5 6)
+ ; => "Hi Finn, 6 extra args"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. 동등성
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 숫자에는 `='를 사용하시오.
+(= 3 3.0) ; => #t
+(= 2 1) ; => #f
+
+;; 개체의 동등성에는 `eq?'를 사용하시오.
+(eq? 3 3) ; => #t
+(eq? 3 3.0) ; => #f
+(eq? (list 3) (list 3)) ; => #f
+
+;; 모음에는 `equal?'을 사용하시오.
+(equal? (list 'a 'b) (list 'a 'b)) ; => #t
+(equal? (list 'a 'b) (list 'b 'a)) ; => #f
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. 흐름 제어하기
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 조건
+
+(if #t ; 조사 식
+ "this is true" ; 그러면 식
+ "this is false") ; 아니면 식
+; => "this is true"
+
+;; 조건에서는 #f가 아니면 참으로 취급된다.
+(member 'Groucho '(Harpo Groucho Zeppo)) ; => '(Groucho Zeppo)
+(if (member 'Groucho '(Harpo Groucho Zeppo))
+ 'yep
+ 'nope)
+; => 'yep
+
+;; `cond'는 연속하여 조사하여 값을 선택한다.
+(cond [(> 2 2) (error "wrong!")]
+ [(< 2 2) (error "wrong again!")]
+ [else 'ok]) ; => 'ok
+
+;;; 양식 맞춤
+
+(define (fizzbuzz? n)
+ (match (list (remainder n 3) (remainder n 5))
+ [(list 0 0) 'fizzbuzz]
+ [(list 0 _) 'fizz]
+ [(list _ 0) 'buzz]
+ [_ #f]))
+
+(fizzbuzz? 15) ; => 'fizzbuzz
+(fizzbuzz? 37) ; => #f
+
+;;; 반복
+
+;; 반복은 (꼬리-) 재귀로 한다.
+(define (loop i)
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i))))
+(loop 5) ; => i=5, i=6, ...
+
+;; 이름 있는 let으로도...
+(let loop ((i 0))
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i)))) ; => i=0, i=1, ...
+
+;; Racket은 매우 유연한 `for' 형식을 가지고 있다:
+(for ([i 10])
+ (printf "i=~a\n" i)) ; => i=0, i=1, ...
+(for ([i (in-range 5 10)])
+ (printf "i=~a\n" i)) ; => i=5, i=6, ...
+
+;;; 다른 Sequence들을 순회하는 반복
+;; `for'는 여러 가지의 sequence를 순회할 수 있다:
+;; 리스트, 벡터, 문자열, 집합, 해시 테이블 등...
+
+(for ([i (in-list '(l i s t))])
+ (displayln i))
+
+(for ([i (in-vector #(v e c t o r))])
+ (displayln i))
+
+(for ([i (in-string "string")])
+ (displayln i))
+
+(for ([i (in-set (set 'x 'y 'z))])
+ (displayln i))
+
+(for ([(k v) (in-hash (hash 'a 1 'b 2 'c 3 ))])
+ (printf "key:~a value:~a\n" k v))
+
+;;; 더 복잡한 반복
+
+;; 여러 sequence에 대한 병렬 순회 (가장 짧은 것 기준으로 중단)
+(for ([i 10] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x 1:y 2:z
+
+;; 중첩 반복
+(for* ([i 2] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x, 0:y, 0:z, 1:x, 1:y, 1:z
+
+;; 조건
+(for ([i 1000]
+ #:when (> i 5)
+ #:unless (odd? i)
+ #:break (> i 10))
+ (printf "i=~a\n" i))
+; => i=6, i=8, i=10
+
+;;; 함축
+;; `for' 반복과 비슷하며, 결과만 수집한다.
+
+(for/list ([i '(1 2 3)])
+ (add1 i)) ; => '(2 3 4)
+
+(for/list ([i '(1 2 3)] #:when (even? i))
+ i) ; => '(2)
+
+(for/list ([i 10] [j '(x y z)])
+ (list i j)) ; => '((0 x) (1 y) (2 z))
+
+(for/list ([i 1000] #:when (> i 5) #:unless (odd? i) #:break (> i 10))
+ i) ; => '(6 8 10)
+
+(for/hash ([i '(1 2 3)])
+ (values i (number->string i)))
+; => '#hash((1 . "1") (2 . "2") (3 . "3"))
+
+;; 반복의 값을 수집하는 여러 가지 방법이 있다:
+(for/sum ([i 10]) (* i i)) ; => 285
+(for/product ([i (in-range 1 11)]) (* i i)) ; => 13168189440000
+(for/and ([i 10] [j (in-range 10 20)]) (< i j)) ; => #t
+(for/or ([i 10] [j (in-range 0 20 2)]) (= i j)) ; => #t
+;; 임의의 조합을 사용하려면 `for/fold'를 사용:
+(for/fold ([sum 0]) ([i '(1 2 3 4)]) (+ sum i)) ; => 10
+;; (이것은 명령형 반복문을 대체하기도 한다.)
+
+;;; 예외
+
+;; 예외를 잡으려면 `with-handlers' 형식을 사용
+(with-handlers ([exn:fail? (lambda (exn) 999)])
+ (+ 1 "2")) ; => 999
+(with-handlers ([exn:break? (lambda (exn) "no time")])
+ (sleep 3)
+ "phew") ; => "phew", but if you break it => "no time"
+
+;; 예외나 다른 값을 던지려면 `raise'를 사용
+(with-handlers ([number? ; catch numeric values raised
+ identity]) ; return them as plain values
+ (+ 1 (raise 2))) ; => 2
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. 변경
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 기존 변수에 새 값을 할당하려면 `set!'을 사용한다.
+(define n 5)
+(set! n (add1 n))
+n ; => 6
+
+;; 명시적인 가변 값을 사용하려면 box 사용 (다른 언어의 포인터나 참조와 비슷함)
+(define n* (box 5))
+(set-box! n* (add1 (unbox n*)))
+(unbox n*) ; => 6
+
+;; 많은 Racket 자료형은 불변이다 (쌍, 리스트 등). 그러나 어떤 것들은
+;; 가변과 불변형이 둘 다 있다. (string, vector, hash table 등)
+
+;; `vector'나 `make-vector'로 가변 벡터를 생성한다.
+(define vec (vector 2 2 3 4))
+(define wall (make-vector 100 'bottle-of-beer))
+;; 칸을 변경하려면 vector-set!을 사용한다.
+(vector-set! vec 0 1)
+(vector-set! wall 99 'down)
+vec ; => #(1 2 3 4)
+
+;; 비어 있는 가변 해시 테이블을 만들고 조작한다.
+(define m3 (make-hash))
+(hash-set! m3 'a 1)
+(hash-set! m3 'b 2)
+(hash-set! m3 'c 3)
+(hash-ref m3 'a) ; => 1
+(hash-ref m3 'd 0) ; => 0
+(hash-remove! m3 'a)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. 모듈
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 모듈은 코드를 여러 파일과 재사용 가능한 라이브러리로 조직하게 한다.
+;; 여기서 우리는 서브-모듈을 사용한다. 이 글이 만드는 전체 모듈("lang" 줄 부터 시작)에 포함된 모듈이다.
+
+(module cake racket/base ; racket/base 기반의 `cake' 모듈 정의
+
+ (provide print-cake) ; 모듈이 노출(export)시키는 함수
+
+ (define (print-cake n)
+ (show " ~a " n #\.)
+ (show " .-~a-. " n #\|)
+ (show " | ~a | " n #\space)
+ (show "---~a---" n #\-))
+
+ (define (show fmt n ch) ; 내부 함수
+ (printf fmt (make-string n ch))
+ (newline)))
+
+;; `require'를 사용하여 모듈에서 모든 `provide'된 이름을 사용한다.
+(require 'cake) ; '는 지역 지역 서브-모듈을 위한 것이다.
+(print-cake 3)
+; (show "~a" 1 #\A) ; => 에러, `show'가 export되지 않았음
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 8. 클래스와 개체
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 클래스 fish%를 생성한다. (-%는 클래스 정의에 쓰이는 관용구)
+(define fish%
+ (class object%
+ (init size) ; 초기화 인자
+ (super-new) ; 상위 클래스 초기화
+ ;; 필드
+ (define current-size size)
+ ;; 공용 메서드
+ (define/public (get-size)
+ current-size)
+ (define/public (grow amt)
+ (set! current-size (+ amt current-size)))
+ (define/public (eat other-fish)
+ (grow (send other-fish get-size)))))
+
+;; fish%의 인스턴스를 생성한다.
+(define charlie
+ (new fish% [size 10]))
+
+;; 개체의 메서드를 호출하기 위해 `send'를 사용한다.
+(send charlie get-size) ; => 10
+(send charlie grow 6)
+(send charlie get-size) ; => 16
+
+;; `fish%'는 보통의 "일급" 값이며, mixin을 줄 수 있다.
+(define (add-color c%)
+ (class c%
+ (init color)
+ (super-new)
+ (define my-color color)
+ (define/public (get-color) my-color)))
+(define colored-fish% (add-color fish%))
+(define charlie2 (new colored-fish% [size 10] [color 'red]))
+(send charlie2 get-color)
+;; 또는, 이름 없이:
+(send (new (add-color fish%) [size 10] [color 'red]) get-color)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 9. 매크로
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 매크로는 언어의 문법을 확장할 수 있게 한다.
+
+;; while 반복문을 추가하자.
+(define-syntax-rule (while condition body ...)
+ (let loop ()
+ (when condition
+ body ...
+ (loop))))
+
+(let ([i 0])
+ (while (< i 10)
+ (displayln i)
+ (set! i (add1 i))))
+
+;; 매크로는 위생적이다. 즉, 기존 변수를 침범할 수 없다.
+(define-syntax-rule (swap! x y) ; -!는 변경의 관용구
+ (let ([tmp x])
+ (set! x y)
+ (set! y tmp)))
+
+(define tmp 2)
+(define other 3)
+(swap! tmp other)
+(printf "tmp = ~a; other = ~a\n" tmp other)
+;; `tmp` 변수는 이름 충돌을 피하기 위해 `tmp_1`로 이름이 변경된다.
+;; (let ([tmp_1 tmp])
+;; (set! tmp other)
+;; (set! other tmp_1))
+
+;; 하지만 그것들은 단지 코드 변형일 뿐이다. 예를 들어:
+(define-syntax-rule (bad-while condition body ...)
+ (when condition
+ body ...
+ (bad-while condition body ...)))
+;; 이 매크로는 엉터리다: 무한 코드를 생성하며,
+;; 이것을 사용하려고 하면 컴파일러가 무한 반복에 빠진다.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 10. 계약(Contract)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 계약은 모듈에서 노출된 값에 대해 제약을 부여한다.
+
+(module bank-account racket
+ (provide (contract-out
+ [deposit (-> positive? any)] ; 값은 양수여야 함
+ [balance (-> positive?)]))
+
+ (define amount 0)
+ (define (deposit a) (set! amount (+ amount a)))
+ (define (balance) amount)
+ )
+
+(require 'bank-account)
+(deposit 5)
+
+(balance) ; => 5
+
+;; 양수가 아닌 값을 예치하려고 하는 고객은 비난받는다.
+;; (deposit -5) ; => deposit: contract violation
+;; expected: positive?
+;; given: -5
+;; more details....
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 11. 입력과 출력
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Racket은 이 "port"라는 개념이 있다. 이것은 다른 언어의
+;; 파일 서술자 (file descriptor)와 매우 비슷하다.
+
+;; "/tmp/tmp.txt"를 열고 "Hello World"를 기록한다.
+;; 그 파일이 이미 있다면 에러를 발생시킨다.
+(define out-port (open-output-file "/tmp/tmp.txt"))
+(displayln "Hello World" out-port)
+(close-output-port out-port)
+
+;; "/tmp/tmp.txt"에 붙이기
+(define out-port (open-output-file "/tmp/tmp.txt"
+ #:exists 'append))
+(displayln "Hola mundo" out-port)
+(close-output-port out-port)
+
+;; 파일에서 다시 읽기
+(define in-port (open-input-file "/tmp/tmp.txt"))
+(displayln (read-line in-port))
+; => "Hello World"
+(displayln (read-line in-port))
+; => "Hola mundo"
+(close-input-port in-port)
+
+;; 다르게, call-with-output-file을 사용하면, 명시적으로 파일을 닫지 않아도 된다.
+(call-with-output-file "/tmp/tmp.txt"
+ #:exists 'update ; 내용을 다시 쓴다.
+ (λ (out-port)
+ (displayln "World Hello!" out-port)))
+
+;; call-with-input-file은 입력에 대해 같은 방식으로 작동한다.
+(call-with-input-file "/tmp/tmp.txt"
+ (λ (in-port)
+ (displayln (read-line in-port))))
+```
+
+## 더 읽을거리
+
+더 배우고 싶으면, [Getting Started with Racket](http://docs.racket-lang.org/getting-started/)도 보시오.
diff --git a/lua.html.markdown b/lua.html.markdown
index be9f3141..0809215f 100644
--- a/lua.html.markdown
+++ b/lua.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
filename: learnlua.lua
diff --git a/markdown.html.markdown b/markdown.html.markdown
new file mode 100644
index 00000000..7541f904
--- /dev/null
+++ b/markdown.html.markdown
@@ -0,0 +1,254 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+filename: markdown.md
+---
+
+Markdown was created by John Gruber in 2004. It's meant to be an easy to read and write syntax which converts easily to HTML (and now many other formats as well).
+
+Give me as much feedback as you want! / Feel free to fork and pull request!
+
+
+```markdown
+<!-- Markdown is a superset of HTML, so any HTML file is valid Markdown, that
+means we can use HTML elements in Markdown, such as the comment element, and
+they won't be affected by a markdown parser. However, if you create an HTML
+element in your markdown file, you cannot use markdown syntax within that
+element's contents. -->
+
+<!-- Markdown also varies in implementation from one parser to a next. This
+guide will attempt to clarify when features are universal or when they are
+specific to a certain parser. -->
+
+<!-- Headers -->
+<!-- You can create HTML elements <h1> through <h6> easily by prepending the
+text you want to be in that element by a number of hashes (#) -->
+# This is an <h1>
+## This is an <h2>
+### This is an <h3>
+#### This is an <h4>
+##### This is an <h5>
+###### This is an <h6>
+
+<!-- Markdown also provides us with two alternative ways of indicating h1 and h2 -->
+This is an h1
+=============
+
+This is an h2
+-------------
+
+<!-- Simple text styles -->
+<!-- Text can be easily styled as italic or bold using markdown -->
+
+*This text is in italics.*
+_And so is this text._
+
+**This text is in bold.**
+__And so is this text.__
+
+***This text is in both.***
+**_As is this!_**
+*__And this!__*
+
+<!-- In Github Flavored Markdown, which is used to render markdown files on
+Github, we also have strikethrough: -->
+
+~~This text is rendered with strikethrough.~~
+
+<!-- Paragraphs are a one or multiple adjacent lines of text separated by one or
+multiple blank lines. -->
+
+This is a paragraph. I'm typing in a paragraph isn't this fun?
+
+Now I'm in paragraph 2.
+I'm still in paragraph 2 too!
+
+
+I'm in paragraph three!
+
+<!-- Should you ever want to insert an HTML <br /> tag, you can end a paragraph
+with two or more spaces and then begin a new paragraph. -->
+
+I end with two spaces (highlight me to see them).
+
+There's a <br /> above me!
+
+<!-- Block quotes are easy and done with the > character. -->
+
+> This is a block quote. You can either
+> manually wrap your lines and put a `>` before every line or you can let your lines get really long and wrap on their own.
+> It doesn't make a difference so long as they start with a `>`.
+
+> You can also use more than one level
+>> of indentation?
+> How neat is that?
+
+<!-- Lists -->
+<!-- Unordered lists can be made using asterisks, pluses, or hyphens -->
+
+* Item
+* Item
+* Another item
+
+or
+
++ Item
++ Item
++ One more item
+
+or
+
+- Item
+- Item
+- One last item
+
+<!-- Ordered lists are done with a number followed by a period -->
+
+1. Item one
+2. Item two
+3. Item three
+
+<!-- You don't even have to label the items correctly and markdown will still
+render the numbers in order, but this may not be a good idea -->
+
+1. Item one
+1. Item two
+1. Item three
+<!-- (This renders the same as the above example) -->
+
+<!-- You can also use sublists -->
+
+1. Item one
+2. Item two
+3. Item three
+ * Sub-item
+ * Sub-item
+4. Item four
+
+<!-- There are even task lists. This creates HTML checkboxes. -->
+
+Boxes below without the 'x' are unchecked HTML checkboxes.
+- [ ] First task to complete.
+- [ ] Second task that needs done
+This checkbox below will be a checked HTML checkbox.
+- [x] This task has been completed
+
+<!-- Code blocks -->
+<!-- You can indicate a code block (which uses the <code> element) by indenting
+a line with four spaces or a tab -->
+
+ This is code
+ So is this
+
+<!-- You can also re-tab (or add an additional four spaces) for indentation
+inside your code -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Inline code can be created using the backtick character ` -->
+
+John didn't even know what the `go_to()` function did!
+
+<!-- In Github Flavored Markdown, you can use a special syntax for code -->
+
+\`\`\`ruby <!-- except remove those backslashes when you do this, just ```ruby ! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- here too, no backslashes, just ``` -->
+
+<-- The above text doesn't require indenting, plus Github will use syntax
+highlighting of the language you specify after the ``` -->
+
+<!-- Horizontal rule (<hr />) -->
+<!-- Horizontal rules are easily added with three or more asterisks or hyphens,
+with or without spaces. -->
+
+***
+---
+- - -
+****************
+
+<!-- Links -->
+<!-- One of the best things about markdown is how easy it is to make links. Put
+the text to display in hard brackets [] followed by the url in parentheses () -->
+
+[Click me!](http://test.com/)
+
+<!-- You can also add a link title using quotes inside the parentheses -->
+
+[Click me!](http://test.com/ "Link to Test.com")
+
+<!-- Relative paths work too. -->
+
+[Go to music](/music/).
+
+<!-- Markdown also supports reference style links -->
+
+[Click this link][link1] for more info about it!
+[Also check out this link][foobar] if you want to.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- The title can also be in single quotes or in parentheses, or omitted
+entirely. The references can be anywhere in your document and the reference IDs
+can be anything so long as they are unique. -->
+
+<!-- There is also "implicit naming" which lets you use the link text as the id -->
+
+[This][] is a link.
+
+[this]: http://thisisalink.com/
+
+<!-- But it's not that commonly used. -->
+
+<!-- Images -->
+<!-- Images are done the same way as links but with an exclamation point in front! -->
+
+![This is the alt-attribute for my image](http://imgur.com/myimage.jpg "An optional title")
+
+<!-- And reference style works as expected -->
+
+![This is the alt-attribute.][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "if you need a title, it's here"
+
+<!-- Miscellany -->
+<!-- Auto-links -->
+
+<http://testwebsite.com/> is equivalent to
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Auto-links for emails -->
+
+<foo@bar.com>
+
+<!-- Escaping characters -->
+
+I want to type *this text surrounded by asterisks* but I don't want it to be
+in italics, so I do this: \*this text surrounded by asterisks\*.
+
+<!-- Tables -->
+<!-- Tables are only available in Github Flavored Markdown and are slightly
+cumbersome, but if you really want it: -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| Left-aligned | Centered | Right-aligned |
+| blah | blah | blah |
+
+<!-- or, for the same results -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ugh this is so ugly | make it | stop
+
+<!-- The end! -->
+
+```
+
+For more info, check out John Gruber's official post of syntax [here](http://daringfireball.net/projects/markdown/syntax) and Adam Pritchard's great cheatsheet [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
diff --git a/matlab.html.markdown b/matlab.html.markdown
index 9baefe68..9dae8ef2 100644
--- a/matlab.html.markdown
+++ b/matlab.html.markdown
@@ -85,7 +85,7 @@ load myFile.mat y % no parentheses, and spaces instead of commas
% Logicals can be applied to matrices:
A > 5
% for each element, if condition is true, that element is 1 in returned matrix
-A[ A > 5 ]
+A( A > 5 )
% returns a vector containing the elements in A for which condition is true
% Strings
@@ -423,7 +423,8 @@ tril(x) % Returns the lower triangular part of x
cross(A,B) % Returns the cross product of the vectors A and B
dot(A,B) % Returns scalar product of two vectors (must have the same length)
transpose(A) % Returns the transpose of A
-flipl(A) % Flip matrix left to right
+fliplr(A) % Flip matrix left to right
+flipud(A) % Flip matrix up to down
% Matrix Factorisations
[L, U, P] = lu(A) % LU decomposition: PA = LU,L is lower triangular, U is upper triangular, P is permutation matrix
diff --git a/nim.html.markdown b/nim.html.markdown
new file mode 100644
index 00000000..c74fece7
--- /dev/null
+++ b/nim.html.markdown
@@ -0,0 +1,265 @@
+---
+language: Nim
+filename: learnNim.nim
+contributors:
+ - ["Jason J. Ayala P.", "http://JasonAyala.com"]
+---
+
+Nim (formally Nimrod) is a statically typed, imperative programming language
+that gives the programmer power without compromises on runtime efficiency.
+
+Nim is efficient, expressive, and elegant.
+
+```ruby
+var # Declare (and assign) variables,
+ letter: char = 'n' # with or without type annotations
+ lang = "N" & "im"
+ nLength : int = len(lang)
+ boat: float
+ truth: bool = false
+
+let # Use let to declare and bind variables *once*.
+ legs = 400 # legs is immutable.
+ arms = 2_000 # _ are ignored and are useful for long numbers.
+ aboutPi = 3.15
+
+const # Constants are computed at compile time. This provides
+ debug = true # performance and is useful in compile time expressions.
+ compileBadCode = false
+
+when compileBadCode: # `when` is a compile time `if`
+ legs = legs + 1 # This error will never be compiled.
+ const input = readline(stdin) # Const values must be known at compile time.
+
+discard 1 > 2 # Note: The compiler will complain if the result of an expression
+ # is unused. `discard` bypasses this.
+
+discard """
+This can work as a multiline comment.
+Or for unparsable, broken code
+"""
+
+#
+# Data Structures
+#
+
+# Tuples
+
+var
+ child: tuple[name: string, age: int] # Tuples have *both* field names
+ today: tuple[sun: string, temp: float] # *and* order.
+
+child = (name: "Rudiger", age: 2) # Assign all at once with literal ()
+today.sun = "Overcast" # or individual fields.
+today.temp = 70.1
+
+# Sequences
+
+var
+ drinks: seq[string]
+
+drinks = @["Water", "Juice", "Chocolate"] # @[V1,..,Vn] is the sequence literal
+
+#
+# Defining Types
+#
+
+# Defining your own types puts the compiler to work for you. It's what makes
+# static typing powerful and useful.
+
+type
+ Name = string # A type alias gives you a new type that is interchangable
+ Age = int # with the old type but is more descriptive.
+ Person = tuple[name: Name, age: Age] # Define data structures too.
+ AnotherSyntax = tuple
+ fieldOne: string
+ secondField: int
+
+var
+ john: Person = (name: "John B.", age: 17)
+ newage: int = 18 # It would be better to use Age than int
+
+john.age = newage # But still works because int and Age are synonyms
+
+type
+ Cash = distinct int # `distinct` makes a new type incompatible with its
+ Desc = distinct string # base type.
+
+var
+ money: Cash = 100.Cash # `.Cash` converts the int to our type
+ description: Desc = "Interesting".Desc
+
+when compileBadCode:
+ john.age = money # Error! age is of type int and money is Cash
+ john.name = description # Compiler says: "No way!"
+
+#
+# More Types and Data Structures
+#
+
+# Enumerations allow a type to have one of a limited number of values
+
+type
+ Color = enum cRed, cBlue, cGreen
+ Direction = enum # Alternative formating
+ dNorth
+ dWest
+ dEast
+ dSouth
+var
+ orient = dNorth # `orient` is of type Direction, with the value `dNorth`
+ pixel = cGreen # `pixel` is of type Color, with the value `cGreen`
+
+discard dNorth > dEast # Enums are usually an "ordinal" type
+
+# Subranges specify a limited valid range
+
+type
+ DieFaces = range[1..20] # Only an int from 1 to 20 is a valid value
+var
+ my_roll: DieFaces = 13
+
+when compileBadCode:
+ my_roll = 23 # Error!
+
+# Arrays
+
+type
+ RollCounter = array[DieFaces, int] # Array's are fixed length and
+ DirNames = array[Direction, string] # indexed by any ordinal type.
+ Truths = array[42..44, bool]
+var
+ counter: RollCounter
+ directions: DirNames
+ possible: Truths
+
+possible = [false, false, false] # Literal arrays are created with [V1,..,Vn]
+possible[42] = true
+
+directions[dNorth] = "Ahh. The Great White North!"
+directions[dWest] = "No, don't go there."
+
+my_roll = 13
+counter[my_roll] += 1
+counter[my_roll] += 1
+
+var anotherArray = ["Default index", "starts at", "0"]
+
+# More data structures are available, including tables, sets, lists, queues,
+# and crit bit trees.
+# http://nimrod-lang.org/lib.html#collections-and-algorithms
+
+#
+# IO and Control Flow
+#
+
+# `case`, `readLine()`
+
+echo "Read any good books lately?"
+case readLine(stdin)
+of "no", "No":
+ echo "Go to your local library."
+of "yes", "Yes":
+ echo "Carry on, then."
+else:
+ echo "That's great; I assume."
+
+# `while`, `if`, `continue`, `break`
+
+import strutils as str # http://nimrod-lang.org/strutils.html
+echo "I'm thinking of a number between 41 and 43. Guess which!"
+let number: int = 42
+var
+ raw_guess: string
+ guess: int
+while guess != number:
+ raw_guess = readLine(stdin)
+ if raw_guess == "": continue # Skip this iteration
+ guess = str.parseInt(raw_guess)
+ if guess == 1001:
+ echo("AAAAAAGGG!")
+ break
+ elif guess > number:
+ echo("Nope. Too high.")
+ elif guess < number:
+ echo(guess, " is too low")
+ else:
+ echo("Yeeeeeehaw!")
+
+#
+# Iteration
+#
+
+for i, elem in ["Yes", "No", "Maybe so"]: # Or just `for elem in`
+ echo(elem, " is at index: ", i)
+
+for k, v in items(@[(person: "You", power: 100), (person: "Me", power: 9000)]):
+ echo v
+
+let myString = """
+an <example>
+`string` to
+play with
+""" # Multiline raw string
+
+for line in splitLines(myString):
+ echo(line)
+
+for i, c in myString: # Index and letter. Or `for j in` for just letter
+ if i mod 2 == 0: continue # Compact `if` form
+ elif c == 'X': break
+ else: echo(c)
+
+#
+# Procedures
+#
+
+type Answer = enum aYes, aNo
+
+proc ask(question: string): Answer =
+ echo(question, " (y/n)")
+ while true:
+ case readLine(stdin)
+ of "y", "Y", "yes", "Yes":
+ return Answer.aYes # Enums can be qualified
+ of "n", "N", "no", "No":
+ return Answer.aNo
+ else: echo("Please be clear: yes or no")
+
+proc addSugar(amount: int = 2) = # Default amount is 2, returns nothing
+ assert(amount > 0 or amount < 9000, "Crazy Sugar")
+ for a in 1..amount:
+ echo(a, " sugar...")
+
+case ask("Would you like sugar in your tea?")
+of aYes:
+ addSugar(3)
+of aNo:
+ echo "Oh do take a little!"
+ addSugar()
+# No need for an `else` here. Only `yes` and `no` are possible.
+
+#
+# FFI
+#
+
+# Because Nim compiles to C, FFI is easy:
+
+proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
+
+let cmp = strcmp("C?", "Easy!")
+```
+
+Additionally, Nim separates itself from its peers with metaprogramming,
+performance, and compile-time features.
+
+## Further Reading
+
+* [Home Page](http://nimrod-lang.org)
+* [Download](http://nimrod-lang.org/download.html)
+* [Community](http://nimrod-lang.org/community.html)
+* [FAQ](http://nimrod-lang.org/question.html)
+* [Documentation](http://nimrod-lang.org/documentation.html)
+* [Manual](http://nimrod-lang.org/manual.html)
+* [Standard Libray](http://nimrod-lang.org/lib.html)
+* [Rosetta Code](http://rosettacode.org/wiki/Category:Nimrod)
diff --git a/nl-nl/coffeescript-nl.html.markdown b/nl-nl/coffeescript-nl.html.markdown
new file mode 100644
index 00000000..70dcd463
--- /dev/null
+++ b/nl-nl/coffeescript-nl.html.markdown
@@ -0,0 +1,109 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["Jelle Besseling", "https://github.com/Jell-E"]
+filename: coffeescript-nl.coffee
+lang: nl-nl
+---
+
+CoffeeScript is een kleine programmeertaal die compileerd naar JavaScript,
+er is geen interpretatie tijdens het uitvoeren.
+Als een van de nakomelingen van JavaScript probeert CoffeeScript om leesbare,
+goed geformatteerdeen goed draaiende JavaScript code te genereren,
+die in elke JavaScript runtime werkt.
+
+Op [de CoffeeScript website](http://coffeescript.org/), staat een
+vollediger tutorial voor CoffeeScript.
+
+``` coffeescript
+# CoffeeScript is een taal voor hipsters.
+# Het gaat mee met alle trends van moderne talen.
+# Dus commentaar begint met een hekje, net zoals bij Python en Ruby.
+
+###
+Blokken commentaar maak je zo, ze vertalen naar JavaScripts */ en /*
+in de uitvoer van de CoffeeScript compiler.
+
+Het is belangrijk dat je ongeveer snapt hoe JavaScript
+werkt voordat je verder gaat.
+###
+
+# Toewijzing:
+getal = 42 #=> var getal = 42;
+tegengestelde = true #=> var tegengestelde = true;
+
+# Voorwaarden:
+getal = -42 if tegengestelde #=> if(tegengestelde) { getal = -42; }
+
+# Functies:
+kwadraat = (x) -> x * x #=> var kwadraat = function(x) { return x * x; }
+
+vul = (houder, vloeistof = "koffie") ->
+ "Nu de #{houder} met #{koffie} aan het vullen..."
+#=>var vul;
+#
+#vul = function(houder, vloeistof) {
+# if (vloeistof == null) {
+# vloeistof = "coffee";
+# }
+# return "Nu de " + houder + " met " + vloeistof + " aan het vullen...";
+#};
+
+# Reeksen:
+lijst = [1..5] #=> var lijst = [1, 2, 3, 4, 5];
+
+# Objecten:
+wiskunde =
+ wortel: Math.sqrt
+ kwadraat: kwadraat
+ derdemacht: (x) -> x * kwadraat x
+#=> var wiskunde = {
+# "wortel": Math.sqrt,
+# "kwadraat": kwadraat,
+# "derdemacht": function(x) { return x * kwadraat(x); }
+#}
+
+# "Splats":
+wedstrijd = (winnaar, lopers...) ->
+ print winnaar, lopers
+#=>wedstrijd = function() {
+# var lopers, winnaar;
+# winnaar = arguments[0], lopers = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winnaar, lopers);
+#};
+
+# Bestaan:
+alert "Ik wist het!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
+
+# Lijst abstractie:
+derdemachten = (wiskunde.derdemacht num for num in lijst)
+#=>derdemachten = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = lijst.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(wiskunde.derdemacht(num));
+# }
+# return _results;
+# })();
+
+etenswaren = ['broccoli', 'spinazie', 'chocolade']
+eet eten for eten in etenswaren when eten isnt 'chocolade'
+#=>etenswaren = ['broccoli', 'spinazie', 'chocolade'];
+#
+#for (_k = 0, _len2 = etenswaren.length; _k < _len2; _k++) {
+# eten = etenswaren[_k];
+# if (eten !== 'chocolade') {
+# eet(eten);
+# }
+#}
+```
+
+## Handige links (in het Engels):
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
index 772e72ca..caad49a5 100644
--- a/objective-c.html.markdown
+++ b/objective-c.html.markdown
@@ -12,7 +12,7 @@ filename: LearnObjectiveC.m
Objective-C is the main programming language used by Apple for the OS X and iOS operating systems and their respective frameworks, Cocoa and Cocoa Touch.
It is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.
-```cpp
+```objective_c
// Single-line comments start with //
/*
diff --git a/ocaml.html.markdown b/ocaml.html.markdown
new file mode 100644
index 00000000..f9db7080
--- /dev/null
+++ b/ocaml.html.markdown
@@ -0,0 +1,372 @@
+---
+language: OCaml
+contributors:
+ - ["Daniil Baturin", "http://baturin.org/"]
+---
+
+OCaml is a strictly evaluated functional language with some imperative
+features.
+
+Along with StandardML and its dialects it belongs to ML language family.
+F# is also heavily influenced by OCaml.
+
+Just like StandardML, OCaml features both an interpreter, that can be
+used interactively, and a compiler.
+The interpreter binary is normally called "ocaml" and the compiler is "ocamlopt".
+There is also a bytecode compiler, "ocamlc", but there are few reasons to use it.
+
+It is strongly and statically typed, but instead of using manually written
+type annotations, it infers types of expressions using Hindley-Milner algorithm.
+It makes type annotations unnecessary in most cases, but can be a major
+source of confusion for beginners.
+
+When you are in the top level loop, OCaml will print the inferred type
+after you enter an expression.
+
+```
+# let inc x = x + 1 ;;
+val inc : int -> int = <fun>
+# let a = 99 ;;
+val a : int = 99
+```
+
+For a source file you can use "ocamlc -i /path/to/file.ml" command
+to print all names and type signatures.
+
+```
+$ cat sigtest.ml
+let inc x = x + 1
+let add x y = x + y
+
+let a = 1
+
+$ ocamlc -i ./sigtest.ml
+val inc : int -> int
+val add : int -> int -> int
+val a : int
+```
+
+Note that type signatures of functions of multiple arguments are
+written in curried form. A function that takes multiple arguments can be
+represented as a composition of functions that take only one argument.
+The "f(x,y) = x + y" function from the example above applied to
+arguments 2 and 3 is equivalent to the "f0(y) = 2 + y" function applied to 3.
+Hence the "int -> int -> int" signature.
+
+
+```ocaml
+(*** Comments ***)
+
+(* Comments are enclosed in (* and *). It's fine to nest comments. *)
+
+(* There are no single-line comments. *)
+
+
+(*** Variables and functions ***)
+
+(* Expressions can be separated by a double semicolon symbol, ";;".
+ In many cases it's redundant, but in this tutorial we use it after
+ every expression for easy pasting into the interpreter shell.
+ Unnecessary use of expression separators in source code files
+ is often considered to be a bad style. *)
+
+(* Variable and function declarations use "let" keyword. *)
+let x = 10 ;;
+
+(* OCaml allows single quote characters in identifiers.
+ Single quote doesn't have a special meaning in this case, it's often used
+ in cases when in other languages one would use names like "foo_tmp". *)
+let foo = 1 ;;
+let foo' = foo * 2 ;;
+
+(* Since OCaml compiler infers types automatically, you normally don't need to
+ specify argument types explicitly. However, you can do it if
+ you want or need to. *)
+let inc_int (x: int) : int = x + 1 ;;
+
+(* One of the cases when explicit type annotations may be needed is
+ resolving ambiguity between two record types that have fields with
+ the same name. The alternative is to encapsulate those types in
+ modules, but both topics are a bit out of scope of this
+ tutorial. *)
+
+(* You need to mark recursive function definitions as such with "rec" keyword. *)
+let rec factorial n =
+ if n = 0 then 1
+ else n * factorial (n-1)
+;;
+
+(* Function application usually doesn't need parentheses around arguments *)
+let fact_5 = factorial 5 ;;
+
+(* ...unless the argument is an expression. *)
+let fact_4 = factorial (5-1) ;;
+let sqr2 = sqr (-2) ;;
+
+(* Every function must have at least one argument.
+ Since some funcions naturally don't take any arguments, there's
+ "unit" type for it that has the only one value written as "()" *)
+let print_hello () = print_endline "hello world" ;;
+
+(* Note that you must specify "()" as argument when calling it. *)
+print_hello () ;;
+
+(* Calling a function with insufficient number of arguments
+ does not cause an error, it produces a new function. *)
+let make_inc x y = x + y ;; (* make_inc is int -> int -> int *)
+let inc_2 = make_inc 2 ;; (* inc_2 is int -> int *)
+inc_2 3 ;; (* Evaluates to 5 *)
+
+(* You can use multiple expressions in function body.
+ The last expression becomes the return value. All other
+ expressions must be of the "unit" type.
+ This is useful when writing in imperative style, the simplest
+ form of it is inserting a debug print. *)
+let print_and_return x =
+ print_endline (string_of_int x);
+ x
+;;
+
+(* Since OCaml is a functional language, it lacks "procedures".
+ Every function must return something. So functions that
+ do not really return anything and are called solely for their
+ side effects, like print_endline, return value of "unit" type. *)
+
+
+(* Definitions can be chained with "let ... in" construct.
+ This is roughly the same to assigning values to multiple
+ variables before using them in expressions in imperative
+ languages. *)
+let x = 10 in
+let y = 20 in
+x + y ;;
+
+(* Alternatively you can use "let ... and ... in" construct.
+ This is especially useful for mutually recursive functions,
+ with ordinary "let .. in" the compiler will complain about
+ unbound values.
+ It's hard to come up with a meaningful but self-contained
+ example of mutually recursive functions, but that syntax
+ works for non-recursive definitions too. *)
+let a = 3 and b = 4 in a * b ;;
+
+(* Anonymous functions use the following syntax: *)
+let my_lambda = fun x -> x * x ;;
+
+(*** Operators ***)
+
+(* There is little distintion between operators and functions.
+ Every operator can be called as a function. *)
+
+(+) 3 4 (* Same as 3 + 4 *)
+
+(* There's a number of built-in operators. One unusual feature is
+ that OCaml doesn't just refrain from any implicit conversions
+ between integers and floats, it also uses different operators
+ for floats. *)
+12 + 3 ;; (* Integer addition. *)
+12.0 +. 3.0 ;; (* Floating point addition. *)
+
+12 / 3 ;; (* Integer division. *)
+12.0 /. 3.0 ;; (* Floating point division. *)
+5 mod 2 ;; (* Remainder. *)
+
+(* Unary minus is a notable exception, it's polymorphic.
+ However, it also has "pure" integer and float forms. *)
+- 3 ;; (* Polymorphic, integer *)
+- 4.5 ;; (* Polymorphic, float *)
+~- 3 (* Integer only *)
+~- 3.4 (* Type error *)
+~-. 3.4 (* Float only *)
+
+(* You can define your own operators or redefine existing ones.
+ Unlike SML or Haskell, only selected symbols can be used
+ for operator names and first symbol defines associativity
+ and precedence rules. *)
+let (+) a b = a - b ;; (* Surprise maintenance programmers. *)
+
+(* More useful: a reciprocal operator for floats.
+ Unary operators must start with "~". *)
+let (~/) x = 1.0 /. x ;;
+~/4.0 (* = 0.25 *)
+
+
+(*** Built-in datastructures ***)
+
+(* Lists are enclosed in square brackets, items are separated by
+ semicolons. *)
+let my_list = [1; 2; 3] ;;
+
+(* Tuples are (optionally) enclosed in parentheses, items are separated
+ by commas. *)
+let first_tuple = 3, 4 ;; (* Has type "int * int". *)
+let second_tuple = (4, 5) ;;
+
+(* Corollary: if you try to separate list items by commas, you get a list
+ with a tuple inside, probably not what you want. *)
+let bad_list = [1, 2] ;; (* Becomes [(1, 2)] *)
+
+(* You can access individual list items with the List.nth function. *)
+List.nth my_list 1 ;;
+
+(* There are higher-order functions for lists such as map and filter. *)
+List.map (fun x -> x * 2) [1; 2; 3] ;;
+List.filter (fun x -> if x mod 2 = 0 then true else false) [1; 2; 3; 4] ;;
+
+(* You can add an item to the beginning of a list with the "::" constructor
+ often referred to as "cons". *)
+1 :: [2; 3] ;; (* Gives [1; 2; 3] *)
+
+(* Arrays are enclosed in [| |] *)
+let my_array = [| 1; 2; 3 |] ;;
+
+(* You can access array items like this: *)
+my_array.(0) ;;
+
+
+(*** Strings and characters ***)
+
+(* Use double quotes for string literals. *)
+let my_str = "Hello world" ;;
+
+(* Use single quotes for character literals. *)
+let my_char = 'a' ;;
+
+(* Single and double quotes are not interchangeable. *)
+let bad_str = 'syntax error' ;; (* Syntax error. *)
+
+(* This will give you a single character string, not a character. *)
+let single_char_str = "w" ;;
+
+(* Strings can be concatenated with the "^" operator. *)
+let some_str = "hello" ^ "world" ;;
+
+(* Strings are not arrays of characters.
+ You can't mix characters and strings in expressions.
+ You can convert a character to a string with "String.make 1 my_char".
+ There are more convenient functions for this purpose in additional
+ libraries such as Core.Std that may not be installed and/or loaded
+ by default. *)
+let ocaml = (String.make 1 'O') ^ "Caml" ;;
+
+(* There is a printf function. *)
+Printf.printf "%d %s" 99 "bottles of beer" ;;
+
+(* Unformatted read and write functions are there too. *)
+print_string "hello world\n" ;;
+print_endline "hello world" ;;
+let line = read_line () ;;
+
+
+(*** User-defined data types ***)
+
+(* You can define types with the "type some_type =" construct. Like in this
+ useless type alias: *)
+type my_int = int ;;
+
+(* More interesting types include so called type constructors.
+ Constructors must start with a capital letter. *)
+type ml = OCaml | StandardML ;;
+let lang = OCaml ;; (* Has type "ml". *)
+
+(* Type constructors don't need to be empty. *)
+type my_number = PlusInfinity | MinusInfinity | Real of float ;;
+let r0 = Real (-3.4) ;; (* Has type "my_number". *)
+
+(* Can be used to implement polymorphic arithmetics. *)
+type number = Int of int | Float of float ;;
+
+(* Point on a plane, essentially a type-constrained tuple *)
+type point2d = Point of float * float ;;
+let my_point = Point (2.0, 3.0) ;;
+
+(* Types can be parameterized, like in this type for "list of lists
+ of anything". 'a can be substituted with any type. *)
+type 'a list_of_lists = 'a list list ;;
+type int_list_list = int list_of_lists ;;
+
+(* Types can also be recursive. Like in this type analogous to
+ built-in list of integers. *)
+type my_int_list = EmptyList | IntList of int * my_int_list ;;
+let l = Cons (1, EmptyList) ;;
+
+
+(*** Pattern matching ***)
+
+(* Pattern matching is somewhat similar to switch statement in imperative
+ languages, but offers a lot more expressive power.
+
+ Even though it may look complicated, it really boils down to matching
+ an argument against an exact value, a predicate, or a type constructor.
+ The type system is what makes it so powerful. *)
+
+(** Matching exact values. **)
+
+let is_zero x =
+ match x with
+ | 0 -> true
+ | _ -> false (* The "_" pattern means "anything else". *)
+;;
+
+(* Alternatively, you can use the "function" keyword. *)
+let is_one = function
+| 1 -> true
+| _ -> false
+;;
+
+(* Matching predicates, aka "guarded pattern matching". *)
+let abs x =
+ match x with
+ | x when x < 0 -> -x
+ | _ -> x
+;;
+
+abs 5 ;; (* 5 *)
+abs (-5) (* 5 again *)
+
+(** Matching type constructors **)
+
+type animal = Dog of string | Cat of string ;;
+
+let say x =
+ match x with
+ | Dog x -> x ^ " says woof"
+ | Cat x -> x ^ " says meow"
+;;
+
+say (Cat "Fluffy") ;; (* "Fluffy says meow". *)
+
+(** Traversing datastructures with pattern matching **)
+
+(* Recursive types can be traversed with pattern matching easily.
+ Let's see how we can traverse a datastructure of the built-in list type.
+ Even though the built-in cons ("::") looks like an infix operator,
+ it's actually a type constructor and can be matched like any other. *)
+let rec sum_list l =
+ match l with
+ | [] -> 0
+ | head :: tail -> head + (sum_list tail)
+;;
+
+sum_list [1; 2; 3] ;; (* Evaluates to 6 *)
+
+(* Built-in syntax for cons obscures the structure a bit, so we'll make
+ our own list for demonstration. *)
+
+type int_list = Nil | Cons of int * int_list ;;
+let rec sum_int_list l =
+ match l with
+ | Nil -> 0
+ | Cons (head, tail) -> head + (sum_int_list tail)
+;;
+
+let t = Cons (1, Cons (2, Cons (3, Nil))) ;;
+sum_int_list t ;;
+
+```
+
+## Further reading
+
+* Visit the official website to get the compiler and read the docs: <http://ocaml.org/>
+* Try interactive tutorials and a web-based interpreter by OCaml Pro: <http://try.ocamlpro.com/>
+* Read "OCaml for the skeptical" course: <http://www2.lib.uchicago.edu/keith/ocaml-class/home.html>
diff --git a/paren.html.markdown b/paren.html.markdown
new file mode 100644
index 00000000..cde14853
--- /dev/null
+++ b/paren.html.markdown
@@ -0,0 +1,193 @@
+---
+
+language: Paren
+filename: learnparen.paren
+contributors:
+ - ["KIM Taegyoon", "https://github.com/kimtg"]
+---
+
+[Paren](https://bitbucket.org/ktg/paren) is a dialect of Lisp. It is designed to be an embedded language.
+
+Some examples are from <http://learnxinyminutes.com/docs/racket/>.
+
+```scheme
+;;; Comments
+# comments
+
+;; Single line comments start with a semicolon or a sharp sign
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 1. Primitive Datatypes and Operators
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Numbers
+123 ; int
+3.14 ; double
+6.02e+23 ; double
+(int 3.14) ; => 3 : int
+(double 123) ; => 123 : double
+
+;; Function application is written (f x y z ...)
+;; where f is a function and x, y, z, ... are operands
+;; If you want to create a literal list of data, use (quote) to stop it from
+;; being evaluated
+(quote (+ 1 2)) ; => (+ 1 2)
+;; Now, some arithmetic operations
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(^ 2 3) ; => 8
+(/ 5 2) ; => 2
+(% 5 2) ; => 1
+(/ 5.0 2) ; => 2.5
+
+;;; Booleans
+true ; for true
+false ; for false
+(! true) ; => false
+(&& true false (prn "doesn't get here")) ; => false
+(|| false true (prn "doesn't get here")) ; => true
+
+;;; Characters are ints.
+(char-at "A" 0) ; => 65
+(chr 65) ; => "A"
+
+;;; Strings are fixed-length array of characters.
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; backslash is an escaping character
+"Foo\tbar\r\n" ; includes C escapes: \t \r \n
+
+;; Strings can be added too!
+(strcat "Hello " "world!") ; => "Hello world!"
+
+;; A string can be treated like a list of characters
+(char-at "Apple" 0) ; => 65
+
+;; Printing is pretty easy
+(pr "I'm" "Paren. ") (prn "Nice to meet you!")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. Variables
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; You can create or set a variable using (set)
+;; a variable name can use any character except: ();#"
+(set some-var 5) ; => 5
+some-var ; => 5
+
+;; Accessing a previously unassigned variable is an exception
+; x ; => Unknown variable: x : nil
+
+;; Local binding: Use lambda calculus! `a' and `b' are bound to `1' and `2' only within the (fn ...)
+((fn (a b) (+ a b)) 1 2) ; => 3
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Collections
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Lists
+
+;; Lists are vector-like data structures. (Random access is O(1).)
+(cons 1 (cons 2 (cons 3 (list)))) ; => (1 2 3)
+;; `list' is a convenience variadic constructor for lists
+(list 1 2 3) ; => (1 2 3)
+;; and a quote can also be used for a literal list value
+(quote (+ 1 2)) ; => (+ 1 2)
+
+;; Can still use `cons' to add an item to the beginning of a list
+(cons 0 (list 1 2 3)) ; => (0 1 2 3)
+
+;; Lists are a very basic type, so there is a *lot* of functionality for
+;; them, a few examples:
+(map inc (list 1 2 3)) ; => (2 3 4)
+(filter (fn (x) (== 0 (% x 2))) (list 1 2 3 4)) ; => (2 4)
+(length (list 1 2 3 4)) ; => 4
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `fn' to create functions.
+;; A function always returns the value of its last expression
+(fn () "Hello World") ; => (fn () Hello World) : fn
+
+;; Use parentheses to call all functions, including a lambda expression
+((fn () "Hello World")) ; => "Hello World"
+
+;; Assign a function to a var
+(set hello-world (fn () "Hello World"))
+(hello-world) ; => "Hello World"
+
+;; You can shorten this using the function definition syntatcic sugae:
+(defn hello-world2 () "Hello World")
+
+;; The () in the above is the list of arguments for the function
+(set hello
+ (fn (name)
+ (strcat "Hello " name)))
+(hello "Steve") ; => "Hello Steve"
+
+;; ... or equivalently, using a sugared definition:
+(defn hello2 (name)
+ (strcat "Hello " name))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. Equality
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; for numbers use `=='
+(== 3 3.0) ; => true
+(== 2 1) ; => false
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. Control Flow
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Conditionals
+
+(if true ; test expression
+ "this is true" ; then expression
+ "this is false") ; else expression
+; => "this is true"
+
+;;; Loops
+
+;; for loop is for number
+;; (for SYMBOL START END STEP EXPR ..)
+(for i 0 10 2 (pr i "")) ; => prints 0 2 4 6 8 10
+(for i 0.0 10 2.5 (pr i "")) ; => prints 0 2.5 5 7.5 10
+
+;; while loop
+((fn (i)
+ (while (< i 10)
+ (pr i)
+ (++ i))) 0) ; => prints 0123456789
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. Mutation
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `set' to assign a new value to a variable or a place
+(set n 5) ; => 5
+(set n (inc n)) ; => 6
+n ; => 6
+(set a (list 1 2)) ; => (1 2)
+(set (nth 0 a) 3) ; => 3
+a ; => (3 2)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. Macros
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Macros let you extend the syntax of the language.
+;; Paren macros are easy.
+;; In fact, (defn) is a macro.
+(defmacro setfn (name ...) (set name (fn ...)))
+(defmacro defn (name ...) (def name (fn ...)))
+
+;; Let's add an infix notation
+(defmacro infix (a op ...) (op a ...))
+(infix 1 + 2 (infix 3 * 4)) ; => 15
+
+;; Macros are not hygienic, you can clobber existing variables!
+;; They are code transformations.
+```
diff --git a/perl.html.markdown b/perl.html.markdown
index da2e0cdf..aac95939 100644
--- a/perl.html.markdown
+++ b/perl.html.markdown
@@ -28,7 +28,8 @@ Perl 5 runs on over 100 platforms from portables to mainframes and is suitable f
my $animal = "camel";
my $answer = 42;
-# Scalar values can be strings, integers or floating point numbers, and Perl will automatically convert between them as required.
+# Scalar values can be strings, integers or floating point numbers, and
+# Perl will automatically convert between them as required.
## Arrays
# An array represents a list of values:
@@ -49,9 +50,11 @@ my %fruit_color = (
apple => "red",
banana => "yellow",
);
-# Scalars, arrays and hashes are documented more fully in perldata. (perldoc perldata).
+# Scalars, arrays and hashes are documented more fully in perldata.
+# (perldoc perldata).
-# More complex data types can be constructed using references, which allow you to build lists and hashes within lists and hashes.
+# More complex data types can be constructed using references, which allow you
+# to build lists and hashes within lists and hashes.
#### Conditional and looping constructs
@@ -92,7 +95,9 @@ foreach (@array) {
#### Regular expressions
-# Perl's regular expression support is both broad and deep, and is the subject of lengthy documentation in perlrequick, perlretut, and elsewhere. However, in short:
+# Perl's regular expression support is both broad and deep, and is the subject
+# of lengthy documentation in perlrequick, perlretut, and elsewhere.
+# However, in short:
# Simple matching
if (/foo/) { ... } # true if $_ contains "foo"
@@ -112,8 +117,9 @@ open(my $in, "<", "input.txt") or die "Can't open input.txt: $!";
open(my $out, ">", "output.txt") or die "Can't open output.txt: $!";
open(my $log, ">>", "my.log") or die "Can't open my.log: $!";
-# You can read from an open filehandle using the "<>" operator. In scalar context it reads a single line from
-# the filehandle, and in list context it reads the whole file in, assigning each line to an element of the list:
+# You can read from an open filehandle using the "<>" operator. In scalar
+# context it reads a single line from the filehandle, and in list context it
+# reads the whole file in, assigning each line to an element of the list:
my $line = <$in>;
my @lines = <$in>;
diff --git a/perl6.html.markdown b/perl6.html.markdown
new file mode 100644
index 00000000..52625bc2
--- /dev/null
+++ b/perl6.html.markdown
@@ -0,0 +1,1481 @@
+---
+name: perl6
+category: language
+language: perl6
+filename: learnperl6.pl
+contributors:
+ - ["Nami-Doc", "http://github.com/Nami-Doc"]
+---
+
+Perl 6 is a highly capable, feature-rich programming language made for the
+upcoming hundred years.
+
+Perl 6 runs on [the Parrot VM](http://parrot.org/), the JVM
+and [the MoarVM](http://moarvm.com).
+
+Meta-note : the triple pound signs are here to denote headlines,
+double paragraphs, and single notes.
+
+`#=>` represents the output of a command.
+
+```perl
+# Single line comment start with a pound
+
+#`(
+ Multiline comments use #` and a quoting construct.
+ (), [], {}, 「」, etc, will work.
+)
+
+### Variables
+
+# In Perl 6, you declare a lexical variable using `my`
+my $variable;
+# Perl 6 has 4 kinds of variables:
+
+## * Scalars. They represent a single value. They start with a `$`
+
+my $str = 'String';
+my $str2 = "String"; # double quotes allow for interpolation
+
+# variable names can contain but not end with simple quotes and dashes,
+# and can contain (and end with) underscores :
+# my $weird'variable-name_ = 5; # works !
+
+my $bool = True; # `True` and `False` are Perl 6's boolean
+my $inverse = !$bool; # You can invert a bool with the prefix `!` operator
+my $forced-bool = so $str; # And you can use the prefix `so` operator
+ # which turns its operand into a Bool
+
+## * Lists. They represent multiple values. Their name start with `@`.
+
+my @array = 'a', 'b', 'c';
+# equivalent to :
+my @letters = <a b c>; # array of words, delimited by space.
+ # Similar to perl5's qw, or Ruby's %w.
+my @array = 1, 2, 3;
+
+say @array[2]; # Array indices start at 0 -- This is the third element
+
+say "Interpolate an array using [] : @array[]";
+#=> Interpolate an array using [] : 1 2 3
+
+@array[0] = -1; # Assign a new value to an array index
+@array[0, 1] = 5, 6; # Assign multiple values
+
+my @keys = 0, 2;
+@array[@keys] = @letters; # Assign using an array
+say @array; #=> a 6 b
+
+# There are two more kinds of lists: Parcel and Arrays.
+# Parcels are immutable lists (you can't modify a list that's not assigned).
+# This is a parcel:
+(1, 2, 3); # Not assigned to anything. Changing an element would provoke an error
+# This is a list:
+my @a = (1, 2, 3); # Assigned to `@a`. Changing elements is okay!
+
+# Lists flatten (in list context). You'll see below how to apply item context
+# or use arrays to have real nested lists.
+
+
+## * Hashes. Key-Value Pairs.
+# Hashes are actually arrays of Pairs (`Key => Value`),
+# except they get "flattened", removing duplicated keys.
+my %hash = 1 => 2,
+ 3 => 4;
+my %hash = autoquoted => "key", # keys *can* get auto-quoted
+ "some other" => "value", # trailing commas are okay
+ ;
+my %hash = <key1 value1 key2 value2>; # you can also create a hash
+ # from an even-numbered array
+my %hash = key1 => 'value1', key2 => 'value2'; # same as this
+
+# You can also use the "colon pair" syntax:
+# (especially handy for named parameters that you'll see later)
+my %hash = :w(1), # equivalent to `w => 1`
+ # this is useful for the `True` shortcut:
+ :truey, # equivalent to `:truey(True)`, or `truey => True`
+ # and for the `False` one:
+ :!falsey, # equivalent to `:falsey(False)`, or `falsey => False`
+ ;
+
+say %hash{'key1'}; # You can use {} to get the value from a key
+say %hash<key2>; # If it's a string, you can actually use <>
+ # (`{key1}` doesn't work, as Perl6 doesn't have barewords)
+
+## * Subs (subroutines, or functions in most other languages).
+# Stored in variable, they use `&`.
+sub say-hello { say "Hello, world" }
+
+sub say-hello-to(Str $name) { # You can provide the type of an argument
+ # and it'll be checked at compile-time.
+
+ say "Hello, $name !";
+}
+
+# Since you can omit parenthesis to call a function with no arguments,
+# you need "&" in the name to capture `say-hello`.
+my &s = &say-hello;
+my &other-s = sub { say "Anonymous function !" }
+
+# A sub can have a "slurpy" parameter, or "doesn't-matter-how-many"
+sub as-many($head, *@rest) { # `*@` (slurpy) will basically "take everything else".
+ # Note: you can have parameters *before* (like here)
+ # a slurpy one, but not *after*.
+ say @rest.join(' / ') ~ " !";
+}
+say as-many('Happy', 'Happy', 'Birthday'); #=> Happy / Birthday !
+ # Note that the splat did not consume
+ # the parameter before.
+
+## You can call a function with an array using the
+# "argument list flattening" operator `|`
+# (it's not actually the only role of this operator, but it's one of them)
+sub concat3($a, $b, $c) {
+ say "$a, $b, $c";
+}
+concat3(|@array); #=> a, b, c
+ # `@array` got "flattened" as a part of the argument list
+
+## It can also have optional arguments:
+sub with-optional($arg?) { # the "?" marks the argument optional
+ say "I might return `(Any)` if I don't have an argument passed,
+ or I'll return my argument";
+ $arg;
+}
+with-optional; # returns Any
+with-optional(); # returns Any
+with-optional(1); # returns 1
+
+## You can also give them a default value when they're not passed:
+sub hello-to($name = "World") {
+ say "Hello, $name !";
+}
+hello-to; #=> Hello, World !
+hello-to(); #=> Hello, World !
+hello-to('You'); #=> Hello, You !
+
+## You can also, by using a syntax akin to the one of hashes (yay unification !),
+## pass *named* arguments to a `sub`.
+sub with-named($normal-arg, :$named) {
+ say $normal-arg + $named;
+}
+with-named(1, named => 6); #=> 7
+# There's one gotcha to be aware of, here:
+# If you quote your key, Perl 6 won't be able to see it at compile time,
+# and you'll have a single Pair object as a positional paramater.
+
+with-named(2, :named(5)); #=> 7
+with-named(3, :4named); #=> 7
+ # (special colon pair syntax for numbers,
+ # to be used with s// and such, see later)
+
+with-named(3); # warns, because we tried to use the undefined $named in a `+`:
+ # by default, named arguments are *optional*
+
+# To make a named argument mandatory, you can use `?`'s inverse, `!`
+sub with-mandatory-named(:$str!) {
+ say "$str !";
+}
+with-mandatory-named(str => "My String"); #=> My String !
+with-mandatory-named; # run time error: "Required named parameter not passed"
+with-mandatory-named(3); # run time error: "Too many positional parameters passed"
+
+## If a sub takes a named boolean argument ...
+sub takes-a-bool($name, :$bool) {
+ say "$name takes $bool";
+}
+# ... you can use the same "short boolean" hash syntax:
+takes-a-bool('config', :bool); # config takes True
+takes-a-bool('config', :!bool); # config takes False
+# or you can use the "adverb" form:
+takes-a-bool('config'):bool; #=> config takes True
+takes-a-bool('config'):!bool; #=> config takes False
+# You'll learn to love (or maybe hate, eh) that syntax later.
+
+
+## You can also provide your named arguments with defaults:
+sub named-def(:$def = 5) {
+ say $def;
+}
+named-def; #=> 5
+named-def(:10def); #=> 10
+named-def(def => 15); #=> 15
+
+# -- Note: we're going to learn *more* on subs really soon,
+# but we need to grasp a few more things to understand their real power. Ready?
+
+### Containers
+# In Perl 6, values are actually stored in "containers".
+# The assignment operator asks the container on the left to store the value on
+# its right. When passed around, containers are marked as immutable.
+# Which means that, in a function, you'll get an error if you try to
+# mutate one of your arguments.
+# If you really need to, you can ask for a mutable container using `is rw`:
+sub mutate($n is rw) {
+ $n++;
+ say "\$n is now $n !";
+}
+
+# If what you want is a copy instead, use `is copy`.
+
+# A sub itself returns a container, which means it can be marked as rw:
+my $x = 42;
+sub mod() is rw { $x }
+mod() = 52; # in this case, the parentheses are mandatory
+ # (else Perl 6 thinks `mod` is a "term")
+say $x; #=> 52
+
+
+### Control Flow Structures
+
+# You don't need to put parenthesis around the condition,
+# but that also means you always have to use brackets (`{ }`) for their body:
+
+## Conditionals
+
+# - `if`
+# Before talking about `if`, we need to know which values are "Truthy"
+# (represent True), and which are "Falsey" (or "Falsy") -- represent False.
+# Only these values are Falsey: (), 0, "0", Nil, A type (like `Str` or `Int`),
+# and of course False itself.
+# Every other value is Truthy.
+if True {
+ say "It's true !";
+}
+
+unless False {
+ say "It's not false !";
+}
+
+# You can also use their postfix versions, with the keyword after:
+say "Quite truthy" if True;
+
+# if (true) say; # This doesn't work !
+
+# - Ternary conditional, "?? !!" (like `x ? y : z` in some other languages)
+my $a = $condition ?? $value-if-true !! $value-if-false;
+
+# - `given`-`when` looks like other languages `switch`, but much more
+# powerful thanks to smart matching and thanks to Perl 6's "topic variable", $_.
+# This variable contains the default argument of a block,
+# a loop's current iteration (unless explicitly named), etc.
+# `given` simply puts its argument into `$_` (like a block would do),
+# and `when` compares it using the "smart matching" (`~~`) operator.
+# Since other Perl 6 constructs use this variable (as said before, like `for`,
+# blocks, etc), this means the powerful `when` is not only applicable along with
+# a `given`, but instead anywhere a `$_` exists.
+given "foo bar" {
+ when /foo/ { # Don't worry about smart matching -- just know `when` uses it.
+ # This is equivalent to `if $_ ~~ /foo/`.
+ say "Yay !";
+ }
+ when $_.chars > 50 { # smart matching anything with True (`$a ~~ True`) is True,
+ # so you can also put "normal" conditionals.
+ say "Quite a long string !";
+ }
+ default { # same as `when *` (using the Whatever Star)
+ say "Something else"
+ }
+}
+
+## Looping constructs
+
+# - `loop` is an infinite loop if you don't pass it arguments,
+# but can also be a c-style `for`:
+loop {
+ say "This is an infinite loop !";
+ last; # last breaks out of the loop, like the `break` keyword in other languages
+}
+
+loop (my $i = 0; $i < 5; $i++) {
+ next if $i == 3; # `next` skips to the next iteration, like `continue`
+ # in other languages. Note that you can also use postfix
+ # conditionals, loops, etc.
+ say "This is a C-style for loop !";
+}
+
+# - `for` - Passes through an array
+for @array -> $variable {
+ say "I've found $variable !";
+}
+
+# As we saw with given, for's default "current iteration" variable is `$_`.
+# That means you can use `when` in a `for` just like you were in a when.
+for @array {
+ say "I've got $_";
+
+ .say; # This is also allowed.
+ # A dot call with no "topic" (receiver) is sent to `$_` by default
+ $_.say; # the above and this are equivalent.
+}
+
+for @array {
+ # You can...
+ next if $_ == 3; # Skip to the next iteration (`continue` in C-like languages).
+ redo if $_ == 4; # Re-do the iteration, keeping the same topic variable (`$_`).
+ last if $_ == 5; # Or break out of a loop (like `break` in C-like languages).
+}
+
+# Note - the "lambda" `->` syntax isn't reserved to `for`:
+if long-computation() -> $result {
+ say "The result is $result";
+}
+
+## Loops can also have a label, and be jumped to through these.
+OUTER: while 1 {
+ say "hey";
+ while 1 {
+ OUTER.last; # All the control keywords must be called on the label itself
+ }
+}
+
+# Now that you've seen how to traverse a list, you need to be aware of something:
+# List context (@) flattens. If you traverse nested lists, you'll actually be traversing a
+# shallow list (except if some sub-list were put in item context ($)).
+for 1, 2, (3, (4, ((5)))) {
+ say "Got $_.";
+} #=> Got 1. Got 2. Got 3. Got 4. Got 5.
+
+# ... However: (forcing item context with `$`)
+for 1, 2, $(3, 4) {
+ say "Got $_.";
+} #=> Got 1. Got 2. Got 3 4.
+
+# Note that the last one actually joined 3 and 4.
+# While `$(...)` will apply item to context to just about anything, you can also create
+# an array using `[]`:
+for [1, 2, 3, 4] {
+ say "Got $_.";
+} #=> Got 1 2 3 4.
+
+# The other difference between `$()` and `[]` is that `[]` always returns a mutable Array
+# whereas `$()` will return a Parcel when given a Parcel.
+
+
+### Operators
+
+## Since Perl languages are very much operator-based languages
+## Perl 6 operators are actually just funny-looking subroutines, in syntactic
+## categories, like infix:<+> (addition) or prefix:<!> (bool not).
+
+## The categories are:
+# - "prefix": before (like `!` in `!True`).
+# - "postfix": after (like `++` in `$a++`).
+# - "infix": in between (like `*` in `4 * 3`).
+# - "circumfix": around (like `[`-`]` in `[1, 2]`).
+# - "post-circumfix": around, after another term (like `{`-`}` in `%hash{'key'}`)
+
+## The associativity and precedence list are explained below.
+
+# Alright, you're set to go !
+
+## * Equality Checking
+
+# - `==` is numeric comparison
+3 == 4; # False
+3 != 4; # True
+
+# - `eq` is string comparison
+'a' eq 'b';
+'a' ne 'b'; # not equal
+'a' !eq 'b'; # same as above
+
+# - `eqv` is canonical equivalence (or "deep equality")
+(1, 2) eqv (1, 3);
+
+# - `~~` is smart matching
+# For a complete list of combinations, use this table:
+# http://perlcabal.org/syn/S03.html#Smart_matching
+'a' ~~ /a/; # true if matches regexp
+'key' ~~ %hash; # true if key exists in hash
+$arg ~~ &bool-returning-function; # `True` if the function, passed `$arg`
+ # as an argument, returns `True`.
+1 ~~ Int; # "has type" (check superclasses and roles)
+1 ~~ True; # smart-matching against a boolean always returns that boolean
+ # (and will warn).
+
+# - `===` is value identity and uses `.WHICH` on the objects to compare them
+# - `=:=` is container identity and uses `VAR()` on the objects to compare them
+
+# You also, of course, have `<`, `<=`, `>`, `>=`.
+# Their string equivalent are also avaiable : `lt`, `le`, `gt`, `ge`.
+3 > 4;
+
+## * Range constructors
+3 .. 7; # 3 to 7, both included
+# `^` on either side them exclusive on that side :
+3 ^..^ 7; # 3 to 7, not included (basically `4 .. 6`)
+# This also works as a shortcut for `0..^N`:
+^10; # means 0..^10
+
+# This also allows us to demonstrate that Perl 6 has lazy/infinite arrays,
+# using the Whatever Star:
+my @array = 1..*; # 1 to Infinite ! `1..Inf` is the same.
+say @array[^10]; # you can pass arrays as subscripts and it'll return
+ # an array of results. This will print
+ # "1 2 3 4 5 6 7 8 9 10" (and not run out of memory !)
+# Note : when reading an infinite list, Perl 6 will "reify" the elements
+# it needs, then keep them in memory. They won't be calculated more than once.
+
+# Warning, though: if you try this example in the REPL and just put `1..*`,
+# Perl 6 will be forced to try and evaluate the whole array (to print it),
+# so you'll end with an infinite loop.
+
+# You can use that in most places you'd expect, even assigning to an array
+my @numbers = ^20;
+@numbers[5..*] = 3, 9 ... * > 90; # The right hand side could be infinite as well.
+ # (but not both, as this would be an infinite loop)
+say @numbers; #=> 3 9 15 21 27 [...] 81 87
+
+
+## * And, Or
+3 && 4; # 4, which is Truthy. Calls `.Bool` on `4` and gets `True`.
+0 || False; # False. Calls `.Bool` on `0`
+
+## * Short-circuit (and tight) versions of the above
+$a && $b && $c; # Returns the first argument that evaluates to False,
+ # or the last argument.
+$a || $b;
+
+# And because you're going to want them,
+# you also have composed assignment operators:
+$a *= 2; # multiply and assignment
+$b %%= 5; # divisible by and assignment
+@array .= sort; # calls the `sort` method and assigns the result back
+
+### More on subs !
+# As we said before, Perl 6 has *really* powerful subs. We're going to see
+# a few more key concepts that make them better than in any other language :-).
+
+## Unpacking !
+# It's the ability to "extract" arrays and keys.
+# It'll work in `my`s and in parameter lists.
+my ($a, $b) = 1, 2;
+say $a; #=> 1
+my ($, $, $c) = 1, 2, 3; # keep the non-interesting anonymous
+say $c; #=> 3
+
+my ($head, *@tail) = 1, 2, 3; # Yes, it's the same as with "slurpy subs"
+my (*@small) = 1;
+
+sub foo(@array [$fst, $snd]) {
+ say "My first is $fst, my second is $snd ! All in all, I'm @array[].";
+ # (^ remember the `[]` to interpolate the array)
+}
+foo(@tail); #=> My first is 2, my second is 3 ! All in all, I'm 2 3
+
+
+# If you're not using the array itself, you can also keep it anonymous,
+# much like a scalar:
+sub first-of-array(@ [$fst]) { $fst }
+first-of-array(@small); #=> 1
+first-of-array(@tail); # Throws an error "Too many positional parameters passed"
+ # (which means the array is too big).
+
+# You can also use a slurp ...
+sub slurp-in-array(@ [$fst, *@rest]) { # You could keep `*@rest` anonymous
+ say $fst + @rest.elems; # `.elems` returns a list's length.
+ # Here, `@rest` is `(3,)`, since `$fst` holds the `2`.
+}
+slurp-in-array(@tail); #=> 3
+
+# You could even extract on a slurpy (but it's pretty useless ;-).)
+sub fst(*@ [$fst]) { # or simply : `sub fst($fst) { ... }`
+ say $fst;
+}
+fst(1); #=> 1
+fst(1, 2); # errors with "Too many positional parameters passed"
+
+# You can also destructure hashes (and classes, which you'll learn about later !)
+# The syntax is basically `%hash-name (:key($variable-to-store-value-in))`.
+# The hash can stay anonymous if you only need the values you extracted.
+sub key-of(% (:value($val), :qua($qua))) {
+ say "Got val $val, $qua times.";
+}
+
+# Then call it with a hash: (you need to keep the brackets for it to be a hash)
+key-of({value => 'foo', qua => 1});
+#key-of(%hash); # the same (for an equivalent `%hash`)
+
+## The last expression of a sub is returned automatically
+# (though you may use the `return` keyword, of course):
+sub next-index($n) {
+ $n + 1;
+}
+my $new-n = next-index(3); # $new-n is now 4
+
+# This is true for everything, except for the looping constructs
+# (due to performance reasons): there's reason to build a list
+# if we're just going to discard all the results.
+# If you still want to build one, you can use the `do` statement prefix:
+# (or the `gather` prefix, which we'll see later)
+sub list-of($n) {
+ do for ^$n { # note the use of the range-to prefix operator `^` (`0..^N`)
+ $_ # current loop iteration
+ }
+}
+my @list3 = list-of(3); #=> (0, 1, 2)
+
+## You can create a lambda with `-> {}` ("pointy block") or `{}` ("block")
+my &lambda = -> $argument { "The argument passed to this lambda is $argument" }
+# `-> {}` and `{}` are pretty much the same thing, except that the former can
+# take arguments, and that the latter can be mistaken as a hash by the parser.
+
+# We can, for example, add 3 to each value of an array using map:
+my @arrayplus3 = map({ $_ + 3 }, @array); # $_ is the implicit argument
+
+# A sub (`sub {}`) has different semantics than a block (`{}` or `-> {}`):
+# A block doesn't have a "function context" (though it can have arguments),
+# which means that if you return from it,
+# you're going to return from the parent function. Compare:
+sub is-in(@array, $elem) {
+ # this will `return` out of the `is-in` sub
+ # once the condition evaluated to True, the loop won't be run anymore
+ map({ return True if $_ == $elem }, @array);
+}
+sub truthy-array(@array) {
+ # this will produce an array of `True` and `False`:
+ # (you can also say `anon sub` for "anonymous subroutine")
+ map(sub ($i) { if $i { return True } else { return False } }, @array);
+ # ^ the `return` only returns from the anonymous `sub`
+}
+
+# You can also use the "whatever star" to create an anonymous function
+# (it'll stop at the furthest operator in the current expression)
+my @arrayplus3 = map(*+3, @array); # `*+3` is the same as `{ $_ + 3 }`
+my @arrayplus3 = map(*+*+3, @array); # Same as `-> $a, $b { $a + $b + 3 }`
+ # also `sub ($a, $b) { $a + $b + 3 }`
+say (*/2)(4); #=> 2
+ # Immediatly execute the function Whatever created.
+say ((*+3)/5)(5); #=> 1.6
+ # works even in parens !
+
+# But if you need to have more than one argument (`$_`)
+# in a block (without wanting to resort to `-> {}`),
+# you can also use the implicit argument syntax, `$^` :
+map({ $^a + $^b + 3 }, @array); # equivalent to following:
+map(sub ($a, $b) { $a + $b + 3 }, @array); # (here with `sub`)
+
+# Note : those are sorted lexicographically.
+# `{ $^b / $^a }` is like `-> $a, $b { $b / $a }`
+
+## Multiple Dispatch
+# Perl 6 can decide which variant of a `sub` to call based on the type of the
+# arguments, or on arbitrary preconditions, like with a type or a `where`:
+
+# with types
+multi sub sayit(Int $n) { # note the `multi` keyword here
+ say "Number: $n";
+}
+multi sayit(Str $s) } # the `sub` is the default
+ say "String: $s";
+}
+sayit("foo"); # prints "String: foo"
+sayit(True); # fails at *compile time* with
+ # "calling 'sayit' will never work with arguments of types ..."
+
+# with arbitrary precondition:
+multi is-big(Int $n where * > 50) { "Yes !" } # using a closure
+multi is-big(Int $ where 10..50) { "Quite." } # Using smart-matching
+ # (could use a regexp, etc)
+multi is-big(Int $) { "No" }
+
+# You can also name these checks, by creating "subsets":
+subset Even of Int where * %% 2;
+
+multi odd-or-even(Even) { "Even" } # The main case using the type.
+ # We don't name the argument.
+multi odd-or-even($) { "Odd" } # "else"
+
+# You can even dispatch based on a positional's argument presence !
+multi with-or-without-you(:$with!) { # You need make it mandatory to
+ # be able to dispatch against it.
+ say "I can live ! Actually, I can't.";
+}
+multi with-or-without-you {
+ say "Definitely can't live.";
+}
+# This is very, very useful for many purposes, like `MAIN` subs (covered later),
+# and even the language itself is using it in several places.
+#
+# - `is`, for example, is actually a `multi sub` named `trait_mod:<is>`,
+# and it works off that.
+# - `is rw`, is simply a dispatch to a function with this signature:
+# sub trait_mod:<is>(Routine $r, :$rw!) {}
+#
+# (commented because running this would be a terrible idea !)
+
+
+### Scoping
+# In Perl 6, contrarily to many scripting languages (like Python, Ruby, PHP),
+# you are to declare your variables before using them. You know `my`.
+# (there are other declarators, `our`, `state`, ..., which we'll see later).
+# This is called "lexical scoping", where in inner blocks,
+# you can access variables from outer blocks.
+my $foo = 'Foo';
+sub foo {
+ my $bar = 'Bar';
+ sub bar {
+ say "$foo $bar";
+ }
+ &bar; # return the function
+}
+foo()(); #=> 'Foo Bar'
+
+# As you can see, `$foo` and `$bar` were captured.
+# But if we were to try and use `$bar` outside of `foo`,
+# the variable would be undefined (and you'd get a compile time error).
+
+# Perl 6 has another kind of scope : dynamic scope.
+# They use the twigil (composed sigil) `*` to mark dynamically-scoped variables:
+my $*a = 1;
+# Dyamically-scoped variables depend on the current call stack,
+# instead of the current block depth.
+sub foo {
+ my $*foo = 1;
+ bar(); # call `bar` in-place
+}
+sub bar {
+ say $*foo; # `$*a` will be looked in the call stack, and find `foo`'s,
+ # even though the blocks aren't nested (they're call-nested).
+ #=> 1
+}
+
+### Object Model
+
+## Perl 6 has a quite comprehensive object model
+# You declare a class with the keyword `class`, fields with `has`,
+# methods with `method`. Every field to private, and is named `$!attr`,
+# but you have `$.` to get a public (immutable) accessor along with it.
+# (using `$.` is like using `$!` plus a `method` with the same name)
+
+# (Perl 6's object model ("SixModel") is very flexible,
+# and allows you to dynamically add methods, change semantics, etc ...
+# (this will not be covered here, and you should refer to the Synopsis).
+
+class A {
+ has $.field; # `$.field` is immutable.
+ # From inside the class, use `$!field` to modify it.
+ has $.other-field is rw; # You can obviously mark a public field `rw`.
+ has Int $!private-field = 10;
+
+ method get-value {
+ $.field + $!private-field + $n;
+ }
+
+ method set-value($n) {
+ # $.field = $n; # As stated before, you can't use the `$.` immutable version.
+ $!field = $n; # This works, because `$!` is always mutable.
+
+ $.other-field = 5; # This works, because `$.other-field` is `rw`.
+ }
+
+ method !private-method {
+ say "This method is private to the class !";
+ }
+};
+
+# Create a new instance of A with $.field set to 5 :
+# Note: you can't set private-field from here (more later on).
+my $a = A.new(field => 5);
+$a.get-value; #=> 18
+#$a.field = 5; # This fails, because the `has $.field` is immutable
+$a.other-field = 10; # This, however, works, because the public field
+ # is mutable (`rw`).
+
+## Perl 6 also has inheritance (along with multiple inheritance)
+# (though considered a misfeature by many)
+
+class A {
+ has $.val;
+
+ submethod not-inherited {
+ say "This method won't be available on B.";
+ say "This is most useful for BUILD, which we'll see later";
+ }
+
+ method bar { $.val * 5 }
+}
+class B is A { # inheritance uses `is`
+ method foo {
+ say $.val;
+ }
+
+ method bar { $.val * 10 } # this shadows A's `bar`
+}
+
+# When you use `my T $var`, `$var` starts off with `T` itself in it,
+# so you can call `new` on it.
+# (`.=` is just the dot-call and the assignment operator:
+# `$a .= b` is the same as `$a = $a.b`)
+# Also note that `BUILD` (the method called inside `new`)
+# will set parent properties too, so you can pass `val => 5`.
+my B $b .= new(val => 5);
+
+# $b.not-inherited; # This won't work, for reasons explained above
+$b.foo; # prints 5
+$b.bar; #=> 50, since it calls B's `bar`
+
+## Roles are supported too (also called Mixins in other languages)
+role PrintableVal {
+ has $!counter = 0;
+ method print {
+ say $.val;
+ }
+}
+
+# you "use" a mixin with "does" :
+class Item does PrintableVal {
+ has $.val;
+
+ # When `does`-ed, a `role` literally "mixes in" the class:
+ # the methods and fields are put together, which means a class can access
+ # the private fields/methods of its roles (but not the inverse !):
+ method access {
+ say $!counter++;
+ }
+
+ # However, this:
+ # method print {}
+ # is ONLY valid when `print` isn't a `multi` with the same dispatch.
+ # (this means a parent class can shadow a child class's `multi print() {}`,
+ # but it's an error if a role does)
+
+ # NOTE: You can use a role as a class (with `is ROLE`). In this case, methods
+ # will be shadowed, since the compiler will consider `ROLE` to be a class.
+}
+
+### Exceptions
+# Exceptions are built on top of classes, in the package `X` (like `X::IO`).
+# Unlike many other languages, in Perl 6, you put the `CATCH` block *within* the
+# block to `try`. By default, a `try` has a `CATCH` block that catches
+# any exception (`CATCH { default {} }`).
+# You can redefine it using `when`s (and `default`)
+# to handle the exceptions you want:
+try {
+ open 'foo';
+ CATCH {
+ when X::AdHoc { say "unable to open file !" }
+ # Any other exception will be re-raised, since we don't have a `default`
+ # Basically, if a `when` matches (or there's a `default`) marks the exception as
+ # "handled" so that it doesn't get re-thrown from the `CATCH`.
+ # You still can re-throw the exception (see below) by hand.
+ }
+}
+
+# You can throw an exception using `die`:
+die X::AdHoc.new(payload => 'Error !');
+
+# You can access the last exception with `$!` (usually used in a `CATCH` block)
+
+# There are also some subtelties to exceptions. Some Perl 6 subs return a `Failure`,
+# which is a kind of "unthrown exception". They're not thrown until you tried to look
+# at their content, unless you call `.Bool`/`.defined` on them - then they're handled.
+# (the `.handled` method is `rw`, so you can mark it as `False` back yourself)
+#
+# You can throw a `Failure` using `fail`. Note that if the pragma `use fatal` is on,
+# `fail` will throw an exception (like `die`).
+fail "foo"; # We're not trying to access the value, so no problem.
+try {
+ fail "foo";
+ CATCH {
+ default { say "It threw because we try to get the fail's value!" }
+ }
+}
+
+# There is also another kind of exception: Control exceptions.
+# Those are "good" exceptions, which happen when you change your program's flow,
+# using operators like `return`, `next` or `last`.
+# You can "catch" those with `CONTROL` (not 100% working in Rakudo yet).
+
+### Packages
+# Packages are a way to reuse code. Packages are like "namespaces", and any
+# element of the six model (`module`, `role`, `class`, `grammar`, `subset`
+# and `enum`) are actually packages. (Packages are the lowest common denomitor)
+# Packages are important - especially as Perl is well-known for CPAN,
+# the Comprehensive Perl Archive Network.
+# You usually don't use packages directly: you use `class Package::Name::Here;`,
+# or if you only want to export variables/subs, you can use `module`:
+module Hello::World { # Bracketed form
+ # If `Hello` doesn't exist yet, it'll just be a "stub",
+ # that can be redeclared as something else later.
+ # ... declarations here ...
+}
+module Parse::Text; # file-scoped form
+grammar Parse::Text::Grammar { # A grammar is a package, which you could `use`
+}
+
+# NOTE for Perl 5 users: even though the `package` keyword exists,
+# the braceless form is invalid (to catch a "perl5ism"). This will error out:
+# package Foo; # because Perl 6 will think the entire file is Perl 5
+# Just use `module` or the brace version of `package`.
+
+# You can use a module (bring its declarations into scope) with `use`
+use JSON::Tiny; # if you installed Rakudo* or Panda, you'll have this module
+say from-json('[1]').perl; #=> [1]
+
+# As said before, any part of the six model is also a package.
+# Since `JSON::Tiny` uses (its own) `JSON::Tiny::Actions` class, you can use it:
+my $actions = JSON::Tiny::Actions.new;
+
+# We'll see how to export variables and subs in the next part:
+
+### Declarators
+# In Perl 6, you get different behaviors based on how you declare a variable.
+# You've already seen `my` and `has`, we'll now explore the others.
+
+## * `our` (happens at `INIT` time -- see "Phasers" below)
+# Along with `my`, there are several others declarators you can use.
+# The first one you'll want for the previous part is `our`.
+# (All packagish things (`class`, `role`, etc) are `our` by default)
+# it's like `my`, but it also creates a package variable:
+module Foo::Bar {
+ our $n = 1; # note: you can't put a type constraint on an `our` variable
+ our sub inc {
+ our sub available { # If you try to make inner `sub`s `our`...
+ # Better know what you're doing (Don't !).
+ say "Don't do that. Seriously. You'd get burned.";
+ }
+ my sub unavailable { # `my sub` is the default
+ say "Can't access me from outside, I'm my !";
+ }
+ }
+
+ say ++$n; # lexically-scoped variables are still available
+}
+say $Foo::Bar::n; #=> 1
+Foo::Bar::inc; #=> 2
+Foo::Bar::inc; #=> 3
+
+## * `constant` (happens at `BEGIN` time)
+# You can use the `constant` keyword to declare a compile-time variable/symbol:
+constant Pi = 3.14;
+constant $var = 1;
+
+# And if you're wondering, yes, it can also contain infinite lists.
+constant why-not = 5, 15 ... *;
+say why-not[^5]; #=> 5 15 25 35 45
+
+## * `state` (happens at run time, but only once)
+# State variables are only executed one time
+# (they exist in other langages such as C as `static`)
+sub fixed-rand {
+ state $val = rand;
+ say $rand;
+}
+fixed-rand for ^10; # will print the same number 10 times
+
+# Note, however, that they exist separately in different enclosing contexts.
+# If you declare a function with a `state` within a loop, it'll re-create the
+# variable for each iteration of the loop. See:
+for ^5 -> $a {
+ sub foo {
+ state $val = rand; # This will be a different value for every value of `$a`
+ }
+ for ^5 -> $b {
+ say foo; # This will print the same value 5 times, but only 5.
+ # Next iteration will re-run `rand`.
+ }
+}
+
+
+
+### Phasers
+# Phasers in Perl 6 are blocks that happen at determined points of time in your
+# program. When the program is compiled, when a for loop runs, when you leave a
+# block, when an exception gets thrown ... (`CATCH` is actually a phaser !)
+# Some of them can be used for their return values, some of them can't
+# (those that can have a "[*]" in the beginning of their explanation text).
+# Let's have a look !
+
+## * Compile-time phasers
+BEGIN { say "[*] Runs at compile time, as soon as possible, only once" }
+CHECK { say "[*] Runs at compile time, instead as late as possible, only once" }
+
+## * Run-time phasers
+INIT { say "[*] Runs at run time, as soon as possible, only once" }
+END { say "Runs at run time, as late as possible, only once" }
+
+## * Block phasers
+ENTER { say "[*] Runs everytime you enter a block, repeats on loop blocks" }
+LEAVE { say "Runs everytime you leave a block, even when an exception happened. Repeats on loop blocks." }
+
+PRE { say "Asserts a precondition at every block entry, before ENTER (especially useful for loops)" }
+POST { say "Asserts a postcondition at every block exit, after LEAVE (especially useful for loops)" }
+
+## * Block/exceptions phasers
+sub {
+ KEEP { say "Runs when you exit a block successfully (without throwing an exception)" }
+ UNDO { say "Runs when you exit a block unsuccessfully (by throwing an exception)" }
+}
+
+## * Loop phasers
+for ^5 {
+ FIRST { say "[*] The first time the loop is run, before ENTER" }
+ NEXT { say "At loop continuation time, before LEAVE" }
+ LAST { say "At loop termination time, after LEAVE" }
+}
+
+## * Role/class phasers
+COMPOSE { "When a role is composed into a class. /!\ NOT YET IMPLEMENTED" }
+
+# They allow for cute trick or clever code ...:
+say "This code took " ~ (time - CHECK time) ~ "s to run";
+
+# ... or clever organization:
+sub do-db-stuff {
+ ENTER $db.start-transaction; # New transaction everytime we enter the sub
+ KEEP $db.commit; # commit the transaction if all went well
+ UNDO $db.rollback; # or rollback if all hell broke loose
+}
+
+### Statement prefixes
+# Those act a bit like phasers: they affect the behavior of the following code.
+# Though, they run in-line with the executable code, so they're in lowercase.
+# (`try` and `start` are theoretically in that list, but explained somewhere else)
+# Note: all of these (except start) don't need explicit brackets `{` and `}`.
+
+# - `do` (that you already saw) - runs a block or a statement as a term
+# You can't normally use a statement as a value (or "term"):
+#
+# my $value = if True { 1 } # `if` is a statement - parse error
+#
+# This works:
+my $a = do if True { 5 } # with `do`, `if` is now a term.
+
+# - `once` - Makes sure a piece of code only runs once
+for ^5 { once say 1 }; #=> 1
+ # Only prints ... once.
+# Like `state`, they're cloned per-scope
+for ^5 { sub { once say 1 }() } #=> 1 1 1 1 1
+ # Prints once per lexical scope
+
+# - `gather` - Co-routine thread
+# Gather allows you to `take` several values in an array,
+# much like `do`, but allows you to take any expression.
+say gather for ^5 {
+ take $_ * 3 - 1;
+ take $_ * 3 + 1;
+} #=> -1 1 2 4 5 7 8 10 11 13
+say join ',', gather if False {
+ take 1;
+ take 2;
+ take 3;
+} # Doesn't print anything.
+
+# - `eager` - Evaluate statement eagerly (forces eager context)
+# Don't try this at home:
+#
+# eager 1..*; # this will probably hang for a while (and might crash ...).
+#
+# But consider:
+constant thrice = gather for ^3 { say take $_ }; # Doesn't print anything
+# versus:
+constant thrice = eager gather for ^3 { say take $_ }; #=> 0 1 2 3 4
+
+# - `lazy` - Defer actual evaluation until value is fetched (forces lazy context)
+# Not yet implemented !!
+
+# - `sink` - An `eager` that discards the results (forces sink context)
+constant nilthingie = sink for ^3 { .say } #=> 0 1 2
+say nilthingie.perl; #=> Nil
+
+# - `quietly` - Supresses warnings
+# Not yet implemented !
+
+# - `contend` - Attempts side effects under STM
+# Not yet implemented !
+
+### More operators thingies !
+
+## Everybody loves operators ! Let's get more of them
+
+# The precedence list can be found here:
+# http://perlcabal.org/syn/S03.html#Operator_precedence
+# But first, we need a little explanation about associativity:
+
+# * Binary operators:
+$a ! $b ! $c; # with a left-associative `!`, this is `($a ! $b) ! $c`
+$a ! $b ! $c; # with a right-associative `!`, this is `$a ! ($b ! $c)`
+$a ! $b ! $c; # with a non-associative `!`, this is illegal
+$a ! $b ! $c; # with a chain-associative `!`, this is `($a ! $b) and ($b ! $c)`
+$a ! $b ! $c; # with a list-associative `!`, this is `infix:<>`
+
+# * Unary operators:
+!$a! # with left-associative `!`, this is `(!$a)!`
+!$a! # with right-associative `!`, this is `!($a!)`
+!$a! # with non-associative `!`, this is illegal
+
+## Create your own operators !
+# Okay, you've been reading all of that, so I guess I should try
+# to show you something exciting.
+# I'll tell you a little secret (or not-so-secret):
+# In Perl 6, all operators are actually just funny-looking subroutines.
+
+# You can declare an operator just like you declare a sub:
+sub prefix:<win>($winner) { # refer to the operator categories
+ # (yes, it's the "words operator" `<>`)
+ say "$winner Won !";
+}
+win "The King"; #=> The King Won !
+ # (prefix is before)
+
+# you can still call the sub with its "full name"
+say prefix:<!>(True); #=> False
+
+sub postfix:<!>(Int $n) {
+ [*] 2..$n; # using the reduce meta-operator ... See below ;-) !
+}
+say 5!; #=> 120
+ # Postfix operators (after) have to come *directly* after the term.
+ # No whitespace. You can use parentheses to disambiguate, i.e. `(5!)!`
+
+
+sub infix:<times>(Int $n, Block $r) { # infix in the middle
+ for ^$n {
+ $r(); # You need the explicit parentheses to call the function in `$r`,
+ # else you'd be referring at the variable itself, like with `&r`.
+ }
+}
+3 times -> { say "hello" }; #=> hello
+ #=> hello
+ #=> hello
+ # You're very recommended to put spaces
+ # around your infix operator calls.
+
+# For circumfix and post-circumfix ones
+sub circumfix:<[ ]>(Int $n) {
+ $n ** $n
+}
+say [5]; #=> 3125
+ # circumfix is around. Again, not whitespace.
+
+sub postcircumfix:<{ }>(Str $s, Int $idx) {
+ # post-circumfix is
+ # "after a term, around something"
+ $s.substr($idx, 1);
+}
+say "abc"{1}; #=> b
+ # after the term `"abc"`, and around the index (1)
+
+# This really means a lot -- because everything in Perl 6 uses this.
+# For example, to delete a key from a hash, you use the `:delete` adverb
+# (a simple named argument underneath):
+%h{$key}:delete;
+# equivalent to:
+postcircumfix:<{ }>(%h, $key, :delete); # (you can call operators like that)
+# It's *all* using the same building blocks!
+# Syntactic categories (prefix infix ...), named arguments (adverbs), ...,
+# - used to build the language - are available to you.
+
+# (you are, obviously, recommended against making an operator out of
+# *everything* -- with great power comes great responsibility)
+
+## Meta operators !
+# Oh boy, get ready. Get ready, because we're dwelving deep
+# into the rabbit's hole, and you probably won't want to go
+# back to other languages after reading that.
+# (I'm guessing you don't want to already at that point).
+# Meta-operators, as their name suggests, are *composed* operators.
+# Basically, they're operators that apply another operator.
+
+## * Reduce meta-operator
+# It's a prefix meta-operator that takes a binary functions and
+# one or many lists. If it doesn't get passed any argument,
+# it either return a "default value" for this operator
+# (a value that wouldn't change the result if passed as one
+# of the element of the list to be passed to the operator),
+# or `Any` if there's none (examples below).
+#
+# Otherwise, it pops an element from the list(s) one at a time, and applies
+# the binary function to the last result (or the list's first element)
+# and the popped element.
+#
+# To sum a list, you could use the reduce meta-operator with `+`, i.e.:
+say [+] 1, 2, 3; #=> 6
+# equivalent to `(1+2)+3`
+say [*] 1..5; #=> 120
+# equivalent to `((((1*2)*3)*4)*5)`.
+
+# You can reduce with any operator, not just with mathematical ones.
+# For example, you could reduce with `//` to get
+# the first defined element of a list:
+say [//] Nil, Any, False, 1, 5; #=> False
+ # (Falsey, but still defined)
+
+
+# Default value examples:
+say [*] (); #=> 1
+say [+] (); #=> 0
+ # In both cases, they're results that, were they in the lists,
+ # wouldn't have any impact on the final value
+ # (since N*1=N and N+0=N).
+say [//]; #=> (Any)
+ # There's no "default value" for `//`.
+
+# You can also call it with a function you made up, using double brackets:
+sub add($a, $b) { $a + $b }
+say [[&add]] 1, 2, 3; #=> 6
+
+## * Zip meta-operator
+# This one is an infix meta-operator than also can be used as a "normal" operator.
+# It takes an optional binary function (by default, it just creates a pair),
+# and will pop one value off of each array and call its binary function on these
+# until it runs out of elements. It runs the an array with all these new elements.
+(1, 2) Z (3, 4); # ((1, 3), (2, 4)), since by default, the function makes an array
+1..3 Z+ 4..6; # (5, 7, 9), using the custom infix:<+> function
+
+# Since `Z` is list-associative (see the list above),
+# you can use it on more than one list
+(True, False) Z|| (False, False) Z|| (False, False); # (True, False)
+
+# And, as it turns out, you can also use the reduce meta-operator with it:
+[Z||] (True, False), (False, False), (False, False); # (True, False)
+
+
+## And to end the operator list:
+
+## * Sequence operator
+# The sequence operator is one of Perl 6's most powerful features:
+# it's composed of first, on the left, the list you want Perl 6 to deduce from
+# (and might include a closure), and on the right, a value or the predicate
+# that says when to stop (or Whatever for a lazy infinite list).
+my @list = 1, 2, 3 ... 10; # basic deducing
+#my @list = 1, 3, 6 ... 10; # this throws you into an infinite loop,
+ # because Perl 6 can't figure out the end
+my @list = 1, 2, 3 ...^ 10; # as with ranges, you can exclude the last element
+ # (the iteration when the predicate matches).
+my @list = 1, 3, 9 ... * > 30; # you can use a predicate
+ # (with the Whatever Star, here).
+my @list = 1, 3, 9 ... { $_ > 30 }; # (equivalent to the above)
+
+my @fib = 1, 1, *+* ... *; # lazy infinite list of prime numbers,
+ # computed using a closure!
+my @fib = 1, 1, -> $a, $b { $a + $b } ... *; # (equivalent to the above)
+my @fib = 1, 1, { $^a + $^b } ... *; #(... also equivalent to the above)
+# $a and $b will always take the previous values, meaning here
+# they'll start with $a = 1 and $b = 1 (values we set by hand).
+# then $a = 1 and $b = 2 (result from previous $a+$b), and so on.
+
+say @fib[^10]; #=> 1 1 2 3 5 8 13 21 34 55
+ # (using a range as the index)
+# Note : as for ranges, once reified, elements aren't re-calculated.
+# That's why `@primes[^100]` will take a long time the first time you print
+# it, then be instant.
+
+
+## * Sort comparison
+# They return one value of the `Order` enum : `Less`, `Same` and `More`
+# (which numerify to -1, 0 or +1).
+1 <=> 4; # sort comparison for numerics
+'a' leg 'b'; # sort comparison for string
+$obj eqv $obj2; # sort comparison using eqv semantics
+
+## * Generic ordering
+3 before 4; # True
+'b' after 'a'; # True
+
+## * Short-circuit default operator
+# Like `or` and `||`, but instead returns the first *defined* value :
+say Any // Nil // 0 // 5; #=> 5
+
+## * Short-circuit exclusive or (XOR)
+# Returns `True` if one (and only one) of its arguments is true
+say True ^^ False; #=> True
+
+## * Flip Flop
+# The flip flop operators (`ff` and `fff`, equivalent to P5's `..`/`...`).
+# are operators that take two predicates to test:
+# They are `False` until their left side returns `True`, then are `True` until
+# their right side returns `True`.
+# Like for ranges, you can exclude the iteration when it became `True`/`False`
+# by using `^` on either side.
+# Let's start with an example :
+for <well met young hero we shall meet later> {
+ # by default, `ff`/`fff` smart-match (`~~`) against `$_`:
+ if 'met' ^ff 'meet' { # Won't enter the if for "met"
+ # (explained in details below).
+ .say
+ }
+
+ if rand == 0 ff rand == 1 { # compare variables other than `$_`
+ say "This ... probably will never run ...";
+ }
+}
+# This will print "young hero we shall meet" (excluding "met"):
+# the flip-flop will start returning `True` when it first encounters "met"
+# (but will still return `False` for "met" itself, due to the leading `^`
+# on `ff`), until it sees "meet", which is when it'll start returning `False`.
+
+# The difference between `ff` (awk-style) and `fff` (sed-style) is that
+# `ff` will test its right side right when its left side changes to `True`,
+# and can get back to `False` right away
+# (*except* it'll be `True` for the iteration that matched) -
+# While `fff` will wait for the next iteration to
+# try its right side, once its left side changed:
+.say if 'B' ff 'B' for <A B C B A>; #=> B B
+ # because the right-hand-side was tested
+ # directly (and returned `True`).
+ # "B"s are printed since it matched that time
+ # (it just went back to `False` right away).
+.say if 'B' fff 'B' for <A B C B A>; #=> B C B
+ # The right-hand-side wasn't tested until
+ # `$_` became "C"
+ # (and thus did not match instantly).
+
+# A flip-flop can change state as many times as needed:
+for <test start print it stop not printing start print again stop not anymore> {
+ .say if $_ eq 'start' ^ff^ $_ eq 'stop'; # exclude both "start" and "stop",
+ #=> "print this printing again"
+}
+
+# you might also use a Whatever Star,
+# which is equivalent to `True` for the left side or `False` for the right:
+for (1, 3, 60, 3, 40, 60) { # Note: the parenthesis are superfluous here
+ # (sometimes called "superstitious parentheses")
+ .say if $_ > 50 ff *; # Once the flip-flop reaches a number greater than 50,
+ # it'll never go back to `False`
+ #=> 60 3 40 60
+}
+
+# You can also use this property to create an `If`
+# that'll not go through the first time :
+for <a b c> {
+ .say if * ^ff *; # the flip-flop is `True` and never goes back to `False`,
+ # but the `^` makes it *not run* on the first iteration
+ #=> b c
+}
+
+
+### Regular Expressions
+# I'm sure a lot of you have been waiting for this one.
+# Well, now that you know a good deal of Perl 6 already, we can get started.
+# First off, you'll have to forget about "PCRE regexps" (perl-compatible regexps).
+#
+# IMPORTANT: Don't skip them because you know PCRE. They're different.
+# Some things are the same (like `?`, `+`, and `*`),
+# but sometimes the semantics change (`|`).
+# Make sure you read carefully, because you might trip over a new behavior.
+#
+# Perl 6 has many features related to RegExps. After all, Rakudo parses itself.
+# We're first going to look at the syntax itself,
+# then talk about grammars (PEG-like), differences between
+# `token`, `regex` and `rule` declarators, and some more.
+# Side note: you still have access to PCRE regexps using the `:P5` modifier.
+# (we won't be discussing this in this tutorial, however)
+#
+# In essence, Perl 6 natively implements PEG ("Parsing Expression Grammars").
+# The pecking order for ambiguous parses is determined by a multi-level
+# tie-breaking test:
+# - Longest token matching. `foo\s+` beats `foo` (by 2 or more positions)
+# - Longest literal prefix. `food\w*` beats `foo\w*` (by 1)
+# - Declaration from most-derived to less derived grammars
+# (grammars are actually classes)
+# - Earliest declaration wins
+say so 'a' ~~ /a/; #=> True
+say so 'a' ~~ / a /; # More readable with some spaces!
+
+# In all our examples, we're going to use the smart-matching operator against
+# a regexp. We're converting the result using `so`, but in fact, it's
+# returning a `Match` object. They know how to respond to list indexing,
+# hash indexing, and return the matched string.
+# The results of the match are available as `$/` (implicitly lexically-scoped).
+# You can also use the capture variables (`$0`, `$1`, ... starting at 0, not 1 !).
+#
+# You can also note that `~~` does not perform start/end checking
+# (meaning the regexp can be matched with just one char of the string),
+# we're going to explain later how you can do it.
+
+# In Perl 6, you can have any alphanumeric as a literal,
+# everything else has to be escaped, using a backslash or quotes.
+say so 'a|b' ~~ / a '|' b /; # `True`. Wouln't mean the same if `|` wasn't escaped
+say so 'a|b' ~~ / a \| b /; # `True`. Another way to escape it.
+
+# The whitespace in a regexp is actually not significant,
+# unless you use the `:s` (`:sigspace`, significant space) modifier.
+say so 'a b c' ~~ / a b c /; # `False`. Space is not significant here
+say so 'a b c' ~~ /:s a b c /; # `True`. We added the modifier `:s` here.
+
+# It is, however, important as for how modifiers (that you're gonna see just below)
+# are applied ...
+
+## Quantifying - `?`, `+`, `*` and `**`.
+# - `?` - 0 or 1
+so 'ac' ~~ / a b c /; # `False`
+so 'ac' ~~ / a b? c /; # `True`, the "b" matched 0 times.
+so 'abc' ~~ / a b? c /; # `True`, the "b" matched 1 time.
+
+# ... As you read just before, whitespace is important because it determines
+# which part of the regexp is the target of the modifier:
+so 'def' ~~ / a b c? /; # `False`. Only the `c` is optional
+so 'def' ~~ / ab?c /; # `False`. Whitespace is not significant
+so 'def' ~~ / 'abc'? /; # `True`. The whole "abc" group is optional.
+
+# Here (and below) the quantifier applies only to the `b`
+
+# - `+` - 1 or more
+so 'ac' ~~ / a b+ c /; # `False`; `+` wants at least one matching
+so 'abc' ~~ / a b+ c /; # `True`; one is enough
+so 'abbbbc' ~~ / a b+ c /; # `True`, matched 4 "b"s
+
+# - `*` - 0 or more
+so 'ac' ~~ / a b* c /; # `True`, they're all optional.
+so 'abc' ~~ / a b* c /; # `True`
+so 'abbbbc' ~~ / a b* c /; # `True`
+so 'aec' ~~ / a b* c /; # `False`. "b"(s) are optional, not replaceable.
+
+# - `**` - (Unbound) Quantifier
+# If you squint hard enough, you might understand
+# why exponentation is used for quantity.
+so 'abc' ~~ / a b ** 1 c /; # `True` (exactly one time)
+so 'abc' ~~ / a b ** 1..3 c /; # `True` (one to three times)
+so 'abbbc' ~~ / a b ** 1..3 c /; # `True`
+so 'abbbbbbc' ~~ / a b ** 1..3 c /; # `False` (too much)
+so 'abbbbbbc' ~~ / a b ** 3..* c /; # `True` (infinite ranges are okay)
+
+# - `<[]>` - Character classes
+# Character classes are the equivalent of PCRE's `[]` classes, but
+# they use a more perl6-ish syntax:
+say 'fooa' ~~ / f <[ o a ]>+ /; #=> 'fooa'
+# You can use ranges:
+say 'aeiou' ~~ / a <[ e..w ]> /; #=> 'aeiou'
+# Just like in normal regexes, if you want to use a special character, escape it
+# (the last one is escaping a space)
+say 'he-he !' ~~ / 'he-' <[ a..z \! \ ]> + /; #=> 'he-he !'
+# You'll get a warning if you put duplicate names
+# (which has the nice effect of catching the wrote quoting:)
+'he he' ~~ / <[ h e ' ' ]> /; # Warns "Repeated characters found in characters class"
+
+# You can also negate them ... (equivalent to `[^]` in PCRE)
+so 'foo' ~~ / <-[ f o ]> + /; # False
+
+# ... and compose them: :
+so 'foo' ~~ / <[ a..z ] - [ f o ]> + /; # False (any letter except f and o)
+so 'foo' ~~ / <-[ a..z ] + [ f o ]> + /; # True (no letter except f and o)
+so 'foo!' ~~ / <-[ a..z ] + [ f o ]> + /; # True (the + doesn't replace the left part)
+
+## Grouping and capturing
+# Group: you can group parts of your regexp with `[]`.
+# These groups are *not* captured (like PCRE's `(?:)`).
+so 'abc' ~~ / a [ b ] c /; # `True`. The grouping does pretty much nothing
+so 'fooABCABCbar' ~~ / foo [ A B C ] + bar /;
+# The previous line returns `True`.
+# We match the "abc" 1 or more time (the `+` was applied to the group).
+
+# But this does not go far enough, because we can't actually get back what
+# we matched.
+# Capture: We can actually *capture* the results of the regexp, using parentheses.
+so 'fooABCABCbar' ~~ / foo ( A B C ) + bar /; # `True`. (using `so` here, `$/` below)
+
+# So, starting with the grouping explanations.
+# As we said before, our `Match` object is available as `$/`:
+say $/; # Will print some weird stuff (we'll explain) (or "Nil" if nothing matched).
+
+# As we also said before, it has array indexing:
+say $/[0]; #=> 「ABC」 「ABC」
+ # These weird brackets are `Match` objects.
+ # Here, we have an array of these.
+say $0; # The same as above.
+
+# Our capture is `$0` because it's the first and only one capture in the regexp.
+# You might be wondering why it's an array, and the answer is simple:
+# Some capture (indexed using `$0`, `$/[0]` or a named one) will be an array
+# IFF it can have more than one element
+# (so, with `*`, `+` and `**` (whatever the operands), but not with `?`).
+# Let's use examples to see that:
+so 'fooABCbar' ~~ / foo ( A B C )? bar /; # `True`
+say $/[0]; #=> 「ABC」
+say $0.WHAT; #=> (Match)
+ # It can't be more than one, so it's only a single match object.
+so 'foobar' ~~ / foo ( A B C )? bar /; #=> True
+say $0.WHAT; #=> (Any)
+ # This capture did not match, so it's empty
+so 'foobar' ~~ / foo ( A B C ) ** 0..1 bar /; # `True`
+say $0.WHAT; #=> (Array)
+ # A specific quantifier will always capture an Array,
+ # may it be a range or a specific value (even 1).
+
+# The captures are indexed per nesting. This means a group in a group will be nested
+# under its parent group: `$/[0][0]`, for this code:
+'hello-~-world' ~~ / ( 'hello' ( <[ \- \~ ]> + ) ) 'world' /;
+say $/[0].Str; #=> hello~
+say $/[0][0].Str; #=> ~
+
+# This stems from a very simple fact: `$/` does not contain strings, integers or arrays,
+# it only contains match objects. These contain the `.list`, `.hash` and `.Str` methods.
+# (but you can also just use `match<key>` for hash access and `match[idx]` for array access)
+say $/[0].list.perl; #=> (Match.new(...),).list
+ # We can see it's a list of Match objects. Those contain a bunch of infos:
+ # where the match started/ended, the "ast" (see actions later), etc.
+ # You'll see named capture below with grammars.
+
+## Alternatives - the `or` of regexps
+# WARNING: They are DIFFERENT from PCRE regexps.
+so 'abc' ~~ / a [ b | y ] c /; # `True`. Either "b" or "y".
+so 'ayc' ~~ / a [ b | y ] c /; # `True`. Obviously enough ...
+
+# The difference between this `|` and the one you're used to is LTM.
+# LTM means "Longest Token Matching". This means that the engine will always
+# try to match as much as possible in the strng
+'foo' ~~ / fo | foo /; # `foo`, because it's longer.
+# To decide which part is the "longest", it first splits the regex in two parts:
+# The "declarative prefix" (the part that can be statically analyzed)
+# and the procedural parts.
+# Declarative prefixes include alternations (`|`), conjuctions (`&`),
+# sub-rule calls (not yet introduced), literals, characters classes and quantifiers.
+# The latter include everything else: back-references, code assertions,
+# and other things that can't traditionnaly be represented by normal regexps.
+#
+# Then, all the alternatives are tried at once, and the longest wins.
+# Exemples:
+# DECLARATIVE | PROCEDURAL
+/ 'foo' \d+ [ <subrule1> || <subrule2> ] /;
+# DECLARATIVE (nested groups are not a problem)
+/ \s* [ \w & b ] [ c | d ] /;
+# However, closures and recursion (of named regexps) are procedural.
+# ... There are also more complicated rules, like specificity
+# (literals win over character classes)
+
+# Note: the first-matching `or` still exists, but is now spelled `||`
+'foo' ~~ / fo || foo /; # `fo` now.
+
+
+
+
+### Extra: the MAIN subroutime
+# The `MAIN` subroutine is called when you run a Perl 6 file directly.
+# It's very powerful, because Perl 6 actually parses the argument
+# and pass them as such to the sub. It also handles named argument (`--foo`)
+# and will even go as far as to autogenerate a `--help`
+sub MAIN($name) { say "Hello, $name !" }
+# This produces:
+# $ perl6 cli.pl
+# Usage:
+# t.pl <name>
+
+# And since it's a regular Perl 6 sub, you can haz multi-dispatch:
+# (using a "Bool" for the named argument so that we can do `--replace`
+# instead of `--replace=1`)
+subset File of Str where *.IO.d; # convert to IO object to check the file exists
+
+multi MAIN('add', $key, $value, Bool :$replace) { ... }
+multi MAIN('remove', $key) { ... }
+multi MAIN('import', File, Str :$as) { ... } # omitting parameter name
+# This produces:
+# $ perl 6 cli.pl
+# Usage:
+# t.pl [--replace] add <key> <value>
+# t.pl remove <key>
+# t.pl [--as=<Str>] import (File)
+# As you can see, this is *very* powerful.
+# It even went as far as to show inline the constants.
+# (the type is only displayed if the argument is `$`/is named)
+```
+
+If you want to go further, you can:
+
+ - Read the [Perl 6 Advent Calendar](http://perl6advent.wordpress.com/). This is probably the greatest source of Perl 6 information, snippets and such.
+ - Come along on `#perl6` at `irc.freenode.net`. The folks here are always helpful.
+ - Check the [source of Perl 6's functions and classes](https://github.com/rakudo/rakudo/tree/nom/src/core). Rakudo is mainly written in Perl 6 (with a lot of NQP, "Not Quite Perl", a Perl 6 subset easier to implement and optimize).
+ - Read the [Synopses](perlcabal.org/syn). They explain it from an implementor point-of-view, but it's still very interesting.
+
diff --git a/php.html.markdown b/php.html.markdown
index e1bb86a0..039288a0 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/pt-br/c-pt.html.markdown b/pt-br/c-pt.html.markdown
new file mode 100644
index 00000000..451df4f3
--- /dev/null
+++ b/pt-br/c-pt.html.markdown
@@ -0,0 +1,649 @@
+---
+language: c
+filename: learnc.c
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+ - ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
+translators:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+lang: pt-br
+filename: c-pt.el
+---
+
+Ah, C. Ainda é **a** linguagem de computação de alta performance.
+
+C é a liguangem de mais baixo nível que a maioria dos programadores
+irão usar, e isso dá a ela uma grande velocidade bruta. Apenas fique
+antento que este manual de gerenciamento de memória e C vai levanter-te
+tão longe quanto você precisa.
+
+```c
+// Comentários de uma linha iniciam-se com // - apenas disponível a partir do C99
+
+/*
+Comentários de multiplas linhas se parecem com este.
+Funcionam no C89 também.
+*/
+
+// Constantes: #define <palavra-chave>
+#definie DAY_IN_YEAR 365
+
+//enumarações também são modos de definir constantes.
+enum day {DOM = 1, SEG, TER, QUA, QUI, SEX, SAB};
+// SEG recebe 2 automaticamente, TER recebe 3, etc.
+
+// Cabeçalhos são inclusos com #include
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+// (Nomes dos arquivos entre <colchetes> são cabeçalhos para bibliotecas padrão de C.)
+// Para cabeçalhos próprios, use aspas ao invés de colchetes:
+#include "minha_biblioteca.h"
+
+// Declare assinaturas das funções no início do arquivo .h ou no topo
+// do seu arquivo .c.
+void funcao_1(char c);
+int funcao_2(void);
+
+// Deve-se declarar um 'protótipo de função' antes do main() quando as ocorrências
+// dessas funções estão após sua função main()
+int soma_dois_ints(int x1, int x2); // protótipo de função
+
+// O ponto de entrada do teu programa é uma função
+// chamada main, com tipo de retorno inteiro
+int main() {
+ // Usa-se printf para escrever na tela,
+ // para "saída formatada"
+ // %d é um inteiro, \n é uma nova linha
+ printf("%d\n", 0); // => Imprime 0
+ // Todos as declarações devem acabar com
+ // ponto e vírgula
+
+ ///////////////////////////////////////
+ // Tipos
+ ///////////////////////////////////////
+
+ // ints normalmente tem 4 bytes
+ int x_int = 0;
+
+ // shorts normalmente tem 2 bytes
+ short x_short = 0;
+
+ // chars sempre tem um byte
+ char x_char = 0;
+ char y_char = 'y'; // Literais de caracter são cercados por '
+
+ // longs tem entre 4 e 8 bytes; longs long tem garantia
+ // de ter pelo menos 64 bits
+ long x_long = 0;
+ long long x_long_long = 0;
+
+ // floats são normalmente números de ponto flutuante
+ // com 32 bits
+ float x_float = 0.0;
+
+ // doubles são normalmente números de ponto flutuante
+ // com 64 bits
+ double x_double = 0.0;
+
+ // Tipos inteiros podem ser sem sinal.
+ unsigned short ux_short;
+ unsigned int ux_int;
+ unsigned long long ux_long_long;
+
+ // caracteres dentro de aspas simples são inteiros
+ // no conjunto de caracteres da máquina.
+ '0' // => 48 na tabela ASCII.
+ 'A' // => 65 na tabela ASCII.
+
+ // sizeof(T) devolve o tamanho de uma variável do tipo T em bytes
+ // sizeof(obj) devolve o tamanho de uma expressão (variável, literal, etc.).
+ printf("%zu\n", sizeof(int)); // => 4 (na maioria das máquinas com palavras de 4 bytes)
+
+ // Se o argumento do operador `sizeof` é uma expressão, então seus argumentos
+ // não são avaliados (exceto em VLAs (veja abaixo)).
+ // O valor devolve, neste caso, é uma constante de tempo de compilação.
+ int a = 1;
+ // size_t é um inteiro sem sinal com pelo menos 2 bytes que representa
+ // o tamanho de um objeto.
+ size_t size = sizeof(a++); // a++ não é avaliada.
+ printf("sizeof(a++) = %zu where a = %d\n", size, a);
+ // imprime "sizeof(a++) = 4 onde a = 1" (quando em uma arquitetura de 32 bits)
+
+ // Arrays precisam ser inicializados com um tamanho concreto
+ char meu_char_array[20]; // Este array ocupa 1 * 20 = 20 bytes
+ int meu_int_array[20]; // Este array ocupa 4 * 20 = 80 bytes
+ // (assumindo palavras de 4 bytes)
+
+ // Você pode inicializar um array com 0 desta forma:
+ char meu_array[20] = {0};
+
+ // Indexar um array é semelhante a outras linguages
+ // Melhor dizendo, outras linguagens são semelhantes a C
+ meu_array[0]; // => 0
+
+ // Array são mutáveis; são apenas memória!
+ meu_array[1] = 2;
+ printf("%d\n", meu_array[1]); // => 2
+
+ // No C99 (e como uma features opcional em C11), arrays de tamanho variável
+ // VLA (do inglês), podem ser declarados também. O tamanho destes arrays
+ // não precisam ser uma constante de tempo de compilação:
+ printf("Entre o tamanho do array: "); // Pergunta ao usuário pelo tamanho
+ char buf[0x100];
+ fgets(buf, sizeof buf, stdin);
+
+ // strtoul transforma a string em um inteiro sem sinal
+ size_t size = strtoul(buf, NULL, 10);
+ int var_length_array[size]; // declara o VLA
+ printf("sizeof array = %zu\n", sizeof var_length_array);
+
+ //Uma possível saída para esse programa seria:
+ // > Entre o tamanho do array:: 10
+ // > sizeof array = 40
+
+ // String são apenas arrays de caracteres terminados por um
+ // byte NUL (0x00), representado em string pelo caracter especial '\0'.
+ // (Não precisamos incluir o byte NUL em literais de string; o compilador
+ // o insere ao final do array para nós.)
+ char uma_string[20] = "Isto é uma string";
+ // Observe que 'é' não está na tabela ASCII
+ // A string vai ser salva, mas a saída vai ser estranha
+ // Porém, comentários podem conter acentos
+ printf("%s\n", uma_string); // %s formata a string
+
+ printf("%d\n", uma_string[16]); // => 0
+ // i.e., byte #17 é 0 (assim como 18, 19, e 20)
+
+ // Se temos caracteres entre aspas simples, temos um caracter literal.
+ // Seu tipo é `int`, *não* `char` (por razões históricas).
+ int cha = 'a'; // ok
+ char chb = 'a'; // ok também (conversão implícita de int para char)
+
+ // Arrays multi-dimensionais:
+ int multi_array[2][5] = {
+ {1, 2, 3, 4, 5},
+ {6, 7, 8, 9, 0}
+ };
+ // Acesso a elementos:
+ int array_int = multi_array[0][2]; // => 3
+
+ ///////////////////////////////////////
+ // Operadores
+ ///////////////////////////////////////
+
+ // Atalho para multiplas declarações:
+ int i1 = 1, i2 = 2;
+ float f1 = 1.0, f2 = 2.0;
+
+ int a, b, c;
+ a = b = c = 0;
+
+ // Aritimética é óbvia
+ i1 + i2; // => 3
+ i2 - i1; // => 1
+ i2 * i1; // => 2
+ i1 / i2; // => 0 (0.5, porém, é truncado para 0)
+
+ f1 / f2; // => 0.5, mais ou menos epsilon
+ // Números e cálculos de ponto flutuante não são exatos
+
+ // Modulo também existe
+ 11 % 3; // => 2
+
+ // Operadores de comparação provavelmente são familiares,
+ // porém não há tipo booleano em C. Usa-se ints no lugar.
+ // (Ou _Bool or bool em C99.)
+ // 0 é falso e qualquer outra coisa é verdadeiro
+ // (Os operadores de comparação devolvem 0 ou 1.)
+ // Comparison operators are probably familiar, but
+ 3 == 2; // => 0 (falso)
+ 3 != 2; // => 1 (verdadeiro)
+ 3 > 2; // => 1
+ 3 < 2; // => 0
+ 2 <= 2; // => 1
+ 2 >= 2; // => 1
+
+ // C não é Python - comparações não se encadeam.
+ int a = 1;
+ // Errado:
+ int entre_0_e_2 = 0 < a < 2;
+ // Correto:
+ int entre_0_e_2 = 0 < a && a < 2;
+
+ // Lógica funciona sobre ints
+ !3; // => 0 (Não lógico)
+ !0; // => 1
+ 1 && 1; // => 1 (E lógico)
+ 0 && 1; // => 0
+ 0 || 1; // => 1 (Ou lógico)
+ 0 || 0; // => 0
+
+ //Expressão condicional ( ? : )
+ int a = 5;
+ int b = 10;
+ int z;
+ z = (a > b) ? a : b; // => 10 "se a > b retorne a, senão retorne b."
+
+ //Operadores de incremento e decremento:
+ char *s = "iLoveC";
+ int j = 0;
+ s[j++]; // => "i". Retorna o j-ésimo item de s E DEPOIS incrementa o valor de j.
+ j = 0;
+ s[++j]; // => "L". Incrementa o valor de j. E DEPOIS retorna o j-ésimo item de s.
+ // o mesmo com j-- e --j
+
+ // Operadores bit a bit!
+ ~0x0F; // => 0xF0 (negação bit a bit, "complemento de 1")
+ 0x0F & 0xF0; // => 0x00 (bit a bit E)
+ 0x0F | 0xF0; // => 0xFF (bit a bit OU)
+ 0x04 ^ 0x0F; // => 0x0B (bit a bit OU EXCLUSIVO)
+ 0x01 << 1; // => 0x02 (bit a bit shift para esquerda (por 1))
+ 0x02 >> 1; // => 0x01 (bit a bit shift para direita (por 1))
+
+ // Cuidado quando fizer shift em inteiro com sinal - o seguinte é indefinido:
+ // - Fazer shift sobre um bit de sinal de um inteiro com sinal (int a = 1 << 32)
+ // - Fazer shift a esquerda sobre um número negativo (int a = -1 << 2)
+ // - Fazer shift maior que a largura do tipo de LHS:
+ // int a = 1 << 32; // Indefinido se int é de tamanho 32 bits
+
+ ///////////////////////////////////////
+ // Estruturas de Controle
+ ///////////////////////////////////////
+
+ if (0) {
+ printf("Nunca rodará\n");
+ } else if (0) {
+ printf("Também nunca rodará\n");
+ } else {
+ printf("Eu serei impresso\n");
+ }
+
+ // Loops while existem
+ int ii = 0;
+ while (ii < 10) { //QUALQUER valor diferente de 0 é verdadeiro
+ printf("%d, ", ii++); // ii++ incrementa o valor de ii APÓS usá-lo
+ } // => imprime "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ int kk = 0;
+ do {
+ printf("%d, ", kk);
+ } while (++kk < 10); // ++kk incrementa o valor de kk ANTES de usá-lo
+ // => imprime "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ // Loops for também
+ int jj;
+ for (jj=0; jj < 10; jj++) {
+ printf("%d, ", jj);
+ } // => imprime "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+
+ printf("\n");
+
+ // *****NOTAS*****:
+ // Loops e Funções PRECISAM ter um corpo. Se nenhum corpo é necessário:
+ int i;
+ for (i = 0; i <= 5; i++) {
+ ; // Use ponto e vírgula para agir como um corpo (declaração nula)
+ }
+
+ // Criando branchs com escolhas múltiplas: switch()
+ switch (alguma_expressao_integral) {
+ case 0: // labels precisam ser expressões integrais **constantes**
+ faca_algo();
+ break; // Sem break, o controle continua após a label
+ case 1:
+ faca_outra_coisa();
+ break;
+ default:
+ // Se `alguma_expressao_integral` não coincidir com nenhuma label
+ fputs("erro!\n", stderr);
+ exit(-1);
+ break;
+ }
+
+
+ ///////////////////////////////////////
+ // Cast de tipos
+ ///////////////////////////////////////
+
+ // Todo valor em C tem um tipo, mas você pode fazer um cast de um valor em outro tipo
+ // se você quiser (com algumas restrições).
+
+ int x_hex = 0x01; // Você pode colocar valores hexadecimais em variáveis
+
+ // Cast entre tipos tentará preservar seus valores numéricos
+ printf("%d\n", x_hex); // => Imprime 1
+ printf("%d\n", (short) x_hex); // => Imprime 1
+ printf("%d\n", (char) x_hex); // => Imprime 1
+
+ // Tipos irão ter overflow sem aviso
+ printf("%d\n", (unsigned char) 257); // => 1 (Max char = 255 se char tem 8 bits)
+
+ // Para determinar o valor máximo de um `char`, de um `signed char` e de
+ // um `unisigned char`, respectivamente, use as macros CHAR_MAX, SCHAR_MAX
+ // e UCHAR_MAX de <limits.h>
+
+ // Tipos inteiros podem sofrer cast para pontos-flutuantes e vice-versa.
+ printf("%f\n", (float)100); // %f formata um float
+ printf("%lf\n", (double)100); // %lf formata um double
+ printf("%d\n", (char)100.0);
+
+ ///////////////////////////////////////
+ // Ponteiros
+ ///////////////////////////////////////
+
+ // Um ponteiro é uma variável declarada para armazenar um endereço de memória.
+ // Seu declaração irá também dizer o tipo de dados para o qual ela aponta. Você
+ // Pode usar o endereço de memória de suas variáveis, então, brincar com eles.
+
+ int x = 0;
+ printf("%p\n", (void *)&x); // Use & para usar o endereço de uma variável
+ // (%p formata um objeto ponteiro do tipo void *)
+ // => Imprime algum endereço de memória;
+
+ // Ponteiros começam com * na sua declaração
+ int *px, nao_eh_um_ponteiro; // px é um ponteiro para um int
+ px = &x; // armazena o endereço de x em px
+ printf("%p\n", (void *)px); // => Imprime algum endereço de memória
+ printf("%zu, %zu\n", sizeof(px), sizeof(nao_eh_um_ponteiro));
+ // => Imprime "8, 4" em um sistema típico de 64 bits
+
+ // Para pegar um valor no endereço apontado por um ponteiro,
+ // coloque * na frente para de-referenciá-lo.
+ // Nota: sim, é confuso usar '*' _tanto_ para declaração de ponteiro
+ // como para de-referenciá-lo.
+ printf("%d\n", *px); // => Imprime 0, o valor de x
+
+ // Você também pode mudar o valor que o ponteiro está apontando.
+ // Teremo que cercar a de-referência entre parenteses, pois
+ // ++ tem uma precedência maior que *.
+ (*px)++; // Incrementa o valor que px está apontando por 1
+ printf("%d\n", *px); // => Imprime 1
+ printf("%d\n", x); // => Imprime 1
+
+ // Arrays são um boa maneira de alocar um bloco contínuo de memória
+ int x_array[20]; // Declara um array de tamanho 20 (não pode-se mudar o tamanho
+ int xx;
+ for (xx = 0; xx < 20; xx++) {
+ x_array[xx] = 20 - xx;
+ } //Inicializa x_array com 20, 19, 18,... 2, 1
+
+ // Declara um ponteiro do tipo int e inicialize ele para apontar para x_array
+ int* x_ptr = x_array;
+ // x_ptr agora aponta para o primeiro elemento do array (o inteiro 20).
+ // Isto funciona porque arrays são apenas ponteiros para seu primeiros elementos.
+ // Por exemplo, quando um array é passado para uma função ou é atribuído a um
+ // ponteiro, ele transforma-se (convertido implicitamente) em um ponteiro.
+ // Exceções: quando o array é o argumento de um operador `&` (endereço-de):
+ // Exceptions: when the array is the argument of the `&` (address-of) operator:
+ int arr[10];
+ int (*ptr_to_arr)[10] = &arr; // &arr não é do tipo `int *`!
+ // É do tipo "ponteiro para array" (de `int`s).
+ // ou quando o array é uma string literal usada para inicializar um array de char:
+ char arr[] = "foobarbazquirk";
+ // ou quando é um argumento dos operadores `sizeof` ou `alignof`:
+ int arr[10];
+ int *ptr = arr; // equivalente a int *ptr = &arr[0];
+ printf("%zu, %zu\n", sizeof arr, sizeof ptr); // provavelmente imprime "40, 4" ou "40, 8"
+
+ // Ponteiros podem ser incrementados ou decrementados baseado no seu tipo
+ // (isto é chamado aritimética de ponteiros
+ printf("%d\n", *(x_ptr + 1)); // => Imprime 19
+ printf("%d\n", x_array[1]); // => Imprime 19
+
+ // Você também pode alocar dinamicamente blocos de memória com a função
+ // da biblioteca padrão malloc, a qual recebe um argumento do tipo size_t
+ // representando o número de bytes a ser alocado (geralmente da heap, apesar de
+ // isto poder não ser verdadeiro em, e.g., sistemas embarcados - o C padrão diz
+ // nada sobre isso).
+ int *my_ptr = malloc(sizeof(*my_ptr) * 20);
+ for (xx = 0; xx < 20; xx++) {
+ *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx
+ } //Inicializa a memória com 20, 19, 18, 17... 2, 1 (como ints)
+
+ // Dereferenciar memória que você não alocou cria
+ // "resultados imprevisíveis" - o programa é dito ter um "comportamento indefinido"
+ printf("%d\n", *(my_ptr + 21)); // => Imprime quem-sabe-o-que? Talvez até quebre o programa.
+
+ // Quando termina-se de usar um bloco de memória alocado, você pode liberá-lo,
+ // ou ninguém mais será capaz de usá-lo até o fim da execução
+ // (Isto cham-se "memory leak"):
+ free(my_ptr);
+
+ // Strings são arrays de char, mas elas geralmente são representadas
+ // como um ponteiro para char (com o apontador para o primeiro elemento do array).
+ // É boa prática usar `const char *' quando de-referenciando uma literal string,
+ // dado que elas não deverão ser modificadas (i.e. "foo"[0] = 'a' é ILEGAL.)
+ const char *my_str = "Esta é a minha literal string";
+ printf("%c\n", *my_str); // => 'T'
+
+ // Este não é o caso se a string for um array
+ // (potencialmente inicializado com um literal string)
+ // que reside em uma memória de escrita, como em:
+ char foo[] = "foo";
+ foo[0] = 'a'; // Isto é legal, foo agora contém "aoo"
+
+ funcao_1();
+} // fim da função main
+
+///////////////////////////////////////
+// Funções
+///////////////////////////////////////
+
+//Sintaxe de declaração de funções:
+// <tipo de retorno> <nome da função>(<argumentos>)
+
+int soma_dois_int(int x1, int x2)
+{
+ return x1 + x2; // Use return para retornar um valor
+}
+
+/*
+Funções são chamadas por valor. Quando uma função é chamada, os argumentos passados
+para a função são cópias dos argumento originais (a não ser arrays). Qualquer coisa
+que você faz nos argumentos de uma função não alteram o valor do argumento original
+onde a função foi chamada.
+
+Use ponteiros se você precisa alterar os valores dos argumentos originais
+
+Exemplo: reversão de string in-place
+*/
+
+// Uma função void não retorna valor algum
+void str_reverse(char *str_in)
+{
+ char tmp;
+ int ii = 0;
+ size_t len = strlen(str_in); // `strlen()` é parte da biblioteca padrão C
+ for (ii = 0; ii < len / 2; ii++) {
+ tmp = str_in[ii];
+ str_in[ii] = str_in[len - ii - 1]; // iiº char do final
+ str_in[len - ii - 1] = tmp;
+ }
+}
+
+/*
+char c[] = "Isto é um teste.";
+str_reverse(c);
+printf("%s\n", c); // => ".etset mu é otsI"
+*/
+
+// Se estiver referenciando variáveis externas à função, use a palavra-chave extern.
+int i = 0;
+void testFunc() {
+ extern int i; //i aqui agora está usando a variável externa
+}
+
+// Faça variáveis externas privadas para o código-fonte com static:
+static int i = 0; // Outros arquivos usando testFunc() não podem acessar a variável i
+void testFunc() {
+ extern int i;
+}
+//**Você pode declarar funções como static para torná-las privadas**
+
+
+///////////////////////////////////////
+// Tipos definidos pelo usuário e structs
+///////////////////////////////////////
+
+// Typedefs podem ser usadas para criar apelidos para tipos
+typedef int meu_tipo;
+meu_tipo var_meu_tipo = 0;
+
+// Structs são apenas coleções de dados, os membros são alocados sequencialmente,
+// na ordem que são escritos:
+struct retangulo {
+ int altura;
+ int largura;
+};
+
+// Geralmente não é verdade que
+// sizeof(struct retangulo) == sizeof(int) + sizeof(int)
+// devido ao potencial de preenchimento entre os membros da estrutura
+// (isto é por razões de alinhamento). [1]
+
+void funcao_1()
+{
+ struct retangulo meu_retan;
+
+ // Acesse os membros da estrutura com .
+ meu_retan.altura = 10;
+ meu_retan.largura = 20;
+
+ // Você pode declarar ponteiros para structs
+ struct retangulo *meu_retan_ptr = &meu_retan;
+
+ // Use de-referenciamento para setar os membros da
+ // struct apontada...
+ (*meu_retan_ptr).altura = 30;
+
+ // ... ou ainda melhor: prefira usar o atalho -> para melhorar legibilidade
+ meu_retan_ptr->largura = 10; // O mesmo que (*meu_retan_ptr).largura = 10;
+}
+
+//Você pode aplicar um typedef para uma struct por conveniência
+typedef struct retangulo retan;
+
+int area(retan r)
+{
+ return r.largura * r.altura;
+}
+
+// Se você tiver structus grande, você pode passá-las "por ponteiro"
+// para evitar cópia de toda a struct:
+int area(const retan *r)
+{
+ return r->largura * r->altura;
+}
+
+///////////////////////////////////////
+// Ponteiros para funções
+///////////////////////////////////////
+/*
+Em tempo de execução, funções são localizadas em endereços de memória
+conhecidos. Ponteiros para funções são como qualquer outro ponteiro
+(apenas guardam endereços de memória), mas podem ser usados para invocar funções
+diretamente e passá-las para por toda parte.
+Entretanto, a sintaxe de definição por ser um pouco confusa.
+
+Exemplo: use str_reverso através de um ponteiro
+*/
+void str_reverso_através_ponteiro(char *str_entrada) {
+ // Define uma variável de ponteiro para função, nomeada f.
+ void (*f)(char *); //Assinatura deve ser exatamente igual à função alvo.
+ f = &str_reverso; //Atribue o endereço da função em si (determinado em tempo de execução.
+ // f = str_reverso; Também funciona - função tornam-se ponteiros, assim como arrays
+ (*f)(str_entrada); // Chamando a função através do ponteiro
+ // f(str_entrada); // Esta é uma sintaxe alternativa, mas equivalente.
+}
+
+/*
+Desde que as assinaturas das funções sejam compatíveis, você pode atribuir qualquer
+função ao mesmo ponteiro. Ponteiros para funções são geralmente um typedef por
+simplicidade e legibilidade, como segue:
+*/
+
+typedef void (*minha_função_type)(char *);
+
+// Declarando o ponteiro:
+// ...
+// minha_função_type f;
+
+//Caracteres especiais:
+'\a' // Alerta (sino)
+'\n' // Nova linha
+'\t' // Tab (justifica texto a esquerda)
+'\v' // Tab vertical
+'\f' // Nova linha (formfeed)
+'\r' // Retorno de carroça
+'\b' // Backspace
+'\0' // Caracter nulo. Geralmente colocado ao final de string em C.
+ // oi\n\0. \0 é usado por convenção para marcar o fim da string.
+'\\' // Barra invertida
+'\?' // Interrogação
+'\'' // Aspas simples
+'\"' // Aspas duplas
+'\xhh' // Número hexadecimal. Exemplo: '\xb' = tab vertical
+'\ooo' // Número octal. Exemplo: '\013' = tab vertical
+
+// formatando impressão:
+"%d" // inteiro
+"%3d" // inteiro com pelo menos 3 dígitos (justifica texto a direita)
+"%s" // string
+"%f" // ponto-flutuante
+"%ld" // long
+"%3.2f" // ponto-flutuante com pelo menos 3 dígitos a esquerda e 2 a direita
+"%7.4s" // (também pode-se fazer com strings)
+"%c" // char
+"%p" // ponteiro
+"%x" // hexadecimal
+"%o" // octal
+"%%" // imprime %
+
+///////////////////////////////////////
+// Ordem de avaliação
+///////////////////////////////////////
+
+//-----------------------------------------------------------//
+// Operadores | Associatividade //
+//-----------------------------------------------------------//
+// () [] -> . | esquerda para direita //
+// ! ~ ++ -- + = *(type)sizeof | direita para esqureda //
+// * / % | esquerda para direita //
+// + - | esquerda para direita //
+// << >> | esquerda para direita //
+// < <= > >= | esquerda para direita //
+// == != | esquerda para direita //
+// & | esquerda para direita //
+// ^ | esquerda para direita //
+// | | esquerda para direita //
+// && | esquerda para direita //
+// || | esquerda para direita //
+// ?: | direita para esqureda //
+// = += -= *= /= %= &= ^= |= <<= >>= | direita para esqureda //
+// , | esquerda para direita //
+//-----------------------------------------------------------//
+
+```
+
+## Leitura adicional
+
+É recomendado ter uma cópia de [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language).
+Este é *o* livro sobre C, escrito pelos criadores da linguage. Mas cuidado - ele é antigo e contém alguns erros (bem,
+ideias que não são consideradas boas hoje) ou práticas mudadas.
+
+Outra boa referência é [Learn C the hard way](http://c.learncodethehardway.org/book/).
+
+Se você tem uma pergunta, leia [compl.lang.c Frequently Asked Questions](http://c-faq.com).
+
+É importante usar espaços e indentação adequadamente e ser consistente com seu estilo de código em geral.
+Código legível é melhor que código 'esperto' e rápido. Para adotar um estilo de código bom e são, veja
+[Linux kernel coding stlye](https://www.kernel.org/doc/Documentation/CodingStyle).
+
+Além disso, Google é teu amigo.
+[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member
diff --git a/pt-br/coffeescript-pt.html.markdown b/pt-br/coffeescript-pt.html.markdown
new file mode 100644
index 00000000..8b1094b1
--- /dev/null
+++ b/pt-br/coffeescript-pt.html.markdown
@@ -0,0 +1,106 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["Miguel Araújo", "https://github.com/miguelarauj1o"]
+lang: pt-br
+filename: learncoffeescript-pt.coffee
+---
+
+CoffeeScript é uma pequena linguagem que compila um-para-um para o JavaScript
+equivalente, e não há interpretação em tempo de execução. Como um dos sucessores
+de JavaScript, CoffeeScript tenta o seu melhor para exibir uma saída legível,
+bem-impressa e bom funcionamento dos códigos JavaScript em todo o tempo de
+execução JavaScript.
+
+Veja também [site do CoffeeScript](http://coffeescript.org/), que tem um tutorial
+completo sobre CoffeeScript.
+
+``` coffeescript
+#CoffeeScript é uma linguagem moderna
+#Segue as tendências de muitas linguagens modernas
+#Assim, os comentários são iguais a Ruby e Python, eles usam símbolos numéricos.
+
+###
+Os comentários em bloco são como estes, e eles traduzem diretamente para '/ *'s e
+'* /'s para o código JavaScript que resulta...
+
+Você deveria entender mais de semântica de JavaScript antes de continuar...
+###
+
+# Tarefa:
+numero = 42 #=> número var = 42;
+oposto = true #=> var oposto = true;
+
+# Condições:
+numero = -42 if oposto #=> if (oposto) {número = -42;}
+
+# Funções:
+quadrado = (x) -> x * x #=> var quadrado = function (x) {return x * x;}
+
+preencher = (recipiente, líquido = "coffee") ->
+ "Preenchendo o #{recipiente} with #{líquido}..."
+#=>var preencher;
+#
+#preencher = function(recipiente, líquido) {
+# if (líquido == null) {
+# líquido = "coffee";
+# }
+# return "Preenchendo o " + recipiente + " with " + líquido + "...";
+#};
+
+# Alcances:
+list = [1 .. 5] #=> lista var = [1, 2, 3, 4, 5];
+
+# Objetos:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Splats:
+corrida = (vencedor, corredores...) ->
+ print vencedor, corredores
+#=>corrida = function() {
+# var corredores, vencedor;
+# vencedor = arguments[0], corredores = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(vencedor, corredores);
+#};
+
+# Existências:
+alert "Eu sabia!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("Eu sabia!"); }
+
+# Compressão de Matrizes:
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+comidas = ['brócolis', 'espinafre', 'chocolate']
+eat alimento for alimento in comidas when alimento isnt 'chocolate'
+#=>comidas = ['brócolis', 'espinafre', 'chocolate'];
+#
+#for (_k = 0, _len2 = comidas.length; _k < _len2; _k++) {
+# alimento = comidas[_k];
+# if (alimento !== 'chocolate') {
+# eat(alimento);
+# }
+
+## Recursos adicionais
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read) \ No newline at end of file
diff --git a/pt-br/git-pt.html.markdown b/pt-br/git-pt.html.markdown
new file mode 100644
index 00000000..6d2a55cd
--- /dev/null
+++ b/pt-br/git-pt.html.markdown
@@ -0,0 +1,402 @@
+---
+category: tool
+tool: git
+contributors:
+ - ["Jake Prather", "http://github.com/JakeHP"]
+translators:
+ - ["Miguel Araújo", "https://github.com/miguelarauj1o"]
+lang: pt-br
+filename: learngit-pt.txt
+---
+
+Git é um sistema de controle de versão distribuído e de gerenciamento de código-fonte.
+
+Ele faz isso através de uma série de momentos instantâneos de seu projeto, e ele funciona
+com esses momentos para lhe fornecer a funcionalidade para a versão e
+gerenciar o seu código-fonte.
+
+## Versionando Conceitos
+
+### O que é controle de versão?
+
+O controle de versão é um sistema que registra alterações em um arquivo ou conjunto
+de arquivos, ao longo do tempo.
+
+### Versionamento Centralizado VS Versionamento Distribuído
+
+* Controle de versão centralizado concentra-se na sincronização, controle e backup de arquivos.
+* Controle de versão distribuído concentra-se na partilha de mudanças. Toda mudança tem um ID único.
+* Sistemas Distribuídos não têm estrutura definida. Você poderia facilmente ter um estilo SVN,
+sistema centralizado, com git.
+
+[Informação Adicional](http://git-scm.com/book/en/Getting-Started-About-Version-Control)
+
+### Porque usar o Git?
+
+* Possibilidade de trabalhar offline
+* Colaborar com os outros é fácil!
+* Ramificação é fácil
+* Mesclagem é fácil
+* Git é rápido
+* Git é flexível.
+
+## Arquitetura Git
+
+### Repositório
+
+Um conjunto de arquivos, diretórios, registros históricos, cometes, e cabeças. Imagine-o
+como uma estrutura de dados de código-fonte, com o atributo que cada "elemento" do
+código-fonte dá-lhe acesso ao seu histórico de revisão, entre outras coisas.
+
+Um repositório git é composto do diretório git. e árvore de trabalho.
+
+### Diretório .git (componente do repositório)
+
+O diretório git. contém todas as configurações, registros, galhos, cabeça(HEAD) e muito mais.
+[Lista Detalhada](http://gitready.com/advanced/2009/03/23/whats-inside-your-git-directory.html)
+
+### Árvore de trabalho (componente do repositório)
+
+Esta é, basicamente, os diretórios e arquivos no seu repositório. Ele é muitas vezes referida
+como seu diretório de trabalho.
+
+### Índice (componente do diretório .git)
+
+O Índice é a área de teste no git. É basicamente uma camada que separa a sua árvore de trabalho
+a partir do repositório Git. Isso dá aos desenvolvedores mais poder sobre o que é enviado para o
+repositório Git.
+
+### Comete (commit)
+
+A commit git é um instantâneo de um conjunto de alterações ou manipulações a sua árvore de trabalho.
+Por exemplo, se você adicionou 5 imagens, e removeu outros dois, estas mudanças serão contidas
+em um commit (ou instantâneo). Esta confirmação pode ser empurrado para outros repositórios, ou não!
+
+### Ramo (branch)
+
+Um ramo é, essencialmente, um ponteiro que aponta para o último commit que você fez. Como
+você se comprometer, este ponteiro irá atualizar automaticamente e apontar para o último commit.
+
+### Cabeça (HEAD) e cabeça (head) (componente do diretório .git)
+
+HEAD é um ponteiro que aponta para o ramo atual. Um repositório tem apenas 1 * ativo * HEAD.
+head é um ponteiro que aponta para qualquer commit. Um repositório pode ter qualquer número de commits.
+
+### Recursos Conceituais
+
+* [Git para Cientistas da Computação](http://eagain.net/articles/git-for-computer-scientists/)
+* [Git para Designers](http://hoth.entp.com/output/git_for_designers.html)
+
+## Comandos
+
+### init
+
+Criar um repositório Git vazio. As configurações do repositório Git, informações armazenadas,
+e mais são armazenados em um diretório (pasta) com o nome ". git".
+
+```bash
+$ git init
+```
+
+### config
+
+Para configurar as definições. Quer seja para o repositório, o próprio sistema, ou
+configurações globais.
+
+```bash
+# Impressão e definir algumas variáveis ​​de configuração básica (global)
+$ git config --global user.email
+$ git config --global user.name
+
+$ git config --global user.email "MyEmail@Zoho.com"
+$ git config --global user.name "My Name"
+```
+
+[Saiba mais sobre o git config.](http://git-scm.com/docs/git-config)
+
+### help
+
+Para lhe dar um acesso rápido a um guia extremamente detalhada de cada comando. ou
+apenas dar-lhe um rápido lembrete de algumas semânticas.
+
+```bash
+# Rapidamente verificar os comandos disponíveis
+$ git help
+
+# Confira todos os comandos disponíveis
+$ git help -a
+
+# Ajuda específica de comando - manual do usuário
+# git help <command_here>
+$ git help add
+$ git help commit
+$ git help init
+```
+
+### status
+
+Para mostrar as diferenças entre o arquivo de índice (basicamente o trabalho de
+copiar/repo) e a HEAD commit corrente.
+
+```bash
+# Irá exibir o ramo, os arquivos não monitorados, as alterações e outras diferenças
+$ git status
+
+# Para saber outras "tid bits" sobre git status
+$ git help status
+```
+
+### add
+
+Para adicionar arquivos para a atual árvore/directory/repo trabalho. Se você não
+der `git add` nos novos arquivos para o trabalhando árvore/diretório, eles não serão
+incluídos em commits!
+
+```bash
+# Adicionar um arquivo no seu diretório de trabalho atual
+$ git add HelloWorld.java
+
+# Adicionar um arquivo em um diretório aninhado
+$ git add /path/to/file/HelloWorld.c
+
+# Suporte a expressões regulares!
+$ git add ./*.java
+```
+
+### branch
+
+Gerenciar seus ramos. Você pode visualizar, editar, criar, apagar ramos usando este comando.
+
+```bash
+# Lista ramos e controles remotos existentes
+$ git branch -a
+
+# Criar um novo ramo
+$ git branch myNewBranch
+
+# Apagar um ramo
+$ git branch -d myBranch
+
+# Renomear um ramo
+# git branch -m <oldname> <newname>
+$ git branch -m myBranchName myNewBranchName
+
+# Editar a descrição de um ramo
+$ git branch myBranchName --edit-description
+```
+
+### checkout
+
+Atualiza todos os arquivos na árvore de trabalho para corresponder à versão no
+índice, ou árvore especificada.
+
+```bash
+# Finalizar um repo - padrão de ramo mestre
+$ git checkout
+# Checa um ramo especificado
+$ git checkout branchName
+# Criar um novo ramo e mudar para ela, como: "<nome> git branch; git checkout <nome>"
+$ git checkout -b newBranch
+```
+
+### clone
+
+Clones, ou cópias, de um repositório existente para um novo diretório. Ele também adiciona
+filiais remotas de rastreamento para cada ramo no repo clonado, que permite que você empurre
+a um ramo remoto.
+
+```bash
+# Clone learnxinyminutes-docs
+$ git clone https://github.com/adambard/learnxinyminutes-docs.git
+```
+
+### commit
+
+Armazena o conteúdo atual do índice em um novo "commit". Este commit contém
+as alterações feitas e uma mensagem criada pelo utilizador.
+
+```bash
+# commit com uma mensagem
+$ git commit -m "Added multiplyNumbers() function to HelloWorld.c"
+```
+
+### diff
+
+Mostra as diferenças entre um arquivo no diretório, o índice de trabalho e commits.
+
+```bash
+# Mostrar diferença entre o seu diretório de trabalho e o índice.
+$ git diff
+
+# Mostrar diferenças entre o índice e o commit mais recente.
+$ git diff --cached
+
+# Mostrar diferenças entre o seu diretório de trabalho e o commit mais recente.
+$ git diff HEAD
+```
+
+### grep
+
+Permite procurar rapidamente um repositório.
+
+Configurações opcionais:
+
+```bash
+# Obrigado ao Travis Jeffery por isto
+# Configure os números de linha a serem mostrados nos resultados de busca grep
+$ git config --global grep.lineNumber true
+
+# Fazer resultados de pesquisa mais legível, incluindo agrupamento
+$ git config --global alias.g "grep --break --heading --line-number"
+```
+
+```bash
+# Procure por "variableName" em todos os arquivos java
+$ git grep 'variableName' -- '*.java'
+
+# Procure por uma linha que contém "arrayListName" e "adicionar" ou "remover"
+$ git grep -e 'arrayListName' --and \( -e add -e remove \)
+```
+
+Google é seu amigo; para mais exemplos
+[Git Grep Ninja](http://travisjeffery.com/b/2012/02/search-a-git-repo-like-a-ninja)
+
+### log
+
+Mostrar commits para o repositório.
+
+```bash
+# Mostrar todos os commits
+$ git log
+
+# Mostrar um número X de commits
+$ git log -n 10
+
+# Mostrar somente commits mesclados
+$ git log --merges
+```
+
+### merge
+
+"Merge" em mudanças de commits externos no branch atual.
+
+```bash
+# Mesclar o ramo especificado para o atual.
+$ git merge branchName
+
+# Gera sempre uma mesclagem commit ao mesclar
+$ git merge --no-ff branchName
+```
+
+### mv
+
+Renomear ou mover um arquivo
+
+```bash
+# Renomear um arquivo
+$ git mv HelloWorld.c HelloNewWorld.c
+
+# Mover um arquivo
+$ git mv HelloWorld.c ./new/path/HelloWorld.c
+
+# Força renomear ou mover
+# "ExistingFile" já existe no diretório, será substituído
+$ git mv -f myFile existingFile
+```
+
+### pull
+
+Puxa de um repositório e se funde com outro ramo.
+
+```bash
+# Atualize seu repo local, através da fusão de novas mudanças
+# A partir da "origem" remoto e ramo "master (mestre)".
+# git pull <remote> <branch>
+# git pull => implícito por padrão => git pull origin master
+$ git pull origin master
+
+# Mesclar em mudanças de ramo remoto e rebase
+# Ramo commita em seu repo local, como: "git pull <remote> <branch>, git rebase <branch>"
+$ git pull origin master --rebase
+```
+
+### push
+
+Empurre e mesclar as alterações de uma ramificação para uma remota e ramo.
+
+```bash
+# Pressione e mesclar as alterações de um repo local para um
+# Chamado remoto "origem" e ramo de "mestre".
+# git push <remote> <branch>
+# git push => implícito por padrão => git push origin master
+$ git push origin master
+
+# Para ligar atual filial local com uma filial remota, bandeira add-u:
+$ git push -u origin master
+# Agora, a qualquer hora que você quer empurrar a partir desse mesmo ramo local, uso de atalho:
+$ git push
+```
+
+### rebase (CAUTELA)
+
+Tire todas as alterações que foram commitadas em um ramo, e reproduzi-las em outro ramo.
+* Não rebase commits que você tenha empurrado a um repo público *.
+
+```bash
+# Rebase experimentBranch para mestre
+# git rebase <basebranch> <topicbranch>
+$ git rebase master experimentBranch
+```
+
+[Leitura Adicional.](http://git-scm.com/book/en/Git-Branching-Rebasing)
+
+### reset (CAUTELA)
+
+Repor o atual HEAD de estado especificado. Isto permite-lhe desfazer fusões (merge),
+puxa (push), commits, acrescenta (add), e muito mais. É um grande comando, mas também
+perigoso se não saber o que se está fazendo.
+
+```bash
+# Repor a área de teste, para coincidir com o último commit (deixa diretório inalterado)
+$ git reset
+
+# Repor a área de teste, para coincidir com o último commit, e substituir diretório trabalhado
+$ git reset --hard
+
+# Move a ponta ramo atual para o especificado commit (deixa diretório inalterado)
+# Todas as alterações ainda existem no diretório.
+$ git reset 31f2bb1
+
+# Move a ponta ramo atual para trás, para o commit especificado
+# E faz o jogo dir trabalho (exclui mudanças não commitadas e todos os commits
+# Após o commit especificado).
+$ git reset --hard 31f2bb1
+```
+
+### rm
+
+O oposto do git add, git rm remove arquivos da atual árvore de trabalho.
+
+```bash
+# remove HelloWorld.c
+$ git rm HelloWorld.c
+
+# Remove um arquivo de um diretório aninhado
+$ git rm /pather/to/the/file/HelloWorld.c
+```
+
+# # Mais informações
+
+* [tryGit - A fun interactive way to learn Git.](http://try.github.io/levels/1/challenges/1)
+
+* [git-scm - Video Tutorials](http://git-scm.com/videos)
+
+* [git-scm - Documentation](http://git-scm.com/docs)
+
+* [Atlassian Git - Tutorials & Workflows](https://www.atlassian.com/git/)
+
+* [SalesForce Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)
+
+* [GitGuys](http://www.gitguys.com/)
+
+* [Git - guia prático](http://rogerdudler.github.io/git-guide/index.pt_BR.html) \ No newline at end of file
diff --git a/pt-br/go-pt.html.markdown b/pt-br/go-pt.html.markdown
index cca58b16..c7339831 100644
--- a/pt-br/go-pt.html.markdown
+++ b/pt-br/go-pt.html.markdown
@@ -6,6 +6,7 @@ filename: learngo-pt.go
lang: pt-br
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["Jose Donizetti", "https://github.com/josedonizetti"]
translators:
- ["Nuno Antunes", "https://github.com/ntns"]
---
@@ -74,7 +75,7 @@ func learnTypes() {
pode incluir quebras de linha.` // mesmo tipo string
// literal não-ASCII. A linguagem Go utiliza de raiz a codificação UTF-8.
- g := 'Σ' // tipo rune, um alias para uint32, que contém um código unicode
+ g := 'Σ' // tipo rune, um alias para int32, que contém um código unicode
f := 3.14195 // float64, número de vírgula flutuante de 64bit (IEEE-754)
c := 3 + 4i // complex128, representado internamente com dois float64s
@@ -306,3 +307,6 @@ a melhor demonstração de código fácil de ler e de perceber, do estilo Go, e
sua escrita idiomática. Ou então clique no nome de uma função na [documentação]
(http://golang.org/pkg/) e veja o código fonte aparecer!
+Outra ótima fonte para aprender Go é o [Go by example](https://gobyexample.com/).
+Apesar de ser em inglês, é possível recodificar os exemplos para aprender sobre
+a linguagem.
diff --git a/pt-br/haskell-pt.html.markdown b/pt-br/haskell-pt.html.markdown
index 55f90bd6..788dc1d2 100644
--- a/pt-br/haskell-pt.html.markdown
+++ b/pt-br/haskell-pt.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
translators:
diff --git a/pt-br/json-pt.html.markdown b/pt-br/json-pt.html.markdown
new file mode 100644
index 00000000..fc63b126
--- /dev/null
+++ b/pt-br/json-pt.html.markdown
@@ -0,0 +1,62 @@
+---
+language: json
+contributors:
+ - ["Anna Harren", "https://github.com/iirelu"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["Miguel Araújo", "https://github.com/miguelarauj1o"]
+lang: pt-br
+filename: learnjson-pt.json
+---
+
+Como JSON é um formato de intercâmbio de dados, este será, muito provavelmente, o
+"Learn X in Y minutes" mais simples existente.
+
+JSON na sua forma mais pura não tem comentários em reais, mas a maioria dos analisadores
+aceitarão comentários no estilo C (//, /\* \*/). Para os fins do presente, no entanto,
+tudo o que é vai ser 100% JSON válido. Felizmente, isso meio que fala por si.
+
+
+```json
+{
+ "chave": "valor",
+
+ "chaves": "deve ser sempre entre aspas (junto ou separado)",
+ "números": 0,
+ "strings": "Olá, mundo. Todo o padrão UNICODE é permitido, junto com \"escapando\".",
+ "possui booleano?": true,
+ "nada": null,
+
+ "número grande": 1.2e+100,
+
+ "objetos": {
+ "comentário": "A maior parte da sua estrutura virá de objetos.",
+
+ "array": [0, 1, 2, 3, "Arrays podem ter qualquer coisa em si.", 5],
+
+ "outro objeto": {
+ "ccomentário": "Estas coisas podem ser aninhadas, muito úteis."
+ }
+ },
+
+ "tolice": [
+ {
+ "fonte de potássio": ["bananas"]
+ },
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, "neo"],
+ [0, 0, 0, 1]
+ ]
+ ],
+
+ "estilo alternativo": {
+ "comentário": "verificar isso!"
+ , "posição da vírgula": "não importa - enquanto é antes do valor, então é válido"
+ , "outro comentário": "que bom"
+ },
+
+ "que foi curto": "E, você está feito. Você já sabe tudo que JSON tem para oferecer.".
+}
+```
diff --git a/pt-br/markdown-pt.html.markdown b/pt-br/markdown-pt.html.markdown
new file mode 100644
index 00000000..4030ce3c
--- /dev/null
+++ b/pt-br/markdown-pt.html.markdown
@@ -0,0 +1,251 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators:
+ - ["Miguel Araújo", "https://github.com/miguelarauj1o"]
+lang: pt-br
+filename: learnmarkdown-pt.md
+---
+
+Markdown foi criado por John Gruber in 2004. Originado para ser fácil de ler e
+escrever sintaxe que converte facilmente em HTML (hoje, suporta outros formatos também).
+
+Dê-me feedback tanto quanto você quiser! / Sinta-se livre para a garfar (fork) e
+puxar o projeto (pull request)
+
+```markdown
+<!-- Markdown é um superconjunto do HTML, de modo que qualquer arvquivo HTML é
+um arquivo Markdown válido, isso significa que nós podemos usar elementos HTML
+em Markdown, como o elemento de comentário, e eles não serão afetados pelo analisador
+de remarcação. No entanto, se você criar um elemento HTML em seu arquivo Markdown, você
+não pode usar sintaxe remarcação dentro desse conteúdo do elemento.-->
+
+<!--Markdown também varia de implementação de um analisador para uma próxima.
+Este guia vai tentar esclarecer quando as características são universais, ou quando eles são
+específico para um determinado parser -->
+
+<!-- Cabeçalhos -->
+<!-- Você pode criar elementos HTML <h1> até <h6> facilmente antecedendo o texto
+que deseja estar nesse elemento por um número de hashes (#) -->
+# Isto é um cabeçalho <h1>
+## Isto é um cabeçalho <h2>
+### Isto é um cabeçalho <h3>
+#### Isto é um cabeçalho <h4>
+##### Isto é um cabeçalho <h5>
+###### Isto é um cabeçalho <h6>
+
+<!-- Markdown também nos fornece duas maneiras alternativas de indicar h1 e h2 -->
+Isto é um cabeçalho h1
+======================
+
+Isto é um cabeçalho h2
+----------------------
+
+<!-- Estilos de texto simples -->
+<!-- O texto pode ser facilmente denominado como remarcação itálico, negrito ou tachado usando -->
+
+*Este texto está em itálico*
+_E este também está._
+
+**Este texto está em negrito**
+__E este também está._
+
+***Este texto está em negrito e itálico.***
+**_E este também está_**
+*--Danouse! Este também__*
+
+<!-- Em GitHub Flavored Markdown, que é usado para processar arquivos Markdown
+Github, nós também temos: -->
+
+~~Este texto é processado com tachado.~~
+
+<!-- Os parágrafos estão uma ou várias linhas adjacentes de texto separadas por
+uma ou múltiplas linhas em branco. -->
+
+Este é um parágrafo. Eu estou digitando em um parágrafo, não é legal?
+
+Agora, eu estou no parágrado 2.
+... Ainda continuo no parágrafo 2! :)
+
+Eu estou no parágrafo três.
+
+<!-- Se você quiser inserir uma tag HTML <br />, você pode acabar com um parágrafo
+com dois ou mais espaços e, em seguida, começar um novo parágrafo -->
+
+Termino com dois espaços (destacar-me para vê-los).
+
+Há um <br /> acima de mim!
+
+<!-- Bloco de citações são fáceis e feito com o caractere >. -->
+
+> Este é um bloco de citação. Você pode
+> Enrolar manualmente suas linhas e colocar um `>` antes de cada linha ou você pode
+> deixar suas linhas ficarem muito longas e enrolar por conta própria. Não faz diferença,
+> desde que eles começam com um `>`.
+
+> Você também pode usar mais de um nível
+>> De recuo?
+> Como pura é isso?
+
+<!-- Listas -->
+<!-- As listas não ordenadas podem ser feitas usando asteriscos, positivos ou hífens -->
+
+* Item
+* Item
+* Outro item
+
+ou
+
++ Item
++ Item
++ Outro item
+
+ou
+
+- Item
+- Item
+- Um último item
+
+<!-- Listas ordenadas são feitas com um número seguido por um ponto -->
+
+1. Item um
+2. Item dois
+3. Tem três
+
+<!-- Você não tem poder para rotular os itens corretamente e a remarcação será ainda
+tornar os números em ordem, mas isso pode não ser uma boa idéia -->
+
+1. Item um
+1. Item dois
+1. Item três
+<!-- (Isto é processado da mesma forma que o exemplo acima) -->
+
+<!-- Você também pode usar subtítulos -->
+
+1. Item um
+2. Item dois
+3. Item três
+ * Sub-item
+ * Sub-item
+4. Item quatro
+
+<!-- blocos de código -->
+<!-- Você pode indicar um bloco de código (que utiliza o elemento <code>) pelo recuo
+uma linha com quatro espaços ou uma guia -->
+
+ Isto é código
+ É assim, sacou?
+
+<!-- Você pode também re-guia (ou adicionar mais quatro espaços adicionais) para o recuo
+dentro do seu código -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Código embutido pode ser criada usando o caractere de crase ` -->
+
+John não sabia nem o que o função 'goto()' fazia!
+
+<!-- Em Github Flavored Markdown, você pode usar uma sintaxe especial para o código -->
+
+\`\`\`ruby <!-- exceto remover essas barras invertidas quando você faz isso, apenas ```
+ruby! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- Aqui também, não barras invertidas, apenas ``` -->
+
+<-- O texto acima não requer recuo, mas o Github vai usar a sintaxe
+destacando do idioma que você especificar após a ``` -->
+
+<!-- Regra Horizontal (<hr />) -->
+<!-- Regras horizontais são facilmente adicionados com três ou mais asteriscos ou hífens,
+com ou sem espaços. -->
+
+***
+---
+- - -
+****************
+
+<!-- Links -->
+<!-- Uma das melhores coisas sobre a remarcação é o quão fácil é fazer ligações. Colocar
+o texto a ser exibido entre parênteses rígidos [] seguido pela url em parênteses () -->
+
+[Click aqui!](http://test.com/)
+
+<!-- Você também pode adicionar um título link usando aspas dentro dos parênteses -->
+
+[Click aqui!](http://test.com/ "Link para Test.com")
+
+<!-- Caminhos relativos funcionam também. -->
+
+[Ir para música](/música/).
+
+<!-- Markdown também suporta ligações de estilo de referência -->
+
+[Clique neste link] [link1] para mais informações sobre isso!
+[Além disso, verifique este link] [foobar] se você quiser.
+
+[link1]: http://test.com/ "Legal!"
+[foobar]: http://foobar.biz/ "OK!"
+
+<!-- O título também pode estar entre aspas simples ou entre parênteses, ou omitido
+inteiramente. As referências podem estar em qualquer lugar no documento e os IDs de referência
+pode ser qualquer um, desde que eles são únicos. -->
+
+<!-- Existe também o "nomear implícita", que permite que você use o texto do link como o id -->
+
+[Este] [] é um link.
+
+[este]: http://thisisalink.com/
+
+<!-- Mas não são usados normalmente-->
+
+<!-- Imagens -->
+<!-- As imagens são feitas da mesma forma que as ligações, mas com um ponto de exclamação na frente! -->
+
+![Este é pairar-texto (texto alternativo) para minha imagem](http://imgur.com/myimage.jpg "Um título opcional")
+
+<!-- E estilo de referência funciona como esperado -->
+
+![Este é o pairar-texto.][Myimage]
+
+[myimage]: relative/urls/legal/image.jpg "se você precisa de um título, é aqui"
+
+<!-- Miscelânea -->
+<!-- Auto-links -->
+
+<http://testwebsite.com/> é equivalente a
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Auto-links para e-mails -->
+
+<foo@bar.com>
+
+<!-- Escapando caracteres -->
+
+Quero digitar * Este texto entre asteriscos *, mas eu não quero que ele seja
+em itálico, então eu faço o seguinte: \*Este texto entre asteriscos \*.
+
+<!-- Tabelas -->
+<!-- Tabelas estão disponíveis apenas no Github Flavored Markdown e são ligeiramente
+complicadas, mas se você realmente quer: -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| esquerda-alin| Centrado | direita-alinh |
+| blah | blah | blah |
+
+<!-- Ou, para os mesmos resultados -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ugh isso é tão feio | faça isto | parar
+
+<!-- O fim! -->
+
+```
+Para mais informações, confira o post oficial de John Gruber de sintaxe [aqui](http://daringfireball.net/projects/markdown/syntax)
+e de Adam Pritchard grande cheatsheet [aqui](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
diff --git a/pt-br/php-pt.html.markdown b/pt-br/php-pt.html.markdown
index 344df43a..0e710742 100644
--- a/pt-br/php-pt.html.markdown
+++ b/pt-br/php-pt.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/purescript.html.markdown b/purescript.html.markdown
new file mode 100644
index 00000000..6bff7545
--- /dev/null
+++ b/purescript.html.markdown
@@ -0,0 +1,195 @@
+---
+language: purescript
+contributors:
+ - ["Fredrik Dyrkell", "http://www.lexicallyscoped.com"]
+---
+
+PureScript is a small strongly, statically typed language compiling to Javascript.
+
+* Learn more at [http://www.purescript.org/](http://www.purescript.org/)
+* Documentation: [http://docs.purescript.org/en/latest/](http://docs.purescript.org/en/latest/)
+* Book: Purescript by Example, [https://leanpub.com/purescript/](https://leanpub.com/purescript/)
+
+```haskell
+
+--
+-- 1. Primitive datatypes that corresponds to their Javascript
+-- equivalents at runtime.
+
+-- Numbers
+1 + 7*5 :: Number -- 36
+-- Types are inferred, so the following works fine
+9 / 2.5 + 4.4 -- 8
+-- Hexadecimal literals
+0xff + 1 -- 256
+-- Unary negation
+6 * -3 -- -18
+6 * negate 3 -- -18
+-- Modulus
+3 % 2 -- 1
+4 % 2 -- 0
+-- Inspect the type of an expression in psci
+:t 9 / 2.5 + 4.4 -- Prim.Number
+
+-- Booleans
+true :: Boolean -- true
+false :: Boolean -- false
+-- Negation
+not true --false
+23 == 23 -- true
+1 /= 4 -- true
+1 >= 4 -- false
+-- Comparisions < <= > >=
+-- are defined in terms of compare
+compare 1 2 -- LT
+compare 2 2 -- EQ
+compare 3 2 -- GT
+-- Conjunction and Disjunction
+true && (9 >= 19 || 1 < 2) -- true
+
+-- Strings
+"Hellow" :: String -- "Hellow"
+-- Multiline string
+"Hellow\
+\orld" -- "Helloworld"
+-- Concatenate
+"such " ++ "amaze" -- "such amaze"
+
+--
+-- 2. Arrays are Javascript arrays, but must be homogeneous
+
+[1,1,2,3,5,8] :: [Number] -- [1,1,2,3,5,8]
+[true, true, false] :: [Boolean] -- [true,true,false]
+-- [1,2, true, "false"] won't work
+-- `Cannot unify Prim.Number with Prim.Boolean`
+-- Cons (prepend)
+1 : [2,4,3] -- [1,2,4,3]
+
+-- Requires purescript-arrays (Data.Array)
+-- and purescript-maybe (Data.Maybe)
+
+-- Safe access return Maybe a
+head [1,2,3] -- Just (1)
+tail [3,2,1] -- Just ([2,1])
+init [1,2,3] -- Just ([1,2])
+last [3,2,1] -- Just (1)
+-- Random access - indexing
+[3,4,5,6,7] !! 2 -- Just (5)
+-- Range
+1..5 -- [1,2,3,4,5]
+length [2,2,2] -- 3
+drop 3 [5,4,3,2,1] -- [2,1]
+take 3 [5,4,3,2,1] -- [5,4,3]
+append [1,2,3] [4,5,6] -- [1,2,3,4,5,6]
+
+--
+-- 3. Records are Javascript objects, with zero or more fields, which
+-- can have different types
+let book = {title: "Foucault's pendulum", author: "Umberto Eco"}
+-- Access properties
+book.title -- "Foucault's pendulum"
+
+getTitle b = b.title
+-- Works on all records with a title (but doesn't require any other field)
+getTitle book -- "Foucault's pendulum"
+getTitle {title: "Weekend in Monaco", artist: "The Rippingtons"} -- "Weekend in Monaco"
+-- Update a record
+changeTitle b t = b {title = t}
+changeTitle book "Ill nome della rosa" -- {title: "Ill nome della
+ -- rosa", author: "Umberto Eco"}
+
+--
+-- 4. Functions
+sumOfSquares x y = x*x+y*y
+sumOfSquares 3 4 -- 25
+-- In psci you have to write `let` in front of the function to get a
+-- top level binding
+mod x y = x % y
+mod 3 2 -- 1
+-- Infix application of function
+3 `mod` 2 -- 1
+
+-- function application have higher precedence than all other
+-- operators
+sumOfSquares 3 4 * sumOfSquares 4 5 -- 1025
+
+-- Conditional
+abs' n = if n>=0 then n else -n
+abs' (-3) -- 3
+
+-- Guarded equations
+abs n | n >= 0 = n
+ | otherwise = -n
+
+-- Pattern matching
+
+-- Note the type signature, input is an array of numbers The pattern
+-- matching destructures and binds the array into parts
+first :: [Number] -> Number
+first (x:_) = x
+first [3,4,5] -- 3
+second :: [Number] -> Number
+second (_:y:_) = y
+second [3,4,5] -- 4
+sumTwo :: [Number] -> [Number]
+sumTwo (x:y:rest) = (x+y) : rest
+sumTwo [2,3,4,5,6] -- [5,4,5,6]
+
+-- sumTwo doesn't handle when the array is empty or just have one
+-- element in which case you get an error
+sumTwo [1] -- Failed pattern match
+
+-- Complementing patterns to match
+-- Good ol' Fibonacci
+fib 1 = 1
+fib 2 = 2
+fib x = fib (x-1) + fib (x-2)
+fib 10 -- 89
+
+-- Use underscore to match any, where you don't care about the binding name
+isZero 0 = true
+isZero _ = false
+
+-- Pattern matching on records
+ecoTitle {author = "Umberto Eco", title = t} = Just t
+ecoTitle _ = Nothing
+
+ecoTitle book -- Just ("Foucault's pendulum")
+ecoTitle {title: "The Quantum Thief", author: "Hannu Rajaniemi"} -- Nothing
+-- ecoTitle requires both field to type check:
+ecoTitle {title: "The Quantum Thief"} -- Object does not have property author
+
+-- Lambda expressions
+(\x -> x*x) 3 -- 9
+(\x y -> x*x + y*y) 4 5 -- 41
+sqr = \x -> x*x
+
+-- Currying
+add x y = x + y -- is equivalent with
+add = \x -> (\y -> x+y)
+add3 = add 3
+:t add3 -- Prim.Number -> Prim.Number
+
+-- Forward and backward function composition
+-- drop 3 followed by taking 5
+(drop 3 >>> take 5) (1..20) -- [4,5,6,7,8]
+-- take 5 followed by dropping 3
+(drop 3 <<< take 5) (1..20) -- [4,5]
+
+-- Operations using higher order functions
+even x = x % 2 == 0
+filter even (1..10) -- [2,4,6,8,10]
+map (\x -> x+11) (1..5) -- [12,13,14,15,16]
+
+-- Requires purescript-foldable-traversabe (Data.Foldable)
+
+foldr (+) 0 (1..10) -- 55
+sum (1..10) -- 55
+product (1..10) -- 3628800
+
+-- Testing with predicate
+any even [1,2,3] -- true
+all even [1,2,3] -- false
+
+```
+
diff --git a/python.html.markdown b/python.html.markdown
index bbc1bd92..ba236fb3 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -3,6 +3,7 @@ language: python
contributors:
- ["Louie Dinh", "http://ldinh.ca"]
- ["Amin Bandali", "http://aminbandali.com"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
filename: learnpython.py
---
@@ -45,12 +46,32 @@ to Python 2.x. Look for another tour of Python 3 soon!
2.0 # This is a float
11.0 / 4.0 # => 2.75 ahhh...much better
+# Result of integer division truncated down both for positive and negative.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # works on floats too
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# Modulo operation
+7 % 3 # => 1
+
+# Exponentiation (x to the y'th power)
+2**4 # => 16
+
# Enforce precedence with parentheses
(1 + 3) * 2 # => 8
-# Boolean values are primitives
-True
-False
+# Boolean Operators
+# Note "and" and "or" are case-sensitive
+True and False #=> False
+False or True #=> True
+
+# Note using Bool operators with ints
+0 and 2 #=> 0
+-5 or 0 #=> -5
+0 == False #=> True
+2 == True #=> False
+1 == True #=> True
# negate with not
not True # => False
@@ -173,7 +194,7 @@ li[::-1] # => [3, 4, 2, 1]
del li[2] # li is now [1, 2, 3]
# You can add lists
-li + other_li # => [1, 2, 3, 4, 5, 6] - Note: li and other_li is left alone
+li + other_li # => [1, 2, 3, 4, 5, 6] - Note: values for li and for other_li are not modified.
# Concatenate lists with "extend()"
li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
@@ -327,6 +348,10 @@ try:
raise IndexError("This is an index error")
except IndexError as e:
pass # Pass is just a no-op. Usually you would do recovery here.
+except (TypeError, NameError):
+ pass # Multiple exceptions can be handled together, if required.
+else: # Optional clause to the try/except block. Must follow all except blocks
+ print "All good!" # Runs only if the code in try raises no exceptions
####################################################
@@ -380,6 +405,22 @@ all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+# Function Scope
+x = 5
+
+def setX(num):
+ # Local var x not the same as global variable x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # global var x is now set to 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
# Python has first class functions
def create_adder(x):
@@ -412,7 +453,10 @@ class Human(object):
# A class attribute. It is shared by all instances of this class
species = "H. sapiens"
- # Basic initializer
+ # Basic initializer, this is called when this class is instantiated.
+ # Note that the double leading and trailing underscores denote objects
+ # or attributes that are used by python but that live in user-controlled
+ # namespaces. You should not invent such names on your own.
def __init__(self, name):
# Assign the argument to the instance's name attribute
self.name = name
@@ -496,11 +540,15 @@ def double_numbers(iterable):
# Instead of generating and returning all values at once it creates one in each
# iteration. This means values bigger than 15 wont be processed in
# double_numbers.
-# Note range is a generator too. Creating a list 1-900000000 would take lot of
-# time to be made
-_range = range(1, 900000000)
+# Note xrange is a generator that does the same thing range does.
+# Creating a list 1-900000000 would take lot of time and space to be made.
+# xrange creates an xrange generator object instead of creating the entire list like range does.
+# We use a trailing underscore in variable names when we want to use a name that
+# would normally collide with a python keyword
+xrange_ = xrange(1, 900000000)
+
# will double all numbers until a result >=30 found
-for i in double_numbers(_range):
+for i in double_numbers(xrange_):
print(i)
if i >= 30:
break
@@ -513,10 +561,10 @@ for i in double_numbers(_range):
from functools import wraps
-def beg(_say):
- @wraps(_say)
+def beg(target_function):
+ @wraps(target_function)
def wrapper(*args, **kwargs):
- msg, say_please = _say(*args, **kwargs)
+ msg, say_please = target_function(*args, **kwargs)
if say_please:
return "{} {}".format(msg, "Please! I am poor :(")
return msg
diff --git a/python3.html.markdown b/python3.html.markdown
new file mode 100644
index 00000000..e478e57f
--- /dev/null
+++ b/python3.html.markdown
@@ -0,0 +1,646 @@
+---
+language: python3
+contributors:
+ - ["Louie Dinh", "http://pythonpracticeprojects.com"]
+ - ["Steven Basart", "http://github.com/xksteven"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
+filename: learnpython3.py
+---
+
+Python was created by Guido Van Rossum in the early 90's. It is now one of the most popular
+languages in existence. I fell in love with Python for its syntactic clarity. It's basically
+executable pseudocode.
+
+Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service]
+
+Note: This article applies to Python 3 specifically. Check out the other tutorial if you want to learn the old Python 2.7
+
+```python
+
+# Single line comments start with a number symbol.
+
+""" Multiline strings can be written
+ using three "'s, and are often used
+ as comments
+"""
+
+####################################################
+## 1. Primitive Datatypes and Operators
+####################################################
+
+# You have numbers
+3 # => 3
+
+# Math is what you would expect
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+
+# Except division which returns floats by default
+35 / 5 # => 7.0
+
+# Result of integer division truncated down both for positive and negative.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # works on floats too
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# When you use a float, results are floats
+3 * 2.0 # => 6.0
+
+# Modulo operation
+7 % 3 # => 1
+
+# Exponentiation (x to the y'th power)
+2**4 # => 16
+
+# Enforce precedence with parentheses
+(1 + 3) * 2 # => 8
+
+# Boolean values are primitives
+True
+False
+
+# negate with not
+not True # => False
+not False # => True
+
+# Boolean Operators
+# Note "and" and "or" are case-sensitive
+True and False #=> False
+False or True #=> True
+
+# Note using Bool operators with ints
+0 and 2 #=> 0
+-5 or 0 #=> -5
+0 == False #=> True
+2 == True #=> False
+1 == True #=> True
+
+# Equality is ==
+1 == 1 # => True
+2 == 1 # => False
+
+# Inequality is !=
+1 != 1 # => False
+2 != 1 # => True
+
+# More comparisons
+1 < 10 # => True
+1 > 10 # => False
+2 <= 2 # => True
+2 >= 2 # => True
+
+# Comparisons can be chained!
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
+
+# Strings are created with " or '
+"This is a string."
+'This is also a string.'
+
+# Strings can be added too! But try not to do this.
+"Hello " + "world!" # => "Hello world!"
+
+# A string can be treated like a list of characters
+"This is a string"[0] # => 'T'
+
+# .format can be used to format strings, like this:
+"{} can be {}".format("strings", "interpolated")
+
+# You can repeat the formatting arguments to save some typing.
+"{0} be nimble, {0} be quick, {0} jump over the {1}".format("Jack", "candle stick")
+#=> "Jack be nimble, Jack be quick, Jack jump over the candle stick"
+
+# You can use keywords if you don't want to count.
+"{name} wants to eat {food}".format(name="Bob", food="lasagna") #=> "Bob wants to eat lasagna"
+
+# If your Python 3 code also needs to run on Python 2.5 and below, you can also
+# still use the old style of formatting:
+"%s can be %s the %s way" % ("strings", "interpolated", "old")
+
+
+# None is an object
+None # => None
+
+# Don't use the equality "==" symbol to compare objects to None
+# Use "is" instead. This checks for equality of object identity.
+"etc" is None # => False
+None is None # => True
+
+# None, 0, and empty strings/lists/dicts all evaluate to False.
+# All other values are True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Variables and Collections
+####################################################
+
+# Python has a print function
+print("I'm Python. Nice to meet you!")
+
+# No need to declare variables before assigning to them.
+# Convention is to use lower_case_with_underscores
+some_var = 5
+some_var # => 5
+
+# Accessing a previously unassigned variable is an exception.
+# See Control Flow to learn more about exception handling.
+some_unknown_var # Raises a NameError
+
+# Lists store sequences
+li = []
+# You can start with a prefilled list
+other_li = [4, 5, 6]
+
+# Add stuff to the end of a list with append
+li.append(1) # li is now [1]
+li.append(2) # li is now [1, 2]
+li.append(4) # li is now [1, 2, 4]
+li.append(3) # li is now [1, 2, 4, 3]
+# Remove from the end with pop
+li.pop() # => 3 and li is now [1, 2, 4]
+# Let's put it back
+li.append(3) # li is now [1, 2, 4, 3] again.
+
+# Access a list like you would any array
+li[0] # => 1
+# Look at the last element
+li[-1] # => 3
+
+# Looking out of bounds is an IndexError
+li[4] # Raises an IndexError
+
+# You can look at ranges with slice syntax.
+# (It's a closed/open range for you mathy types.)
+li[1:3] # => [2, 4]
+# Omit the beginning
+li[2:] # => [4, 3]
+# Omit the end
+li[:3] # => [1, 2, 4]
+# Select every second entry
+li[::2] # =>[1, 4]
+# Revert the list
+li[::-1] # => [3, 4, 2, 1]
+# Use any combination of these to make advanced slices
+# li[start:end:step]
+
+# Remove arbitrary elements from a list with "del"
+del li[2] # li is now [1, 2, 3]
+
+# You can add lists
+# Note: values for li and for other_li are not modified.
+li + other_li # => [1, 2, 3, 4, 5, 6]
+
+# Concatenate lists with "extend()"
+li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
+
+# Check for existence in a list with "in"
+1 in li # => True
+
+# Examine the length with "len()"
+len(li) # => 6
+
+
+# Tuples are like lists but are immutable.
+tup = (1, 2, 3)
+tup[0] # => 1
+tup[0] = 3 # Raises a TypeError
+
+# You can do all those list thingies on tuples too
+len(tup) # => 3
+tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
+tup[:2] # => (1, 2)
+2 in tup # => True
+
+# You can unpack tuples (or lists) into variables
+a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
+# Tuples are created by default if you leave out the parentheses
+d, e, f = 4, 5, 6
+# Now look how easy it is to swap two values
+e, d = d, e # d is now 5 and e is now 4
+
+
+# Dictionaries store mappings
+empty_dict = {}
+# Here is a prefilled dictionary
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# Look up values with []
+filled_dict["one"] # => 1
+
+# Get all keys as a list with "keys()".
+# We need to wrap the call in list() because we are getting back an iterable. We'll talk about those later.
+# Note - Dictionary key ordering is not guaranteed.
+# Your results might not match this exactly.
+list(filled_dict.keys()) # => ["three", "two", "one"]
+
+
+# Get all values as a list with "values()". Once again we need to wrap it in list() to get it out of the iterable.
+# Note - Same as above regarding key ordering.
+list(filled_dict.values()) # => [3, 2, 1]
+
+
+# Check for existence of keys in a dictionary with "in"
+"one" in filled_dict # => True
+1 in filled_dict # => False
+
+# Looking up a non-existing key is a KeyError
+filled_dict["four"] # KeyError
+
+# Use "get()" method to avoid the KeyError
+filled_dict.get("one") # => 1
+filled_dict.get("four") # => None
+# The get method supports a default argument when the value is missing
+filled_dict.get("one", 4) # => 1
+filled_dict.get("four", 4) # => 4
+
+# "setdefault()" inserts into a dictionary only if the given key isn't present
+filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5
+filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5
+
+# Adding to a dictionary
+filled_dict.update({"four":4}) #=> {"one": 1, "two": 2, "three": 3, "four": 4}
+#filled_dict["four"] = 4 #another way to add to dict
+
+# Remove keys from a dictionary with del
+del filled_dict["one"] # Removes the key "one" from filled dict
+
+
+# Sets store ... well sets
+empty_set = set()
+# Initialize a set with a bunch of values. Yeah, it looks a bit like a dict. Sorry.
+some_set = {1, 1, 2, 2, 3, 4} # some_set is now {1, 2, 3, 4}
+
+#Can set new variables to a set
+filled_set = some_set
+
+# Add one more item to the set
+filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5}
+
+# Do set intersection with &
+other_set = {3, 4, 5, 6}
+filled_set & other_set # => {3, 4, 5}
+
+# Do set union with |
+filled_set | other_set # => {1, 2, 3, 4, 5, 6}
+
+# Do set difference with -
+{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}
+
+# Check for existence in a set with in
+2 in filled_set # => True
+10 in filled_set # => False
+
+
+####################################################
+## 3. Control Flow and Iterables
+####################################################
+
+# Let's just make a variable
+some_var = 5
+
+# Here is an if statement. Indentation is significant in python!
+# prints "some_var is smaller than 10"
+if some_var > 10:
+ print("some_var is totally bigger than 10.")
+elif some_var < 10: # This elif clause is optional.
+ print("some_var is smaller than 10.")
+else: # This is optional too.
+ print("some_var is indeed 10.")
+
+
+"""
+For loops iterate over lists
+prints:
+ dog is a mammal
+ cat is a mammal
+ mouse is a mammal
+"""
+for animal in ["dog", "cat", "mouse"]:
+ # You can use format() to interpolate formatted strings
+ print("{} is a mammal".format(animal))
+
+"""
+"range(number)" returns a list of numbers
+from zero to the given number
+prints:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+While loops go until a condition is no longer met.
+prints:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # Shorthand for x = x + 1
+
+# Handle exceptions with a try/except block
+try:
+ # Use "raise" to raise an error
+ raise IndexError("This is an index error")
+except IndexError as e:
+ pass # Pass is just a no-op. Usually you would do recovery here.
+except (TypeError, NameError):
+ pass # Multiple exceptions can be handled together, if required.
+else: # Optional clause to the try/except block. Must follow all except blocks
+ print("All good!") # Runs only if the code in try raises no exceptions
+
+# Python offers a fundamental abstraction called the Iterable.
+# An iterable is an object that can be treated as a sequence.
+# The object returned the range function, is an iterable.
+
+filled_dict = {"one": 1, "two": 2, "three": 3}
+our_iterable = filled_dict.keys()
+print(our_iterable) #=> range(1,10). This is an object that implements our Iterable interface
+
+# We can loop over it.
+for i in our_iterable:
+ print(i) # Prints one, two, three
+
+# However we cannot address elements by index.
+our_iterable[1] # Raises a TypeError
+
+# An iterable is an object that knows how to create an iterator.
+our_iterator = iter(our_iterable)
+
+# Our iterator is an object that can remember the state as we traverse through it.
+# We get the next object by calling the __next__ function.
+our_iterator.__next__() #=> "one"
+
+# It maintains state as we call __next__.
+our_iterator.__next__() #=> "two"
+our_iterator.__next__() #=> "three"
+
+# After the iterator has returned all of its data, it gives you a StopIterator Exception
+our_iterator.__next__() # Raises StopIteration
+
+# You can grab all the elements of an iterator by calling list() on it.
+list(filled_dict.keys()) #=> Returns ["one", "two", "three"]
+
+
+
+####################################################
+## 4. Functions
+####################################################
+
+# Use "def" to create new functions
+def add(x, y):
+ print("x is {} and y is {}".format(x, y))
+ return x + y # Return values with a return statement
+
+# Calling functions with parameters
+add(5, 6) # => prints out "x is 5 and y is 6" and returns 11
+
+# Another way to call functions is with keyword arguments
+add(y=6, x=5) # Keyword arguments can arrive in any order.
+
+
+# You can define functions that take a variable number of
+# positional arguments
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) # => (1, 2, 3)
+
+
+# You can define functions that take a variable number of
+# keyword arguments, as well
+def keyword_args(**kwargs):
+ return kwargs
+
+# Let's call it to see what happens
+keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"}
+
+
+# You can do both at once, if you like
+def all_the_args(*args, **kwargs):
+ print(args)
+ print(kwargs)
+"""
+all_the_args(1, 2, a=3, b=4) prints:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# When calling functions, you can do the opposite of args/kwargs!
+# Use * to expand tuples and use ** to expand kwargs.
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
+all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
+all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+
+
+# Function Scope
+x = 5
+
+def setX(num):
+ # Local var x not the same as global variable x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # global var x is now set to 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+
+# Python has first class functions
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) # => 13
+
+# There are also anonymous functions
+(lambda x: x > 2)(3) # => True
+
+# TODO - Fix for iterables
+# There are built-in higher order functions
+map(add_10, [1, 2, 3]) # => [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# We can use list comprehensions for nice maps and filters
+# List comprehension stores the output as a list which can itself be a nested list
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
+
+####################################################
+## 5. Classes
+####################################################
+
+
+# We subclass from object to get a class.
+class Human(object):
+
+ # A class attribute. It is shared by all instances of this class
+ species = "H. sapiens"
+
+ # Basic initializer, this is called when this class is instantiated.
+ # Note that the double leading and trailing underscores denote objects
+ # or attributes that are used by python but that live in user-controlled
+ # namespaces. You should not invent such names on your own.
+ def __init__(self, name):
+ # Assign the argument to the instance's name attribute
+ self.name = name
+
+ # An instance method. All methods take "self" as the first argument
+ def say(self, msg):
+ return "{name}: {message}".format(name=self.name, message=msg)
+
+ # A class method is shared among all instances
+ # They are called with the calling class as the first argument
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # A static method is called without a class or instance reference
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# Instantiate a class
+i = Human(name="Ian")
+print(i.say("hi")) # prints out "Ian: hi"
+
+j = Human("Joel")
+print(j.say("hello")) # prints out "Joel: hello"
+
+# Call our class method
+i.get_species() # => "H. sapiens"
+
+# Change the shared attribute
+Human.species = "H. neanderthalensis"
+i.get_species() # => "H. neanderthalensis"
+j.get_species() # => "H. neanderthalensis"
+
+# Call the static method
+Human.grunt() # => "*grunt*"
+
+
+####################################################
+## 6. Modules
+####################################################
+
+# You can import modules
+import math
+print(math.sqrt(16)) # => 4
+
+# You can get specific functions from a module
+from math import ceil, floor
+print(ceil(3.7)) # => 4.0
+print(floor(3.7)) # => 3.0
+
+# You can import all functions from a module.
+# Warning: this is not recommended
+from math import *
+
+# You can shorten module names
+import math as m
+math.sqrt(16) == m.sqrt(16) # => True
+
+# Python modules are just ordinary python files. You
+# can write your own, and import them. The name of the
+# module is the same as the name of the file.
+
+# You can find out which functions and attributes
+# defines a module.
+import math
+dir(math)
+
+
+####################################################
+## 7. Advanced
+####################################################
+
+# Generators help you make lazy code
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# A generator creates values on the fly.
+# Instead of generating and returning all values at once it creates one in each
+# iteration. This means values bigger than 15 wont be processed in
+# double_numbers.
+# Note range is a generator too. Creating a list 1-900000000 would take lot of
+# time to be made
+# We use a trailing underscore in variable names when we want to use a name that
+# would normally collide with a python keyword
+range_ = range(1, 900000000)
+# will double all numbers until a result >=30 found
+for i in double_numbers(range_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decorators
+# in this example beg wraps say
+# Beg will call say. If say_please is True then it will change the returned
+# message
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, "Please! I am poor :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Can you buy me a beer?"
+ return msg, say_please
+
+
+print(say()) # Can you buy me a beer?
+print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(
+```
+
+## Ready For More?
+
+### Free Online
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+
+* [The Official Docs](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Dead Tree
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/r.html.markdown b/r.html.markdown
index ea94ae42..7cb56fd7 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -6,34 +6,42 @@ contributors:
filename: learnr.r
---
-R is a statistical computing language. It has lots of libraries for uploading and cleaning data sets, running statistical procedures, and making graphs. You can also run `R`commands within a LaTeX document.
+R is a statistical computing language. It has lots of libraries for uploading and cleaning data sets, running statistical procedures, and making graphs. You can also run `R` commands within a LaTeX document.
-```python
+```r
# Comments start with number symbols.
-# You can't make a multi-line comment per se,
+# You can't make multi-line comments,
# but you can stack multiple comments like so.
-# in Windows, hit COMMAND-ENTER to execute a line
+# in Windows or Mac, hit COMMAND-ENTER to execute a line
-###################################################################
+
+#############################################################################
# Stuff you can do without understanding anything about programming
-###################################################################
+#############################################################################
+
+# In this section, we show off some of the cool stuff you can do in
+# R without understanding anything about programming. Do not worry
+# about understanding everything the code does. Just enjoy!
-data() # Browse pre-loaded data sets
-data(rivers) # Lengths of Major North American Rivers
-ls() # Notice that "rivers" appears in the workspace
-head(rivers) # peek at the dataset
+data() # browse pre-loaded data sets
+data(rivers) # get this one: "Lengths of Major North American Rivers"
+ls() # notice that "rivers" now appears in the workspace
+head(rivers) # peek at the data set
# 735 320 325 392 524 450
+
length(rivers) # how many rivers were measured?
# 141
-summary(rivers)
+summary(rivers) # what are some summary statistics?
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 135.0 310.0 425.0 591.2 680.0 3710.0
-stem(rivers) #stem-and-leaf plot (like a histogram)
-#
+
+# make a stem-and-leaf plot (a histogram-like data visualization)
+stem(rivers)
+
# The decimal point is 2 digit(s) to the right of the |
#
# 0 | 4
@@ -56,8 +64,8 @@ stem(rivers) #stem-and-leaf plot (like a histogram)
# 34 |
# 36 | 1
-
-stem(log(rivers)) #Notice that the data are neither normal nor log-normal! Take that, Bell Curve fundamentalists.
+stem(log(rivers)) # Notice that the data are neither normal nor log-normal!
+# Take that, Bell curve fundamentalists.
# The decimal point is 1 digit(s) to the left of the |
#
@@ -80,17 +88,19 @@ stem(log(rivers)) #Notice that the data are neither normal nor log-normal! Take
# 80 |
# 82 | 2
+# make a histogram:
+hist(rivers, col="#333333", border="white", breaks=25) # play around with these parameters
+hist(log(rivers), col="#333333", border="white", breaks=25) # you'll do more plotting later
-hist(rivers, col="#333333", border="white", breaks=25) #play around with these parameters
-hist(log(rivers), col="#333333", border="white", breaks=25) #you'll do more plotting later
-
-#Here's another neat data set that comes pre-loaded. R has tons of these. data()
+# Here's another neat data set that comes pre-loaded. R has tons of these.
data(discoveries)
-plot(discoveries, col="#333333", lwd=3, xlab="Year", main="Number of important discoveries per year")
-plot(discoveries, col="#333333", lwd=3, type = "h", xlab="Year", main="Number of important discoveries per year")
+plot(discoveries, col="#333333", lwd=3, xlab="Year",
+ main="Number of important discoveries per year")
+plot(discoveries, col="#333333", lwd=3, type = "h", xlab="Year",
+ main="Number of important discoveries per year")
-
-#rather than leaving the default ordering (by year) we could also sort to see what's typical
+# Rather than leaving the default ordering (by year),
+# we could also sort to see what's typical:
sort(discoveries)
# [1] 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
# [26] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3
@@ -117,231 +127,250 @@ stem(discoveries, scale=2)
max(discoveries)
# 12
-
summary(discoveries)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 0.0 2.0 3.0 3.1 4.0 12.0
-
-
-
-#Basic statistical operations don't require any programming knowledge either
-
-#roll a die a few times
+# Roll a die a few times
round(runif(7, min=.5, max=6.5))
# 1 4 6 1 4 6 4
+# Your numbers will differ from mine unless we set the same random.seed(31337)
-#your numbers will differ from mine unless we set the same random.seed(31337)
-
-
-#draw from a standard Gaussian 9 times
+# Draw from a standard Gaussian 9 times
rnorm(9)
# [1] 0.07528471 1.03499859 1.34809556 -0.82356087 0.61638975 -1.88757271
# [7] -0.59975593 0.57629164 1.08455362
-
-
-
-
-
-
-#########################
-# Basic programming stuff
-#########################
-
-# NUMBERS
-
-# "numeric" means double-precision floating-point numbers
-5 # 5
-class(5) # "numeric"
-5e4 # 50000 #handy when dealing with large,small,or variable orders of magnitude
-6.02e23 # Avogadro's number
-1.6e-35 # Planck length
-
-# long-storage integers are written with L
-5L # 5
-class(5L) # "integer"
-
-# Try ?class for more information on the class() function
-# In fact, you can look up the documentation on `xyz` with ?xyz
-# or see the source for `xyz` by evaluating xyz
-
-# Arithmetic
-10 + 66 # 76
-53.2 - 4 # 49.2
-2 * 2.0 # 4
-3L / 4 # 0.75
-3 %% 2 # 1
-
-# Weird number types
-class(NaN) # "numeric"
+##################################################
+# Data types and basic arithmetic
+##################################################
+
+# Now for the programming-oriented part of the tutorial.
+# In this section you will meet the important data types of R:
+# integers, numerics, characters, logicals, and factors.
+# There are others, but these are the bare minimum you need to
+# get started.
+
+# INTEGERS
+# Long-storage integers are written with L
+5L # 5
+class(5L) # "integer"
+# (Try ?class for more information on the class() function.)
+# In R, every single value, like 5L, is considered a vector of length 1
+length(5L) # 1
+# You can have an integer vector with length > 1 too:
+c(4L, 5L, 8L, 3L) # 4 5 8 3
+length(c(4L, 5L, 8L, 3L)) # 4
+class(c(4L, 5L, 8L, 3L)) # "integer"
+
+# NUMERICS
+# A "numeric" is a double-precision floating-point number
+5 # 5
+class(5) # "numeric"
+# Again, everything in R is a vector;
+# you can make a numeric vector with more than one element
+c(3,3,3,2,2,1) # 3 3 3 2 2 1
+# You can use scientific notation too
+5e4 # 50000
+6.02e23 # Avogadro's number
+1.6e-35 # Planck length
+# You can also have infinitely large or small numbers
class(Inf) # "numeric"
-class(-Inf) # "numeric" #used in for example integrate( dnorm(x), 3, Inf ) -- which obviates Z-score tables
-
-# but beware, NaN isn't the only weird type...
-class(NA) # see below
-class(NULL) # NULL
-
-
-# SIMPLE LISTS
-c(6, 8, 7, 5, 3, 0, 9) # 6 8 7 5 3 0 9
-c('alef', 'bet', 'gimmel', 'dalet', 'he') # "alef" "bet" "gimmel" "dalet" "he"
-c('Z', 'o', 'r', 'o') == "Zoro" # FALSE FALSE FALSE FALSE
-
-#some more nice built-ins
-5:15 # 5 6 7 8 9 10 11 12 13 14 15
-
-seq(from=0, to=31337, by=1337)
-# [1] 0 1337 2674 4011 5348 6685 8022 9359 10696 12033 13370 14707
-# [13] 16044 17381 18718 20055 21392 22729 24066 25403 26740 28077 29414 30751
-
-letters
-# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
-# [20] "t" "u" "v" "w" "x" "y" "z"
-
-month.abb # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
-
-
-# Access the n'th element of a list with list.name[n] or sometimes list.name[[n]]
-letters[18] # "r"
-LETTERS[13] # "M"
-month.name[9] # "September"
-c(6, 8, 7, 5, 3, 0, 9)[3] # 7
-
-
+class(-Inf) # "numeric"
+# You might use "Inf", for example, in integrate( dnorm(x), 3, Inf);
+# this obviates Z-score tables.
+
+# BASIC ARITHMETIC
+# You can do arithmetic with numbers
+# Doing arithmetic on a mix of integers and numerics gives you another numeric
+10L + 66L # 76 # integer plus integer gives integer
+53.2 - 4 # 49.2 # numeric minus numeric gives numeric
+2.0 * 2L # 4 # numeric times integer gives numeric
+3L / 4 # 0.75 # integer over numeric gives numeric
+3 %% 2 # 1 # the remainder of two numerics is another numeric
+# Illegal arithmetic yeilds you a "not-a-number":
+0 / 0 # NaN
+class(NaN) # "numeric"
+# You can do arithmetic on two vectors with length greater than 1,
+# so long as the larger vector's length is an integer multiple of the smaller
+c(1,2,3) + c(1,2,3) # 2 4 6
# CHARACTERS
-
# There's no difference between strings and characters in R
-
-"Horatio" # "Horatio"
+"Horatio" # "Horatio"
class("Horatio") # "character"
-substr("Fortuna multis dat nimis, nulli satis.", 9, 15) # "multis "
-gsub('u', 'ø', "Fortuna multis dat nimis, nulli satis.") # "Fortøna møltis dat nimis, nølli satis."
-
-
+class('H') # "character"
+# Those were both character vectors of length 1
+# Here is a longer one:
+c('alef', 'bet', 'gimmel', 'dalet', 'he')
+# =>
+# "alef" "bet" "gimmel" "dalet" "he"
+length(c("Call","me","Ishmael")) # 3
+# You can do regex operations on character vectors:
+substr("Fortuna multis dat nimis, nulli satis.", 9, 15) # "multis "
+gsub('u', 'ø', "Fortuna multis dat nimis, nulli satis.") # "Fortøna møltis dat nimis, nølli satis."
+# R has several built-in character vectors:
+letters
+# =>
+# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
+# [20] "t" "u" "v" "w" "x" "y" "z"
+month.abb # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
# LOGICALS
-
-# booleans
+# In R, a "logical" is a boolean
class(TRUE) # "logical"
class(FALSE) # "logical"
-# Behavior is normal
+# Their behavior is normal
TRUE == TRUE # TRUE
TRUE == FALSE # FALSE
FALSE != FALSE # FALSE
FALSE != TRUE # TRUE
# Missing data (NA) is logical, too
class(NA) # "logical"
-
-
+# Here we get a logical vector with many elements:
+c('Z', 'o', 'r', 'r', 'o') == "Zorro" # FALSE FALSE FALSE FALSE FALSE
+c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
# FACTORS
-
# The factor class is for categorical data
-# which can be ordered (like childrens' grade levels)
-# or unordered (like gender)
-levels(factor(c("female", "male", "male", "female", "NA", "female"))) # "female" "male" "NA"
-
+# Factors can be ordered (like childrens' grade levels) or unordered (like gender)
factor(c("female", "female", "male", "NA", "female"))
# female female male NA female
# Levels: female male NA
+# The "levels" are the values the categorical data can take
+levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male" "NA"
+# If a factor vector has length 1, its levels will have length 1, too
+length(factor("male")) # 1
+length(levels(factor("male"))) # 1
+# Factors are commonly seen in data frames, a data structure we will cover later
+data(infert) # "Infertility after Spontaneous and Induced Abortion"
+levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
+
+# NULL
+# "NULL" is a weird one; use it to "blank out" a vector
+class(NULL) # NULL
+parakeet
+# =>
+# [1] "beak" "feathers" "wings" "eyes"
+parakeet <- NULL
+parakeet
+# =>
+# NULL
+
+# TYPE COERCION
+# Type-coercion is when you force a value to take on a different type
+as.character(c(6, 8)) # "6" "8"
+as.logical(c(1,0,1,1)) # TRUE FALSE TRUE TRUE
+# If you put elements of different types into a vector, weird coercions happen:
+c(TRUE, 4) # 1 4
+c("dog", TRUE, 4) # "dog" "TRUE" "4"
+as.numeric("Bilbo")
+# =>
+# [1] NA
+# Warning message:
+# NAs introduced by coercion
-data(infert) #Infertility after Spontaneous and Induced Abortion
-levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
+# Also note: those were just the basic data types
+# There are many more data types, such as for dates, time series, etc.
-# VARIABLES
+##################################################
+# Variables, loops, if/else
+##################################################
-# Lots of way to assign stuff
+# A variable is like a box you store a value in for later use.
+# We call this "assigning" the value to the variable.
+# Having variables lets us write loops, functions, and if/else statements
+
+# VARIABLES
+# Lots of way to assign stuff:
x = 5 # this is possible
y <- "1" # this is preferred
TRUE -> z # this works but is weird
-# We can use coerce variables to different classes
-as.numeric(y) # 1
-as.character(x) # "5"
-
# LOOPS
-
# We've got for loops
for (i in 1:4) {
print(i)
}
-
# We've got while loops
a <- 10
while (a > 4) {
cat(a, "...", sep = "")
a <- a - 1
}
-
# Keep in mind that for and while loops run slowly in R
# Operations on entire vectors (i.e. a whole row, a whole column)
# or apply()-type functions (we'll discuss later) are preferred
# IF/ELSE
-
# Again, pretty standard
if (4 > 3) {
- print("Huzzah! It worked!")
+ print("4 is greater than 3")
} else {
- print("Noooo! This is blatantly illogical!")
+ print("4 is not greater than 3")
}
# =>
-# [1] "Huzzah! It worked!"
+# [1] "4 is greater than 3"
# FUNCTIONS
-
# Defined like so:
jiggle <- function(x) {
x = x + rnorm(1, sd=.1) #add in a bit of (controlled) noise
return(x)
}
-
# Called like any other R function:
jiggle(5) # 5±ε. After set.seed(2716057), jiggle(5)==5.005043
-#########################
-# Fun with data: vectors, matrices, data frames, and arrays
-#########################
+
+
+###########################################################################
+# Data structures: Vectors, matrices, data frames, and arrays
+###########################################################################
# ONE-DIMENSIONAL
-# You can vectorize anything, so long as all components have the same type
+# Let's start from the very beginning, and with something you already know: vectors.
vec <- c(8, 9, 10, 11)
vec # 8 9 10 11
-# The class of a vector is the class of its components
-class(vec) # "numeric"
-# If you vectorize items of different classes, weird coercions happen
-c(TRUE, 4) # 1 4
-c("dog", TRUE, 4) # "dog" "TRUE" "4"
-
-# We ask for specific components like so (R starts counting from 1)
-vec[1] # 8
+# We ask for specific elements by subsetting with square brackets
+# (Note that R starts counting from 1)
+vec[1] # 8
+letters[18] # "r"
+LETTERS[13] # "M"
+month.name[9] # "September"
+c(6, 8, 7, 5, 3, 0, 9)[3] # 7
# We can also search for the indices of specific components,
which(vec %% 2 == 0) # 1 3
-# or grab just the first or last entry in the vector
+# grab just the first or last few entries in the vector,
head(vec, 1) # 8
-tail(vec, 1) # 11
+tail(vec, 2) # 10 11
+# or figure out if a certain value is in the vector
+any(vec == 10) # TRUE
# If an index "goes over" you'll get NA:
vec[6] # NA
# You can find the length of your vector with length()
length(vec) # 4
-
# You can perform operations on entire vectors or subsets of vectors
vec * 4 # 16 20 24 28
vec[2:3] * 5 # 25 30
-# and there are many built-in functions to summarize vectors
+any(vec[2:3] == 8) # FALSE
+# and R has many built-in functions to summarize vectors
mean(vec) # 9.5
var(vec) # 1.666667
-sd(vec) # 1.290994
+sd(vec) # 1.290994
max(vec) # 11
min(vec) # 8
sum(vec) # 38
+# Some more nice built-ins:
+5:15 # 5 6 7 8 9 10 11 12 13 14 15
+seq(from=0, to=31337, by=1337)
+# =>
+# [1] 0 1337 2674 4011 5348 6685 8022 9359 10696 12033 13370 14707
+# [13] 16044 17381 18718 20055 21392 22729 24066 25403 26740 28077 29414 30751
# TWO-DIMENSIONAL (ALL ONE CLASS)
@@ -361,6 +390,7 @@ mat[1,] # 1 4
3 * mat[,1] # 3 6 9
# Ask for a specific cell
mat[3,2] # 6
+
# Transpose the whole matrix
t(mat)
# =>
@@ -368,6 +398,14 @@ t(mat)
# [1,] 1 2 3
# [2,] 4 5 6
+# Matrix multiplication
+mat %*% t(mat)
+# =>
+# [,1] [,2] [,3]
+# [1,] 17 22 27
+# [2,] 22 29 36
+# [3,] 27 36 45
+
# cbind() sticks vectors together column-wise to make a matrix
mat2 <- cbind(1:4, c("dog", "cat", "bird", "dog"))
mat2
@@ -390,33 +428,138 @@ mat3
# [,1] [,2] [,3] [,4]
# [1,] 1 2 4 5
# [2,] 6 7 0 4
-# Aah, everything of the same class. No coercions. Much better.
+# Ah, everything of the same class. No coercions. Much better.
# TWO-DIMENSIONAL (DIFFERENT CLASSES)
-# For columns of different classes, use the data frame
-dat <- data.frame(c(5,2,1,4), c("dog", "cat", "bird", "dog"))
-names(dat) <- c("number", "species") # name the columns
-class(dat) # "data.frame"
-dat
+# For columns of different types, use a data frame
+# This data structure is so useful for statistical programming,
+# a version of it was added to Python in the package "pandas".
+
+students <- data.frame(c("Cedric","Fred","George","Cho","Draco","Ginny"),
+ c(3,2,2,1,0,-1),
+ c("H", "G", "G", "R", "S", "G"))
+names(students) <- c("name", "year", "house") # name the columns
+class(students) # "data.frame"
+students
# =>
-# number species
-# 1 5 dog
-# 2 2 cat
-# 3 1 bird
-# 4 4 dog
-class(dat$number) # "numeric"
-class(dat[,2]) # "factor"
+# name year house
+# 1 Cedric 3 H
+# 2 Fred 2 G
+# 3 George 2 G
+# 4 Cho 1 R
+# 5 Draco 0 S
+# 6 Ginny -1 G
+class(students$year) # "numeric"
+class(students[,3]) # "factor"
+# find the dimensions
+nrow(students) # 6
+ncol(students) # 3
+dim(students) # 6 3
# The data.frame() function converts character vectors to factor vectors
+# by default; turn this off by setting stringsAsFactors = FALSE when
+# you create the data.frame
+?data.frame
# There are many twisty ways to subset data frames, all subtly unalike
-dat$number # 5 2 1 4
-dat[,1] # 5 2 1 4
-dat[,"number"] # 5 2 1 4
+students$year # 3 2 2 1 0 -1
+students[,2] # 3 2 2 1 0 -1
+students[,"year"] # 3 2 2 1 0 -1
+
+# An augmented version of the data.frame structure is the data.table
+# If you're working with huge or panel data, or need to merge a few data
+# sets, data.table can be a good choice. Here's a whirlwind tour:
+install.packages("data.table") # download the package from CRAN
+require(data.table) # load it
+students <- as.data.table(students)
+students # note the slightly different print-out
+# =>
+# name year house
+# 1: Cedric 3 H
+# 2: Fred 2 G
+# 3: George 2 G
+# 4: Cho 1 R
+# 5: Draco 0 S
+# 6: Ginny -1 G
+students[name=="Ginny"] # get rows with name == "Ginny"
+# =>
+# name year house
+# 1: Ginny -1 G
+students[year==2] # get rows with year == 2
+# =>
+# name year house
+# 1: Fred 2 G
+# 2: George 2 G
+# data.table makes merging two data sets easy
+# let's make another data.table to merge with students
+founders <- data.table(house=c("G","H","R","S"),
+ founder=c("Godric","Helga","Rowena","Salazar"))
+founders
+# =>
+# house founder
+# 1: G Godric
+# 2: H Helga
+# 3: R Rowena
+# 4: S Salazar
+setkey(students, house)
+setkey(founders, house)
+students <- founders[students] # merge the two data sets by matching "house"
+setnames(students, c("house","houseFounderName","studentName","year"))
+students[,order(c("name","year","house","houseFounderName")), with=F]
+# =>
+# studentName year house houseFounderName
+# 1: Fred 2 G Godric
+# 2: George 2 G Godric
+# 3: Ginny -1 G Godric
+# 4: Cedric 3 H Helga
+# 5: Cho 1 R Rowena
+# 6: Draco 0 S Salazar
+
+# data.table makes summary tables easy
+students[,sum(year),by=house]
+# =>
+# house V1
+# 1: G 3
+# 2: H 3
+# 3: R 1
+# 4: S 0
+
+# To drop a column from a data.frame or data.table,
+# assign it the NULL value
+students$houseFounderName <- NULL
+students
+# =>
+# studentName year house
+# 1: Fred 2 G
+# 2: George 2 G
+# 3: Ginny -1 G
+# 4: Cedric 3 H
+# 5: Cho 1 R
+# 6: Draco 0 S
+
+# Drop a row by subsetting
+# Using data.table:
+students[studentName != "Draco"]
+# =>
+# house studentName year
+# 1: G Fred 2
+# 2: G George 2
+# 3: G Ginny -1
+# 4: H Cedric 3
+# 5: R Cho 1
+# Using data.frame:
+students <- as.data.frame(students)
+students[students$house != "G",]
+# =>
+# house houseFounderName studentName year
+# 4 H Helga Cedric 3
+# 5 R Rowena Cho 1
+# 6 S Salazar Draco 0
-# MULTI-DIMENSIONAL (ALL OF ONE CLASS)
+# MULTI-DIMENSIONAL (ALL ELEMENTS OF ONE TYPE)
# Arrays creates n-dimensional tables
+# All elements must be of the same type
# You can make a two-dimensional table (sort of like a matrix)
array(c(c(1,2,4,5),c(8,9,3,6)), dim=c(2,4))
# =>
@@ -446,15 +589,23 @@ array(c(c(c(2,300,4),c(8,9,0)),c(c(5,60,0),c(66,7,847))), dim=c(3,2,2))
list1 <- list(time = 1:40)
list1$price = c(rnorm(40,.5*list1$time,4)) # random
list1
-
# You can get items in the list like so
-list1$time
-# You can subset list items like vectors
+list1$time # one way
+list1[["time"]] # another way
+list1[[1]] # yet another way
+# =>
+# [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
+# [34] 34 35 36 37 38 39 40
+# You can subset list items like any other vector
list1$price[4]
-#########################
+# Lists are not the most efficient data structure to work with in R;
+# unless you have a very good reason, you should stick to data.frames
+# Lists are often returned by functions that perform linear regressions
+
+##################################################
# The apply() family of functions
-#########################
+##################################################
# Remember mat?
mat
@@ -467,7 +618,7 @@ mat
# over rows (MAR = 1) or columns (MAR = 2)
# That is, R does FUN to each row (or column) of X, much faster than a
# for or while loop would do
-apply(mat, MAR = 2, myFunc)
+apply(mat, MAR = 2, jiggle)
# =>
# [,1] [,2]
# [1,] 3 15
@@ -478,16 +629,18 @@ apply(mat, MAR = 2, myFunc)
# Don't feel too intimidated; everyone agrees they are rather confusing
# The plyr package aims to replace (and improve upon!) the *apply() family.
-
install.packages("plyr")
require(plyr)
?plyr
+
+
#########################
# Loading data
#########################
# "pets.csv" is a file on the internet
+# (but it could just as easily be be a file on your own computer)
pets <- read.csv("http://learnxinyminutes.com/docs/pets.csv")
pets
head(pets, 2) # first two rows
@@ -499,10 +652,13 @@ write.csv(pets, "pets2.csv") # to make a new .csv file
# Try ?read.csv and ?write.csv for more information
+
+
#########################
# Plots
#########################
+# BUILT-IN PLOTTING FUNCTIONS
# Scatterplots!
plot(list1$time, list1$price, main = "fake data")
# Regressions!
@@ -512,18 +668,25 @@ linearModel # outputs result of regression
abline(linearModel, col = "red")
# Get a variety of nice diagnostics
plot(linearModel)
-
# Histograms!
hist(rpois(n = 10000, lambda = 5), col = "thistle")
-
# Barplots!
barplot(c(1,4,5,1,2), names.arg = c("red","blue","purple","green","yellow"))
+# GGPLOT2
+# But these are not even the prettiest of R's plots
# Try the ggplot2 package for more and better graphics
-
install.packages("ggplot2")
require(ggplot2)
?ggplot2
+pp <- ggplot(students, aes(x=house))
+pp + geom_histogram()
+ll <- as.data.table(list1)
+pp <- ggplot(ll, aes(x=time,price))
+pp + geom_point()
+# ggplot2 has excellent documentation (available http://docs.ggplot2.org/current/)
+
+
```
diff --git a/ro-ro/bash-ro.html.markdown b/ro-ro/bash-ro.html.markdown
index fa91cca4..debeb67a 100644
--- a/ro-ro/bash-ro.html.markdown
+++ b/ro-ro/bash-ro.html.markdown
@@ -12,16 +12,18 @@ lang: ro-ro
filename: LearnBash-ro.sh
---
-Bash este numele shell-ului unix, care a fost de asemenea distribuit drept shell pentru pentru sistemul de operare GNU si ca shell implicit pentru Linux si Mac OS X.
+Bash este numele shell-ului unix, care a fost de asemenea distribuit drept shell pentru sistemul de operare GNU si ca shell implicit pentru Linux si Mac OS X.
Aproape toate exemplele de mai jos pot fi parte dintr-un script sau pot fi executate direct in linia de comanda.
[Citeste mai multe:](http://www.gnu.org/software/bash/manual/bashref.html)
```bash
#!/bin/bash
-# Prima linie din script se numeste "shebang" care spune systemului cum sa execute scriptul
+# Prima linie din script se numeste "shebang"
+# care spune systemului cum sa execute scriptul
# http://en.wikipedia.org/wiki/Shebang_(Unix)
-# Dupa cum te-ai prins deja, comentariile incep cu #. Shebang este de asemenea un comentariu.
+# Dupa cum te-ai prins deja, comentariile incep cu #.
+# Shebang este de asemenea un comentariu.
# Exemplu simplu de hello world:
echo Hello world!
@@ -41,7 +43,8 @@ VARIABLE = "Niste text"
echo $VARIABLE
echo "$VARIABLE"
echo '$VARIABLE'
-# Atunci cand folosesti variabila, o atribui, o exporti sau altfel, numele ei se scrie fara $.
+# Atunci cand folosesti variabila, o atribui, o exporti sau altfel,
+# numele ei se scrie fara $.
# Daca vrei sa folosesti valoarea variabilei, atunci trebuie sa folosesti $.
# Atentie la faptul ca ' (apostrof) nu va inlocui variabla cu valoarea ei.
@@ -55,7 +58,8 @@ echo ${VARIABLE:0:7}
# Valoarea implicita a unei variabile:
echo ${FOO:-"ValoareaImplicitaDacaFOOLipsesteSauEGoala"}
-# Asta functioneaza pentru null (FOO=), sir de caractere gol (FOO=""), zero (FOO=0) returneaza 0
+# Asta functioneaza pentru null (FOO=),
+# sir de caractere gol (FOO=""), zero (FOO=0) returneaza 0
# Variabile pre-existente
echo "Ulima valoare returnata de ultimul program rulat: $?"
@@ -70,7 +74,8 @@ read NAME # Observa faptul ca nu a trebuit sa declaram o variabila noua
echo Salut, $NAME!
# Avem obisnuita instructiune "if"
-# Foloseste "man test" pentru mai multe informatii despre instructinea conditionala
+# Foloseste "man test" pentru mai multe informatii
+# despre instructinea conditionala
if [ $NAME -ne $USER ]
then
echo "Numele tau este username-ul tau"
@@ -79,8 +84,8 @@ else
fi
# Este de asemenea si executarea conditionala de comenzi
-echo "Intotdeauna executat" || echo "Executat numai daca prima instructiune esueaza"
-echo "Intotdeauna executat" && echo "Executat numai daca prima instructiune NU esueaza"
+echo "Intotdeauna executat" || echo "Executat daca prima instructiune esueaza"
+echo "Intotdeauna executat" && echo "Executat daca prima instructiune NU esueaza"
# Expresiile apar in urmatorul format
echo $(( 10 + 5 ))
@@ -93,9 +98,10 @@ ls
# Aceste comenzi au optiuni care la controleaza executia
ls -l # Listeaza fiecare fisier si director pe o linie separata
-# Rezultatele comenzii precedente poate fi trimis urmatoarei comenzi drept argument
-# Comanda grep filtreaza argumentele trimise cu sabloane. Astfel putem vedea fiserele
-# .txt din directorul curent.
+# Rezultatele comenzii anterioare pot fi
+# trimise urmatoarei comenzi drept argument
+# Comanda grep filtreaza argumentele trimise cu sabloane.
+# Astfel putem vedea fiserele .txt din directorul curent.
ls -l | grep "\.txt"
# De asemenea poti redirectiona o comanda, input si error output
@@ -106,17 +112,17 @@ python2 hello.py 2> "error.err"
# Daca vrei sa fie concatenate poti folosi ">>"
# Comenzile pot fi inlocuite in interiorul altor comenzi folosind $( ):
-# Urmatoarea comanda afiseaza numarul de fisiere si directoare din directorul curent
+# Urmatoarea comanda afiseaza numarul de fisiere
+# si directoare din directorul curent
echo "Sunt $(ls | wc -l) fisiere aici."
-# The same can be done using backticks `` but they can't be nested - the preferred way
-# is to use $( ).
-# Acelasi lucru se poate obtine folosind apostrf-ul inversat ``, dar nu pot fi folosite
-# unele in interiorul celorlalte asa ca modalitatea preferata este de a folosi $( )
+# Acelasi lucru se poate obtine folosind apostrf-ul inversat ``,
+# dar nu pot fi folosite unele in interiorul celorlalte asa ca modalitatea
+# preferata este de a folosi $( )
echo "Sunt `ls | wc -l` fisiere aici."
-# Bash foloseste o instructiune 'case' care functioneaza in mod similar cu instructiunea
-# switch din Java si C++
+# Bash foloseste o instructiune 'case' care functioneaza
+# in mod similar cu instructiunea switch din Java si C++
case "$VARIABLE" in
0) echo "Este un zero.";;
1) echo "Este un unu.";;
diff --git a/ro-ro/ruby-ro.html.markdown b/ro-ro/ruby-ro.html.markdown
index 27c6c462..12672b68 100644
--- a/ro-ro/ruby-ro.html.markdown
+++ b/ro-ro/ruby-ro.html.markdown
@@ -78,9 +78,9 @@ false.class #=> FalseClass
'Sunt un sir de caractere'.class #=> String
"Si eu sunt un sir de caractere".class #=> String
-fi_inlocuit = "inlocui o valoare in string"
+fi_inlocuit = "fi inlocuit"
"Pot #{fi_inlocuit} atunci cand folosesc dublu apostrof"
-#=> "Pot inlocui o valoare intr-un sir de caractere atunci cand folosesc dublu apostrof"
+#=> "Pot fi inlocuit atunci cand folosesc dublu apostrof"
# Printeaza
@@ -106,7 +106,8 @@ adresa = '/nume/nu atat de bun/'
# Simbolurile (sunt obiecte)
# Simbolurile sunt constante imutabile, reutilizabile, reprezentate intern
-# de o valoare numerica. Sunt deseori folosite in locul sirurilor de caractere pentru a da un nume reprezentativ unei valori
+# de o valoare numerica. Sunt deseori folosite in locul sirurilor de caractere
+# pentru a da un nume reprezentativ unei valori
:exemplu_simbol.class #=> Symbol
@@ -160,10 +161,12 @@ hash.keys #=> ['culoare', 'numar']
hash['culoare'] #=> 'verde'
hash['numar'] #=> 5
-# Incercand sa accesezi un element dintr-un hash printr-o cheie care nu exista va returna "nil".
+# Incercand sa accesezi un element dintr-un hash
+# printr-o cheie care nu exista va returna "nil".
hash['nimic_aici'] #=> nil
-# Incepand cu Ruby 1.9, este o sintaxa speciala pentru atunci cand se folosesc simboluri drept chei:
+# Incepand cu Ruby 1.9, este o sintaxa speciala
+# pentru atunci cand se folosesc simboluri drept chei:
hash_nou = { defcon: 3, actiune: true}
@@ -195,10 +198,11 @@ end
# TOTUSI, Nici una nu foloseste instructiunea for
# In locul acesteia ar trebui sa folosesti metoda "each" si sa ii trimiti un block
# Un bloc este o bucata de cod pe care o poti trimite unei metode precum "each".
-# Este analog pentru "lambda", functii anonime, sau closures in alte limbaje de programare.
+# Este analog pentru "lambda", functii anonime,
+# sau closures in alte limbaje de programare.
#
-# The "each" method of a range runs the block once for each element of the range.
-# Metoda "each" a unui interval, ruleaza block-ul o data pentru fiecare element din interval.
+# Metoda "each" a unui interval, ruleaza block-ul o data
+# pentru fiecare element din interval.
# Block-ul primeste ca si parametru un index
# Invocand metoda "each" cu un block, arata in urmatorul fel:
@@ -256,7 +260,8 @@ def dublu(x)
x * 2
end
-# Functille (si toate block-urile) returneaza implicit valoarea ultimei instructiuni
+# Functille (si toate block-urile)
+# returneaza implicit valoarea ultimei instructiuni
dublu(2) #=> 4
# Parantezele sunt optionale cand rezultatul nu este ambiguu
@@ -312,7 +317,8 @@ class Om
def initialize(nume, varsta=0)
# Atribuie argumentul, variabilei "nume", care apartine doar unei instante
@nume = nume
- # Daca varsta nu este data, o sa ii atribuim valoarea implicita din lista de argumente (0, in cazul nostru)
+ # Daca varsta nu este data, o sa ii atribuim valoarea implicita
+ # din lista de argumente (0, in cazul nostru)
@varsta = varsta
end
@@ -326,14 +332,17 @@ class Om
@nume
end
- # Functionalitatea de mai sus poate fi obtinuta folosing metoda "attr_accessor" dupa cum urmeaza:
+ # Functionalitatea de mai sus poate fi obtinuta
+ # folosing metoda "attr_accessor" dupa cum urmeaza:
attr_accessor :nume
- # Metodele pentru a lua si a seta valoarea unei variabile pot fi de asemenea obtinute individial:
+ # Metodele pentru a lua si a seta valoarea unei variabile
+ # pot fi de asemenea obtinute individial:
attr_reader :nume
attr_writer :nume
- # O metoda apartinand unei clase foloseste "self" pentru a se diferentia de metodele unei instante ale clasei respective
+ # O metoda apartinand unei clase foloseste "self" pentru a se diferentia
+ # de metodele unei instante ale clasei respective
# Poate fi invocata doar pe clasa, si nu pe o instanta a acesteia
def self.spune(msg)
puts "#{msg}"
@@ -380,8 +389,10 @@ defined? @@var #=> "class variable"
Var = "Sunt o constanta"
defined? Var #=> "constant"
-# Clasele sunt de asemenea obiecte in ruby. Astfel incat clasele pot avea variabile care apartin unei instante
-# O variabila care apartine unei clase poate fi accesata de toate instantele acesteia si de clasele care o extind
+# Clasele sunt de asemenea obiecte in ruby. Astfel incat clasele
+# pot avea variabile care apartin unei instante
+# O variabila care apartine unei clase poate fi accesata de toate
+# instantele acesteia si de clasele care o extind
# clasa parinte
class Om
@@ -406,7 +417,8 @@ Muncitor.foo # 0
Om.foo = 2 # 2
Muncitor.foo # 2
-# Variabilele care apartin unei instante ale unei clase, nu sunt impartite de (copii acesteia) clasele care o extind
+# Variabilele care apartin unei instante ale unei clase,
+# nu sunt impartite de (copii acesteia) clasele care o extind
class Om
@bar = 0
diff --git a/ru-ru/coffeescript-ru.html.markdown b/ru-ru/coffeescript-ru.html.markdown
new file mode 100644
index 00000000..f8416f38
--- /dev/null
+++ b/ru-ru/coffeescript-ru.html.markdown
@@ -0,0 +1,104 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["asaskevich", "http://github.com/asaskevich"]
+filename: learncoffee-ru.coffee
+lang: ru-ru
+---
+
+CoffeeScript - это небольшой язык, который компилируется один-в-один в эквивалентный код на языке JavaScript, а потому он не интерпретируется во время исполнения JavaScript кода.
+Ключевой особенностью CoffeeScript является то, что он пытается создать читабельный, качественно оформленный и плавный JavaScript код, прекрасно работающий в любой среде JavaScript.
+
+Также загляните на официальный сайт [языка](http://coffeescript.org/), где можно найти весьма полное учебное пособие по CoffeeScript.
+
+```coffeescript
+# CoffeeScript - язык хипстеров.
+# Язык использует самое модное из множества современных языков.
+# Эти комментарии по стилю похожи на комментарии Ruby или Python, они используют "решетку" в качестве знака комментария.
+
+###
+Блоки комментариев выделяются тремя символами "решетки", в результирующем JavaScript коде они будут преобразованы в '/ * и '* /'.
+
+Перед тем, как идти далее, Вам нужно понимать семантику JavaScript.
+###
+
+# Присвоение:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# Условия:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# Функции:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+fill = (container, liquid = "coffee") ->
+ "Заполняем #{container} жидкостью #{liquid}..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "coffee";
+# }
+# return "Заполняем " + container + " жидкостью " + liquid + "...";
+#};
+
+# Списки и диапазоны:
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# Объекты:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Многоточия:
+race = (winner, runners...) ->
+ print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
+
+# Проверка на существование объекта:
+alert "Так и знал!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("Так и знал!"); }
+
+# Итерации по массивам:
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['broccoli', 'spinach', 'chocolate']
+eat food for food in foods when food isnt 'chocolate'
+#=>foods = ['broccoli', 'spinach', 'chocolate'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'chocolate') {
+# eat(food);
+# }
+#}
+```
+
+## На почитать
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
+- [CoffeeScript на русском](http://cidocs.ru/coffeescript/)
diff --git a/ru-ru/go-ru.html.markdown b/ru-ru/go-ru.html.markdown
index ffda01b7..44a22b45 100644
--- a/ru-ru/go-ru.html.markdown
+++ b/ru-ru/go-ru.html.markdown
@@ -13,11 +13,11 @@ lang: ru-ru
---
Go - это язык общего назначения, целью которого является удобство, простота,
-конкуррентность. Это не тренд в компьютерных науках, а новейший и быстрый
+конкурентность. Это не тренд в компьютерных науках, а новейший и быстрый
способ решать насущные проблемы.
Концепции Go схожи с другими императивными статически типизированными языками.
-Быстро компилируется и быстро исполняется, имеет легкие в понимании конструкции
+Быстро компилируется и быстро исполняется, имеет лёгкие в понимании конструкции
для создания масштабируемых и многопоточных программ.
Может похвастаться отличной стандартной библиотекой и большим комьюнити, полным
@@ -57,7 +57,7 @@ func main() {
func beyondHello() {
var x int // Переменные должны быть объявлены до их использования.
x = 3 // Присвоение значения переменной.
- // Краткое определение := позволяет объявить перменную с автоматической
+ // Краткое определение := позволяет объявить переменную с автоматической
// подстановкой типа из значения.
y := 4
sum, prod := learnMultiple(x, y) // Функция возвращает два значения.
@@ -70,7 +70,7 @@ func learnMultiple(x, y int) (sum, prod int) {
return x + y, x * y // Возврат двух значений.
}
-// Некотрые встроенные типы и литералы.
+// Некоторые встроенные типы и литералы.
func learnTypes() {
// Краткое определение переменной говорит само за себя.
s := "Learn Go!" // Тип string.
@@ -79,7 +79,7 @@ func learnTypes() {
может содержать переносы строк` // Тоже тип данных string
// Символ не из ASCII. Исходный код Go в кодировке UTF-8.
- g := 'Σ' // тип rune, это алиас для типа uint32, содержит символ юникода.
+ g := 'Σ' // тип rune, это алиас для типа int32, содержит символ юникода.
f := 3.14195 // float64, 64-х битное число с плавающей точкой (IEEE-754).
c := 3 + 4i // complex128, внутри себя содержит два float64.
@@ -97,7 +97,7 @@ func learnTypes() {
// Слайсы (slices) имеют динамическую длину. И массивы, и слайсы имеют свои
// преимущества, но слайсы используются гораздо чаще.
- s3 := []int{4, 5, 9} // Сравните с a3. Тут нет троеточия.
+ s3 := []int{4, 5, 9} // Сравните с a3, тут нет троеточия.
s4 := make([]int, 4) // Выделение памяти для слайса из 4-х int (нули).
var d2 [][]float64 // Только объявление, память не выделяется.
bs := []byte("a slice") // Синтаксис приведения типов.
@@ -113,7 +113,7 @@ func learnTypes() {
delete(m, "three") // Встроенная функция, удаляет элемент из map-а.
// Неиспользуемые переменные в Go являются ошибкой.
- // Нижнее подчеркивание позволяет игнорировать такие переменные.
+ // Нижнее подчёркивание позволяет игнорировать такие переменные.
_, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
// Вывод считается использованием переменной.
fmt.Println(s, c, a4, s3, d2, m)
@@ -121,16 +121,16 @@ func learnTypes() {
learnFlowControl() // Идем дальше.
}
-// У Go есть полноценный сборщик мусора. В нем есть указатели но нет арифметики
+// У Go есть полноценный сборщик мусора. В нем есть указатели, но нет арифметики
// указателей. Вы можете допустить ошибку с указателем на nil, но не с
// инкрементацией указателя.
func learnMemory() (p, q *int) {
// Именованные возвращаемые значения p и q являются указателями на int.
p = new(int) // Встроенная функция new выделяет память.
- // Выделенный int проинициализирован нулем, p больше не содержит nil.
+ // Выделенный int проинициализирован нулём, p больше не содержит nil.
s := make([]int, 20) // Выделение единого блока памяти под 20 int-ов.
s[3] = 7 // Присвоить значение одному из них.
- r := -2 // Определить еще одну локальную переменную.
+ r := -2 // Определить ещё одну локальную переменную.
return &s[3], &r // Амперсанд(&) обозначает получение адреса переменной.
}
@@ -139,7 +139,7 @@ func expensiveComputation() float64 {
}
func learnFlowControl() {
- // If-ы всегда требуют наличине фигурных скобок, но не круглых.
+ // If-ы всегда требуют наличие фигурных скобок, но не круглых.
if true {
fmt.Println("told ya")
}
@@ -178,7 +178,7 @@ func learnFlowControl() {
}
// Функции являются замыканиями.
xBig := func() bool {
- return x > 10000 // Ссылается на x, объявленый выше switch.
+ return x > 10000 // Ссылается на x, объявленный выше switch.
}
fmt.Println("xBig:", xBig()) // true (т.к. мы присвоили x = e^10).
x = 1.3e3 // Тут х == 1300
@@ -189,7 +189,7 @@ func learnFlowControl() {
love:
learnDefer() // Быстрый обзор важного ключевого слова.
- learnInterfaces() // О! Интерфейсы, идем далее.
+ learnInterfaces() // О! Интерфейсы, идём далее.
}
func learnDefer() (ok bool) {
@@ -214,7 +214,7 @@ type pair struct {
// Объявление метода для типа pair. Теперь pair реализует интерфейс Stringer.
func (p pair) String() string { // p в данном случае называют receiver-ом.
- // Sprintf – еще одна функция из пакета fmt.
+ // Sprintf – ещё одна функция из пакета fmt.
// Обращение к полям p через точку.
return fmt.Sprintf("(%d, %d)", p.x, p.y)
}
@@ -234,7 +234,7 @@ func learnInterfaces() {
fmt.Println(p) // Вывод такой же, что и выше. Println вызывает метод String.
fmt.Println(i) // Вывод такой же, что и выше.
- learnVariadicParams("Учиться", "учиться", "и еще раз учиться!")
+ learnVariadicParams("Учиться", "учиться", "и ещё раз учиться!")
}
// Функции могут иметь варьируемое количество параметров.
@@ -263,22 +263,22 @@ func learnErrorHandling() {
// выведет "strconv.ParseInt: parsing "non-int": invalid syntax"
fmt.Println(err)
}
- // Мы еще обратимся к интерфейсам чуть позже, а пока...
+ // Мы ещё обратимся к интерфейсам чуть позже, а пока...
learnConcurrency()
}
-// c – это тип данных channel (канал), объект для конкуррентного взаимодействия.
+// c – это тип данных channel (канал), объект для конкурентного взаимодействия.
func inc(i int, c chan int) {
c <- i + 1 // когда channel слева, <- являтся оператором "отправки".
}
-// Будем использовать функцию inc для конкуррентной инкрементации чисел.
+// Будем использовать функцию inc для конкурентной инкрементации чисел.
func learnConcurrency() {
// Тот же make, что и в случае со slice. Он предназначен для выделения
// памяти и инициализации типов slice, map и channel.
c := make(chan int)
- // Старт трех конкуррентных goroutine. Числа будут инкрементированы
- // конкуррентно и, может быть параллельно, если машина правильно
+ // Старт трех конкурентных goroutine. Числа будут инкрементированы
+ // конкурентно и, может быть параллельно, если машина правильно
// сконфигурирована и позволяет это делать. Все они будут отправлены в один
// и тот же канал.
go inc(0, c) // go начинает новую горутину.
@@ -291,7 +291,7 @@ func learnConcurrency() {
cs := make(chan string) // другой канал, содержит строки.
cc := make(chan chan string) // канал каналов со строками.
go func() { c <- 84 }() // пуск новой горутины для отправки значения
- go func() { cs <- "wordy" }() // еще раз, теперь для cs
+ go func() { cs <- "wordy" }() // ещё раз, теперь для cs
// Select тоже что и switch, но работает с каналами. Он случайно выбирает
// готовый для взаимодействия канал.
select {
@@ -327,7 +327,7 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Основа всех основ в Go это [официальный веб сайт](http://golang.org/).
Там можно пройти туториал, поиграться с интерактивной средой Go и почитать
-объемную документацию.
+объёмную документацию.
Для живого ознакомления рекомендуется почитать исходные коды [стандартной
библиотеки Go](http://golang.org/src/pkg/). Отлично задокументированная, она
diff --git a/ru-ru/haskell-ru.html.markdown b/ru-ru/haskell-ru.html.markdown
new file mode 100644
index 00000000..e15fe6b7
--- /dev/null
+++ b/ru-ru/haskell-ru.html.markdown
@@ -0,0 +1,546 @@
+---
+language: Haskell
+contributors:
+ - ["Adit Bhargava", "http://adit.io"]
+translators:
+ - ["Aleksey Pirogov", "http://astynax.github.io"]
+lang: ru-ru
+---
+
+Haskell разрабатывался, как чистый функциональный язык программирования, применимый на практике. Язык известен благодаря своей системе типов, и "знаменит" благодаря монадам. [Меня][autor] же Haskell заставляет возвращаться к себе снова и снова именно своей элегантностью и [я][autor] получаю истинное удовольствие, программируя на Haskell.
+
+```haskell
+-- Однострочные комментарии начинаются с двух дефисов
+{- Многострочный комментарий
+заключается в пару фигурных скобок с дефисами с внутренней стороны.
+-}
+
+-------------------------------------------------------
+-- 1. Примитивные типы и простейшие операции над ними
+-------------------------------------------------------
+
+-- Числа объявляются просто
+3 -- 3
+
+-- Арифметика тоже выглядит вполне ожидаемо
+1 + 1 -- 2
+8 - 1 -- 7
+10 * 2 -- 20
+35 / 5 -- 7.0
+
+-- Операция деления всегда возвращает действительное число
+35 / 4 -- 8.75
+
+-- Делим нацело так
+35 `div` 4 -- 8
+
+-- Булевы значения - тоже примитивные значения
+True
+False
+
+-- Булева алгебра
+not True -- False
+not False -- True
+1 == 1 -- True
+1 /= 1 -- False
+1 < 10 -- True
+
+-- В примере выше `not`, это функция, принимающая один аргумент.
+-- При вызове функции в Haskell список аргументов
+-- не нужно заключать в скобки - аргументы просто
+-- перечисляются через пробелы сразу после имени функции.
+-- Т.о. типичный вызов выглядит так:
+-- func arg1 arg2 arg3...
+-- Ниже же будет показано, как определять свои функции.
+
+-- Строки и символы
+"Это строка."
+'ы' -- а это символ
+'Нельзя заключать длинные строки в одинарные кавычки.' -- ошибка!
+
+-- Строки можно конкатенировать
+"Привет" ++ ", Мир!" -- "Привет, Мир!"
+
+-- При этом строки - это просто списки символов!
+"Я - строка!" !! 0 -- 'Я'
+
+
+----------------------------------------------------
+-- Списки и Кортежи
+----------------------------------------------------
+
+-- Все элементы списка в Haskell
+-- должны иметь один и тот же тип.
+
+-- Эти два списка - эквивалентны:
+[1, 2, 3, 4, 5]
+[1..5]
+
+-- Haskell позволяет определять даже бесконечные списки!
+[1..] -- список всех натуральных чисел!
+
+-- Бесконечные списки возможно в Haskell потому, что он "ленив".
+-- В Haskell все вычисления производятся тогда и только тогда,
+-- когда их результат потребуется.
+-- Эта стратегия так и называется - "lazy evaluation".
+-- Скажем, если вам нужен тысячный элемент из
+-- списка натуральных чисел (бесконечного) и вы напишете так:
+
+[1..] !! 999 -- 1000
+
+-- То Haskell вычислит элементы этого списка от 1 до 1000...
+-- ... и остановится, ведь последующие элементы пока не нужны.
+-- Это значит, что остальные элементы нашего
+-- "бесконечного" списка не будут вычисляться! По крайней мере,
+-- пока не понадобятся и они.
+
+-- Списки можно объединять
+[1..5] ++ [6..10]
+
+-- И добавлять значения в начало
+0:[1..5] -- [0, 1, 2, 3, 4, 5]
+
+-- А можно обратиться по индексу
+[0..] !! 5 -- 5
+
+-- Вот ещё несколько функций, часто используемых со списками
+head [1..5] -- 1
+tail [1..5] -- [2, 3, 4, 5]
+init [1..5] -- [1, 2, 3, 4]
+last [1..5] -- 5
+
+-- list comprehensions - "формулы" для описания списков
+[x*2 | x <- [1..5]] -- [2, 4, 6, 8, 10]
+
+-- можно указать условие попадания элементов в список
+[x*2 | x <- [1..5], x*2 > 4] -- [6, 8, 10]
+
+-- Списки могут даже состоять из других списков
+[[1,2,3],[4,5,6]] !! 1 !! 2 -- 6 (вторая строка, третий столбец)
+
+-- Кортежи позволяют своим элементам иметь различные типы,
+-- но при этом кортежи имеют фиксированную длину.
+-- Кортеж:
+("haskell", 1)
+
+-- Часто кортежи из двух элементов называются "парами".
+-- Элементы пары можно получать так:
+fst ("haskell", 1) -- "haskell"
+snd ("haskell", 1) -- 1
+
+----------------------------------------------------
+-- 3. Функции
+----------------------------------------------------
+-- Простая функция, принимающая два аргумента
+add a b = a + b
+
+-- Внимание!
+-- Если вы используете ghci (интерактивный интерпретатор Haskell),
+-- вам нужно использовать ключевое слово `let`, примерно так:
+-- let add a b = a + b
+
+-- Вызовем нашу функцию
+add 1 2 -- 3
+
+-- Функцию можно поместить между первым и вторым аргументами,
+-- если заключить её имя в обратные кавычки
+1 `add` 2 -- 3
+
+{- Вы можете также определять функции, имя которых
+вообще не содержит букв! Таки функции и называются "операторами",
+и, да, вы можете определять свои операторы!
+Скажем, оператор целочисленного деления можно определить так -}
+(//) a b = a `div` b
+35 // 4 -- 8
+{- Здесь оператор заключен в скобки - как говорят,
+поставлен в префиксную позицию.
+В префиксной позиции оператор можно не только определять,
+но и вызывать -}
+(+) 1 2 -- 3
+
+-- Охранные выражения (guards) порой удобны,
+-- если наша функция ветвится
+fib x
+ | x < 2 = x
+ | otherwise = fib (x - 1) + fib (x - 2)
+
+{- Сопоставление с образцом (pattern matching)
+чем-то напоминает охранные выражения.
+Здесь мы видим три определения функции fib.
+При вызове функции по имени Haskell использует
+первое определение, к образцу которого
+"подойдет" набор аргументов -}
+fib 1 = 1
+fib 2 = 2
+fib x = fib (x - 1) + fib (x - 2)
+
+-- Pattern matching для кортежей выглядит так
+foo (x, y) = (x + 1, y + 2)
+
+{- Pattern matching для списков устроен чуть сложнее.
+Пусть `x` - первый элемент списка, а `xs` - остальные элементы.
+Тогда операции `head` и `tail` могут быть определены так -}
+myHead (x:xs) = x
+myTail (x:xs) = xs
+
+-- Функцию отображения мы можем написать так
+myMap func [] = []
+myMap func (x:xs) = func x:(myMap func xs)
+
+-- При сопоставлении происходит привязка
+-- элементов значения с именами в образце
+fstPlusThird (a : _ : b : _) = a + b
+fstPlusThird [1,2,3,4,5] -- 4
+-- Значения, для которых вместо имени указано `_`,
+-- игнорируются. Это удобно, когда важен сам факт
+-- совпадения образца
+oneElem [_] = True
+oneElem _ = False
+
+startsWith x (y:_) = x == y
+startsWith _ _ = False
+
+startsWith 'H' "Hello!" -- True
+startsWith 'H' "hello!" -- False
+
+{- Обратите внимание на тот факт,
+что первый аргумент нашей функции `myMap` - тоже функция!
+Функции, подобно `myMap`, принимающие другие функции
+в качестве параметров, или, скажем, возвращающие функции
+в качестве результата, называются
+Функциями Высших Порядков (ФВП, High Order Functions, HOF)
+-}
+
+-- Вместе с ФВП часто используются анонимные функции
+myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7]
+-- Такие функции описываются в виде
+-- \arg1 arg1 .. -> expression
+
+-- Популярные в других языках ФВП присутствуют и в Haskell
+map (\x -> x * 10) [1..5] -- [10, 20, 30, 40, 50]
+filter (\x -> x > 2) [1..5] -- [3, 4, 5]
+
+{- Функция свертки
+(она же `reduce` или `inject` в других языках)
+в Haskell представлены функциями `foldr` и `foldl`.
+Суть свертки можно представить так:
+
+foldl f x0 [x1,x2,x3] -> (f (f (f x0 x1) x2) x3)
+foldr f x0 [x1,x2,x3] -> (f x1 (f x2 (f x3 x0)))
+
+Здесь x0 - начальное значения так называемого "аккумулятора"
+-}
+-- Эти два вызова дают одинаковый результат
+foldr (\x acc -> acc + x) 0 [1..5] -- 15
+foldl (\acc x -> acc + x) 0 [1..5] -- 15
+-- Тут можно даже заменить анонимную функцию на оператор
+foldr (+) 0 [1..5] -- 15
+foldl (+) 0 [1..5] -- 15
+
+-- Зато здесь разница видна
+foldr (\x acc -> (x + 10) : acc) [] [1..3] -- [11, 12, 13]
+foldl (\acc x -> (x + 10) : acc) [] [1..3] -- [13, 12, 11]
+
+{- Часто в качестве начального значения
+удобно брать крайнее значение списка (крайнее слева или справа).
+Для этого есть пара функций - `foldr1` и `foldl1` -}
+foldr1 (+) [1..5] -- 15
+foldl1 (+) [1..5] -- 15
+
+----------------------------------------------------
+-- 4. Больше о функциях
+----------------------------------------------------
+
+{- Каррирование (currying)
+Если в Haskell при вызове функции передать не все аргументы,
+Функция становится "каррированой" - результатом вызова станет
+новая функция, которая при вызове и примет оставшиеся аргументы -}
+
+add a b = a + b
+foo = add 10 -- теперь foo будет принимать число
+ -- и добавлять к нему 10
+foo 5 -- 15
+
+-- Для операторов можно "опустить" любой из двух аргументов
+-- Используя этот факт можно определить
+-- функцию `foo` из кода выше несколько иначе
+foo = (+10)
+foo 5 -- 15
+
+-- Поупражняемся
+map (10-) [1..3] -- [9, 8, 7]
+filter (<5) [1..10] -- [1, 2, 3, 4]
+
+{- Композиция функций
+Функция (.) соединяет пару функций в цепочку.
+К примеру, можно соединить функцию, добавляющую 10,
+с функцией, умножающей на 5 -}
+foo = (*5) . (+10)
+
+-- (5 + 10) * 5 = 75
+foo 5 -- 75
+
+{- Управление приоритетом вычисления
+В Haskell есть функция `$`, которая применяет
+свой первый аргумент ко второму с наименьшим приоритетом
+(обычное применение функций имеет наивысший приоритет)
+Эта функция часто позволяет избежать использования
+"лишних" скобок -}
+head (tail (tail "abcd")) -- 'c'
+head $ tail $ tail "abcd" -- 'c'
+-- того же эффекта иногда можно достичь использованием композиции
+(head . tail . tail) "abcd" -- 'c'
+head . tail . tail $ "abcd" -- 'c'
+{- Тут стоит сразу запомнить, что композиция функций
+возвращает именно новую функцию, как в последнем примере.
+Т.е. можно делать так -}
+third = head . tail . tail
+-- но не так
+third = head $ tail $ tail -- (head (tail (tail))) - ошибка!
+
+----------------------------------------------------
+-- 5. Сигнатуры типов
+----------------------------------------------------
+
+{- Haskell обладает очень сильной системой типов.
+И типизация в Haskell - строгая. Каждое выражение имеет тип,
+который может быть описан сигнатурой.
+Сигнатура записывается в форме
+expression :: type signature
+-}
+
+-- Типы примитивов
+5 :: Integer
+"hello" :: String
+True :: Bool
+
+{- Функции тоже имеют тип
+`not` принимает булево значение и возвращает булев результат
+not :: Bool -> Bool
+
+Вот функция двух аргументов
+add :: Integer -> Integer -> Integer
+
+Тут то мы и видим предпосылки к каррированию: тип
+на самом деле выглядит так (скобки просто обычно опускаются)
+add :: (Integer -> Integer) -> Integer
+т.е. функция принимает аргумент,
+и возвращает функцию от второго аргумента! -}
+
+-- Считается хорошим тоном указывать сигнатуру определений,
+-- которые доступны другим разработчикам (публичны). Пример:
+double :: Integer -> Integer
+double x = x * 2
+
+----------------------------------------------------
+-- 6. Управление потоком исполнения
+----------------------------------------------------
+
+-- Выражение `if`
+haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome"
+
+-- Выражение `if` можно записать и в несколько строк.
+-- Соблюдайте отступы!
+haskell = if 1 == 1
+ then "awesome"
+ else "awful"
+
+-- Так как `if` - выражение, ветка `else` обязательна!
+-- И более того, результаты выражений в ветках `then` и `else`
+-- должны иметь одинаковый тип!
+
+-- `case`-выражение выглядит так
+case args of -- парсим аргументы командной строки
+ "help" -> printHelp
+ "start" -> startProgram
+ _ -> putStrLn "bad args"
+
+-- При вычислении результата `case`-выражения производится
+-- сопоставление с образцом:
+fib x = case x of
+ 1 -> 1
+ 2 -> 1
+ _ -> fib (x - 1) + fib (x - 2)
+
+-- В Haskell нет циклов - вместо них используются рекурсия,
+-- отображение, фильтрация и свертка (map/filter/fold)
+map (*2) [1..5] -- [2, 4, 6, 8, 10]
+
+for array func = map func array
+for [0..3] $ \i -> show i -- ["0", "1", "2", "3"]
+for [0..3] show -- ["0", "1", "2", "3"]
+
+----------------------------------------------------
+-- 7. Пользовательские типы данных
+----------------------------------------------------
+
+-- Создадим свой Haskell-тип данных
+
+data Color = Red | Blue | Green
+
+-- Попробуем использовать
+
+say :: Color -> String
+say Red = "You are Red!"
+say Blue = "You are Blue!"
+say Green = "You are Green!"
+
+-- Типы могут иметь параметры (параметры типов)
+
+data Maybe a = Nothing | Just a
+
+-- Все эти выражения имеют тип `Maybe`
+Just "hello" -- :: `Maybe String`
+Just 1 -- :: `Maybe Int`
+Nothing -- :: `Maybe a` для любого `a`
+
+-- Типы могут быть достаточно сложными
+data Figure = Rectangle (Int, Int) Int Int
+ | Square (Int, Int) Int
+ | Point (Int, Int)
+
+area :: Figure -> Int
+area (Point _) = 0
+area (Square _ s) = s * s
+area (Rectangle _ w h) = w * h
+
+----------------------------------------------------
+-- 8. Ввод-вывод в Haskell
+----------------------------------------------------
+
+-- Полноценно объяснить тему ввода-вывода невозможно
+-- без объяснения монад, но для использования в простых случаях
+-- вводного описания будет достаточно.
+
+-- Когда программа на Haskell выполняется,
+-- вызывается функция с именем `main`.
+-- Эта функция должна вернуть значение типа `IO ()`
+-- Например
+
+main :: IO ()
+main = putStrLn $ "Hello, sky! " ++ (say Blue)
+-- `putStrLn` имеет тип `String -> IO ()`
+
+-- Проще всего реализовать программу с вводом-выводом (IO),
+-- если вы реализуете функцию с типом `String -> String`.
+-- Далее ФВП
+-- interact :: (String -> String) -> IO ()
+-- сделает всё за нас!
+
+countLines :: String -> String
+countLines = show . length . lines
+-- здесь `lines` разделяет строку на список строк
+-- по символу перевода строки
+
+main' :: IO ()
+main' = interact countLines
+
+{- Вы можете думать о типе `IO ()`,
+как о некотором представлении последовательности
+действий, которые должен совершить компьютер.
+Такое представление напоминает программу
+на императивном языке программирования. Для описания
+такой последовательности используется `do`-нотация -}
+
+sayHello :: IO ()
+sayHello = do
+ putStrLn "What is your name?"
+ name <- getLine -- запрашиваем строку и связываем с "name"
+ putStrLn $ "Hello, " ++ name
+
+-- Упражнение:
+-- напишите свою реализацию функции `interact`,
+-- которая запрашивает и обрабатывает только одну строку
+
+{- Код функции `sayHello` не будет исполняться
+при её определении. Единственное место, где IO-действия
+могут быть произведены - функция `main`!
+Чтобы эта программа выполнила действия в функции `sayHello`,
+закомментируйте предыдущее определение функции `main`
+и добавьте новое определение:
+
+main = sayHello -}
+
+{- Давайте подробнее рассмотрим, как работает функция `getLine`
+Её тип:
+ getLine :: IO String
+Вы можете думать, что значение типа `IO a` представляет
+собой компьютерную программу, в результате выполнения которой
+генерируется значение типа `a`, в дополнение
+к остальным эффектам, производимым при выполнении - таким как
+печать текста на экран. Это значение типа `a` мы можем
+сохранить с помощью оператора `<-`. Мы даже можем реализовать
+свое действие, возвращающее значение: -}
+
+action :: IO String
+action = do
+ putStrLn "This is a line. Duh"
+ input1 <- getLine
+ input2 <- getLine
+ -- Тип блока `do` будет соответствовать типу последнего
+ -- выполненного в блоке выражения.
+ -- Заметим, что `return` - не ключевое слово, а функция
+ -- типа `a -> IO a`
+ return (input1 ++ "\n" ++ input2) -- return :: String -> IO String
+
+-- Теперь это действие можно использовать вместо `getLine`:
+
+main'' = do
+ putStrLn "I will echo two lines!"
+ result <- action
+ putStrLn result
+ putStrLn "This was all, folks!"
+
+{- Тип `IO` - пример "монады". Языку Haskell нужны монады,
+чтобы оставаться преимущественно чистым функциональным языком.
+Любые функции, взаимодействующие с внешним миром
+(производящие ввод-вывод) имеют `IO` в своих сигнатурах.
+Это позволяет судить о функции как о "чистой" - такая не будет
+производить ввод-вывод. В ином случая функция - не "чистая".
+
+Такой подход позволяет очень просто разрабатывать многопоточные
+программы - чистые функции, запущенные параллельно
+не будут конфликтовать между собой в борьбе за ресурсы. -}
+
+----------------------------------------------------
+-- 9. Haskell REPL
+----------------------------------------------------
+
+{- Интерактивная консоль Haskell запускается командой `ghci`.
+Теперь можно вводить строки кода на Haskell.
+Связывание значений с именами производится
+с помощью выражения `let`: -}
+
+let foo = 5
+
+-- Тип значения или выражения можно узнать
+-- с помощью команды `:t`:
+
+>:t foo
+foo :: Integer
+
+-- Также можно выполнять действия с типом `IO ()`
+
+> sayHello
+What is your name?
+Friend!
+Hello, Friend!
+
+```
+
+Многое о Haskell, например классы типов и монады невозможно уместить в столь короткую статью. Огромное количество очень интересных идей лежит в основе языка, и именно благодаря этому фундаменту на языке так приятно писать код. Позволю себе привести ещё один маленький пример кода на Haskell - реализацию быстрой сортировки:
+
+```haskell
+qsort [] = []
+qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater
+ where lesser = filter (< p) xs
+ greater = filter (>= p) xs
+```
+
+Haskell прост в установке, забирайте [здесь](http://www.haskell.org/platform/) и пробуйте! Это же так интересно!.
+
+Более глубокое погрузиться в язык позволят прекрасные книги
+[Learn you a Haskell](http://learnyouahaskell.com/) и
+[Real World Haskell](http://book.realworldhaskell.org/).
+
+[autor]: http://adit.io имеется в виду автор оригинального текста Adit Bhargava *(примечание переводчика)*
diff --git a/ru-ru/julia-ru.html.markdown b/ru-ru/julia-ru.html.markdown
index cd55e116..29392604 100644
--- a/ru-ru/julia-ru.html.markdown
+++ b/ru-ru/julia-ru.html.markdown
@@ -1,5 +1,5 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
translators:
diff --git a/ru-ru/markdown-ru.html.markdown b/ru-ru/markdown-ru.html.markdown
new file mode 100644
index 00000000..eb8e4881
--- /dev/null
+++ b/ru-ru/markdown-ru.html.markdown
@@ -0,0 +1,279 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+ - ["Pirogov Alexey", "http://twitter.com/alex_pir"]
+filename: markdown-ru.md
+lang: ru-ru
+---
+
+Язык разметки Markdown создан Джоном Грубером (англ. John Gruber)
+и Аароном Шварцем (англ. Aaron H. Swartz) в 2004 году.
+Авторы задавались целью создать максимально удобочитаемый
+и удобный в публикации облегчённый язык разметки,
+пригодный для последующего преобразования в HTML
+(а также и в другие форматы).
+
+ ```markdown
+<!-- Markdown является надмножеством HTML, поэтому любой HTML-файл является
+валидным документом Markdown, что позволяет использовать напрямую
+любые элементы HTML-разметки, такие, например, как этот комментарий.
+ Встроенные в документ HTML-элементы не затрагиваются парсером Markdown
+и попадают в итоговый HTML без изменений. Однако, следует понимать,
+что эта же особенность не позволяет использовать разметку Markdown внутри
+HTML-элементов -->
+
+<!-- Ещё одна особенность формата Markdown состоит в том, что поддерживаемые
+возможности разметки зависят от конкретной реализации парсера. В данном
+руководстве возможности, поддерживаемые лишь определёнными парсерами,
+сопровождаются соответствующими примечаниями. -->
+
+<!-- Заголовки -->
+
+<!-- HTML-элементы от <h1> до <h6> размечаются очень просто:
+текст, который должен стать заголовком, предваряется
+соответствующим количеством символов "#": -->
+# Это заголовок h1
+## Это заголовок h2
+### Это заголовок h3
+#### Это заголовок h4
+##### Это заголовок h5
+###### Это заголовок h6
+
+<!-- Markdown позволяет размечать заголовки <h1> и <h2> ещё одним способом: -->
+Это заголовок h1
+================
+
+А это заголовок h2
+------------------
+
+<!-- Простейшая стилизация текста -->
+
+<!-- Текст легко сделать полужирным и/или курсивным: -->
+
+*Этот текст будет выведен курсивом.*
+_Так же, как этот._
+
+**А этот текст будет полужирным.**
+__И этот тоже.__
+
+***Полужирный курсив.***
+**_И тут!_**
+*__И даже здесь!__*
+
+<!-- В Github Flavored Markdown (версии Markdown, использующейся в Github,
+для рендеринга Markdown-документов) текст можно сделать зачёркнутым: -->
+
+~~Зачёркнутый текст.~~
+
+<!-- Абзацами являются любые строки, следующие друг за другом.
+Разделяются же абзацы одной или несколькими пустыми строками: -->
+
+Это абзац. Всё предельно просто.
+
+А тут уже параграф №2.
+Эта строка всё ещё относится к параграфу №2!
+
+
+О, а вот это уже параграф №3!
+
+<!-- Для вставки принудительных переносов можно использовать HTML-тэг <br/>: -->
+
+Принудительный <br/> перенос!
+
+<!-- Цитаты размечаются с помощью символа ">": -->
+
+> Это цитата. В цитатах можно
+> принудительно переносить строки, вставляя ">" в начало каждой следующей строки. А можно просто оставлять достаточно длинными, и такие длинные строки будут перенесены автоматически.
+> Разницы между этими двумя подходами к переносу строк нет, коль скоро
+> каждая строка начинается с символа ">"
+
+> А ещё цитаты могут быть многоуровневыми:
+>> как здесь
+>>> и здесь :)
+> Неплохо?
+
+<!-- Списки -->
+<!-- Маркированные списки размечаются вставкой в начало каждого элемента
+одного из символов "*", "+" или "-":
+(символ должен быть одним и тем же для всех элементов) -->
+
+* Список,
+* Размеченный
+* Звёздочками
+
+либо
+
++ Список,
++ Размеченный
++ Плюсами
+
+либо
+
+- Список,
+- Размеченный
+- Дефисами
+
+<!-- В нумерованных списках каждая строка начинается
+с числа и точки вслед за ним: -->
+
+1. Первый элемент
+2. Второй элемент
+3. Третий элемент
+
+<!-- Заметьте, нумеровать элементы корректно необязательно. Достаточно указать
+любое число в начале каждого элемента и рендер пронумерует элементы сам!
+Правда, злоупотреблять этим не стоит :) -->
+
+1. Первый элемент
+1. Второй элемент
+1. Третий элемент
+<!-- (Этот список будет отрендерен так же, как и предыдущий!) -->
+
+<!-- Списки могут быть вложенными: -->
+
+1. Введение
+2. Начало работы
+3. Примеры использования
+ * Простые
+ * Сложные
+4. Заключение
+
+<!-- Блоки с исходным кодом -->
+<!-- Фрагменты исходного кода выделяются очень просто - каждая строка блока должна иметь отступ в четыре пробела либо в один символ табуляции -->
+
+ Это код,
+ причём - многострочный
+
+<!-- Дополнительные отступы в коде следует делать с помощью четырёх пробелов: -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Иногда бывает нужно вставить фрагмент кода прямо в строку текста,
+не выделяя код в блок. Для этого фрагменты кода нужно обрамлять
+символами "`": -->
+
+Например, можно выделить имя функции `go_to()` прямо посреди текста.
+
+<!-- Github Flavored Markdown позволяет указать для блока кода синтаксис оного.
+В этом случае синтаксис внутри блока будет подсвечен. Пример: -->
+
+\`\`\`ruby <!-- Только нужно будет убрать символы "\", оставив лишь "```ruby" -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- И здесь тоже backslashes нужно убрать, т.е. оставить "```" -->
+
+<-- Обратите внимание: фрагмент, указанный выше, не предваряется отступами,
+поскольку Github сам в состоянии определить границы блока - по строкам "```" -->
+
+<!-- Горизонтальный разделитель (<hr />) -->
+<!-- Разделители добавляются вставкой строки из трёх и более
+(одинаковых) символов "*" или "-": -->
+
+***
+---
+- - - <!-- между символами допустимы пробелы -->
+****************
+
+<!-- Ссылки -->
+<!-- Одной из сильных сторон Markdown можно смело считать то,
+как просто размечаются гиперссылки. Для создания ссылки укажите
+текст ссылки, заключив его в квадратные скобки,
+и сразу после - url, заключенный в "круглые" -->
+
+[Ссылка!](http://test.com/)
+
+<!-- Также для ссылки можно указать всплывающую подсказку: -->
+
+[Ссылка!](http://test.com/ "Ссылка на Test.com")
+
+<!-- В url можно использовать относительные пути: -->
+
+[Перейти к музыке](/music/).
+
+<!-- Markdown позволяет размечать ссылку в виде сноски: -->
+
+[Здесь][link1] высможете узнать больше!
+А можно кликнуть [сюда][foobar], если очень хочется.
+
+<!-- где-нибудь внизу -->
+[link1]: http://test.com/ "Круто!"
+[foobar]: http://foobar.biz/ "Тоже хорошо!"
+
+<!-- Примечания:
+- Подсказка может быть заключена в одинарные кавычки вместо двойных,
+ а также в круглые скобки.
+- Сноска может находиться в любом месте документа и может иметь
+идентификатор (далее ID) произвольной длины,
+лишь бы это ID был уникальным. -->
+
+<!-- Также при разметке ссылок-сносок можно опустить ID,
+если текст ссылки уникален в пределах документа: -->
+
+Ссылка на [Google][].
+
+[google]: http://google.com/
+
+<!-- Правда, эта возможность не очень распространена. -->
+
+<!-- Изображения -->
+<!-- Разметка изображений очень похожа на разметку ссылок.
+Нужно всего лишь добавить "!" перед ссылкой! -->
+
+![Альтернативный текст для изображения](http://imgur.com/myimage.jpg "Подсказка")
+
+<!-- Изображения тоже могут быть оформлены, как сноски: -->
+
+![Альтернативный текст][myimage]
+
+![То же изображение ещё раз][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "подсказка"
+
+<!-- Ещё немного ссылок: -->
+<!-- Автоссылки -->
+
+Ссылка вида <http://testwebsite.com/> эквивалентна
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Автоссылки для адресов электронной почты -->
+
+<foo@bar.com>
+
+<!-- Экранирование символов -->
+
+<!-- Может потребоваться вставить спецсимвол в текст "как есть",
+т.е. защитить его от обработки парсером.
+Такой символ должен быть "экранирован" с помощью обратной косой черты
+(символа "\"): -->
+
+\*текст, заключённый в звёздочки!\*
+
+<!-- Таблицы -->
+<!-- Таблицы официально поддерживаются только в Github Flavored Markdown,
+да и синтаксис имеют не слишком удобный.
+Но если очень нужно, размечайте таблицы так: -->
+
+| Столбец 1 | Столбец 2 | Столбец 3 |
+| :----------- | :----------: | -----------: |
+| Выравнивание | Выравнивание | Выравнивание |
+| влево | по центру | вправо |
+
+<!-- Или более компактно -->
+
+Колонка 1|Колонка 2|Колонка 3
+:--|:-:|--:
+Выглядит|это|страшновато...
+
+<!-- Ну вот и всё! -->
+
+```
+
+За более подробной информацией обращайтесь к [статье](http://daringfireball.net/projects/markdown/syntax) Джона Грубера о синтаксисе Markdown.
+
+Также часто бывает полезной отличная ["шпаргалка"](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) по Markdown от Adam Pritchard.
+
+Если вдруг встретите ошибки в переводе или же захотите его дополнить, делайте pull requests - авторы всегда рады обратной связи!
diff --git a/ru-ru/objective-c-ru.html.markdown b/ru-ru/objective-c-ru.html.markdown
index 72e3b9e0..3246de82 100644
--- a/ru-ru/objective-c-ru.html.markdown
+++ b/ru-ru/objective-c-ru.html.markdown
@@ -13,7 +13,7 @@ Objective-C — компилируемый объектно-ориентиров
построенный на основе языка Си и парадигм Smalltalk.
В частности, объектная модель построена в стиле Smalltalk — то есть объектам посылаются сообщения.
-```cpp
+```objective_c
// Однострочный комментарий
/*
diff --git a/ru-ru/php-ru.html.markdown b/ru-ru/php-ru.html.markdown
index edcac4dd..53b2f916 100644
--- a/ru-ru/php-ru.html.markdown
+++ b/ru-ru/php-ru.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/ru-ru/python-ru.html.markdown b/ru-ru/python-ru.html.markdown
index 204eb357..d59d3e21 100644
--- a/ru-ru/python-ru.html.markdown
+++ b/ru-ru/python-ru.html.markdown
@@ -5,25 +5,29 @@ contributors:
- ["Louie Dinh", "http://ldinh.ca"]
translators:
- ["Yury Timofeev", "http://twitter.com/gagar1n"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
filename: learnpython-ru.py
---
-Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из самых популярных
-языков. Я люблю его за его понятный и доходчивый синтаксис - это почти что исполняемый псевдокод.
+Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из
+самых популярных языков. Я люблю его за понятный и доходчивый синтаксис — это
+почти что исполняемый псевдокод.
-С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh) или louiedinh [at] [google's email service]
+С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh)
+или louiedinh [at] [почтовый сервис Google]
-Замечание: Эта статья относится к Python 2.7, но должно работать и в Python 2.x. Скоро будет версия и для Python 3!
+Замечание: Эта статья относится к Python 2.7, но должно работать и в Python 2.x.
+Скоро будет версия и для Python 3!
```python
-# Однострочные комментарии начинаются с hash-символа.
+# Однострочные комментарии начинаются с символа решётки.
""" Многострочный текст может быть
записан, используя 3 знака " и обычно используется
в качестве комментария
"""
####################################################
-## 1. Примитивные типы данных и операторов
+## 1. Примитивные типы данных и операторы
####################################################
# У вас есть числа
@@ -36,17 +40,31 @@ filename: learnpython-ru.py
35 / 5 #=> 7
# А вот деление немного сложнее. В этом случае происходит деление
-# целых чисел и результат автоматически округляется в меньшую сторону.
+# целых чисел, и результат автоматически округляется в меньшую сторону.
5 / 2 #=> 2
-# Чтобы научиться делить, сначала нужно немного узнать о дробных числах.
-2.0 # Это дробное число
+# Чтобы научиться делить, сначала нужно немного узнать о числах
+# с плавающей запятой.
+2.0 # Это число с плавающей запятой
11.0 / 4.0 #=> 2.75 Вооот... Так гораздо лучше
+# Результат целочисленного деления округляется в меньшую сторону
+# как для положительных, так и для отрицательных чисел.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # работает и для чисел с плавающей запятой
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# Остаток от деления
+7 % 3 # => 1
+
+# Возведение в степень
+2 ** 4 # => 16
+
# Приоритет операций указывается скобками
(1 + 3) * 2 #=> 8
-# Логические значения являются примитивами
+# Логические (булевы) значения являются примитивами
True
False
@@ -54,15 +72,15 @@ False
not True #=> False
not False #=> True
-# Равенство это ==
+# Равенство — это ==
1 == 1 #=> True
2 == 1 #=> False
-# Неравенство это !=
+# Неравенство — это !=
1 != 1 #=> False
2 != 1 #=> True
-# Еще немного сравнений
+# Ещё немного сравнений
1 < 10 #=> True
1 > 10 #=> False
2 <= 2 #=> True
@@ -85,9 +103,10 @@ not False #=> True
# Символ % используется для форматирования строк, например:
"%s могут быть %s" % ("строки", "интерполированы")
-# Новый метод форматирования строк - использование метода format.
+# Новый способ форматирования строк — использование метода format.
# Это предпочитаемый способ.
"{0} могут быть {1}".format("строки", "форматированы")
+
# Если вы не хотите считать, можете использовать ключевые слова.
"{name} хочет есть {food}".format(name="Боб", food="лазанью")
@@ -95,7 +114,7 @@ not False #=> True
None #=> None
# Не используйте оператор равенства '=='' для сравнения
-# объектов с None. Используйте для этого 'is'
+# объектов с None. Используйте для этого «is»
"etc" is None #=> False
None is None #=> True
@@ -113,17 +132,18 @@ None is None #=> True
## 2. Переменные и коллекции
####################################################
-# Печатать довольно просто
-print "Я Python. Приятно познакомиться!"
-
+# У Python есть функция Print, доступная в версиях 2.7 и 3,
+print("Я Python. Приятно познакомиться!")
+# ...и старый оператор print, доступный в версиях 2.x, но удалённый в версии 3.
+print "И я тоже Python!"
# Необязательно объявлять переменные перед их инициализацией.
-some_var = 5 # По соглашению используется нижний_регистр_с_подчеркиваниями
+some_var = 5 # По соглашению используется нижний_регистр_с_подчёркиваниями
some_var #=> 5
-# При попытке доступа к неинициализированной переменной,
+# При попытке доступа к неинициализированной переменной
# выбрасывается исключение.
-# См. раздел "Поток управления" для информации об исключениях.
+# См. раздел «Поток управления» для информации об исключениях.
some_other_var # Выбрасывает ошибку именования
# if может быть использован как выражение
@@ -149,24 +169,30 @@ li[0] #=> 1
# Обратимся к последнему элементу
li[-1] #=> 3
-# Попытка выйти за границы массива приведет к IndexError
-li[4] # Выдает IndexError
+# Попытка выйти за границы массива приведёт к ошибке индекса
+li[4] # Выдаёт IndexError
# Можно обращаться к диапазону, используя "кусочный синтаксис" (slice syntax)
-# (Для тех, кто любит математику, это называется замкнуто/открытый интервал.)
+# (Для тех, кто любит математику, это называется замкнуто-открытый интервал).
li[1:3] #=> [2, 4]
# Опускаем начало
li[2:] #=> [4, 3]
# Опускаем конец
li[:3] #=> [1, 2, 4]
+# Выбираем каждый второй элемент
+li[::2] # =>[1, 4]
+# Переворачиваем список
+li[::-1] # => [3, 4, 2, 1]
+# Используйте сочетания всего вышеназванного для выделения более сложных кусков
+# li[начало:конец:шаг]
# Удаляем произвольные элементы из списка оператором del
del li[2] # [1, 2, 3]
# Вы можете складывать списки
-li + other_li #=> [1, 2, 3, 4, 5, 6] - Замечание: li и other_li остаются нетронутыми
+li + other_li #=> [1, 2, 3, 4, 5, 6] — Замечание: li и other_li не изменяются
-# Конкатенировать списки можно методом extend
+# Объединять списки можно методом extend
li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
# Проверить элемент на вхождение в список можно оператором in
@@ -176,12 +202,12 @@ li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
len(li) #=> 6
-# Кортежи - это такие списки, только неизменяемые
+# Кортежи — это такие списки, только неизменяемые
tup = (1, 2, 3)
tup[0] #=> 1
-tup[0] = 3 # Выдает TypeError
+tup[0] = 3 # Выдаёт TypeError
-# Все то же самое можно делать и с кортежами
+# Всё то же самое можно делать и с кортежами
len(tup) #=> 3
tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
tup[:2] #=> (1, 2)
@@ -203,33 +229,33 @@ filled_dict = {"one": 1, "two": 2, "three": 3}
# Значения ищутся по ключу с помощью оператора []
filled_dict["one"] #=> 1
-# Можно получить все ключи в виде списка
+# Можно получить все ключи в виде списка с помощью метода keys
filled_dict.keys() #=> ["three", "two", "one"]
-# Замечание - сохранение порядка ключей в словаре не гарантируется
+# Замечание: сохранение порядка ключей в словаре не гарантируется
# Ваши результаты могут не совпадать с этими.
-# Можно получить и все значения в виде списка
+# Можно получить и все значения в виде списка, используйте метод values
filled_dict.values() #=> [3, 2, 1]
-# То же самое замечание насчет порядка ключей справедливо и здесь
+# То же самое замечание насчёт порядка ключей справедливо и здесь
# При помощи оператора in можно проверять ключи на вхождение в словарь
"one" in filled_dict #=> True
1 in filled_dict #=> False
-# Попытка получить значение по несуществующему ключу выбросит KeyError
+# Попытка получить значение по несуществующему ключу выбросит ошибку ключа
filled_dict["four"] # KeyError
# Чтобы избежать этого, используйте метод get
filled_dict.get("one") #=> 1
filled_dict.get("four") #=> None
-# Метод get также принимает аргумент default, значение которого будет
+# Метод get также принимает аргумент по умолчанию, значение которого будет
# возвращено при отсутствии указанного ключа
filled_dict.get("one", 4) #=> 1
filled_dict.get("four", 4) #=> 4
-# Метод setdefault - это безопасный способ добавить новую пару ключ-значение в словарь
+# Метод setdefault вставляет пару ключ-значение, только если такого ключа нет
filled_dict.setdefault("five", 5) #filled_dict["five"] возвращает 5
-filled_dict.setdefault("five", 6) #filled_dict["five"] по прежнему возвращает 5
+filled_dict.setdefault("five", 6) #filled_dict["five"] по-прежнему возвращает 5
# Множества содержат... ну, в общем, множества
@@ -237,8 +263,8 @@ empty_set = set()
# Инициализация множества набором значений
some_set = set([1,2,2,3,4]) # some_set теперь равно set([1, 2, 3, 4])
-# Начиная с Python 2.7, вы можете использовать {} чтобы обьявить множество
-filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
+# Начиная с Python 2.7, вы можете использовать {}, чтобы объявить множество
+filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
# Добавление новых элементов в множество
filled_set.add(5) # filled_set равно {1, 2, 3, 4, 5}
@@ -262,33 +288,33 @@ filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
## 3. Поток управления
####################################################
-# Для начала заведем переменную
+# Для начала заведём переменную
some_var = 5
# Так выглядит выражение if. Отступы в python очень важны!
-# результат: "some_var меньше, чем 10"
+# результат: «some_var меньше, чем 10»
if some_var > 10:
- print "some_var намного больше, чем 10."
+ print("some_var намного больше, чем 10.")
elif some_var < 10: # Выражение elif необязательно.
- print "some_var меньше, чем 10."
+ print("some_var меньше, чем 10.")
else: # Это тоже необязательно.
- print "some_var равно 10."
+ print("some_var равно 10.")
"""
Циклы For проходят по спискам
Результат:
- собака это млекопитающее
- кошка это млекопитающее
- мышь это млекопитающее
+ собака — это млекопитающее
+ кошка — это млекопитающее
+ мышь — это млекопитающее
"""
for animal in ["собака", "кошка", "мышь"]:
# Можете использовать оператор % для интерполяции форматированных строк
- print "%s это млекопитающее" % animal
+ print("%s — это млекопитающее" % animal)
"""
-`range(number)` возвращает список чисел
+«range(число)» возвращает список чисел
от нуля до заданного числа
Результат:
0
@@ -297,7 +323,7 @@ for animal in ["собака", "кошка", "мышь"]:
3
"""
for i in range(4):
- print i
+ print(i)
"""
Циклы while продолжаются до тех пор, пока указанное условие не станет ложным.
@@ -309,19 +335,24 @@ for i in range(4):
"""
x = 0
while x < 4:
- print x
- x += 1 # То же самое, что x = x + 1
+ print(x)
+ x += 1 # Краткая запись для x = x + 1
-# Обрабывайте исключения блоками try/except
+# Обрабатывайте исключения блоками try/except
# Работает в Python 2.6 и выше:
try:
- # Для выбора ошибки используется raise
- raise IndexError("Это IndexError")
+ # Чтобы выбросить ошибку, используется raise
+ raise IndexError("Это ошибка индекса")
except IndexError as e:
# pass это просто отсутствие оператора. Обычно здесь происходит
- # восстановление от ошибки.
+ # восстановление после ошибки.
pass
+except (TypeError, NameError):
+ pass # Несколько исключений можно обработать вместе, если нужно.
+else: # Необязательное выражение. Должно следовать за последним блоком except
+ print("Всё хорошо!") # Выполнится, только если не было никаких исключений
+
####################################################
@@ -330,23 +361,23 @@ except IndexError as e:
# Используйте def для создания новых функций
def add(x, y):
- print "x равен %s, а y равен %s" % (x, y)
+ print("x равен %s, а y равен %s" % (x, y))
return x + y # Возвращайте результат выражением return
# Вызов функции с аргументами
-add(5, 6) #=> prints out "x равен 5, а y равен 6" и возвращает 11
+add(5, 6) #=> выводит «x равен 5, а y равен 6» и возвращает 11
-# Другой способ вызова функции с аргументами
+# Другой способ вызова функции — вызов с именованными аргументами
add(y=6, x=5) # Именованные аргументы можно указывать в любом порядке.
-# Вы можете определить функцию, принимающую неизвестное количество аргументов
+# Вы можете определить функцию, принимающую изменяемое число аргументов
def varargs(*args):
return args
varargs(1, 2, 3) #=> (1,2,3)
-# А также можете определить функцию, принимающую изменяющееся количество
+# А также можете определить функцию, принимающую изменяемое число
# именованных аргументов
def keyword_args(**kwargs):
return kwargs
@@ -356,8 +387,8 @@ keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
# Если хотите, можете использовать оба способа одновременно
def all_the_args(*args, **kwargs):
- print args
- print kwargs
+ print(args)
+ print(kwargs)
"""
all_the_args(1, 2, a=3, b=4) выводит:
(1, 2)
@@ -368,11 +399,28 @@ all_the_args(1, 2, a=3, b=4) выводит:
# Используйте символ * для передачи кортежей и ** для передачи словарей
args = (1, 2, 3, 4)
kwargs = {"a": 3, "b": 4}
-all_the_args(*args) # эквивалент foo(1, 2, 3, 4)
-all_the_args(**kwargs) # эквивалент foo(a=3, b=4)
-all_the_args(*args, **kwargs) # эквивалент foo(1, 2, 3, 4, a=3, b=4)
+all_the_args(*args) # эквивалентно foo(1, 2, 3, 4)
+all_the_args(**kwargs) # эквивалентно foo(a=3, b=4)
+all_the_args(*args, **kwargs) # эквивалентно foo(1, 2, 3, 4, a=3, b=4)
-# Python имеет функции первого класса
+# Область определения функций
+x = 5
+
+def setX(num):
+ # Локальная переменная x — это не то же самое, что глобальная переменная x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # Глобальная переменная x теперь равна 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+# В Python есть функции первого класса
def create_adder(x):
def adder(y):
return x + y
@@ -388,7 +436,7 @@ add_10(3) #=> 13
map(add_10, [1,2,3]) #=> [11, 12, 13]
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
-# Мы можем использовать списки для удобного отображения и фильтрации
+# Для удобного отображения и фильтрации можно использовать списочные включения
[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
@@ -402,7 +450,11 @@ class Human(object):
# Атрибут класса. Он разделяется всеми экземплярами этого класса
species = "H. sapiens"
- # Обычный конструктор
+ # Обычный конструктор, вызывается при инициализации экземпляра класса
+ # Обратите внимание, что двойное подчёркивание в начале и в конце имени
+ # означает объекты и атрибуты, которые используются Python, но находятся
+ # в пространствах имён, управляемых пользователем.
+ # Не придумывайте им имена самостоятельно.
def __init__(self, name):
# Присваивание значения аргумента атрибуту класса name
self.name = name
@@ -423,17 +475,17 @@ class Human(object):
return "*grunt*"
-# Инстанцирование класса
+# Инициализация экземпляра класса
i = Human(name="Иван")
-print i.say("привет") # "Иван: привет"
+print(i.say("привет")) # Выводит: «Иван: привет»
-j = Human("Петр")
-print j.say("Привет") # "Петр: привет"
+j = Human("Пётр")
+print(j.say("Привет")) # Выводит: «Пётр: привет»
# Вызов метода класса
i.get_species() #=> "H. sapiens"
-# Присвоение разделяемому атрибуту
+# Изменение разделяемого атрибута
Human.species = "H. neanderthalensis"
i.get_species() #=> "H. neanderthalensis"
j.get_species() #=> "H. neanderthalensis"
@@ -448,12 +500,12 @@ Human.grunt() #=> "*grunt*"
# Вы можете импортировать модули
import math
-print math.sqrt(16) #=> 4
+print(math.sqrt(16)) #=> 4
# Вы можете импортировать отдельные функции модуля
from math import ceil, floor
-print ceil(3.7) #=> 4.0
-print floor(3.7) #=> 3.0
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7)) #=> 3.0
# Можете импортировать все функции модуля.
# (Хотя это и не рекомендуется)
@@ -463,7 +515,7 @@ from math import *
import math as m
math.sqrt(16) == m.sqrt(16) #=> True
-# Модули в Python это обычные файлы с кодом python. Вы
+# Модули в Python — это обычные Python-файлы. Вы
# можете писать свои модули и импортировать их. Название
# модуля совпадает с названием файла.
@@ -472,18 +524,72 @@ math.sqrt(16) == m.sqrt(16) #=> True
import math
dir(math)
+####################################################
+## 7. Дополнительно
+####################################################
+
+# Генераторы помогут выполнить ленивые вычисления
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# Генератор создаёт значения на лету.
+# Он не возвращает все значения разом, а создаёт каждое из них при каждой
+# итерации. Это значит, что значения больше 15 в double_numbers
+# обработаны не будут.
+# Обратите внимание: xrange — это генератор, который делает то же, что и range.
+# Создание списка чисел от 1 до 900000000 требует много места и времени.
+# xrange создаёт объект генератора, а не список сразу, как это делает range.
+# Если нам нужно имя переменной, совпадающее с ключевым словом Python,
+# мы используем подчёркивание в конце
+xrange_ = xrange(1, 900000000)
+
+# Будет удваивать все числа, пока результат не будет >= 30
+for i in double_numbers(xrange_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Декораторы
+# В этом примере beg оборачивает say
+# Метод beg вызовет say. Если say_please равно True,
+# он изменит возвращаемое сообщение
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, " Пожалуйста! У меня нет денег :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Вы не купите мне пива?"
+ return msg, say_please
+
+
+print(say()) # Вы не купите мне пива?
+print(say(say_please=True)) # Вы не купите мне пива? Пожалуйста! У меня нет денег :(
```
-## Хотите еще?
+## Хотите ещё?
### Бесплатные онлайн-материалы
* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
* [Dive Into Python](http://www.diveintopython.net/)
-* [The Official Docs](http://docs.python.org/2.6/)
+* [Официальная документация](http://docs.python.org/2.6/)
* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
* [Python Module of the Week](http://pymotw.com/2/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
### Платные
diff --git a/ru-ru/python3-ru.html.markdown b/ru-ru/python3-ru.html.markdown
new file mode 100644
index 00000000..637c0157
--- /dev/null
+++ b/ru-ru/python3-ru.html.markdown
@@ -0,0 +1,630 @@
+---
+language: python3
+lang: ru-ru
+contributors:
+ - ["Louie Dinh", "http://ldinh.ca"]
+ - ["Steven Basart", "http://github.com/xksteven"]
+translators:
+ - ["Andre Polykanine", "https://github.com/Oire"]
+filename: learnpython3-ru.py
+---
+
+Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из
+самых популярных языков. Я люблю его за понятный и доходчивый синтаксис — это
+почти что исполняемый псевдокод.
+
+С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh)
+или louiedinh [at] [почтовый сервис Google]
+
+Замечание: Эта статья относится только к Python 3.
+Если вы хотите изучить Python 2.7, обратитесь к другой статье.
+
+```python
+# Однострочные комментарии начинаются с символа решётки.
+""" Многострочный текст может быть
+ записан, используя 3 знака " и обычно используется
+ в качестве встроенной документации
+"""
+
+####################################################
+## 1. Примитивные типы данных и операторы
+####################################################
+
+# У вас есть числа
+3 #=> 3
+
+# Математика работает вполне ожидаемо
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+
+# Кроме деления, которое по умолчанию возвращает число с плавающей запятой
+35 / 5 # => 7.0
+
+# Результат целочисленного деления округляется в меньшую сторону
+# как для положительных, так и для отрицательных чисел.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # работает и для чисел с плавающей запятой
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# Когда вы используете числа с плавающей запятой,
+# результатом будет также число с плавающей запятой
+3 * 2.0 # => 6.0
+
+# Остаток от деления
+7 % 3 # => 1
+
+# Возведение в степень
+2 ** 4 # => 16
+
+# Приоритет операций указывается скобками
+(1 + 3) * 2 #=> 8
+
+# Для логических (булевых) значений существует отдельный примитивный тип
+True
+False
+
+# Для отрицания используется ключевое слово not
+not True #=> False
+not False #=> True
+
+# Равенство — это ==
+1 == 1 #=> True
+2 == 1 #=> False
+
+# Неравенство — это !=
+1 != 1 #=> False
+2 != 1 #=> True
+
+# Ещё немного сравнений
+1 < 10 #=> True
+1 > 10 #=> False
+2 <= 2 #=> True
+2 >= 2 #=> True
+
+# Сравнения могут быть записаны цепочкой:
+1 < 2 < 3 #=> True
+2 < 3 < 2 #=> False
+
+# Строки определяются символом " или '
+"Это строка."
+'Это тоже строка.'
+
+# И строки тоже могут складываться! Хотя лучше этого не делайте.
+"Привет " + "мир!" #=> "Привет мир!"
+
+# Со строкой можно работать, как со списком символов
+"Это строка"[0] #=> 'Э'
+
+# Метод format используется для форматирования строк:
+"{0} могут быть {1}".format("строки", "форматированы")
+
+# Вы можете повторять аргументы форматирования, чтобы меньше печатать.
+"Ехал {0} через реку, видит {0} - в реке {1}! Сунул {0} руку в реку, {1} за руку греку цап!".format("грека", "рак")
+#=> "Ехал грека через реку, видит грека - в реке рак! Сунул грека руку в реку, рак за руку греку цап!"
+# Если вы не хотите считать, можете использовать ключевые слова.
+"{name} хочет есть {food}".format(name="Боб", food="лазанью")
+
+# Если ваш код на Python 3 нужно запускать также и под Python 2.5 и ниже,
+# вы также можете использовать старый способ форматирования:
+"%s можно %s %s способом" % ("строки", "интерполировать", "старым")
+
+# None является объектом
+None #=> None
+
+# Не используйте оператор равенства '==' для сравнения
+# объектов с None. Используйте для этого 'is'
+"etc" is None #=> False
+None is None #=> True
+
+# Оператор «is» проверяет идентичность объектов. Он не
+# очень полезен при работе с примитивными типами, но
+# зато просто незаменим при работе с объектами.
+
+# None, 0 и пустые строки/списки/словари приводятся к False.
+# Все остальные значения равны True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Переменные и коллекции
+####################################################
+
+# У Python есть функция Print
+print("Я Python. Приятно познакомиться!")
+
+# Необязательно объявлять переменные перед их инициализацией.
+# По соглашению используется нижний_регистр_с_подчёркиваниями
+some_var = 5
+some_var #=> 5
+
+# При попытке доступа к неинициализированной переменной
+# выбрасывается исключение.
+# Об исключениях см. раздел «Поток управления и итерируемые объекты».
+some_unknown_var # Выбрасывает ошибку именования
+
+# Списки хранят последовательности
+li = []
+# Можно сразу начать с заполненным списком
+other_li = [4, 5, 6]
+
+# Объекты добавляются в конец списка методом append
+li.append(1) # [1]
+li.append(2) # [1, 2]
+li.append(4) # [1, 2, 4]
+li.append(3) # [1, 2, 4, 3]
+# И удаляются с конца методом pop
+li.pop() #=> возвращает 3 и li становится равен [1, 2, 4]
+# Положим элемент обратно
+li.append(3) # [1, 2, 4, 3].
+
+# Обращайтесь со списком, как с обычным массивом
+li[0] #=> 1
+# Обратимся к последнему элементу
+li[-1] #=> 3
+
+# Попытка выйти за границы массива приведёт к ошибке индекса
+li[4] # Выдаёт IndexError
+
+# Можно обращаться к диапазону, используя "кусочный синтаксис" (slice syntax)
+# (Для тех, кто любит математику, это называется замкнуто-открытый интервал).
+li[1:3] #=> [2, 4]
+# Опускаем начало
+li[2:] #=> [4, 3]
+# Опускаем конец
+li[:3] #=> [1, 2, 4]
+# Выбираем каждый второй элемент
+li[::2] # =>[1, 4]
+# Переворачиваем список
+li[::-1] # => [3, 4, 2, 1]
+# Используйте сочетания всего вышеназванного для выделения более сложных кусков
+# li[начало:конец:шаг]
+
+# Удаляем произвольные элементы из списка оператором del
+del li[2] # [1, 2, 3]
+
+# Вы можете складывать списки
+li + other_li #=> [1, 2, 3, 4, 5, 6] — Замечание: li и other_li не изменяются
+
+# Объединять списки можно методом extend
+li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
+
+# Проверить элемент на вхождение в список можно оператором in
+1 in li #=> True
+
+# Длина списка вычисляется функцией len
+len(li) #=> 6
+
+
+# Кортежи — это такие списки, только неизменяемые
+tup = (1, 2, 3)
+tup[0] #=> 1
+tup[0] = 3 # Выдаёт TypeError
+
+# Всё то же самое можно делать и с кортежами
+len(tup) #=> 3
+tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tup[:2] #=> (1, 2)
+2 in tup #=> True
+
+# Вы можете распаковывать кортежи (или списки) в переменные
+a, b, c = (1, 2, 3) # a == 1, b == 2 и c == 3
+# Кортежи создаются по умолчанию, если опущены скобки
+d, e, f = 4, 5, 6
+# Обратите внимание, как легко поменять местами значения двух переменных
+e, d = d, e # теперь d == 5, а e == 4
+
+
+# Словари содержат ассоциативные массивы
+empty_dict = {}
+# Вот так описывается предзаполненный словарь
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# Значения ищутся по ключу с помощью оператора []
+filled_dict["one"] #=> 1
+
+# Все значения в виде списка получаются с помощью метода keys().
+# Его вызов нужно обернуть в list(), так как обратно мы получаем
+# итерируемый объект, о которых поговорим позднее.
+list(filled_dict.keys()) # => ["three", "two", "one"]
+# Замечание: сохранение порядка ключей в словаре не гарантируется
+# Ваши результаты могут не совпадать с этими.
+
+# Все значения в виде списка можно получить с помощью values().
+# И снова нам нужно обернуть вызов в list(), чтобы превратить
+# итерируемый объект в список.
+list(filled_dict.values()) # => [3, 2, 1]
+# То же самое замечание насчёт порядка ключей справедливо и здесь
+
+# При помощи оператора in можно проверять ключи на вхождение в словарь
+"one" in filled_dict #=> True
+1 in filled_dict #=> False
+
+# Попытка получить значение по несуществующему ключу выбросит ошибку ключа
+filled_dict["four"] # KeyError
+
+# Чтобы избежать этого, используйте метод get
+filled_dict.get("one") #=> 1
+filled_dict.get("four") #=> None
+# Метод get также принимает аргумент по умолчанию, значение которого будет
+# возвращено при отсутствии указанного ключа
+filled_dict.get("one", 4) #=> 1
+filled_dict.get("four", 4) #=> 4
+
+# Метод setdefault вставляет пару ключ-значение, только если такого ключа нет
+filled_dict.setdefault("five", 5) #filled_dict["five"] возвращает 5
+filled_dict.setdefault("five", 6) #filled_dict["five"] по-прежнему возвращает 5
+
+# Удаляйте ключи из словаря с помощью оператора del
+del filled_dict["one"] # Удаляет ключ «one» из словаря
+
+
+# Множества содержат... ну, в общем, множества
+empty_set = set()
+# Инициализация множества набором значений.
+# Да, оно выглядит примерно как словарь… ну извините, так уж вышло.
+filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
+
+# Множеству можно назначать новую переменную
+filled_set = some_set
+
+# Добавление новых элементов в множество
+filled_set.add(5) # filled_set равно {1, 2, 3, 4, 5}
+
+# Пересечение множеств: &
+other_set = {3, 4, 5, 6}
+filled_set & other_set #=> {3, 4, 5}
+
+# Объединение множеств: |
+filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+
+# Разность множеств: -
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# Проверка на вхождение во множество: in
+2 in filled_set #=> True
+10 in filled_set #=> False
+
+
+####################################################
+## 3. Поток управления и итерируемые объекты
+####################################################
+
+# Для начала заведём переменную
+some_var = 5
+
+# Так выглядит выражение if. Отступы в python очень важны!
+# результат: «some_var меньше, чем 10»
+if some_var > 10:
+ print("some_var намного больше, чем 10.")
+elif some_var < 10: # Выражение elif необязательно.
+ print("some_var меньше, чем 10.")
+else: # Это тоже необязательно.
+ print("some_var равно 10.")
+
+
+# Циклы For проходят по спискам. Результат:
+ # собака — это млекопитающее
+ # кошка — это млекопитающее
+ # мышь — это млекопитающее
+for animal in ["собака", "кошка", "мышь"]:
+ # Можете использовать format() для интерполяции форматированных строк
+ print("{} — это млекопитающее".format(animal))
+
+"""
+«range(число)» возвращает список чисел
+от нуля до заданного числа
+Результат:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+Циклы while продолжаются до тех пор, пока указанное условие не станет ложным.
+Результат:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # Краткая запись для x = x + 1
+
+# Обрабатывайте исключения блоками try/except
+try:
+ # Чтобы выбросить ошибку, используется raise
+ raise IndexError("Это ошибка индекса")
+except IndexError as e:
+ # pass это просто отсутствие оператора. Обычно здесь происходит
+ # восстановление после ошибки.
+ pass
+except (TypeError, NameError):
+ pass # Несколько исключений можно обработать вместе, если нужно.
+else: # Необязательное выражение. Должно следовать за последним блоком except
+ print("Всё хорошо!") # Выполнится, только если не было никаких исключений
+
+# Python предоставляет фундаментальную абстракцию,
+# которая называется итерируемым объектом (an iterable).
+# Итерируемый объект — это объект, который воспринимается как последовательность.
+# Объект, который возвратила функция range(), итерируемый.
+filled_dict = {"one": 1, "two": 2, "three": 3}
+our_iterable = filled_dict.keys()
+print(our_iterable) #=> range(1,10). Это объект, реализующий интерфейс iterable
+
+# Мы можем проходить по нему циклом.
+for i in our_iterable:
+ print(i) # Выводит one, two, three
+
+# Но мы не можем обращаться к элементу по индексу.
+our_iterable[1] # Выбрасывает ошибку типа
+
+# Итерируемый объект знает, как создавать итератор.
+our_iterator = iter(our_iterable)
+
+# Итератор может запоминать состояние при проходе по объекту.
+# Мы получаем следующий объект, вызывая функцию __next__.
+our_iterator.__next__() #=> "one"
+
+# Он сохраняет состояние при вызове __next__.
+our_iterator.__next__() #=> "two"
+our_iterator.__next__() #=> "three"
+
+# Возвратив все данные, итератор выбрасывает исключение StopIterator
+our_iterator.__next__() # Выбрасывает исключение остановки итератора
+
+# Вы можете получить сразу все элементы итератора, вызвав на нём функцию list().
+list(filled_dict.keys()) #=> Возвращает ["one", "two", "three"]
+
+
+####################################################
+## 4. Функции
+####################################################
+
+# Используйте def для создания новых функций
+def add(x, y):
+ print("x равен %s, а y равен %s" % (x, y))
+ return x + y # Возвращайте результат выражением return
+
+# Вызов функции с аргументами
+add(5, 6) #=> выводит «x равен 5, а y равен 6» и возвращает 11
+
+# Другой способ вызова функции — вызов с именованными аргументами
+add(y=6, x=5) # Именованные аргументы можно указывать в любом порядке.
+
+# Вы можете определить функцию, принимающую изменяемое число аргументов
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# А также можете определить функцию, принимающую изменяемое число
+# именованных аргументов
+def keyword_args(**kwargs):
+ return kwargs
+
+# Вызовем эту функцию и посмотрим, что из этого получится
+keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+
+# Если хотите, можете использовать оба способа одновременно
+def all_the_args(*args, **kwargs):
+ print(args)
+ print(kwargs)
+"""
+all_the_args(1, 2, a=3, b=4) выводит:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# Вызывая функции, можете сделать наоборот!
+# Используйте символ * для передачи кортежей и ** для передачи словарей
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # эквивалентно foo(1, 2, 3, 4)
+all_the_args(**kwargs) # эквивалентно foo(a=3, b=4)
+all_the_args(*args, **kwargs) # эквивалентно foo(1, 2, 3, 4, a=3, b=4)
+
+# Область определения функций
+x = 5
+
+def setX(num):
+ # Локальная переменная x — это не то же самое, что глобальная переменная x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # Глобальная переменная x теперь равна 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+# В Python функции — «объекты первого класса». Это означает, что их можно использовать наравне с любыми другими значениями
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) #=> 13
+
+# Также есть и анонимные функции
+(lambda x: x > 2)(3) #=> True
+
+# Есть встроенные функции высшего порядка
+map(add_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# Для удобного отображения и фильтрации можно использовать списочные включения
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. Классы
+####################################################
+
+# Чтобы получить класс, мы наследуемся от object.
+class Human(object):
+
+ # Атрибут класса. Он разделяется всеми экземплярами этого класса
+ species = "H. sapiens"
+
+ # Обычный конструктор, вызывается при инициализации экземпляра класса
+ # Обратите внимание, что двойное подчёркивание в начале и в конце имени
+ # означает объекты и атрибуты, которые используются Python, но находятся
+ # в пространствах имён, управляемых пользователем.
+ # Не придумывайте им имена самостоятельно.
+ def __init__(self, name):
+ # Присваивание значения аргумента атрибуту класса name
+ self.name = name
+
+ # Метод экземпляра. Все методы принимают self в качестве первого аргумента
+ def say(self, msg):
+ return "{name}: {message}".format(name=self.name, message=msg)
+
+ # Метод класса разделяется между всеми экземплярами
+ # Они вызываются с указыванием вызывающего класса в качестве первого аргумента
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # Статический метод вызывается без ссылки на класс или экземпляр
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# Инициализация экземпляра класса
+i = Human(name="Иван")
+print(i.say("привет")) # Выводит: «Иван: привет»
+
+j = Human("Пётр")
+print(j.say("Привет")) # Выводит: «Пётр: привет»
+
+# Вызов метода класса
+i.get_species() #=> "H. sapiens"
+
+# Изменение разделяемого атрибута
+Human.species = "H. neanderthalensis"
+i.get_species() #=> "H. neanderthalensis"
+j.get_species() #=> "H. neanderthalensis"
+
+# Вызов статического метода
+Human.grunt() #=> "*grunt*"
+
+
+####################################################
+## 6. Модули
+####################################################
+
+# Вы можете импортировать модули
+import math
+print(math.sqrt(16)) #=> 4
+
+# Вы можете импортировать отдельные функции модуля
+from math import ceil, floor
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7)) #=> 3.0
+
+# Можете импортировать все функции модуля.
+# (Хотя это и не рекомендуется)
+from math import *
+
+# Можете сокращать имена модулей
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# Модули в Python — это обычные Python-файлы. Вы
+# можете писать свои модули и импортировать их. Название
+# модуля совпадает с названием файла.
+
+# Вы можете узнать, какие функции и атрибуты определены
+# в модуле
+import math
+dir(math)
+
+####################################################
+## 7. Дополнительно
+####################################################
+
+# Генераторы помогут выполнить ленивые вычисления
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# Генератор создаёт значения на лету.
+# Он не возвращает все значения разом, а создаёт каждое из них при каждой
+# итерации. Это значит, что значения больше 15 в double_numbers
+# обработаны не будут.
+# Обратите внимание: range — это тоже генератор.
+# Создание списка чисел от 1 до 900000000 требует много места и времени.
+# Если нам нужно имя переменной, совпадающее с ключевым словом Python,
+# мы используем подчёркивание в конце
+range_ = range(1, 900000000)
+
+# Будет удваивать все числа, пока результат не превысит 30
+for i in double_numbers(xrange_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Декораторы
+# В этом примере beg оборачивает say
+# Метод beg вызовет say. Если say_please равно True,
+# он изменит возвращаемое сообщение
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, " Пожалуйста! У меня нет денег :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Вы не купите мне пива?"
+ return msg, say_please
+
+
+print(say()) # Вы не купите мне пива?
+print(say(say_please=True)) # Вы не купите мне пива? Пожалуйста! У меня нет денег :(
+
+```
+
+## Хотите ещё?
+
+### Бесплатные онлайн-материалы
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+* [Официальная документация](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Платные
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/ruby-ecosystem.html.markdown b/ruby-ecosystem.html.markdown
index d186f712..8b292edd 100644
--- a/ruby-ecosystem.html.markdown
+++ b/ruby-ecosystem.html.markdown
@@ -3,21 +3,22 @@ category: tool
tool: ruby ecosystem
contributors:
- ["Jon Smock", "http://github.com/jonsmock"]
+ - ["Rafal Chmiel", "http://github.com/rafalchmiel"]
---
-People using ruby generally have a way to install different ruby versions,
+People using Ruby generally have a way to install different Ruby versions,
manage their packages (or gems), and manage their gem dependencies.
## Ruby Managers
-Some platforms have ruby pre-installed or available as a package. Most rubyists
-do not use these, or if they do, they only use them to bootstrap another ruby
-installer or implementation. Instead rubyists tend to install a ruby manager to
-install and switch between many versions of ruby and their projects' ruby
+Some platforms have Ruby pre-installed or available as a package. Most rubyists
+do not use these, or if they do, they only use them to bootstrap another Ruby
+installer or implementation. Instead rubyists tend to install a Ruby manager to
+install and switch between many versions of Ruby and their projects' Ruby
environments.
-The following are the popular ruby/environment managers:
+The following are the popular Ruby environment managers:
* [RVM](https://rvm.io/) - Installs and switches between rubies. RVM also has
the concept of gemsets to isolate projects' environments completely.
@@ -32,11 +33,11 @@ The following are the popular ruby/environment managers:
Ruby was created by Yukihiro "Matz" Matsumoto, who remains somewhat of a
[BDFL](https://en.wikipedia.org/wiki/Benevolent_Dictator_for_Life), although
-that is changing recently. As a result, the reference implementation of ruby is
-called MRI (Matz' Reference Implementation), and when you hear a ruby version,
+that is changing recently. As a result, the reference implementation of Ruby is
+called MRI (Matz' Reference Implementation), and when you hear a Ruby version,
it is referring to the release version of MRI.
-The three major version of ruby in use are:
+The three major version of Ruby in use are:
* 2.0.0 - Released in February 2013. Most major libraries and frameworks support
2.0.0.
@@ -52,38 +53,38 @@ the community has moved to at least 1.9.2 or 1.9.3.
## Ruby Implementations
-The ruby ecosystem enjoys many different implementations of ruby, each with
+The Ruby ecosystem enjoys many different implementations of Ruby, each with
unique strengths and states of compatability. To be clear, the different
-implementations are written in different languages, but *they are all ruby*.
+implementations are written in different languages, but *they are all Ruby*.
Each implementation has special hooks and extra features, but they all run
-normal ruby files well. For instance, JRuby is written in Java, but you do
+normal Ruby files well. For instance, JRuby is written in Java, but you do
not need to know Java to use it.
Very mature/compatible:
-* MRI - Written in C, this is the reference implementation of ruby. By
+* [MRI](https://github.com/ruby/ruby) - Written in C, this is the reference implementation of Ruby. By
definition it is 100% compatible (with itself). All other rubies
maintain compatibility with MRI (see [RubySpec](#rubyspec) below).
-* JRuby - Written in Java and ruby, this robust implementation is quite fast.
+* [JRuby](http://jruby.org/) - Written in Java and Ruby, this robust implementation is quite fast.
Most importantly, JRuby's strength is JVM/Java interop, leveraging existing
JVM tools, projects, and languages.
-* Rubinius - Written primarily in ruby itself with a C++ bytecode VM. Also
- mature and fast. Because it is implemented in ruby itself, it exposes many VM
+* [Rubinius](http://rubini.us/) - Written primarily in Ruby itself with a C++ bytecode VM. Also
+ mature and fast. Because it is implemented in Ruby itself, it exposes many VM
features into rubyland.
Medium mature/compatible:
-* Maglev - Built on top of Gemstone, a Smalltalk VM. Smalltalk has some
- impressive tooling, and this project tries to bring that into ruby
+* [Maglev](http://maglev.github.io/) - Built on top of Gemstone, a Smalltalk VM. Smalltalk has some
+ impressive tooling, and this project tries to bring that into Ruby
development.
-* RubyMotion - Brings ruby to iOS development.
+* [RubyMotion](http://www.rubymotion.com/) - Brings Ruby to iOS development.
Less mature/compatible:
-* Topaz - Written in RPython (using the PyPy toolchain), Topaz is fairly young
- and not yet compatible. It shows promise to be a high-performance ruby
+* [Topaz](http://topazruby.com/) - Written in RPython (using the PyPy toolchain), Topaz is fairly young
+ and not yet compatible. It shows promise to be a high-performance Ruby
implementation.
-* IronRuby - Written in C# targeting the .NET platform, work on IronRuby seems
+* [IronRuby](http://ironruby.net/) - Written in C# targeting the .NET platform, work on IronRuby seems
to have stopped since Microsoft pulled their support.
Ruby implementations may have their own release version numbers, but they always
@@ -93,14 +94,14 @@ which MRI version to target.
## RubySpec
-Most ruby implementations rely heavily on [RubySpec](http://rubyspec.org/). Ruby
+Most Ruby implementations rely heavily on [RubySpec](http://rubyspec.org/). Ruby
has no official specification, so the community has written executable specs in
-ruby to test their implementations' compatability with MRI.
+Ruby to test their implementations' compatibility with MRI.
## RubyGems
-[RubyGems](http://rubygems.org/) is a community-run package manager for ruby.
-RubyGems ships with ruby, so there is no need to download it separately.
+[RubyGems](http://rubygems.org/) is a community-run package manager for Ruby.
+RubyGems ships with Ruby, so there is no need to download it separately.
Ruby packages are called "gems," and they can be hosted by the community at
RubyGems.org. Each gem contains its source code and some metadata, including
@@ -121,17 +122,17 @@ dependency graph to resolve.
# Testing
-Testing is a large part of ruby culture. Ruby comes with its own Unit-style
-testing framework called minitest (Or TestUnit for ruby version 1.8.x). There
+Testing is a large part of Ruby culture. Ruby comes with its own Unit-style
+testing framework called minitest (Or TestUnit for Ruby version 1.8.x). There
are many testing libraries with different goals.
-* TestUnit - Ruby 1.8's built-in "Unit-style" testing framework
-* minitest - Ruby 1.9/2.0's built-in testing framework
-* RSpec - A testing framework that focuses on expressivity
-* Cucumber - A BDD testing framework that parses Gherkin formatted tests
+* [TestUnit](http://ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html) - Ruby 1.8's built-in "Unit-style" testing framework
+* [minitest](http://ruby-doc.org/stdlib-2.0.0/libdoc/minitest/rdoc/MiniTest.html) - Ruby 1.9/2.0's built-in testing framework
+* [RSpec](http://rspec.info/) - A testing framework that focuses on expressivity
+* [Cucumber](http://cukes.info/) - A BDD testing framework that parses Gherkin formatted tests
## Be Nice
-The ruby community takes pride in being an open, diverse, welcoming community.
+The Ruby community takes pride in being an open, diverse, welcoming community.
Matz himself is extremely friendly, and the generosity of rubyists on the whole
is amazing.
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 962853a2..3c67de2e 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -9,6 +9,7 @@ contributors:
- ["Nick LaMuro", "https://github.com/NickLaMuro"]
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
- ["Ariel Krakowski", "http://www.learneroo.com"]
+ - ["Dzianis Dashkevich", "https://github.com/dskecse"]
---
@@ -35,7 +36,7 @@ You shouldn't either
8 - 1 #=> 7
10 * 2 #=> 20
35 / 5 #=> 7
-2 ** 5 #=> 32
+2**5 #=> 32
# Arithmetic is just syntactic sugar
# for calling a method on an object
@@ -78,14 +79,17 @@ false.class #=> FalseClass
'I am a string'.class #=> String
"I am a string too".class #=> String
-placeholder = "use string interpolation"
+placeholder = 'use string interpolation'
"I can #{placeholder} when using double quoted strings"
#=> "I can use string interpolation when using double quoted strings"
+# Prefer single quoted strings to double quoted ones where possible
+# Double quoted strings perform additional inner calculations
+
# Combine strings, but not with numbers
-"hello " + "world" #=> "hello world"
-"hello " + 3 #=> TypeError: can't convert Fixnum into String
-"hello " + 3.to_s #=> "hello 3"
+'hello ' + 'world' #=> "hello world"
+'hello ' + 3 #=> TypeError: can't convert Fixnum into String
+'hello ' + 3.to_s #=> "hello 3"
# print to the output
puts "I'm printing!"
@@ -130,7 +134,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
# Arrays can contain different types of items
-[1, "hello", false] #=> [1, "hello", false]
+[1, 'hello', false] #=> [1, "hello", false]
# Arrays can be indexed
# From the front
@@ -157,7 +161,7 @@ array << 6 #=> [1, 2, 3, 4, 5, 6]
# Hashes are Ruby's primary dictionary with keys/value pairs.
# Hashes are denoted with curly braces:
-hash = {'color' => 'green', 'number' => 5}
+hash = { 'color' => 'green', 'number' => 5 }
hash.keys #=> ['color', 'number']
@@ -170,7 +174,7 @@ hash['nothing here'] #=> nil
# Since Ruby 1.9, there's a special syntax when using symbols as keys:
-new_hash = { defcon: 3, action: true}
+new_hash = { defcon: 3, action: true }
new_hash.keys #=> [:defcon, :action]
@@ -180,11 +184,11 @@ new_hash.keys #=> [:defcon, :action]
# Control structures
if true
- "if statement"
+ 'if statement'
elsif false
- "else if, optional"
+ 'else if, optional'
else
- "else, also optional"
+ 'else, also optional'
end
for counter in 1..5
@@ -216,7 +220,7 @@ end
#=> iteration 5
# You can also surround blocks in curly brackets:
-(1..5).each {|counter| puts "iteration #{counter}"}
+(1..5).each { |counter| puts "iteration #{counter}" }
# The contents of data structures can also be iterated using each.
array.each do |element|
@@ -241,32 +245,30 @@ grade = 'B'
case grade
when 'A'
- puts "Way to go kiddo"
+ puts 'Way to go kiddo'
when 'B'
- puts "Better luck next time"
+ puts 'Better luck next time'
when 'C'
- puts "You can do better"
+ puts 'You can do better'
when 'D'
- puts "Scraping through"
+ puts 'Scraping through'
when 'F'
- puts "You failed!"
+ puts 'You failed!'
else
- puts "Alternative grading system, eh?"
+ puts 'Alternative grading system, eh?'
end
-
#=> "Better luck next time"
# cases can also use ranges
grade = 82
case grade
- when 90..100
- puts "Hooray!"
- when 80...90
- puts "OK job"
- else
- puts "You failed!"
+when 90..100
+ puts 'Hooray!'
+when 80...90
+ puts 'OK job'
+else
+ puts 'You failed!'
end
-
#=> "OK job"
@@ -284,23 +286,23 @@ double 3 #=> 6
double double 3 #=> 12
-def sum(x,y)
+def sum(x, y)
x + y
end
# Method arguments are separated by a comma
sum 3, 4 #=> 7
-sum sum(3,4), 5 #=> 12
+sum sum(3, 4), 5 #=> 12
# yield
# All methods have an implicit, optional block parameter
# it can be called with the 'yield' keyword
def surround
- puts "{"
+ puts '{'
yield
- puts "}"
+ puts '}'
end
surround { puts 'hello world' }
@@ -311,25 +313,25 @@ surround { puts 'hello world' }
# You can pass a block to a function
-# "&" marks a reference to a passed block
+# "&" marks a reference to a passed block
def guests(&block)
- block.call "some_argument"
+ block.call 'some_argument'
end
-
+
# You can pass a list of arguments, which will be converted into an array
-# That's what splat operator ("*") is for
+# That's what splat operator ("*") is for
def guests(*array)
- array.each { |guest| puts "#{guest}" }
+ array.each { |guest| puts guest }
end
# Define a class with the class keyword
class Human
# A class variable. It is shared by all instances of this class.
- @@species = "H. sapiens"
+ @@species = 'H. sapiens'
# Basic initializer
- def initialize(name, age=0)
+ def initialize(name, age = 0)
# Assign the argument to the "name" instance variable for the instance
@name = name
# If no age given, we will fall back to the default in the arguments list.
@@ -356,20 +358,19 @@ class Human
# A class method uses self to distinguish from instance methods.
# It can only be called on the class, not an instance.
def self.say(msg)
- puts "#{msg}"
+ puts msg
end
def species
@@species
end
-
end
# Instantiate a class
-jim = Human.new("Jim Halpert")
+jim = Human.new('Jim Halpert')
-dwight = Human.new("Dwight K. Schrute")
+dwight = Human.new('Dwight K. Schrute')
# Let's call a couple of methods
jim.species #=> "H. sapiens"
@@ -380,7 +381,7 @@ dwight.species #=> "H. sapiens"
dwight.name #=> "Dwight K. Schrute"
# Call the class method
-Human.say("Hi") #=> "Hi"
+Human.say('Hi') #=> "Hi"
# Variable's scopes are defined by the way we name them.
# Variables that start with $ have global scope
@@ -399,7 +400,7 @@ defined? @@var #=> "class variable"
Var = "I'm a constant"
defined? Var #=> "constant"
-# Class also is object in ruby. So class can have instance variables.
+# Class is also an object in ruby. So class can have instance variables.
# Class variable is shared among the class and all of its descendants.
# base class
@@ -415,7 +416,7 @@ class Human
end
end
-# derived class
+# derived class
class Worker < Human
end
@@ -451,8 +452,8 @@ module ModuleExample
end
end
-# Including modules binds the methods to the object instance
-# Extending modules binds the methods to the class instance
+# Including modules binds their methods to the class instances
+# Extending modules binds their methods to the class itself
class Person
include ModuleExample
@@ -467,7 +468,7 @@ Person.new.foo # => 'foo'
Book.foo # => 'foo'
Book.new.foo # => NoMethodError: undefined method `foo'
-# Callbacks when including and extending a module are executed
+# Callbacks are executed when including and extending a module
module ConcernExample
def self.included(base)
@@ -500,9 +501,8 @@ Something.new.qux # => 'qux'
## Additional resources
-- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
+- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
- [Official Documentation](http://www.ruby-doc.org/core-2.1.1/)
- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
-- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
-
-
+- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
+- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) - A community-driven Ruby coding style guide.
diff --git a/rust.html.markdown b/rust.html.markdown
new file mode 100644
index 00000000..3717a7d9
--- /dev/null
+++ b/rust.html.markdown
@@ -0,0 +1,265 @@
+---
+language: rust
+contributors:
+ - ["P1start", "http://p1start.github.io/"]
+filename: learnrust.rs
+---
+
+Rust is an in-development programming language developed by Mozilla Research.
+It is relatively unique among systems languages in that it can assert memory
+safety *at compile time*. Rust’s first alpha release occurred in January
+2012, and development moves so quickly that at the moment the use of stable
+releases is discouraged, and instead one should use nightly builds.
+
+Although Rust is a relatively low-level language, Rust has some functional
+concepts that are generally found in higher-level languages. This makes
+Rust not only fast, but also easy and efficient to code in.
+
+```rust
+// This is a comment. Single-line look like this...
+/* ...and multi-line comment look like this */
+
+///////////////
+// 1. Basics //
+///////////////
+
+// Functions
+fn add2(x: int, y: int) -> int {
+ // Implicit return (no semicolon)
+ x + y
+}
+
+// Main function
+fn main() {
+ // Numbers //
+
+ // Immutable bindings
+ let x: int = 1;
+
+ // Integer/float suffixes
+ let y: int = 13i;
+ let f: f64 = 1.3f64;
+
+ // Type inference
+ let implicit_x = 1i;
+ let implicit_f = 1.3f64;
+
+ // Maths
+ let sum = x + y + 13i;
+
+ // Mutable variable
+ let mut mutable = 1;
+ mutable += 2;
+
+ // Strings //
+
+ // String literals
+ let x: &'static str = "hello world!";
+
+ // Printing
+ println!("{} {}", f, x); // 1.3 hello world
+
+ // A `String` - a heap-allocated string
+ let s: String = "hello world".to_string();
+
+ // A string slice - an immutable view into another string
+ // This is basically an immutable pointer to a string - it doesn’t
+ // actually contain the characters of a string, just a pointer to
+ // something that does (in this case, `s`)
+ let s_slice: &str = s.as_slice();
+
+ println!("{} {}", s, s_slice); // hello world hello world
+
+ // Vectors/arrays //
+
+ // A fixed-size array
+ let four_ints: [int, ..4] = [1, 2, 3, 4];
+
+ // A dynamically-sized vector
+ let mut vector: Vec<int> = vec![1, 2, 3, 4];
+ vector.push(5);
+
+ // A slice - an immutable view into a vector or array
+ // This is much like a string slice, but for vectors
+ let slice: &[int] = vector.as_slice();
+
+ println!("{} {}", vector, slice); // [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]
+
+ //////////////
+ // 2. Types //
+ //////////////
+
+ // Struct
+ struct Point {
+ x: int,
+ y: int,
+ }
+
+ let origin: Point = Point { x: 0, y: 0 };
+
+ // Tuple struct
+ struct Point2(int, int);
+
+ let origin2 = Point2(0, 0);
+
+ // Basic C-like enum
+ enum Direction {
+ Left,
+ Right,
+ Up,
+ Down,
+ }
+
+ let up = Up;
+
+ // Enum with fields
+ enum OptionalInt {
+ AnInt(int),
+ Nothing,
+ }
+
+ let two: OptionalInt = AnInt(2);
+ let nothing: OptionalInt = Nothing;
+
+ // Generics //
+
+ struct Foo<T> { bar: T }
+
+ // This is defined in the standard library as `Option`
+ enum Optional<T> {
+ SomeVal(T),
+ NoVal,
+ }
+
+ // Methods //
+
+ impl<T> Foo<T> {
+ // Methods take an explicit `self` parameter
+ fn get_bar(self) -> T {
+ self.bar
+ }
+ }
+
+ let a_foo = Foo { bar: 1i };
+ println!("{}", a_foo.get_bar()); // 1
+
+ // Traits (interfaces) //
+
+ trait Frobnicate<T> {
+ fn frobnicate(self) -> Option<T>;
+ }
+
+ impl<T> Frobnicate<T> for Foo<T> {
+ fn frobnicate(self) -> Option<T> {
+ Some(self.bar)
+ }
+ }
+
+ println!("{}", a_foo.frobnicate()); // Some(1)
+
+ /////////////////////////
+ // 3. Pattern matching //
+ /////////////////////////
+
+ let foo = AnInt(1);
+ match foo {
+ AnInt(n) => println!("it’s an int: {}", n),
+ Nothing => println!("it’s nothing!"),
+ }
+
+ // Advanced pattern matching
+ struct FooBar { x: int, y: OptionalInt }
+ let bar = FooBar { x: 15, y: AnInt(32) };
+
+ match bar {
+ FooBar { x: 0, y: AnInt(0) } =>
+ println!("The numbers are zero!"),
+ FooBar { x: n, y: AnInt(m) } if n == m =>
+ println!("The numbers are the same"),
+ FooBar { x: n, y: AnInt(m) } =>
+ println!("Different numbers: {} {}", n, m),
+ FooBar { x: _, y: Nothing } =>
+ println!("The second number is Nothing!"),
+ }
+
+ /////////////////////
+ // 4. Control flow //
+ /////////////////////
+
+ // `for` loops/iteration
+ let array = [1i, 2, 3];
+ for i in array.iter() {
+ println!("{}", i);
+ }
+
+ for i in range(0u, 10) {
+ print!("{} ", i);
+ }
+ println!("");
+ // prints `0 1 2 3 4 5 6 7 8 9 `
+
+ // `if`
+ if 1i == 1 {
+ println!("Maths is working!");
+ } else {
+ println!("Oh no...");
+ }
+
+ // `if` as expression
+ let value = if true {
+ "good"
+ } else {
+ "bad"
+ };
+
+ // `while` loop
+ while 1i == 1 {
+ println!("The universe is operating normally.");
+ }
+
+ // Infinite loop
+ loop {
+ println!("Hello!");
+ }
+
+ /////////////////////////////////
+ // 5. Memory safety & pointers //
+ /////////////////////////////////
+
+ // Owned pointer - only one thing can ‘own’ this pointer at a time
+ let mut mine: Box<int> = box 3;
+ *mine = 5; // dereference
+ let mut now_its_mine = mine;
+ *now_its_mine += 2;
+ println!("{}", now_its_mine); // 7
+ // println!("{}", mine); // this would error
+
+ // Reference - an immutable pointer that refers to other data
+ let mut var = 4i;
+ var = 3;
+ let ref_var: &int = &var;
+ println!("{}", var); // Unlike `box`, `var` can still be used
+ println!("{}", *ref_var);
+ // var = 5; // this would error
+ // *ref_var = 6; // this would too
+
+ // Mutable reference
+ let mut var2 = 4i;
+ let ref_var2: &mut int = &mut var2;
+ *ref_var2 += 2;
+ println!("{}", *ref_var2); // 6
+ // var2 = 2; // this would error
+}
+```
+
+## Further reading
+
+There’s a lot more to Rust—this is just the basics of Rust so you can
+understand the most important things. To learn more about Rust, read [The Rust
+Guide](http://doc.rust-lang.org/guide.html) and check out the
+[/r/rust](http://reddit.com/r/rust) subreddit. The folks on the #rust channel
+on irc.mozilla.org are also always keen to help newcomers.
+
+You can also try out features of Rust with an online compiler at the official
+[Rust playpen](http://play.rust-lang.org) or on the main
+[Rust website](http://rust-lang.org).
diff --git a/scala.html.markdown b/scala.html.markdown
index 2666746e..5a0cc0ff 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -9,7 +9,7 @@ filename: learn.scala
Scala - the scalable language
-```cpp
+```scala
/*
Set yourself up:
@@ -37,7 +37,7 @@ println("Hello world!")
print("Hello world")
// Declaring values is done using either var or val
-// val declarations are immutable, whereas var's are mutable. Immutablility is
+// val declarations are immutable, whereas var's are mutable. Immutability is
// a good thing.
val x = 10 // x is now 10
x = 20 // error: reassignment to val
@@ -243,7 +243,7 @@ i // Show the value of i. Note that while is a loop in the classical sense -
// A do while loop
do {
- println("x is still less then 10");
+ println("x is still less than 10");
x += 1
} while (x < 10)
@@ -299,7 +299,6 @@ Person("George", "1234") == Person("Kate", "1236")
-
// Pattern matching
val me = Person("George", "1234")
@@ -322,15 +321,21 @@ kate match { case Person("Kate", _) => "Girl"; case Person("George", _) => "Boy"
// Regular expressions
-
val email = "(.*)@(.*)".r // Invoking r on String makes it a Regex
-
-val email(user, domain) = "henry@zkpr.com"
-
-"mrbean@pyahoo.com" match {
- case email(name, domain) => "I know your name, " + name
+val serialKey = """(\d{5})-(\d{5})-(\d{5})-(\d{5})""".r // Using verbatim (multiline) syntax
+
+val matcher = (value: String) => {
+ println(value match {
+ case email(name, domain) => s"It was an email: $name"
+ case serialKey(p1, p2, p3, p4) => s"Serial key: $p1, $p2, $p3, $p4"
+ case _ => s"No match on '$value'" // default if no match found
+ })
}
+matcher("mrbean@pyahoo.com") // => "It was an email: mrbean"
+matcher("nope..") // => "No match on 'nope..'"
+matcher("52917") // => "No match on '52917'"
+matcher("52752-16432-22178-47917") // => "Serial key: 52752, 16432, 22178, 47917"
// Strings
@@ -347,17 +352,27 @@ println("ABCDEF".length)
println("ABCDEF".substring(2, 6))
println("ABCDEF".replace("C", "3"))
+// String interpolation
val n = 45
-println(s"We have $n apples")
+println(s"We have $n apples") // => "We have 45 apples"
+// Expressions inside interpolated strings are also possible
val a = Array(11, 9, 6)
-println(s"My second daughter is ${a(2-1)} years old")
+println(s"My second daughter is ${a(0) - a(2)} years old.") // => "My second daughter is 5 years old."
+println(s"We have double the amount of ${n / 2.0} in apples.") // => "We have double the amount of 22.5 in apples."
+println(s"Power of 2: ${math.pow(2, 2)}") // => "Power of 2: 4"
+
+// Formatting with interpolated strings (note the prefixed f)
+println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // "Power of 5: 25"
+println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // "Square root of 122"
+
+// Ignoring special characters.
+println(raw"New line feed: \n. Carriage return: \r.") // => "New line feed: \n. Carriage return: \r."
// Some characters need to be 'escaped', e.g. a double quote inside a string:
-val a = "They stood outside the \"Rose and Crown\""
+val a = "They stood outside the \"Rose and Crown\"" // => "They stood outside the "Rose and Crown""
// Triple double-quotes let strings span multiple rows and contain quotes
-
val html = """<form id="daform">
<p>Press belo', Joe</p>
| <input type="submit">
@@ -403,7 +418,10 @@ for(line <- Source.fromFile("myfile.txt").getLines())
println(line)
// To write a file use Java's PrintWriter
-
+val writer = new PrintWriter("myfile.txt")
+writer.write("Writing line for line" + util.Properties.lineSeparator)
+writer.write("Another line here" + util.Properties.lineSeparator)
+writer.close()
```
diff --git a/swift.html.markdown b/swift.html.markdown
new file mode 100644
index 00000000..005e511c
--- /dev/null
+++ b/swift.html.markdown
@@ -0,0 +1,494 @@
+---
+language: swift
+contributors:
+ - ["Grant Timmerman", "http://github.com/grant"]
+ - ["Christopher Bess", "http://github.com/cbess"]
+filename: learnswift.swift
+---
+
+Swift is a programming language for iOS and OS X development created by Apple. Designed to coexist with Objective-C and to be more resilient against erroneous code, Swift was introduced in 2014 at Apple's developer conference WWDC. It is built with the LLVM compiler included in Xcode 6 beta.
+
+The official [Swift Programming Language](https://itunes.apple.com/us/book/swift-programming-language/id881256329) book from Apple is now available via iBooks.
+
+See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html), which has a complete tutorial on Swift.
+
+```swift
+// import a module
+import UIKit
+
+//
+// MARK: Basics
+//
+
+// Xcode supports landmarks to annotate your code and lists them in the jump bar
+// MARK: Section mark
+// TODO: Do something soon
+// FIXME Fix this code
+
+println("Hello, world")
+
+// variables (var) value can change after being set
+// constants (let) value can NOT be changed after being set
+
+var myVariable = 42
+let øπΩ = "value" // unicode variable names
+let π = 3.1415926
+let convenience = "keyword" // contextual variable name
+let weak = "keyword"; let override = "another keyword" // statements can be separated by a semi-colon
+let `class` = "keyword" // backticks allow keywords to be used as variable names
+let explicitDouble: Double = 70
+let intValue = 0007 // 7
+let largeIntValue = 77_000 // 77000
+let label = "some text " + String(myVariable) // Casting
+let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation
+
+// Build Specific values
+// uses -D build configuration
+#if false
+ println("Not printed")
+ let buildValue = 3
+#else
+ let buildValue = 7
+#endif
+println("Build value: \(buildValue)") // Build value: 7
+
+/*
+ Optionals are a Swift language feature that allows you to store a `Some` or
+ `None` value.
+
+ Because Swift requires every property to have a value, even nil must be
+ explicitly stored as an Optional value.
+
+ Optional<T> is an enum.
+*/
+var someOptionalString: String? = "optional" // Can be nil
+// same as above, but ? is a postfix operator (syntax candy)
+var someOptionalString2: Optional<String> = "optional"
+
+if someOptionalString != nil {
+ // I am not nil
+ if someOptionalString!.hasPrefix("opt") {
+ println("has the prefix")
+ }
+
+ let empty = someOptionalString?.isEmpty
+}
+someOptionalString = nil
+
+// implicitly unwrapped optional
+var unwrappedString: String! = "Value is expected."
+// same as above, but ! is a postfix operator (more syntax candy)
+var unwrappedString2: ImplicitlyUnwrappedOptional<String> = "Value is expected."
+
+if let someOptionalStringConstant = someOptionalString {
+ // has `Some` value, non-nil
+ if !someOptionalStringConstant.hasPrefix("ok") {
+ // does not have the prefix
+ }
+}
+
+// Swift has support for storing a value of any type.
+// AnyObject == id
+// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc)
+var anyObjectVar: AnyObject = 7
+anyObjectVar = "Changed value to a string, not good practice, but possible."
+
+/*
+Comment here
+ /*
+ Nested comments are also supported
+ */
+*/
+
+//
+// MARK: Collections
+//
+
+/*
+ Array and Dictionary types are structs. So `let` and `var` also indicate
+ that they are mutable (var) or immutable (let) when declaring these types.
+*/
+
+// Array
+var shoppingList = ["catfish", "water", "lemons"]
+shoppingList[1] = "bottle of water"
+let emptyArray = [String]() // immutable
+var emptyMutableArray = [String]() // mutable
+
+
+// Dictionary
+var occupations = [
+ "Malcolm": "Captain",
+ "kaylee": "Mechanic"
+]
+occupations["Jayne"] = "Public Relations"
+let emptyDictionary = [String: Float]() // immutable
+var emptyMutableDictionary = [String: Float]() // mutable
+
+
+//
+// MARK: Control Flow
+//
+
+// for loop (array)
+let myArray = [1, 1, 2, 3, 5]
+for value in myArray {
+ if value == 1 {
+ println("One!")
+ } else {
+ println("Not one!")
+ }
+}
+
+// for loop (dictionary)
+var dict = ["one": 1, "two": 2]
+for (key, value) in dict {
+ println("\(key): \(value)")
+}
+
+// for loop (range)
+for i in -1...shoppingList.count {
+ println(i)
+}
+shoppingList[1...2] = ["steak", "peacons"]
+// use ..< to exclude the last number
+
+// while loop
+var i = 1
+while i < 1000 {
+ i *= 2
+}
+
+// do-while loop
+do {
+ println("hello")
+} while 1 == 2
+
+// Switch
+let vegetable = "red pepper"
+switch vegetable {
+case "celery":
+ let vegetableComment = "Add some raisins and make ants on a log."
+case "cucumber", "watercress":
+ let vegetableComment = "That would make a good tea sandwich."
+case let x where x.hasSuffix("pepper"):
+ let vegetableComment = "Is it a spicy \(x)?"
+default: // required (in order to cover all possible input)
+ let vegetableComment = "Everything tastes good in soup."
+}
+
+
+//
+// MARK: Functions
+//
+
+// Functions are a first-class type, meaning they can be nested
+// in functions and can be passed around
+
+// Function with Swift header docs (format as reStructedText)
+/**
+A greet operation
+
+- A bullet in docs
+- Another bullet in the docs
+
+:param: name A name
+:param: day A day
+:returns: A string containing the name and day value.
+*/
+func greet(name: String, day: String) -> String {
+ return "Hello \(name), today is \(day)."
+}
+greet("Bob", "Tuesday")
+
+// Function that returns multiple items in a tuple
+func getGasPrices() -> (Double, Double, Double) {
+ return (3.59, 3.69, 3.79)
+}
+let pricesTuple = getGasPrices()
+let price = pricesTuple.2 // 3.79
+// Ignore Tuple (or other) values by using _ (underscore)
+let (_, price1, _) = pricesTuple // price1 == 3.69
+println(price1 == pricesTuple.1) // true
+println("Gas price: \(price)")
+
+// Variadic Args
+func setup(numbers: Int...) {
+ // its an array
+ let number = numbers[0]
+ let argCount = numbers.count
+}
+
+// Passing and returning functions
+func makeIncrementer() -> (Int -> Int) {
+ func addOne(number: Int) -> Int {
+ return 1 + number
+ }
+ return addOne
+}
+var increment = makeIncrementer()
+increment(7)
+
+// pass by ref
+func swapTwoInts(inout a: Int, inout b: Int) {
+ let tempA = a
+ a = b
+ b = tempA
+}
+var someIntA = 7
+var someIntB = 3
+swapTwoInts(&someIntA, &someIntB)
+println(someIntB) // 7
+
+
+//
+// MARK: Closures
+//
+var numbers = [1, 2, 6]
+
+// Functions are special case closures ({})
+
+// Closure example.
+// `->` separates the arguments and return type
+// `in` separates the closure header from the closure body
+numbers.map({
+ (number: Int) -> Int in
+ let result = 3 * number
+ return result
+})
+
+// When the type is known, like above, we can do this
+numbers = numbers.map({ number in 3 * number })
+// Or even this
+//numbers = numbers.map({ $0 * 3 })
+
+print(numbers) // [3, 6, 18]
+
+// Trailing closure
+numbers = sorted(numbers) { $0 > $1 }
+
+print(numbers) // [18, 6, 3]
+
+// Super shorthand, since the < operator infers the types
+
+numbers = sorted(numbers, < )
+
+print(numbers) // [3, 6, 18]
+
+//
+// MARK: Structures
+//
+
+// Structures and classes have very similar capabilites
+struct NamesTable {
+ let names: [String]
+
+ // Custom subscript
+ subscript(index: Int) -> String {
+ return names[index]
+ }
+}
+
+// Structures have an auto-generated (implicit) designated initializer
+let namesTable = NamesTable(names: ["Me", "Them"])
+//let name = namesTable[2]
+//println("Name is \(name)") // Name is Them
+
+//
+// MARK: Classes
+//
+
+// Classes, structures and its members have three levels of access control
+// They are: internal (default), public, private
+
+public class Shape {
+ public func getArea() -> Int {
+ return 0;
+ }
+}
+
+// All methods and properties of a class are public.
+// If you just need to store data in a
+// structured object, you should use a `struct`
+
+internal class Rect: Shape {
+ var sideLength: Int = 1
+
+ // Custom getter and setter property
+ private var perimeter: Int {
+ get {
+ return 4 * sideLength
+ }
+ set {
+ // `newValue` is an implicit variable available to setters
+ sideLength = newValue / 4
+ }
+ }
+
+ // Lazily load a property
+ // subShape remains nil (uninitialized) until getter called
+ lazy var subShape = Rect(sideLength: 4)
+
+ // If you don't need a custom getter and setter,
+ // but still want to run code before and after getting or setting
+ // a property, you can use `willSet` and `didSet`
+ var identifier: String = "defaultID" {
+ // the `willSet` arg will be the variable name for the new value
+ willSet(someIdentifier) {
+ print(someIdentifier)
+ }
+ }
+
+ init(sideLength: Int) {
+ self.sideLength = sideLength
+ // always super.init last when init custom properties
+ super.init()
+ }
+
+ func shrink() {
+ if sideLength > 0 {
+ --sideLength
+ }
+ }
+
+ override func getArea() -> Int {
+ return sideLength * sideLength
+ }
+}
+
+// A simple class `Square` extends `Rect`
+class Square: Rect {
+ convenience init() {
+ self.init(sideLength: 5)
+ }
+}
+
+var mySquare = Square()
+print(mySquare.getArea()) // 25
+mySquare.shrink()
+print(mySquare.sideLength) // 4
+
+// compare instances, not the same as == which compares objects (equal to)
+if mySquare === mySquare {
+ println("Yep, it's mySquare")
+}
+
+
+//
+// MARK: Enums
+//
+
+// Enums can optionally be of a specific type or on their own.
+// They can contain methods like classes.
+
+enum Suit {
+ case Spades, Hearts, Diamonds, Clubs
+ func getIcon() -> String {
+ switch self {
+ case .Spades: return "♤"
+ case .Hearts: return "♡"
+ case .Diamonds: return "♢"
+ case .Clubs: return "♧"
+ }
+ }
+}
+
+
+//
+// MARK: Protocols
+//
+
+// `protocol`s can require that conforming types have specific
+// instance properties, instance methods, type methods,
+// operators, and subscripts.
+
+protocol ShapeGenerator {
+ var enabled: Bool { get set }
+ func buildShape() -> Shape
+}
+
+// Protocols declared with @objc allow optional functions,
+// which allow you to check for conformance
+@objc protocol TransformShape {
+ optional func reshaped()
+ optional func canReshape() -> Bool
+}
+
+class MyShape: Rect {
+ var delegate: TransformShape?
+
+ func grow() {
+ sideLength += 2
+
+ if let allow = self.delegate?.canReshape?() {
+ // test for delegate then for method
+ self.delegate?.reshaped?()
+ }
+ }
+}
+
+
+//
+// MARK: Other
+//
+
+// `extension`s: Add extra functionality to an already existing type
+
+// Square now "conforms" to the `Printable` protocol
+extension Square: Printable {
+ var description: String {
+ return "Area: \(self.getArea()) - ID: \(self.identifier)"
+ }
+}
+
+println("Square: \(mySquare)")
+
+// You can also extend built-in types
+extension Int {
+ var customProperty: String {
+ return "This is \(self)"
+ }
+
+ func multiplyBy(num: Int) -> Int {
+ return num * self
+ }
+}
+
+println(7.customProperty) // "This is 7"
+println(14.multiplyBy(2)) // 42
+
+// Generics: Similar to Java and C#. Use the `where` keyword to specify the
+// requirements of the generics.
+
+func findIndex<T: Equatable>(array: [T], valueToFind: T) -> Int? {
+ for (index, value) in enumerate(array) {
+ if value == valueToFind {
+ return index
+ }
+ }
+ return nil
+}
+let foundAtIndex = findIndex([1, 2, 3, 4], 3)
+println(foundAtIndex == 2) // true
+
+// Operators:
+// Custom operators can start with the characters:
+// / = - + * % < > ! & | ^ . ~
+// or
+// Unicode math, symbol, arrow, dingbat, and line/box drawing characters.
+prefix operator !!! {}
+
+// A prefix operator that triples the side length when used
+prefix func !!! (inout shape: Square) -> Square {
+ shape.sideLength *= 3
+ return shape
+}
+
+// current value
+println(mySquare.sideLength) // 4
+
+// change side length using custom !!! operator, increases size by 3
+!!!mySquare
+println(mySquare.sideLength) // 12
+
+```
diff --git a/tmux.html.markdown b/tmux.html.markdown
new file mode 100644
index 00000000..ebc312ed
--- /dev/null
+++ b/tmux.html.markdown
@@ -0,0 +1,244 @@
+---
+category: tool
+tool: tmux
+contributors:
+ - ["kaernyk", "https://github.com/kaernyk"]
+ - ["jmaud", "https://github.com/jmaud"]
+filename: LearnTmux.txt
+---
+
+
+<a href="http://tmux.sourceforge.net/">
+tmux</a> is a terminal multiplexer: it enables a number of terminals
+to be created, accessed, and controlled from a single screen. tmux
+may be detached from a screen and continue running in the background
+then later reattached.
+
+
+```
+
+ tmux [command] # Run a command
+ # 'tmux' with no commands will create a new session
+
+ new # Create a new session
+ -s "Session" # Create named session
+ -n "Window" # Create named Window
+ -c "/dir" # Start in target directory
+
+ attach # Attach last/available session
+ -t "#" # Attach target session
+ -d # Detach the session from other instances
+
+ ls # List open sessions
+ -a # List all open sessions
+
+ lsw # List windows
+ -a # List all windows
+ -s # List all windows in session
+
+ lsp # List panes
+ -a # List all panes
+ -s # List all panes in session
+ -t # List app panes in target
+
+ kill-window # Kill current window
+ -t "#" # Kill target window
+ -a # Kill all windows
+ -a -t "#" # Kill all windows but the target
+
+ kill-session # Kill current session
+ -t "#" # Kill target session
+ -a # Kill all sessions
+ -a -t "#" # Kill all sessions but the target
+
+
+
+## Key Bindings
+
+# The method of controlling an attached tmux session is via key
+# combinations called 'Prefix' keys.
+
+----------------------------------------------------------------------
+ (C-b) = Ctrl + b # 'Prefix' combination required to use keybinds
+
+ (M-1) = Meta + 1 -or- Alt + 1
+----------------------------------------------------------------------
+
+ ? # List all key bindings
+ : # Enter the tmux command prompt
+ r # Force redraw of the attached client
+ c # Create a new window
+
+ ! # Break the current pane out of the window.
+ % # Split the current pane into two, left and right
+ " # Split the current pane into two, top and bottom
+
+ n # Change to the next window
+ p # Change to the previous window
+ { # Swap the current pane with the previous pane
+ } # Swap the current pane with the next pane
+
+ s # Select a new session for the attached client
+ interactively
+ w # Choose the current window interactively
+ 0 to 9 # Select windows 0 to 9
+
+ d # Detach the current client
+ D # Choose a client to detach
+
+ & # Kill the current window
+ x # Kill the current pane
+
+ Up, Down # Change to the pane above, below, left, or right
+ Left, Right
+
+ M-1 to M-5 # Arrange panes:
+ # 1) even-horizontal
+ # 2) even-vertical
+ # 3) main-horizontal
+ # 4) main-vertical
+ # 5) tiled
+
+ C-Up, C-Down # Resize the current pane in steps of one cell
+ C-Left, C-Right
+
+ M-Up, M-Down # Resize the current pane in steps of five cells
+ M-Left, M-Right
+
+```
+
+
+### Configuring ~/.tmux.conf
+
+ tmux.conf can be used to set options automatically on start up, much
+like how .vimrc or init.el are used.
+
+
+```
+# Example tmux.conf
+# 2014.10
+
+
+### General
+###########################################################################
+
+# Enable UTF-8
+setw -g utf8 on
+set-option -g status-utf8 on
+
+# Scrollback/History limit
+set -g history-limit 2048
+
+# Index Start
+set -g base-index 1
+
+# Mouse
+set-option -g mouse-select-pane on
+
+# Force reload of config file
+unbind r
+bind r source-file ~/.tmux.conf
+
+
+### Keybinds
+###########################################################################
+
+# Unbind C-b as the default prefix
+unbind C-b
+
+# Set new default prefix
+set-option -g prefix `
+
+# Return to previous window when prefix is pressed twice
+bind C-a last-window
+bind ` last-window
+
+# Allow swapping C-a and ` using F11/F12
+bind F11 set-option -g prefix C-a
+bind F12 set-option -g prefix `
+
+# Keybind preference
+setw -g mode-keys vi
+set-option -g status-keys vi
+
+# Moving between panes with vim movement keys
+bind h select-pane -L
+bind j select-pane -D
+bind k select-pane -U
+bind l select-pane -R
+
+# Window Cycle/Swap
+bind e previous-window
+bind f next-window
+bind E swap-window -t -1
+bind F swap-window -t +1
+
+# Easy split pane commands
+bind = split-window -h
+bind - split-window -v
+unbind '"'
+unbind %
+
+# Activate inner-most session (when nesting tmux) to send commands
+bind a send-prefix
+
+
+### Theme
+###########################################################################
+
+# Statusbar Color Palatte
+set-option -g status-justify left
+set-option -g status-bg black
+set-option -g status-fg white
+set-option -g status-left-length 40
+set-option -g status-right-length 80
+
+# Pane Border Color Palette
+set-option -g pane-active-border-fg green
+set-option -g pane-active-border-bg black
+set-option -g pane-border-fg white
+set-option -g pane-border-bg black
+
+# Message Color Palette
+set-option -g message-fg black
+set-option -g message-bg green
+
+# Window Status Color Palette
+setw -g window-status-bg black
+setw -g window-status-current-fg green
+setw -g window-status-bell-attr default
+setw -g window-status-bell-fg red
+setw -g window-status-content-attr default
+setw -g window-status-content-fg yellow
+setw -g window-status-activity-attr default
+setw -g window-status-activity-fg yellow
+
+
+### UI
+###########################################################################
+
+# Notification
+setw -g monitor-activity on
+set -g visual-activity on
+set-option -g bell-action any
+set-option -g visual-bell off
+
+# Automatically set window titles
+set-option -g set-titles on
+set-option -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name,active (or not)
+
+# Statusbar Adjustments
+set -g status-left "#[fg=red] #H#[fg=green]:#[fg=white]#S#[fg=green] |#[default]"
+
+# Show performance counters in statusbar
+# Requires https://github.com/thewtex/tmux-mem-cpu-load/
+set -g status-interval 4
+set -g status-right "#[fg=green] | #[fg=white]#(tmux-mem-cpu-load)#[fg=green] | #[fg=cyan]%H:%M #[default]"
+
+```
+
+<a href="http://tmux.sourceforge.net/">Tmux | Home</a><br>
+<a href="http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux">Tmux Manual page</a><br>
+<a href="http://wiki.gentoo.org/wiki/Tmux">Archlinux Wiki</a><br>
+<a href="https://wiki.archlinux.org/index.php/Tmux">Gentoo Wiki</a><br>
+<a href="https://stackoverflow.com/questions/11558907/is-there-a-better-way-to-display-cpu-usage-in-tmux">Display CPU/MEM % in statusbar</a><br>
diff --git a/tr-tr/objective-c-tr.html.markdown b/tr-tr/objective-c-tr.html.markdown
index 854d70f6..f27cbf08 100644
--- a/tr-tr/objective-c-tr.html.markdown
+++ b/tr-tr/objective-c-tr.html.markdown
@@ -14,7 +14,7 @@ kendi çatıları olan Cocoa ve Cocoa Touch için kullanılan bir programlama di
Genel açamlı, object-oriented bir yapıya sahip programlama dilidir. C
programlama diline Smalltalk stilinde mesajlaşma ekler.
-```cpp
+```objective_c
// Tek satır yorum // işaretleri ile başlar
/*
diff --git a/tr-tr/php-tr.html.markdown b/tr-tr/php-tr.html.markdown
index 3db437cf..5258d785 100644
--- a/tr-tr/php-tr.html.markdown
+++ b/tr-tr/php-tr.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
filename: learnphp-tr.php
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
diff --git a/typescript.html.markdown b/typescript.html.markdown
new file mode 100644
index 00000000..9f04169a
--- /dev/null
+++ b/typescript.html.markdown
@@ -0,0 +1,158 @@
+---
+language: TypeScript
+contributors:
+ - ["Philippe Vlérick", "https://github.com/pvlerick"]
+filename: learntypescript.ts
+---
+
+TypeScript is a language that aims at easing development of large scale applications written in JavaScript.
+TypeScript adds common concepts such as classes, modules, interfaces, generics and (optional) static typing to JavaScript.
+It is a superset of JavaScript: all JavaScript code is valid TypeScript code so it can be added seamlessly to any project. The TypeScript compiler emits JavaScript.
+
+This article will focus only on TypeScript extra syntax, as oposed to [JavaScript] (../javascript/).
+
+To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript.
+
+```js
+//There are 3 basic types in TypeScript
+var isDone: boolean = false;
+var lines: number = 42;
+var name: string = "Anders";
+
+//..When it's impossible to know, there is the "Any" type
+var notSure: any = 4;
+notSure = "maybe a string instead";
+notSure = false; // okay, definitely a boolean
+
+//For collections, there are typed arrays and generic arrays
+var list: number[] = [1, 2, 3];
+//Alternatively, using the generic array type
+var list: Array<number> = [1, 2, 3];
+
+//For enumerations:
+enum Color {Red, Green, Blue};
+var c: Color = Color.Green;
+
+//Lastly, "void" is used in the special case of a function not returning anything
+function bigHorribleAlert(): void {
+ alert("I'm a little annoying box!");
+}
+
+//Functions are first class citizens, support the lambda "fat arrow" syntax and use type inference
+//All examples are equivalent, the same signature will be infered by the compiler, and same JavaScript will be emitted
+var f1 = function(i: number) : number { return i * i; }
+var f2 = function(i: number) { return i * i; } //Return type infered
+var f3 = (i : number) : number => { return i * i; }
+var f4 = (i: number) => { return i * i; } //Return type infered
+var f5 = (i: number) => i * i; //Return type infered, one-liner means no return keyword needed
+
+//Interfaces are structural, anything that has the properties is compliant with the interface
+interface Person {
+ name: string;
+ //Optional properties, marked with a "?"
+ age?: number;
+ //And of course functions
+ move(): void;
+}
+
+//..Object that implements the "Person" interface
+var p : Person = { name: "Bobby", move : () => {} }; //Can be treated as a Person since it has the name and age properties
+//..Objects that have the optional property:
+var validPerson : Person = { name: "Bobby", age: 42, move: () => {} };
+var invalidPerson : Person = { name: "Bobby", age: true }; //Is not a person because age is not a number
+
+//..Interfaces can also describe a function type
+interface SearchFunc {
+ (source: string, subString: string): boolean;
+}
+//..Only the parameters' types are important, names are not important.
+var mySearch: SearchFunc;
+mySearch = function(src: string, sub: string) {
+ return src.search(sub) != -1;
+}
+
+//Classes - members are public by default
+class Point {
+ //Properties
+ x: number;
+
+ //Constructor - the public/private keywords in this context will generate the boiler plate code
+ // for the property and the initialization in the constructor.
+ // In this example, "y" will be defined just like "x" is, but with less code
+ //Default values are also supported
+ constructor(x: number, public y: number = 0) {
+ this.x = x;
+ }
+
+ //Functions
+ dist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
+
+ //Static members
+ static origin = new Point(0, 0);
+}
+
+var p1 = new Point(10 ,20);
+var p2 = new Point(25); //y will be 0
+
+//Inheritance
+class Point3D extends Point {
+ constructor(x: number, y: number, public z: number = 0) {
+ super(x, y); //Explicit call to the super class constructor is mandatory
+ }
+
+ //Overwrite
+ dist() {
+ var d = super.dist();
+ return Math.sqrt(d * d + this.z * this.z);
+ }
+}
+
+//Modules, "." can be used as separator for sub modules
+module Geometry {
+ export class Square {
+ constructor(public sideLength: number = 0) {
+ }
+ area() {
+ return Math.pow(this.sideLength, 2);
+ }
+ }
+}
+
+var s1 = new Geometry.Square(5);
+
+//..Local alias for referencing a module
+import G = Geometry;
+
+var s2 = new G.Square(10);
+
+//Generics
+//..Classes
+class Tuple<T1, T2> {
+ constructor(public item1: T1, public item2: T2) {
+ }
+}
+
+//..Interfaces
+interface Pair<T> {
+ item1: T;
+ item2: T;
+}
+
+//..And functions
+var pairToTuple = function<T>(p: Pair<T>) {
+ return new Tuple(p.item1, p.item2);
+};
+
+var tuple = pairToTuple({ item1:"hello", item2:"world"});
+
+//Including references to a definition file:
+/// <reference path="jquery.d.ts" />
+
+```
+
+## Further Reading
+ * [TypeScript Official website] (http://www.typescriptlang.org/)
+ * [TypeScript language specifications (pdf)] (http://go.microsoft.com/fwlink/?LinkId=267238)
+ * [Anders Hejlsberg - Introducing TypeScript on Channel 9] (http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript)
+ * [Source Code on GitHub] (https://github.com/Microsoft/TypeScript)
+ * [Definitely Typed - repository for type definitions] (http://definitelytyped.org/)
diff --git a/vi-vn/objective-c-vi.html.markdown b/vi-vn/objective-c-vi.html.markdown
index 6d19ca02..c97bb560 100644
--- a/vi-vn/objective-c-vi.html.markdown
+++ b/vi-vn/objective-c-vi.html.markdown
@@ -12,7 +12,7 @@ filename: LearnObjectiveC-vi.m
Objective-C là ngôn ngữ lập trình chính được sử dụng bởi Apple cho các hệ điều hành OS X, iOS và các framework tương ứng của họ, Cocoa và Cocoa Touch.
Nó là một ngôn ngữ lập trình mục đích tổng quát, hướng đối tượng có bổ sung thêm kiểu truyền thông điệp giống Smalltalk vào ngôn ngữ lập trình C.
-```cpp
+```objective_c
// Chú thích dòng đơn bắt đầu với //
/*
diff --git a/whip.html.markdown b/whip.html.markdown
index 3429ec24..3faee98a 100644
--- a/whip.html.markdown
+++ b/whip.html.markdown
@@ -31,7 +31,7 @@ not_in_form
(called_function args)
; Majority of operations are done with functions
-; All the basic arihmetic is pretty straight forward
+; All the basic arithmetic is pretty straight forward
(+ 1 1) ; => 2
(- 2 1) ; => 1
(* 1 2) ; => 2
@@ -48,7 +48,7 @@ not_in_form
true
false
-; String are created with ".
+; Strings are created with ".
"Hello, world"
; Single chars are created with '.
@@ -66,7 +66,7 @@ false
(= 1 1) ; => true
(equal 2 1) ; => false
-; For example, inequality would be combinding the not and equal functions.
+; For example, inequality would be combining the not and equal functions.
(! (= 2 1)) ; => true
; More comparisons
@@ -96,10 +96,10 @@ undefined ; user to indicate a value that hasn't been set
; 2. Vairbles, Lists, and Dicts
; Variables are declared with the `def` or `let` functions.
-; Variab;es that haven't been set will be `undefined`.
+; Variables that haven't been set will be `undefined`.
(def some_var 5)
; `def` will keep the variable in the global context.
-; `let` will only have the variable inside it's context, and has a wierder syntax.
+; `let` will only have the variable inside its context, and has a wierder syntax.
(let ((a_var 5)) (+ a_var 5)) ; => 10
(+ a_var 5) ; = undefined + 5 => undefined
@@ -129,7 +129,7 @@ undefined ; user to indicate a value that hasn't been set
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; 3. Logic and Control sequences
-; The `if` function is pretty simple, though different than most imperitave langs.
+; The `if` function is pretty simple, though different than most imperative langs.
(if true "returned if first arg is true" "returned if first arg is false")
; => "returned if first arg is true"
@@ -153,18 +153,18 @@ undefined ; user to indicate a value that hasn't been set
; Lambdas in Whip are declared with the `lambda` or `->` function.
; And functions are really just lambdas with names.
-(def my_function (-> (x y) (+ (x y) 10)))
-; | | | |
+(def my_function (-> (x y) (+ (+ x y) 10)))
+; | | | |
; | | | returned value(with scope containing argument vars)
; | | arguments
; | lambda declaration function
; |
-; name of the to-be-decalred lambda
+; name of the to-be-declared lambda
(my_function 10 10) ; = (+ (+ 10 10) 10) => 30
; Obiously, all lambdas by definition are anonymous and
-; technically always used anonymouesly. Redundancy.
+; technically always used anonymously. Redundancy.
((lambda (x) x) 10) ; => 10
;;;;;;;;;;;;;;;;
diff --git a/xml.html.markdown b/xml.html.markdown
index 349d4763..94fc93f4 100644
--- a/xml.html.markdown
+++ b/xml.html.markdown
@@ -11,7 +11,7 @@ Unlike HTML, XML does not specifies how to display or to format data, just carry
* XML Syntax
-```XML
+```xml
<!-- Comments in XML are like this -->
<?xml version="1.0" encoding="UTF-8"?>
@@ -37,7 +37,7 @@ Unlike HTML, XML does not specifies how to display or to format data, just carry
</bookstore>
<!-- Above is a typical XML file.
- It starts with a declaration, informing some metadata (optional)
+ It starts with a declaration, informing some metadata (optional).
XML uses a tree structure. Above, the root node is 'bookstore', which has
three child nodes, all 'books'. Those nodes has more child nodes, and so on...
@@ -51,8 +51,8 @@ Unlike HTML, XML does not specifies how to display or to format data, just carry
Usually, the XML parser uses this information to store the data properly.
It is characterized by appearing in parenthesis within the opening tag
2 - Elements -> That's pure data.
- That's what the parser will retrive from the XML file.
- Elements appear between the open and close tags, without paranthesis. -->
+ That's what the parser will retrieve from the XML file.
+ Elements appear between the open and close tags, without parenthesis. -->
<!-- Below, an element with two attributes -->
@@ -64,7 +64,7 @@ Unlike HTML, XML does not specifies how to display or to format data, just carry
* Well-Formated Document x Validation
A XML document is well-formated if it is syntactically correct.
-However, is possible to inject more constraints in the document,
+However, it is possible to inject more constraints in the document,
using document definitions, such as DTD and XML Schema.
A XML document which follows a document definition is called valid,
@@ -72,7 +72,7 @@ regarding that document.
With this tool, you can check the XML data outside the application logic.
-```XML
+```xml
<!-- Below, you can see an simplified version of bookstore document,
with the addition of DTD definition.-->
@@ -100,7 +100,7 @@ With this tool, you can check the XML data outside the application logic.
<!-- The DTD starts with a declaration.
Following, the root node is declared, requiring 1 or more child nodes 'book'.
- Eeach 'book' should contain exactly one 'title' and 'price' and an attribute
+ Each 'book' should contain exactly one 'title' and 'price' and an attribute
called 'category', with "Literature" as its default value.
The 'title' and 'price' nodes contain a parsed character data.-->
@@ -123,9 +123,4 @@ With this tool, you can check the XML data outside the application logic.
<price>30.00</price>
</book>
</bookstore>
-
-
-```
-
-
-
+``` \ No newline at end of file
diff --git a/yaml.html.markdown b/yaml.html.markdown
index c5d15895..6e3e2c94 100644
--- a/yaml.html.markdown
+++ b/yaml.html.markdown
@@ -33,7 +33,7 @@ however: "A string, enclosed in quotes."
"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
# Multiple-line strings can be written either as a 'literal block' (using |),
-# or a 'folded block' (using '>')
+# or a 'folded block' (using '>').
literal_block: |
This entire block of text will be the value of the 'literal_block' key,
with line breaks being preserved.
@@ -66,7 +66,7 @@ a_nested_map:
# Maps don't have to have string keys.
0.25: a float key
-# Keys can also be multi-line objects, using ? to indicate the start of a key
+# Keys can also be multi-line objects, using ? to indicate the start of a key.
? |
This is a key
that has multiple lines
@@ -79,7 +79,7 @@ a_nested_map:
a_sequence:
- Item 1
- Item 2
- - 0.5 # sequences can contain disparate types
+ - 0.5 # sequences can contain disparate types.
- Item 4
- key: value
another_key: another_value
diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown
index 223f6e35..1e10416e 100644
--- a/zh-cn/c-cn.html.markdown
+++ b/zh-cn/c-cn.html.markdown
@@ -566,7 +566,7 @@ typedef void (*my_fnp_type)(char *);
'\'' // 单引号
'\"' // 双引号
'\xhh' // 十六进制数字. 例子: '\xb' = vertical tab
-'\ooo' // 十进制数字. 例子: '\013' = vertical tab
+'\ooo' // 八进制数字. 例子: '\013' = vertical tab
// 打印格式:
"%d" // 整数
@@ -579,7 +579,7 @@ typedef void (*my_fnp_type)(char *);
"%c" // 字母
"%p" // 指针
"%x" // 十六进制
-"%o" // 十进制
+"%o" // 八进制
"%%" // 打印 %
///////////////////////////////////////
diff --git a/zh-cn/common-lisp-cn.html.markdown b/zh-cn/common-lisp-cn.html.markdown
index c4dc3274..b82829a9 100644
--- a/zh-cn/common-lisp-cn.html.markdown
+++ b/zh-cn/common-lisp-cn.html.markdown
@@ -17,7 +17,7 @@ ANSI Common Lisp 是一个广泛通用于各个工业领域的、支持多种范
另外还有一本热门的近期出版的
[Land of Lisp](http://landoflisp.com/).
-```scheme
+```common-lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 0. 语法
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/zh-cn/elixir-cn.html.markdown b/zh-cn/elixir-cn.html.markdown
index 7a1ca084..daee8d3c 100644
--- a/zh-cn/elixir-cn.html.markdown
+++ b/zh-cn/elixir-cn.html.markdown
@@ -8,7 +8,7 @@ filename: learnelixir-cn.ex
lang: zh-cn
---
-Elixir 是一门构建在Elang VM 之上的函数式编程语言。Elixir 完全兼容 Eralng,
+Elixir 是一门构建在Erlang VM 之上的函数式编程语言。Elixir 完全兼容 Erlang,
另外还提供了更标准的语法,特性。
```elixir
diff --git a/zh-cn/erlang-cn.html.markdown b/zh-cn/erlang-cn.html.markdown
new file mode 100644
index 00000000..32e84278
--- /dev/null
+++ b/zh-cn/erlang-cn.html.markdown
@@ -0,0 +1,259 @@
+---
+language: erlang
+lang: zh-cn
+contributors:
+ - ["Giovanni Cappellotto", "http://www.focustheweb.com/"]
+translators:
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+filename: erlang-cn.erl
+---
+
+```erlang
+% 百分比符号标明注释的开始。
+
+%% 两个符号通常用于注释函数。
+
+%%% 三个符号通常用于注释模块。
+
+% Erlang 里使用三种标点符号:
+% 逗号 (`,`) 分隔函数调用中的参数、数据构建和模式。
+% 句号 (`.`) (后跟空格)分隔函数和 shell 中的表达式。
+% 分号 (`;`) 分隔语句。以下环境中使用语句:
+% 函数定义和`case`、`if`、`try..catch`、`receive`表达式。
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 1. 变量和模式匹配
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+Num = 42. % 变量必须以大写字母开头。
+
+% Erlang 的变量只能赋值一次。如果给变量赋不同的值,会导致错误:
+Num = 43. % ** exception error: no match of right hand side value 43
+
+% 大多数语言中`=`表示赋值语句,在Erlang中,则表示模式匹配。
+% `Lhs = Rhs`实际上意味着:
+% 演算右边(Rhs), 将结果与左边的模式匹配。
+Num = 7 * 6.
+
+% 浮点数
+Pi = 3.14159.
+
+% Atoms 用于表示非数字的常量。
+% Atom 以小写字母开始,包含字母、数字、`_`和`@`。
+Hello = hello.
+OtherNode = example@node.
+
+% Atom 中如果包含特殊字符,可以用单引号括起。
+AtomWithSpace = 'some atom with space'.
+
+% Erlang 的元组类似 C 的 struct.
+Point = {point, 10, 45}.
+
+% 使用模式匹配操作符`=`获取元组的值。
+{point, X, Y} = Point. % X = 10, Y = 45
+
+% 我们可以使用`_`存放我们不感兴趣的变量。
+% `_`被称为匿名变量。和其他变量不同,
+% 同一个模式中的多个`_`变量不必绑定到相同的值。
+Person = {person, {name, {first, joe}, {last, armstrong}}, {footsize, 42}}.
+{_, {_, {_, Who}, _}, _} = Person. % Who = joe
+
+% 列表使用方括号,元素间使用逗号分隔。
+% 列表的元素可以是任意类型。
+% 列表的第一个元素称为列表的 head,其余元素称为列表的 tail。
+ThingsToBuy = [{apples, 10}, {pears, 6}, {milk, 3}].
+
+% 若`T`是一个列表,那么`[H|T]`同样是一个列表,head为`H`,tail为`T`.
+% `|`分隔列表的 head 和 tail.
+% `[]`是空列表。
+% 我们可以使用模式匹配操作来抽取列表中的元素。
+% 如果我们有一个非空的列表`L`,那么`[X|Y] = L`则
+% 抽取 L 的 head 至 X,tail 至 Y (X、Y需为未定义的变量)。
+[FirstThing|OtherThingsToBuy] = ThingsToBuy.
+% FirstThing = {apples, 10}
+% OtherThingsToBuy = {pears, 6}, {milk, 3}
+
+% Erlang 中的字符串其实是由整数组成的数组。字符串使用双引号。
+Name = "Hello".
+[72, 101, 108, 108, 111] = "Hello".
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 2. 循序编程
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Module 是 Erlang 代码的基本单位。我们编写的所有函数都储存在 module 中。
+% Module 存储在后缀为 `.erl` 的文件中。
+% Module 必须事先编译。编译好的 module 以 `.beam` 结尾。
+-module(geometry).
+-export([area/1]). % module 对外暴露的函数列表
+
+% `area`函数包含两个分句,分句间以分号相隔。
+% 最后一个分句以句号加换行结尾。
+% 每个分句由头、体两部门组成。
+% 头部包含函数名称和用括号括起的模式,
+% 体部包含一系列表达式,如果头部的模式和调用时的参数匹配,这些表达式会被演算。
+% 模式匹配依照定义时的顺序依次进行。
+area({rectangle, Width, Ht}) -> Width * Ht;
+area({circle, R}) -> 3.14159 * R * R.
+
+% 编译文件为 geometry.erl.
+c(geometry). % {ok,geometry}
+
+% 调用函数时必须使用 module 名和函数名。
+geometry:area({rectangle, 10, 5}). % 50
+geometry:area({circle, 1.4}). % 6.15752
+
+% 在 Erlang 中,同一模块中,参数数目不同,名字相同的函数是完全不同的函数。
+-module(lib_misc).
+-export([sum/1]). % 对外暴露的`sum`函数接受一个参数:由整数组成的列表。
+sum(L) -> sum(L, 0).
+sum([], N) -> N;
+sum([H|T], N) -> sum(T, H+N).
+
+% fun 是匿名函数。它们没有名字,不过可以赋值给变量。
+Double = fun(X) -> 2*X end. % `Double` 指向匿名函数 #Fun<erl_eval.6.17052888>
+Double(2). % 4
+
+% fun 可以作为函数的参数和返回值。
+Mult = fun(Times) -> ( fun(X) -> X * Times end ) end.
+Triple = Mult(3).
+Triple(5). % 15
+
+% 列表解析是创建列表的表达式(不使用fun、map 或 filter)。
+% `[F(X) || X <- L]` 表示 "由 `F(X)` 组成的列表,其中 `X` 取自列表 `L`。
+L = [1,2,3,4,5].
+[2*X || X <- L]. % [2,4,6,8,10]
+% 列表解析可以使用生成器,也可以使用过滤器,过滤器用于筛选列表的一部分。
+EvenNumbers = [N || N <- [1, 2, 3, 4], N rem 2 == 0]. % [2, 4]
+
+% Guard 是用于增强模式匹配的结构。
+% Guard 可用于简单的测试和比较。
+% Guard 可用于函数定义的头部,以`when`关键字开头,或者其他可以使用表达式的地方。
+max(X, Y) when X > Y -> X;
+max(X, Y) -> Y.
+
+% guard 可以由一系列 guard 表达式组成,这些表达式以逗号分隔。
+% `GuardExpr1, GuardExpr2, ..., GuardExprN` 为真,当且仅当每个 guard 表达式均为真。
+is_cat(A) when is_atom(A), A =:= cat -> true;
+is_cat(A) -> false.
+is_dog(A) when is_atom(A), A =:= dog -> true;
+is_dog(A) -> false.
+
+% guard 序列 `G1; G2; ...; Gn` 为真,当且仅当其中任意一个 guard 表达式为真。
+is_pet(A) when is_dog(A); is_cat(A) -> true;
+is_pet(A) -> false.
+
+% Record 可以将元组中的元素绑定到特定的名称。
+% Record 定义可以包含在 Erlang 源代码中,也可以放在后缀为`.hrl`的文件中(Erlang 源代码中 include 这些文件)。
+-record(todo, {
+ status = reminder, % Default value
+ who = joe,
+ text
+}).
+
+% 在定义某个 record 之前,我们需要在 shell 中导入 record 的定义。
+% 我们可以使用 shell 函数`rr` (read records 的简称)。
+rr("records.hrl"). % [todo]
+
+% 创建和更新 record。
+X = #todo{}.
+% #todo{status = reminder, who = joe, text = undefined}
+X1 = #todo{status = urgent, text = "Fix errata in book"}.
+% #todo{status = urgent, who = joe, text = "Fix errata in book"}
+X2 = X1#todo{status = done}.
+% #todo{status = done,who = joe,text = "Fix errata in book"}
+
+% `case` 表达式。
+% `filter` 返回由列表`L`中所有满足`P(x)`为真的元素`X`组成的列表。
+filter(P, [H|T]) ->
+ case P(H) of
+ true -> [H|filter(P, T)];
+ false -> filter(P, T)
+ end;
+filter(P, []) -> [].
+filter(fun(X) -> X rem 2 == 0 end, [1, 2, 3, 4]). % [2, 4]
+
+% `if` 表达式。
+max(X, Y) ->
+ if
+ X > Y -> X;
+ X < Y -> Y;
+ true -> nil;
+ end.
+
+% 警告: `if` 表达式里至少有一个 guard 为真,否则会触发异常。
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 3. 异常
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% 当遇到内部错误或显式调用时,会触发异常。
+% 显式调用包括 `throw(Exception)`, `exit(Exception)` 和
+% `erlang:error(Exception)`.
+generate_exception(1) -> a;
+generate_exception(2) -> throw(a);
+generate_exception(3) -> exit(a);
+generate_exception(4) -> {'EXIT', a};
+generate_exception(5) -> erlang:error(a).
+
+% Erlang 有两种捕获异常的方法。其一是将调用包裹在`try...catch`表达式中。
+catcher(N) ->
+ try generate_exception(N) of
+ Val -> {N, normal, Val}
+ catch
+ throw:X -> {N, caught, thrown, X};
+ exit:X -> {N, caught, exited, X};
+ error:X -> {N, caught, error, X}
+ end.
+
+% 另一种方式是将调用包裹在`catch`表达式中。
+% 此时异常会被转化为一个描述错误的元组。
+catcher(N) -> catch generate_exception(N).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 4. 并发
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Erlang 依赖于 actor并发模型。在 Erlang 编写并发程序的三要素:
+% 创建进程,发送消息,接收消息
+
+% 启动一个新的进程使用`spawn`函数,接收一个函数作为参数
+
+F = fun() -> 2 + 2 end. % #Fun<erl_eval.20.67289768>
+spawn(F). % <0.44.0>
+
+% `spawn` 函数返回一个pid(进程标识符),你可以使用pid向进程发送消息。
+% 使用 `!` 操作符发送消息。
+% 我们需要在进程内接收消息,要用到 `receive` 机制。
+
+-module(caculateGeometry).
+-compile(export_all).
+caculateAera() ->
+ receive
+ {rectangle, W, H} ->
+ W * H;
+ {circle, R} ->
+ 3.14 * R * R;
+ _ ->
+ io:format("We can only caculate area of rectangles or circles.")
+ end.
+
+% 编译这个模块,在 shell 中创建一个进程,并执行 `caculateArea` 函数。
+c(caculateGeometry).
+CaculateAera = spawn(caculateGeometry, caculateAera, []).
+CaculateAera ! {circle, 2}. % 12.56000000000000049738
+
+% shell也是一个进程(process), 你可以使用`self`获取当前 pid
+
+self(). % <0.41.0>
+
+```
+
+## References
+
+* ["Learn You Some Erlang for great good!"](http://learnyousomeerlang.com/)
+* ["Programming Erlang: Software for a Concurrent World" by Joe Armstrong](http://pragprog.com/book/jaerlang/programming-erlang)
+* [Erlang/OTP Reference Documentation](http://www.erlang.org/doc/)
+* [Erlang - Programming Rules and Conventions](http://www.erlang.se/doc/programming_rules.shtml)
diff --git a/zh-cn/go-cn.html.markdown b/zh-cn/go-cn.html.markdown
index 4a87dc21..9f6a8c15 100644
--- a/zh-cn/go-cn.html.markdown
+++ b/zh-cn/go-cn.html.markdown
@@ -68,7 +68,7 @@ func learnTypes() {
can include line breaks.` // 同样是String类型
// 非ascii字符。Go使用UTF-8编码。
- g := 'Σ' // rune类型,uint32的别名,使用UTF-8编码
+ g := 'Σ' // rune类型,int32的别名,使用UTF-8编码
f := 3.14195 // float64类型,IEEE-754 64位浮点数
c := 3 + 4i // complex128类型,内部使用两个float64表示
diff --git a/zh-cn/haskell-cn.html.markdown b/zh-cn/haskell-cn.html.markdown
index 8d51f144..cb7ccdee 100644
--- a/zh-cn/haskell-cn.html.markdown
+++ b/zh-cn/haskell-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
filename: learn-haskell-zh.hs
contributors:
- ["Adit Bhargava", "http://adit.io"]
diff --git a/zh-cn/javascript-cn.html.markdown b/zh-cn/javascript-cn.html.markdown
index 86ad1d07..7dee9cc4 100644
--- a/zh-cn/javascript-cn.html.markdown
+++ b/zh-cn/javascript-cn.html.markdown
@@ -363,8 +363,8 @@ var myNumberObj = new Number(12)
myNumber == myNumberObj // = true
// 但是它们并非严格等价
-typeof(myNumber) // = 'number'
-typeof(myNumberObj) // = 'object'
+typeof myNumber // = 'number'
+typeof myNumberObj // = 'object'
myNumber === myNumberObj // = false
if (0){
// 这段代码不会执行,因为0代表假
diff --git a/zh-cn/json-cn.html.markdown b/zh-cn/json-cn.html.markdown
new file mode 100644
index 00000000..3a8db2cf
--- /dev/null
+++ b/zh-cn/json-cn.html.markdown
@@ -0,0 +1,51 @@
+---
+language: json
+contributors:
+ - ["Anna Harren", "https://github.com/iirelu"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnjson-cn.json
+lang: zh-cn
+---
+
+因为JSON是一个极其简单的数据交换形式,这个最有可能将会是曾经最简单
+的Learn X in Y Minutes。
+
+最纯正形式的JSON没有实际的注解,但是大多数解析器将会
+接受C-风格(//, /\* \*/)的注解。为了这个目的,但是,
+一切都将会是100%有效的JSON。幸亏,它是不言自明的。
+
+```json
+{
+ "numbers": 0,
+ "strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
+ "has bools?": true,
+ "nothingness": null,
+
+ "big number": 1.2e+100,
+
+ "objects": {
+ "comment": "Most of your structure will come from objects.",
+
+ "array": [0, 1, 2, 3, "Arrays can have anything in them.", 5],
+
+ "another object": {
+ "comment": "These things can be nested, very useful."
+ }
+ },
+
+ "silliness": [
+ {
+ "sources of potassium": ["bananas"]
+ },
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, "neo"],
+ [0, 0, 0, 1]
+ ]
+ ],
+
+ "that was short": "And, you're done. You now know everything JSON has to offer."
+}
+```
diff --git a/zh-cn/julia-cn.html.markdown b/zh-cn/julia-cn.html.markdown
new file mode 100644
index 00000000..1f91d52c
--- /dev/null
+++ b/zh-cn/julia-cn.html.markdown
@@ -0,0 +1,729 @@
+---
+language: Julia
+filename: learn-julia-zh.jl
+contributors:
+ - ["Jichao Ouyang", "http://oyanglul.us"]
+translators:
+ - ["Jichao Ouyang", "http://oyanglul.us"]
+lang: zh-cn
+---
+
+```ruby
+# 单行注释只需要一个井号
+#= 多行注释
+ 只需要以 '#=' 开始 '=#' 结束
+ 还可以嵌套.
+=#
+
+####################################################
+## 1. 原始类型与操作符
+####################################################
+
+# Julia 中一切皆是表达式。
+
+# 这是一些基本数字类型.
+3 # => 3 (Int64)
+3.2 # => 3.2 (Float64)
+2 + 1im # => 2 + 1im (Complex{Int64})
+2//3 # => 2//3 (Rational{Int64})
+
+# 支持所有的普通中缀操作符。
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+35 / 5 # => 7.0
+5 / 2 # => 2.5 # 用 Int 除 Int 永远返回 Float
+div(5, 2) # => 2 # 使用 div 截断小数点
+5 \ 35 # => 7.0
+2 ^ 2 # => 4 # 次方, 不是二进制 xor
+12 % 10 # => 2
+
+# 用括号提高优先级
+(1 + 3) * 2 # => 8
+
+# 二进制操作符
+~2 # => -3 # 非
+3 & 5 # => 1 # 与
+2 | 4 # => 6 # 或
+2 $ 4 # => 6 # 异或
+2 >>> 1 # => 1 # 逻辑右移
+2 >> 1 # => 1 # 算术右移
+2 << 1 # => 4 # 逻辑/算术 右移
+
+# 可以用函数 bits 查看二进制数。
+bits(12345)
+# => "0000000000000000000000000000000000000000000000000011000000111001"
+bits(12345.0)
+# => "0100000011001000000111001000000000000000000000000000000000000000"
+
+# 布尔值是原始类型
+true
+false
+
+# 布尔操作符
+!true # => false
+!false # => true
+1 == 1 # => true
+2 == 1 # => false
+1 != 1 # => false
+2 != 1 # => true
+1 < 10 # => true
+1 > 10 # => false
+2 <= 2 # => true
+2 >= 2 # => true
+# 比较可以串联
+1 < 2 < 3 # => true
+2 < 3 < 2 # => false
+
+# 字符串可以由 " 创建
+"This is a string."
+
+# 字符字面量可用 ' 创建
+'a'
+
+# 可以像取数组取值一样用 index 取出对应字符
+"This is a string"[1] # => 'T' # Julia 的 index 从 1 开始 :(
+# 但是对 UTF-8 无效,
+# 因此建议使用遍历器 (map, for loops, 等).
+
+# $ 可用于字符插值:
+"2 + 2 = $(2 + 2)" # => "2 + 2 = 4"
+# 可以将任何 Julia 表达式放入括号。
+
+# 另一种格式化字符串的方式是 printf 宏.
+@printf "%d is less than %f" 4.5 5.3 # 5 is less than 5.300000
+
+# 打印字符串很容易
+println("I'm Julia. Nice to meet you!")
+
+####################################################
+## 2. 变量与集合
+####################################################
+
+# 给变量赋值就是声明变量
+some_var = 5 # => 5
+some_var # => 5
+
+# 访问未声明变量会抛出异常
+try
+ some_other_var # => ERROR: some_other_var not defined
+catch e
+ println(e)
+end
+
+# 变量名需要以字母开头.
+# 之后任何字母,数字,下划线,叹号都是合法的。
+SomeOtherVar123! = 6 # => 6
+
+# 甚至可以用 unicode 字符
+☃ = 8 # => 8
+# 用数学符号非常方便
+2 * π # => 6.283185307179586
+
+# 注意 Julia 的命名规约:
+#
+# * 变量名为小写,单词之间以下划线连接('\_')。
+#
+# * 类型名以大写字母开头,单词以 CamelCase 方式连接。
+#
+# * 函数与宏的名字小写,无下划线。
+#
+# * 会改变输入的函数名末位为 !。
+# 这类函数有时被称为 mutating functions 或 in-place functions.
+
+# 数组存储一列值,index 从 1 开始。
+a = Int64[] # => 0-element Int64 Array
+
+# 一维数组可以以逗号分隔值的方式声明。
+b = [4, 5, 6] # => 包含 3 个 Int64 类型元素的数组: [4, 5, 6]
+b[1] # => 4
+b[end] # => 6
+
+# 二维数组以分号分隔维度。
+matrix = [1 2; 3 4] # => 2x2 Int64 数组: [1 2; 3 4]
+
+# 使用 push! 和 append! 往数组末尾添加元素
+push!(a,1) # => [1]
+push!(a,2) # => [1,2]
+push!(a,4) # => [1,2,4]
+push!(a,3) # => [1,2,4,3]
+append!(a,b) # => [1,2,4,3,4,5,6]
+
+# 用 pop 弹出末尾元素
+pop!(b) # => 6 and b is now [4,5]
+
+# 可以再放回去
+push!(b,6) # b 又变成了 [4,5,6].
+
+a[1] # => 1 # 永远记住 Julia 的 index 从 1 开始!
+
+# 用 end 可以直接取到最后索引. 可用作任何索引表达式
+a[end] # => 6
+
+# 还支持 shift 和 unshift
+shift!(a) # => 返回 1,而 a 现在时 [2,4,3,4,5,6]
+unshift!(a,7) # => [7,2,4,3,4,5,6]
+
+# 以叹号结尾的函数名表示它会改变参数的值
+arr = [5,4,6] # => 包含三个 Int64 元素的数组: [5,4,6]
+sort(arr) # => [4,5,6]; arr 还是 [5,4,6]
+sort!(arr) # => [4,5,6]; arr 现在是 [4,5,6]
+
+# 越界会抛出 BoundsError 异常
+try
+ a[0] # => ERROR: BoundsError() in getindex at array.jl:270
+ a[end+1] # => ERROR: BoundsError() in getindex at array.jl:270
+catch e
+ println(e)
+end
+
+# 错误会指出发生的行号,包括标准库
+# 如果你有 Julia 源代码,你可以找到这些地方
+
+# 可以用 range 初始化数组
+a = [1:5] # => 5-element Int64 Array: [1,2,3,4,5]
+
+# 可以切割数组
+a[1:3] # => [1, 2, 3]
+a[2:end] # => [2, 3, 4, 5]
+
+# 用 splice! 切割原数组
+arr = [3,4,5]
+splice!(arr,2) # => 4 ; arr 变成了 [3,5]
+
+# 用 append! 连接数组
+b = [1,2,3]
+append!(a,b) # a 变成了 [1, 2, 3, 4, 5, 1, 2, 3]
+
+# 检查元素是否在数组中
+in(1, a) # => true
+
+# 用 length 获得数组长度
+length(a) # => 8
+
+# Tuples 是 immutable 的
+tup = (1, 2, 3) # => (1,2,3) # an (Int64,Int64,Int64) tuple.
+tup[1] # => 1
+try:
+ tup[1] = 3 # => ERROR: no method setindex!((Int64,Int64,Int64),Int64,Int64)
+catch e
+ println(e)
+end
+
+# 大多数组的函数同样支持 tuples
+length(tup) # => 3
+tup[1:2] # => (1,2)
+in(2, tup) # => true
+
+# 可以将 tuples 元素分别赋给变量
+a, b, c = (1, 2, 3) # => (1,2,3) # a is now 1, b is now 2 and c is now 3
+
+# 不用括号也可以
+d, e, f = 4, 5, 6 # => (4,5,6)
+
+# 单元素 tuple 不等于其元素值
+(1,) == 1 # => false
+(1) == 1 # => true
+
+# 交换值
+e, d = d, e # => (5,4) # d is now 5 and e is now 4
+
+
+# 字典Dictionaries store mappings
+empty_dict = Dict() # => Dict{Any,Any}()
+
+# 也可以用字面量创建字典
+filled_dict = ["one"=> 1, "two"=> 2, "three"=> 3]
+# => Dict{ASCIIString,Int64}
+
+# 用 [] 获得键值
+filled_dict["one"] # => 1
+
+# 获得所有键
+keys(filled_dict)
+# => KeyIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# 注意,键的顺序不是插入时的顺序
+
+# 获得所有值
+values(filled_dict)
+# => ValueIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# 注意,值的顺序也一样
+
+# 用 in 检查键值是否已存在,用 haskey 检查键是否存在
+in(("one", 1), filled_dict) # => true
+in(("two", 3), filled_dict) # => false
+haskey(filled_dict, "one") # => true
+haskey(filled_dict, 1) # => false
+
+# 获取不存在的键的值会抛出异常
+try
+ filled_dict["four"] # => ERROR: key not found: four in getindex at dict.jl:489
+catch e
+ println(e)
+end
+
+# 使用 get 可以提供默认值来避免异常
+# get(dictionary,key,default_value)
+get(filled_dict,"one",4) # => 1
+get(filled_dict,"four",4) # => 4
+
+# 用 Sets 表示无序不可重复的值的集合
+empty_set = Set() # => Set{Any}()
+# 初始化一个 Set 并定义其值
+filled_set = Set(1,2,2,3,4) # => Set{Int64}(1,2,3,4)
+
+# 添加值
+push!(filled_set,5) # => Set{Int64}(5,4,2,3,1)
+
+# 检查是否存在某值
+in(2, filled_set) # => true
+in(10, filled_set) # => false
+
+# 交集,并集,差集
+other_set = Set(3, 4, 5, 6) # => Set{Int64}(6,4,5,3)
+intersect(filled_set, other_set) # => Set{Int64}(3,4,5)
+union(filled_set, other_set) # => Set{Int64}(1,2,3,4,5,6)
+setdiff(Set(1,2,3,4),Set(2,3,5)) # => Set{Int64}(1,4)
+
+
+####################################################
+## 3. 控制流
+####################################################
+
+# 声明一个变量
+some_var = 5
+
+# 这是一个 if 语句,缩进不是必要的
+if some_var > 10
+ println("some_var is totally bigger than 10.")
+elseif some_var < 10 # elseif 是可选的.
+ println("some_var is smaller than 10.")
+else # else 也是可选的.
+ println("some_var is indeed 10.")
+end
+# => prints "some var is smaller than 10"
+
+
+# For 循环遍历
+# Iterable 类型包括 Range, Array, Set, Dict, 以及 String.
+for animal=["dog", "cat", "mouse"]
+ println("$animal is a mammal")
+ # 可用 $ 将 variables 或 expression 转换为字符串into strings
+end
+# prints:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+# You can use 'in' instead of '='.
+for animal in ["dog", "cat", "mouse"]
+ println("$animal is a mammal")
+end
+# prints:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+for a in ["dog"=>"mammal","cat"=>"mammal","mouse"=>"mammal"]
+ println("$(a[1]) is a $(a[2])")
+end
+# prints:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+for (k,v) in ["dog"=>"mammal","cat"=>"mammal","mouse"=>"mammal"]
+ println("$k is a $v")
+end
+# prints:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+# While 循环
+x = 0
+while x < 4
+ println(x)
+ x += 1 # x = x + 1
+end
+# prints:
+# 0
+# 1
+# 2
+# 3
+
+# 用 try/catch 处理异常
+try
+ error("help")
+catch e
+ println("caught it $e")
+end
+# => caught it ErrorException("help")
+
+
+####################################################
+## 4. 函数
+####################################################
+
+# 用关键字 'function' 可创建一个新函数
+#function name(arglist)
+# body...
+#end
+function add(x, y)
+ println("x is $x and y is $y")
+
+ # 最后一行语句的值为返回
+ x + y
+end
+
+add(5, 6) # => 在 "x is 5 and y is 6" 后会打印 11
+
+# 还可以定义接收可变长参数的函数
+function varargs(args...)
+ return args
+ # 关键字 return 可在函数内部任何地方返回
+end
+# => varargs (generic function with 1 method)
+
+varargs(1,2,3) # => (1,2,3)
+
+# 省略号 ... 被称为 splat.
+# 刚刚用在了函数定义中
+# 还可以用在函数的调用
+# Array 或者 Tuple 的内容会变成参数列表
+Set([1,2,3]) # => Set{Array{Int64,1}}([1,2,3]) # 获得一个 Array 的 Set
+Set([1,2,3]...) # => Set{Int64}(1,2,3) # 相当于 Set(1,2,3)
+
+x = (1,2,3) # => (1,2,3)
+Set(x) # => Set{(Int64,Int64,Int64)}((1,2,3)) # 一个 Tuple 的 Set
+Set(x...) # => Set{Int64}(2,3,1)
+
+
+# 可定义可选参数的函数
+function defaults(a,b,x=5,y=6)
+ return "$a $b and $x $y"
+end
+
+defaults('h','g') # => "h g and 5 6"
+defaults('h','g','j') # => "h g and j 6"
+defaults('h','g','j','k') # => "h g and j k"
+try
+ defaults('h') # => ERROR: no method defaults(Char,)
+ defaults() # => ERROR: no methods defaults()
+catch e
+ println(e)
+end
+
+# 还可以定义键值对的参数
+function keyword_args(;k1=4,name2="hello") # note the ;
+ return ["k1"=>k1,"name2"=>name2]
+end
+
+keyword_args(name2="ness") # => ["name2"=>"ness","k1"=>4]
+keyword_args(k1="mine") # => ["k1"=>"mine","name2"=>"hello"]
+keyword_args() # => ["name2"=>"hello","k1"=>4]
+
+# 可以组合各种类型的参数在同一个函数的参数列表中
+function all_the_args(normal_arg, optional_positional_arg=2; keyword_arg="foo")
+ println("normal arg: $normal_arg")
+ println("optional arg: $optional_positional_arg")
+ println("keyword arg: $keyword_arg")
+end
+
+all_the_args(1, 3, keyword_arg=4)
+# prints:
+# normal arg: 1
+# optional arg: 3
+# keyword arg: 4
+
+# Julia 有一等函数
+function create_adder(x)
+ adder = function (y)
+ return x + y
+ end
+ return adder
+end
+
+# 这是用 "stabby lambda syntax" 创建的匿名函数
+(x -> x > 2)(3) # => true
+
+# 这个函数和上面的 create_adder 一模一样
+function create_adder(x)
+ y -> x + y
+end
+
+# 你也可以给内部函数起个名字
+function create_adder(x)
+ function adder(y)
+ x + y
+ end
+ adder
+end
+
+add_10 = create_adder(10)
+add_10(3) # => 13
+
+
+# 内置的高阶函数有
+map(add_10, [1,2,3]) # => [11, 12, 13]
+filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# 还可以使用 list comprehensions 替代 map
+[add_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+
+####################################################
+## 5. 类型
+####################################################
+
+# Julia 有类型系统
+# 所有的值都有类型;但变量本身没有类型
+# 你可以用 `typeof` 函数获得值的类型
+typeof(5) # => Int64
+
+# 类型是一等值
+typeof(Int64) # => DataType
+typeof(DataType) # => DataType
+# DataType 是代表类型的类型,也代表他自己的类型
+
+# 类型可用作文档化,优化,以及调度
+# 并不是静态检查类型
+
+# 用户还可以自定义类型
+# 跟其他语言的 records 或 structs 一样
+# 用 `type` 关键字定义新的类型
+
+# type Name
+# field::OptionalType
+# ...
+# end
+type Tiger
+ taillength::Float64
+ coatcolor # 不附带类型标注的相当于 `::Any`
+end
+
+# 构造函数参数是类型的属性
+tigger = Tiger(3.5,"orange") # => Tiger(3.5,"orange")
+
+# 用新类型作为构造函数还会创建一个类型
+sherekhan = typeof(tigger)(5.6,"fire") # => Tiger(5.6,"fire")
+
+# struct 类似的类型被称为具体类型
+# 他们可被实例化但不能有子类型
+# 另一种类型是抽象类型
+
+# abstract Name
+abstract Cat # just a name and point in the type hierarchy
+
+# 抽象类型不能被实例化,但是可以有子类型
+# 例如,Number 就是抽象类型
+subtypes(Number) # => 6-element Array{Any,1}:
+ # Complex{Float16}
+ # Complex{Float32}
+ # Complex{Float64}
+ # Complex{T<:Real}
+ # ImaginaryUnit
+ # Real
+subtypes(Cat) # => 0-element Array{Any,1}
+
+# 所有的类型都有父类型; 可以用函数 `super` 得到父类型.
+typeof(5) # => Int64
+super(Int64) # => Signed
+super(Signed) # => Real
+super(Real) # => Number
+super(Number) # => Any
+super(super(Signed)) # => Number
+super(Any) # => Any
+# 所有这些类型,除了 Int64, 都是抽象类型.
+
+# <: 是类型集成操作符
+type Lion <: Cat # Lion 是 Cat 的子类型
+ mane_color
+ roar::String
+end
+
+# 可以继续为你的类型定义构造函数
+# 只需要定义一个同名的函数
+# 并调用已有的构造函数设置一个固定参数
+Lion(roar::String) = Lion("green",roar)
+# 这是一个外部构造函数,因为他再类型定义之外
+
+type Panther <: Cat # Panther 也是 Cat 的子类型
+ eye_color
+ Panther() = new("green")
+ # Panthers 只有这个构造函数,没有默认构造函数
+end
+# 使用内置构造函数,如 Panther,可以让你控制
+# 如何构造类型的值
+# 应该尽可能使用外部构造函数而不是内部构造函数
+
+####################################################
+## 6. 多分派
+####################################################
+
+# 在Julia中, 所有的具名函数都是类属函数
+# 这意味着他们都是有很大小方法组成的
+# 每个 Lion 的构造函数都是类属函数 Lion 的方法
+
+# 我们来看一个非构造函数的例子
+
+# Lion, Panther, Tiger 的 meow 定义为
+function meow(animal::Lion)
+ animal.roar # 使用点符号访问属性
+end
+
+function meow(animal::Panther)
+ "grrr"
+end
+
+function meow(animal::Tiger)
+ "rawwwr"
+end
+
+# 试试 meow 函数
+meow(tigger) # => "rawwr"
+meow(Lion("brown","ROAAR")) # => "ROAAR"
+meow(Panther()) # => "grrr"
+
+# 再看看层次结构
+issubtype(Tiger,Cat) # => false
+issubtype(Lion,Cat) # => true
+issubtype(Panther,Cat) # => true
+
+# 定义一个接收 Cats 的函数
+function pet_cat(cat::Cat)
+ println("The cat says $(meow(cat))")
+end
+
+pet_cat(Lion("42")) # => prints "The cat says 42"
+try
+ pet_cat(tigger) # => ERROR: no method pet_cat(Tiger,)
+catch e
+ println(e)
+end
+
+# 在面向对象语言中,通常都是单分派
+# 这意味着分派方法是通过第一个参数的类型决定的
+# 在Julia中, 所有参数类型都会被考虑到
+
+# 让我们定义有多个参数的函数,好看看区别
+function fight(t::Tiger,c::Cat)
+ println("The $(t.coatcolor) tiger wins!")
+end
+# => fight (generic function with 1 method)
+
+fight(tigger,Panther()) # => prints The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => prints The orange tiger wins!
+
+# 让我们修改一下传入具体为 Lion 类型时的行为
+fight(t::Tiger,l::Lion) = println("The $(l.mane_color)-maned lion wins!")
+# => fight (generic function with 2 methods)
+
+fight(tigger,Panther()) # => prints The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => prints The green-maned lion wins!
+
+# 把 Tiger 去掉
+fight(l::Lion,c::Cat) = println("The victorious cat says $(meow(c))")
+# => fight (generic function with 3 methods)
+
+fight(Lion("balooga!"),Panther()) # => prints The victorious cat says grrr
+try
+ fight(Panther(),Lion("RAWR")) # => ERROR: no method fight(Panther,Lion)
+catch
+end
+
+# 在试试让 Cat 在前面
+fight(c::Cat,l::Lion) = println("The cat beats the Lion")
+# => Warning: New definition
+# fight(Cat,Lion) at none:1
+# is ambiguous with
+# fight(Lion,Cat) at none:2.
+# Make sure
+# fight(Lion,Lion)
+# is defined first.
+#fight (generic function with 4 methods)
+
+# 警告说明了无法判断使用哪个 fight 方法
+fight(Lion("RAR"),Lion("brown","rarrr")) # => prints The victorious cat says rarrr
+# 结果在老版本 Julia 中可能会不一样
+
+fight(l::Lion,l2::Lion) = println("The lions come to a tie")
+fight(Lion("RAR"),Lion("brown","rarrr")) # => prints The lions come to a tie
+
+
+# Under the hood
+# 你还可以看看 llvm 以及生成的汇编代码
+
+square_area(l) = l * l # square_area (generic function with 1 method)
+
+square_area(5) #25
+
+# 给 square_area 一个整形时发生什么
+code_native(square_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1 # Prologue
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # movsxd RAX, EDI # Fetch l from memory?
+ # imul RAX, RAX # Square l and store the result in RAX
+ # pop RBP # Restore old base pointer
+ # ret # Result will still be in RAX
+
+code_native(square_area, (Float32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiply (AVX)
+ # pop RBP
+ # ret
+
+code_native(square_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiply (AVX)
+ # pop RBP
+ # ret
+ #
+# 注意 只要参数中又浮点类型,Julia 就使用浮点指令
+# 让我们计算一下圆的面积
+circle_area(r) = pi * r * r # circle_area (generic function with 1 method)
+circle_area(5) # 78.53981633974483
+
+code_native(circle_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory
+ # movabs RAX, 4593140240 # Load pi
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r
+ # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r
+ # pop RBP
+ # ret
+ #
+
+code_native(circle_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # movabs RAX, 4593140496
+ # Source line: 1
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX]
+ # vmulsd XMM0, XMM1, XMM0
+ # pop RBP
+ # ret
+ #
+```
diff --git a/zh-cn/livescript-cn.html.markdown b/zh-cn/livescript-cn.html.markdown
new file mode 100644
index 00000000..fea00bc1
--- /dev/null
+++ b/zh-cn/livescript-cn.html.markdown
@@ -0,0 +1,322 @@
+---
+language: LiveScript
+filename: learnLivescript.ls
+contributors:
+ - ["Christina Whyte", "http://github.com/kurisuwhyte/"]
+translators:
+ - ["ShengDa Lyu", "http://github.com/SDLyu/"]
+lang: zh-cn
+---
+
+LiveScript 是一种具有函数式特性且编译成 JavaScript 的语言,能对应 JavaScript 的基本语法。
+还有些额外的特性如:柯里化,组合函数,模式匹配,还有借镜于 Haskell,F# 和 Scala 的许多特点。
+
+LiveScript 诞生于 [Coco][],而 Coco 诞生于 [CoffeeScript][]。
+LiveScript 目前已释出稳定版本,开发中的新版本将会加入更多特性。
+
+[Coco]: http://satyr.github.io/coco/
+[CoffeeScript]: http://coffeescript.org/
+
+非常期待您的反馈,你可以通过
+[@kurisuwhyte](https://twitter.com/kurisuwhyte) 与我连系 :)
+
+
+```coffeescript
+# 与 CoffeeScript 一样,LiveScript 使用 # 单行注解。
+
+/*
+ 多行注解与 C 相同。使用注解可以避免被当成 JavaScript 输出。
+*/
+```
+```coffeescript
+# 语法的部份,LiveScript 使用缩进取代 {} 来定义区块,
+# 使用空白取代 () 来执行函数。
+
+
+########################################################################
+## 1. 值类型
+########################################################################
+
+# `void` 取代 `undefined` 表示未定义的值
+void # 与 `undefined` 等价但更安全(不会被覆写)
+
+# 空值则表示成 Null。
+null
+
+
+# 最基本的值类型数据是罗辑类型:
+true
+false
+
+# 罗辑类型的一些别名,等价于前者:
+on; off
+yes; no
+
+
+# 数字与 JS 一样,使用倍精度浮点数表示。
+10
+0.4 # 开头的 0 是必要的
+
+
+# 可以使用底线及单位后缀提高可读性,编译器会自动略过底线及单位后缀。
+12_344km
+
+
+# 字串与 JS 一样,是一种不可变的字元序列:
+"Christina" # 单引号也可以!
+"""Multi-line
+ strings
+ are
+ okay
+ too."""
+
+# 在前面加上 \ 符号也可以表示字串:
+\keyword # => 'keyword'
+
+
+# 数组是值的有序集合。
+fruits =
+ * \apple
+ * \orange
+ * \pear
+
+# 可以用 [] 简洁地表示数组:
+fruits = [ \apple, \orange, \pear ]
+
+
+# 你可以更方便地建立字串数组,并使用空白区隔元素。
+fruits = <[ apple orange pear ]>
+
+# 以 0 为起始值的数组下标获取元素:
+fruits[0] # => "apple"
+
+
+# 对象是无序键值对集合(更多给节将在下面章节讨论)。
+person =
+ name: "Christina"
+ likes:
+ * "kittens"
+ * "and other cute stuff"
+
+# 你也可以用更简洁的方式表示对象:
+person = {name: "Christina", likes: ["kittens", "and other cute stuff"]}
+
+# 可以通过键值获取值:
+person.name # => "Christina"
+person["name"] # => "Christina"
+
+
+# 正则表达式的使用跟 JavaScript 一样:
+trailing-space = /\s$/ # dashed-words 变成 dashedWords
+
+# 你也可以用多行描述表达式!(注解和空白会被忽略)
+funRE = //
+ function\s+(.+) # name
+ \s* \((.*)\) \s* # arguments
+ { (.*) } # body
+ //
+
+
+########################################################################
+## 2. 基本运算
+########################################################################
+
+# 数值操作符与 JavaScript 一样:
+1 + 2 # => 3
+2 - 1 # => 1
+2 * 3 # => 6
+4 / 2 # => 2
+3 % 2 # => 1
+
+
+# 比较操作符大部份也一样,除了 `==` 等价于 JS 中的 `===`,
+# JS 中的 `==` 在 LiveScript 里等价于 `~=`,
+# `===` 能进行对象、数组和严格比较。
+2 == 2 # => true
+2 == "2" # => false
+2 ~= "2" # => true
+2 === "2" # => false
+
+[1,2,3] == [1,2,3] # => false
+[1,2,3] === [1,2,3] # => true
+
++0 == -0 # => true
++0 === -0 # => false
+
+# 其它关系操作符包括 <、<=、> 和 >=
+
+# 罗辑值可以通过 `or`、`and` 和 `not` 结合:
+true and false # => false
+false or true # => true
+not false # => true
+
+
+# 集合也有一些便利的操作符
+[1, 2] ++ [3, 4] # => [1, 2, 3, 4]
+'a' in <[ a b c ]> # => true
+'name' of { name: 'Chris' } # => true
+
+
+########################################################################
+## 3. 函数
+########################################################################
+
+# 因为 LiveScript 是函数式特性的语言,你可以期待函数在语言里被高规格的对待。
+add = (left, right) -> left + right
+add 1, 2 # => 3
+
+# 加上 ! 防止函数执行后的返回值
+two = -> 2
+two!
+
+# LiveScript 与 JavaScript 一样使用函式作用域,且一样拥有闭包的特性。
+# 与 JavaScript 不同的地方在于,`=` 变量赋值时,左边的对象永远不用变量宣告。
+
+# `:=` 操作符允许*重新賦值*父作用域里的变量。
+
+
+# 你可以解构函数的参数,从不定长度的参数结构里获取感兴趣的值。
+tail = ([head, ...rest]) -> rest
+tail [1, 2, 3] # => [2, 3]
+
+# 你也可以使用一元或二元操作符转换参数。当然也可以预设传入的参数值。
+foo = (a = 1, b = 2) -> a + b
+foo! # => 3
+
+# 你可以以拷贝的方式传入参数来避免副作用,例如:
+copy = (^^target, source) ->
+ for k,v of source => target[k] = v
+ target
+a = { a: 1 }
+copy a, { b: 2 } # => { a: 1, b: 2 }
+a # => { a: 1 }
+
+
+# 使用长箭号取代短箭号来柯里化一个函数:
+add = (left, right) --> left + right
+add1 = add 1
+add1 2 # => 3
+
+# 函式里有一个隐式的 `it` 变量,意谓着你不用宣告它。
+identity = -> it
+identity 1 # => 1
+
+# 操作符在 LiveScript 里不是一個函数,但你可以简单地将它们转换成函数!
+# Enter the operator sectioning:
+divide-by-2 = (/ 2)
+[2, 4, 8, 16].map(divide-by-2) .reduce (+)
+
+
+# LiveScript 里不只有应用函数,如同其它良好的函数式语言,你可以合并函数获得更多发挥:
+double-minus-one = (- 1) . (* 2)
+
+# 除了普通的数学公式合并 `f . g` 之外,还有 `>>` 和 `<<` 操作符定义函数的合并顺序。
+double-minus-one = (* 2) >> (- 1)
+double-minus-one = (- 1) << (* 2)
+
+
+# 说到合并函数的参数, LiveScript 使用 `|>` 和 `<|` 操作符将参数传入:
+map = (f, xs) --> xs.map f
+[1 2 3] |> map (* 2) # => [2 4 6]
+
+# 你也可以选择填入值的位置,只需要使用底线 _ 标记:
+reduce = (f, xs, initial) --> xs.reduce f, initial
+[1 2 3] |> reduce (+), _, 0 # => 6
+
+
+# 你也能使 _ 让任何函数变成偏函数应用:
+div = (left, right) -> left / right
+div-by-2 = div _, 2
+div-by-2 4 # => 2
+
+
+# 最后,也很重要的,LiveScript 拥有後呼叫特性, 可以是基於回调的代码
+# (你可以试试其它函数式特性的解法,比如 Promises):
+readFile = (name, f) -> f name
+a <- readFile 'foo'
+b <- readFile 'bar'
+console.log a + b
+
+# 等同於:
+readFile 'foo', (a) -> readFile 'bar', (b) -> console.log a + b
+
+
+########################################################################
+## 4. 模式、判断和流程控制
+########################################################################
+
+# 流程控制可以使用 `if...else` 表达式:
+x = if n > 0 then \positive else \negative
+
+# 除了 `then` 你也可以使用 `=>`
+x = if n > 0 => \positive
+ else \negative
+
+# 过於复杂的流程可以用 `switch` 表达式代替:
+y = {}
+x = switch
+ | (typeof y) is \number => \number
+ | (typeof y) is \string => \string
+ | 'length' of y => \array
+ | otherwise => \object # `otherwise` 和 `_` 是等价的。
+
+# 函数主体、宣告式和赋值式可以表式成 `switch`,这可以省去一些代码:
+take = (n, [x, ...xs]) -->
+ | n == 0 => []
+ | _ => [x] ++ take (n - 1), xs
+
+
+########################################################################
+## 5. 推导式
+########################################################################
+
+# 在 JavaScript 的标准函式库里有一些辅助函数能帮助处理列表及对象
+#(LiveScript 则带有一个 prelude.ls ,作为标准函式库的补充 ),
+# 推导式能让你使用优雅的语法且快速地处理这些事:
+oneToTwenty = [1 to 20]
+evens = [x for x in oneToTwenty when x % 2 == 0]
+
+# 在推导式里 `when` 和 `unless` 可以当成过滤器使用。
+
+# 对象推导式在使用上也是同样的方式,差别在于你使用的是对象而不是数组:
+copy = { [k, v] for k, v of source }
+
+
+########################################################################
+## 6. OOP
+########################################################################
+
+# 虽然 LiveScript 是一门函数式语言,但具有一些命令式及面向对象的特性。
+# 像是 class 语法和一些借镜於 CoffeeScript 的类别继承语法糖:
+class Animal
+ (@name, kind) ->
+ @kind = kind
+ action: (what) -> "*#{@name} (a #{@kind}) #{what}*"
+
+class Cat extends Animal
+ (@name) -> super @name, 'cat'
+ purr: -> @action 'purrs'
+
+kitten = new Cat 'Mei'
+kitten.purr! # => "*Mei (a cat) purrs*"
+
+# 除了类别的单一继承模式之外,还提供了像混入 (Mixins) 这种特性。
+# Mixins 在语言里被当成普通对象:
+Huggable =
+ hug: -> @action 'is hugged'
+
+class SnugglyCat extends Cat implements Huggable
+
+kitten = new SnugglyCat 'Purr'
+kitten.hug! # => "*Mei (a cat) is hugged*"
+```
+
+## 延伸阅读
+
+LiveScript 还有许多强大之处,但这些应该足够启发你写些小型函数式程式了。
+[LiveScript](http://livescript.net/)有更多关于 LiveScript 的资讯
+和线上编译器等着你来试!
+
+你也可以参考
+[prelude.ls](http://gkz.github.io/prelude-ls/),和一些 `#livescript`
+的网络聊天室频道。
diff --git a/zh-cn/lua-cn.html.markdown b/zh-cn/lua-cn.html.markdown
index 95a94c76..53a603a2 100644
--- a/zh-cn/lua-cn.html.markdown
+++ b/zh-cn/lua-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
lang: zh-cn
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
@@ -9,6 +9,7 @@ contributors:
- ["Amr Tamimi", "https://amrtamimi.com"]
translators:
- ["Jakukyo Friel", "http://weakish.github.io"]
+filename: lua-cn.lua
---
```lua
diff --git a/zh-cn/markdown-cn.html.markdown b/zh-cn/markdown-cn.html.markdown
new file mode 100644
index 00000000..eecb8c5b
--- /dev/null
+++ b/zh-cn/markdown-cn.html.markdown
@@ -0,0 +1,240 @@
+---
+language: Markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators:
+ - ["Fangzhou Chen","https://github.com/FZSS"]
+filename: learnmarkdown-cn.md
+lang: zh-cn
+---
+
+Markdown 由 John Gruber 于 2004年创立. 它旨在成为一门容易读写的语法结构,并可以便利地转换成 HTML(以及其他很多)格式。
+
+欢迎您多多反馈以及分支和请求合并。
+
+
+```markdown
+<!-- Markdown 是 HTML 的父集,所以任何 HTML 文件都是有效的 Markdown。
+这意味着我们可以在 Markdown 里使用任何 HTML 元素,比如注释元素,
+且不会被 Markdown 解析器所影响。不过如果你在 Markdown 文件内创建了 HTML 元素,
+你将无法在 HTML 元素的内容中使用 Markdown 语法。-->
+
+<!-- 在不同的解析器中,Markdown 的实现方法有所不同。
+此教程会指出当某功能是否通用及是否只对某一解析器有效。 -->
+
+<!-- 标头 -->
+<!-- 通过在文本前加上不同数量的hash(#), 你可以创建相对应的 <h1>
+到 <h6> HTML元素。-->
+
+# 这是一个 <h1>
+## 这是一个 <h2>
+### 这是一个 <h3>
+#### 这是一个 <h4>
+##### 这是一个 <h5>
+###### 这是一个 <h6>
+
+<!-- 对于 <h1> 和 <h2> 元素,Markdown 额外提供了两种添加方式。 -->
+这是一个 h1
+=============
+
+这是一个 h2
+-------------
+
+<!-- 简易文本样式 -->
+<!-- 文本的斜体,粗体,和删除线在 Markdown 中可以轻易地被实现。-->
+
+*此文本为斜体。*
+_此文本也是。_
+
+**此文本为粗体。**
+__此文本也是__
+
+***此文本是斜体加粗体。***
+**_或者这样。_**
+*__这个也是!__*
+
+<!-- 在 Github 采用的 Markdown 中 -->
+
+~~此文本为删除线效果。~~
+
+<!-- 单个段落由一句或多句邻近的句子组成,这些句子由一个或多个空格分隔。-->
+
+这是第一段落. 这句话在同一个段落里,好玩么?
+
+现在我是第二段落。
+这句话也在第二段落!
+
+这句话在第三段落!
+
+<!-- 如果你插入一个 HTML中的<br />标签,你可以在段末加入两个以上的空格,
+然后另起一段。-->
+
+此段落结尾有两个空格(选中以显示)。
+
+上文有一个 <br /> !
+
+<!-- 段落引用可由 > 字符轻松实现。-->
+
+> 这是一个段落引用. 你可以
+> 手动断开你的句子,然后在每句句子前面添加 “>” 字符。或者让你的句子变得很长,以至于他们自动得断开。
+> 只要你的文字以“>” 字符开头,两种方式无异。
+
+> 你也对文本进行
+>> 多层引用
+> 这多机智啊!
+
+<!-- 序列 -->
+<!-- 无序序列可由星号,加号或者减号来建立 -->
+
+* 项目
+* 项目
+* 另一个项目
+
+或者
+
++ 项目
++ 项目
++ 另一个项目
+
+或者
+
+- 项目
+- 项目
+- 最后一个项目
+
+<!-- 有序序列可由数字加点来实现 -->
+
+1. 项目一
+2. 项目二
+3. 项目三
+
+<!-- 即使你的标签数字有误,Markdown 依旧会呈现出正确的序号,
+不过这并不是一个好主意-->
+
+1. 项目一
+1. 项目二
+1. 项目三
+<!-- (此段与前例一模一样) -->
+
+<!-- 你也可以使用子序列 -->
+
+1. 项目一
+2. 项目二
+3. 项目三
+ * 子项目
+ * 子项目
+4. 项目四
+
+<!-- 代码段落 -->
+<!-- 代码段落(HTML中 <code>标签)可以由缩进四格(spaces)
+或者一个标签页(tab)实现-->
+
+ This is code
+ So is this
+
+<!-- 在你的代码中,你仍然使用tab可以进行缩进操作 -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- 内联代码可由反引号 ` 实现 -->
+
+John 甚至不知道 `go_to()` 方程是干嘛的!
+
+<!-- 在Github的 Markdown中,对于代码你可以使用特殊的语法 -->
+
+\`\`\`ruby <!-- 插入时记得移除反斜线, 仅留```ruby ! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- 这里也是,移除反斜线,仅留 ``` -->
+
+<!-- 以上代码不需要缩进,而且 Github 会根据```后表明的语言来进行语法高亮 -->
+
+<!-- 水平线 (<hr />) -->
+<!-- 水平线可由三个或以上的星号或者减号创建,可带可不带空格。 -->
+
+***
+---
+- - -
+****************
+
+<!-- 链接 -->
+<!-- Markdown 最棒的地方就是简易的链接制作。链接文字放在中括号[]内,
+在随后的括弧()内加入url。-->
+
+[点我点我!](http://test.com/)
+
+<!-- 你也可以为链接加入一个标题:在括弧内使用引号 -->
+
+[点我点我!](http://test.com/ "连接到Test.com")
+
+<!-- 相对路径也可以有 -->
+
+[去 music](/music/).
+
+<!-- Markdown同样支持引用样式的链接 -->
+
+[点此链接][link1]以获取更多信息!
+[看一看这个链接][foobar] 如果你愿意的话.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- 链接的标题可以处于单引号中,括弧中或是被忽略。引用名可以在文档的任意何处,
+并且可以随意命名,只要名称不重复。-->
+
+<!-- “隐含式命名” 的功能可以让链接文字作为引用名 -->
+
+[This][] is a link.
+
+[this]: http://thisisalink.com/
+
+<!-- 但这并不常用 -->
+
+<!-- 图像 -->
+<!-- 图像与链接相似,只需在前添加一个感叹号 -->
+
+![这是我图像的悬停文本(alt text)](http://imgur.com/myimage.jpg "可选命名")
+
+<!-- 引用样式也同样起作用 -->
+
+![这是我的悬停文本.][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "在此输入标题"
+
+<!-- 杂项 -->
+<!-- 自动链接 -->
+
+<http://testwebsite.com/> 与
+[http://testwebsite.com/](http://testwebsite.com/) 等同
+
+<!-- 电子邮件的自动链接 -->
+
+<foo@bar.com>
+
+<!-- 转义字符 -->
+
+我希望 *将这段文字置于星号之间* 但是我不希望它被
+斜体化, 所以我就: \*这段置文字于星号之间\*。
+
+<!-- 表格 -->
+<!-- 表格只被 Github 的 Markdown 支持,并且有一点笨重,但如果你真的要用的话: -->
+
+| 第一列 | 第二列 | 第三列 |
+| :---------- | :------: | ----------: |
+| 左对齐 | 居个中 | 右对齐 |
+| 某某某 | 某某某 | 某某某 |
+
+<!-- 或者, 同样的 -->
+
+第一列 | 第二列 | 第三列
+:-- | :-: | --:
+这太丑了 | 药不能 | 停
+
+<!-- 结束! -->
+
+```
+
+更多信息, 请于[此处](http://daringfireball.net/projects/Markdown/syntax)参见 John Gruber 关于语法的官方帖子,及于[此处](https://github.com/adam-p/Markdown-here/wiki/Markdown-Cheatsheet) 参见 Adam Pritchard 的摘要笔记。
diff --git a/zh-cn/php-cn.html.markdown b/zh-cn/php-cn.html.markdown
index 24939681..2def7f1c 100644
--- a/zh-cn/php-cn.html.markdown
+++ b/zh-cn/php-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/zh-cn/r-cn.html.markdown b/zh-cn/r-cn.html.markdown
index 19c5f25d..0c46bc22 100644
--- a/zh-cn/r-cn.html.markdown
+++ b/zh-cn/r-cn.html.markdown
@@ -13,7 +13,7 @@ lang: zh-cn
R 是一门统计语言。它有很多数据分析和挖掘程序包。可以用来统计、分析和制图。
你也可以在 LaTeX 文档中运行 `R` 命令。
-```python
+```r
# 评论以 # 开始
# R 语言原生不支持 多行注释
diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown
index 3c47f3f9..99250b43 100644
--- a/zh-cn/ruby-cn.html.markdown
+++ b/zh-cn/ruby-cn.html.markdown
@@ -40,7 +40,7 @@ translators:
1.+(3) #=> 4
10.* 5 #=> 50
-# 特殊的只也是对象
+# 特殊的值也是对象
nil # 空
true # 真
false # 假
diff --git a/zh-cn/scala-cn.html.markdown b/zh-cn/scala-cn.html.markdown
index 24f73bb5..58f5cd47 100644
--- a/zh-cn/scala-cn.html.markdown
+++ b/zh-cn/scala-cn.html.markdown
@@ -11,7 +11,7 @@ lang: zh-cn
Scala - 一门可拓展性的语言
-```cpp
+```scala
/*
自行设置:
@@ -369,7 +369,7 @@ import scala.collection.immutable._
import scala.collection.immutable.{List, Map}
// 使用 '=>' 来重命名一个 import
-import scala.collection.immutable{ List => ImmutableList }
+import scala.collection.immutable.{ List => ImmutableList }
// import 除了一些类的其它所有的类。下面的例子除去了 Map 类和 Set 类:
import scala.collection.immutable.{Map => _, Set => _, _}
diff --git a/zh-cn/swift-cn.html.markdown b/zh-cn/swift-cn.html.markdown
new file mode 100644
index 00000000..b9696c72
--- /dev/null
+++ b/zh-cn/swift-cn.html.markdown
@@ -0,0 +1,227 @@
+---
+language: swift
+filename: learnswift-cn.swift
+contributors:
+ - ["Grant Timmerman", "http://github.com/grant"]
+translators:
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+lang: zh-cn
+---
+
+Swift 是Apple 开发的用于iOS 和OS X 开发的编程语言。Swift 于2014年Apple WWDC (全球开发者大会)中被引入,用以与Objective-C 共存,同时对错误代码更具弹性。Swift 由Xcode 6 beta 中包含的LLVM编译器编译。
+
+参阅:Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html) ——一个完整的Swift 教程
+
+```swift
+//
+// 基础
+//
+
+println("Hello, world")
+var myVariable = 42
+let myConstant = 3.1415926
+let explicitDouble: Double = 70
+let label = "some text " + String(myVariable) // Casting
+let piText = "Pi = \(myConstant)" // String interpolation
+var optionalString: String? = "optional" // Can be nil
+optionalString = nil
+
+
+//
+// 数组与字典(关联数组)
+//
+
+// 数组
+var shoppingList = ["catfish", "water", "lemons"]
+shoppingList[1] = "bottle of water"
+let emptyArray = String[]()
+
+// 字典
+var occupations = [
+ "Malcolm": "Captain",
+ "kaylee": "Mechanic"
+]
+occupations["Jayne"] = "Public Relations"
+let emptyDictionary = Dictionary<String, Float>()
+
+
+//
+// 控制流
+//
+
+// 用于数组的for 循环
+let myArray = [1, 1, 2, 3, 5]
+for value in myArray {
+ if value == 1 {
+ println("One!")
+ } else {
+ println("Not one!")
+ }
+}
+
+// 用于字典的for 循环
+for (key, value) in dict {
+ println("\(key): \(value)")
+}
+
+// 用于区间的for 循环
+for i in -1...1 { // [-1, 0, 1]
+ println(i)
+}
+// 使用 .. 表示的区间不包含最后一个元素 [-1,0,1)
+
+// while 循环
+var i = 1
+while i < 1000 {
+ i *= 2
+}
+
+// do-while 循环
+do {
+ println("hello")
+} while 1 == 2
+
+// Switch
+let vegetable = "red pepper"
+switch vegetable {
+case "celery":
+ let vegetableComment = "Add some raisins and make ants on a log."
+case "cucumber", "watercress":
+ let vegetableComment = "That would make a good tea sandwich."
+case let x where x.hasSuffix("pepper"):
+ let vegetableComment = "Is it a spicy \(x)?"
+default: // 必须 (为了覆盖所有可能的输入)
+ let vegetableComment = "Everything tastes good in soup."
+}
+
+
+//
+// 函数
+//
+
+// 函数是一等类型,这意味着可以在函数中构建函数
+// 并且可以被传递
+
+// 函数
+func greet(name: String, day: String) -> String {
+ return "Hello \(name), today is \(day)."
+}
+greet("Bob", "Tuesday")
+
+// 使用多元数组返回多返回值的函数
+func getGasPrices() -> (Double, Double, Double) {
+ return (3.59, 3.69, 3.79)
+}
+
+// 不定参数
+func setup(numbers: Int...) {}
+
+// 传递、返回函数
+func makeIncrementer() -> (Int -> Int) {
+ func addOne(number: Int) -> Int {
+ return 1 + number
+ }
+ return addOne
+}
+var increment = makeIncrementer()
+increment(7)
+
+
+//
+// 闭包
+//
+
+// 函数是特殊的闭包({})
+
+// 闭包示例.
+// `->` 分隔参数和返回类型
+// `in` 分隔闭包头和闭包体
+numbers.map({
+ (number: Int) -> Int in
+ let result = 3 * number
+ return result
+ })
+
+// 当类型已知时,可以这样做:
+var numbers = [1, 2, 6]
+numbers = numbers.map({ number in 3 * number })
+print(numbers) // [3, 6, 18]
+
+
+//
+// 类
+//
+
+// 类的全部方法和属性都是public 的
+// 如果你在一个数据结构中只需储存数据,
+// 应使用 `struct`
+
+// 集成自`Shape` 类的简单的类`Square
+class Rect: Shape {
+ var sideLength: Int = 1
+
+ // Custom getter and setter property
+ var perimeter: Int {
+ get {
+ return 4 * sideLength
+ }
+ set {
+ sideLength = newValue / 4
+ }
+ }
+
+ init(sideLength: Int) {
+ super.init()
+ self.sideLength = sideLength
+ }
+
+ func shrink() {
+ if sideLength > 0 {
+ --sideLength
+ }
+ }
+
+ override func getArea() -> Int {
+ return sideLength * sideLength
+ }
+}
+var mySquare = new Square(sideLength: 5)
+print(mySquare.getArea()) // 25
+mySquare.shrink()
+print(mySquare.sideLength) // 4
+
+// 如果你不需要自定义getter 和setter,
+// 但仍希望在获取或设置一个属性之前或之后运行
+// 一些代码,你可以使用`willSet` 和 `didSet`
+
+
+//
+// 枚举类型
+//
+
+// 枚举类型可以是某种指定的类型,抑或自成一种类型
+// 像类一样,枚举类型可以包含方法
+
+enum Suit {
+ case Spades, Hearts, Diamonds, Clubs
+ func getIcon() -> String {
+ switch self {
+ case .Spades: return "♤"
+ case .Hearts: return "♡"
+ case .Diamonds: return "♢"
+ case .Clubs: return "♧"
+ }
+ }
+}
+
+
+//
+// 其它
+//
+
+// `协议(protocol)`: 与Java 的接口(Interface) 类似.
+// `扩展(extension)`: 为现有类型添加额外特性
+// 泛型: 与Java 相似。使用`where` 关键字指定
+// 泛型的要求.
+
+```
diff --git a/zh-cn/xml-cn.html.markdown b/zh-cn/xml-cn.html.markdown
new file mode 100644
index 00000000..bf0b074f
--- /dev/null
+++ b/zh-cn/xml-cn.html.markdown
@@ -0,0 +1,127 @@
+---
+language: xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnxml-cn.xml
+lang: zh-cn
+---
+
+XML是一种标记语言,被设计用来存储数据和传输数据。
+
+不像HTML, XML不指定怎样显示或格式化数据,只是携带它。
+
+
+* XML 语法
+
+```xml
+<!-- XML中的注解像这样 -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<bookstore>
+ <book category="COOKING">
+ <title lang="en">Everyday Italian</title>
+ <author>Giada De Laurentiis</author>
+ <year>2005</year>
+ <price>30.00</price>
+ </book>
+ <book category="CHILDREN">
+ <title lang="en">Harry Potter</title>
+ <author>J K. Rowling</author>
+ <year>2005</year>
+ <price>29.99</price>
+ </book>
+ <book category="WEB">
+ <title lang="en">Learning XML</title>
+ <author>Erik T. Ray</author>
+ <year>2003</year>
+ <price>39.95</price>
+ </book>
+</bookstore>
+
+<!-- 上面是一个典型的XML文件。
+ 它以一个声明开始,通知一些元数据(自选的)
+
+ XML使用一个树的结构。上面的文件中,根节点是'bookstore',它有三个孩子节点,
+ 所有的'books'。那些节点有更多的孩子节点,等等。。。
+
+ 节点用开放/关闭标签创建, 并且孩子就是在开发和关闭标签之间的节点。-->
+
+
+
+<!-- XML 携带两类信息:
+ 1 - 属性 -> 那是关于一个元素的元数据。
+ 通常,XML解析器使用这些信息去正确地存储数据。
+ 它通过在开放标签里出现在插入语中来表示。
+ 2 - 元素 -> 那是纯数据。
+ 那就是解析器将从XML文件提取的东西。
+ 元素出现在开放和关闭标签之间,没插入语。-->
+
+
+<!-- 下面, 一个有两个属性的元素-->
+<file type="gif" id="4293">computer.gif</file>
+
+
+```
+
+* 良好格式的文件 x 验证
+
+一个XML文件是良好格式的如果它是语法正确的。
+但是, 使用文件定义,比如DTD和XML概要,在文件中插入更多的限制是可能的。
+
+一个遵守一个文件定义的XML文件被叫做有效的,对于那个文件来说。
+
+有了这个工具,你能够在应用逻辑之外检查XML数据。
+
+```xml
+
+<!-- 下面, 你能够看到一个简化版本的增加了DTD定义的bookstore文件。-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "Bookstore.dtd">
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+
+<!-- 这个DTD可能是像这样的:-->
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+
+<!-- 这个DTD以一个声明开始。
+ 接下来, 根节点被声明, 它需要一个或多个孩子节点'book'。
+ 每个 'book' 应该准确包含一个 'title' 和 'price' 和
+ 一个被叫做'category'的缺省值为"Literature"的属性。
+ 这个'title' 和 'price'节点包含一个解析过的字符数据。-->
+
+<!-- 这个DTD可以在XML文件中本身被声明。-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+``` \ No newline at end of file
diff --git a/zh-cn/yaml-cn.html.markdown b/zh-cn/yaml-cn.html.markdown
new file mode 100644
index 00000000..fc510eb5
--- /dev/null
+++ b/zh-cn/yaml-cn.html.markdown
@@ -0,0 +1,136 @@
+---
+language: yaml
+contributors:
+ - ["Adam Brenecki", "https://github.com/adambrenecki"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnyaml-cn.yaml
+lang: zh-cn
+---
+
+YAML是一个数据序列化语言,被设计成人类直接可写可读的。
+
+它是JSON的严格超集,增加了语法显著换行符和缩进,就像Python。但和Python不一样,
+YAML根本不容许文字制表符。
+
+
+```yaml
+# YAML中的注解看起来像这样。
+
+################
+# 标量类型 #
+################
+
+# 我们的根对象 (它们在整个文件里延续) 将会是一个地图,
+# 它等价于在别的语言里的一个字典,哈西表或对象。
+key: value
+another_key: Another value goes here.
+a_number_value: 100
+scientific_notation: 1e+12
+boolean: true
+null_value: null
+key with spaces: value
+# 注意到字符串不需要被引用。但是,它们可以被引用。
+"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
+
+# 多行字符串既可以写成像一个'文字块'(使用 |),
+# 或像一个'折叠块'(使用 '>')。
+literal_block: |
+ This entire block of text will be the value of the 'literal_block' key,
+ with line breaks being preserved.
+
+ The literal continues until de-dented, and the leading indentation is
+ stripped.
+
+ Any lines that are 'more-indented' keep the rest of their indentation -
+ these lines will be indented by 4 spaces.
+folded_style: >
+ This entire block of text will be the value of 'folded_style', but this
+ time, all newlines will be replaced with a single space.
+
+ Blank lines, like above, are converted to a newline character.
+
+ 'More-indented' lines keep their newlines, too -
+ this text will appear over two lines.
+
+####################
+# 集合类型 #
+####################
+
+# 嵌套是通过缩进完成的。
+a_nested_map:
+ key: value
+ another_key: Another Value
+ another_nested_map:
+ hello: hello
+
+# 地图不用有字符串键值。
+0.25: a float key
+
+# 键值也可以是多行对象,用?表明键值的开始。
+? |
+ This is a key
+ that has multiple lines
+: and this is its value
+
+# YAML也容许键值是集合类型,但是很多语言将会抱怨。
+
+# 序列 (等价于表或数组) 看起来像这样:
+a_sequence:
+ - Item 1
+ - Item 2
+ - 0.5 # 序列可以包含不同类型。
+ - Item 4
+ - key: value
+ another_key: another_value
+ -
+ - This is a sequence
+ - inside another sequence
+
+# 因为YAML是JSON的超集,你也可以写JSON风格的地图和序列:
+json_map: {"key": "value"}
+json_seq: [3, 2, 1, "takeoff"]
+
+#######################
+# 其余的YAML特点 #
+#######################
+
+# YAML还有一个方便的特点叫'锚',它让你简单地在整个文件里重复内容。
+# 两个键值将会有相同的值:
+anchored_content: &anchor_name This string will appear as the value of two keys.
+other_anchor: *anchor_name
+
+# YAML还有标签,你可以用它显示地声明类型。
+explicit_string: !!str 0.5
+# 一些解析器实现特定语言的标签,就像这个为了Python的复数类型。
+python_complex_number: !!python/complex 1+2j
+
+####################
+# 其余的YAML类型 #
+####################
+
+# 字符串和数字不是仅有的YAML可以理解的标量。
+# ISO 格式的日期和日期时间文字也是可以被解析的。
+datetime: 2001-12-15T02:59:43.1Z
+datetime_with_spaces: 2001-12-14 21:59:43.10 -5
+date: 2002-12-14
+
+# 这个!!binary标签表明一个字符串实际上是一个二进制blob的base64编码表示。
+gif_file: !!binary |
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
+
+# YAML还有一个集合类型,它看起来像这样:
+set:
+ ? item1
+ ? item2
+ ? item3
+
+# 像Python一样,集合仅是有null数值的地图;上面的集合等价于:
+set2:
+ item1: null
+ item2: null
+ item3: null
+```