summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown45
-rw-r--r--c.html.markdown883
-rw-r--r--compojure.html.markdown225
-rw-r--r--csharp.html.markdown2
-rw-r--r--de-de/coffeescript-de.html.markdown106
-rw-r--r--de-de/go-de.html.markdown2
-rw-r--r--de-de/haskell-de.html.markdown425
-rw-r--r--de-de/javascript-de.html.markdown4
-rw-r--r--es-es/bash-es.html.markdown195
-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/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/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/csharp-fr.html.markdown2
-rw-r--r--fr-fr/ruby-fr.html.markdown4
-rw-r--r--git.html.markdown2
-rw-r--r--go.html.markdown499
-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.markdown4
-rw-r--r--ko-kr/go-kr.html.markdown2
-rw-r--r--ko-kr/javascript-kr.html.markdown4
-rw-r--r--learntmux.html.markdown71
-rw-r--r--matlab.html.markdown5
-rw-r--r--perl6.html.markdown1344
-rw-r--r--pt-br/git-pt.html.markdown402
-rw-r--r--pt-br/go-pt.html.markdown2
-rw-r--r--pt-br/json-pt.html.markdown62
-rw-r--r--pt-br/markdown-pt.html.markdown251
-rw-r--r--purescript.html.markdown195
-rw-r--r--python.html.markdown52
-rw-r--r--python3.html.markdown69
-rw-r--r--ru-ru/go-ru.html.markdown44
-rw-r--r--ruby-ecosystem.html.markdown67
-rw-r--r--scala.html.markdown44
-rw-r--r--swift.html.markdown345
-rw-r--r--typescript.html.markdown158
-rw-r--r--whip.html.markdown16
-rw-r--r--zh-cn/go-cn.html.markdown2
-rw-r--r--zh-cn/javascript-cn.html.markdown4
-rw-r--r--zh-cn/julia-cn.html.markdown729
50 files changed, 8444 insertions, 947 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index d5d08e9d..57fb5c55 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -6,6 +6,8 @@ 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/"]
filename: LearnBash.sh
---
@@ -71,15 +73,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 +134,28 @@ 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
+# 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 +182,14 @@ 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
```
diff --git a/c.html.markdown b/c.html.markdown
index 22f251f2..79b7aec7 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -16,16 +16,16 @@ 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.
-*/
+ */
-// 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 +34,386 @@ 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 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 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 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 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 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 (some_integral_expression) {
- case 0: // labels need to be integral *constant* expressions
- 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 `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
+ // 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 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)
+
+ 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.
+ // 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 e = 5;
+ int f = 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 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-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 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 +425,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 +442,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 +461,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 +484,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 +495,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 +516,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 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
+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 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.
+ // 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 +555,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 (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
-'\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" // hexadecimal
-"%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
///////////////////////////////////////
diff --git a/compojure.html.markdown b/compojure.html.markdown
new file mode 100644
index 00000000..56f43cb7
--- /dev/null
+++ b/compojure.html.markdown
@@ -0,0 +1,225 @@
+---
+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}))
+```
+
+Create a project with [Leiningen](http://leiningen.org/):
+
+```
+lein new myapp
+```
+
+Add your dependencies:
+
+```
+[compojure "1.1.8"]
+[http-kit "2.1.16"]
+```
+
+And 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")))
+```
+
+Route patterns may include named parameters,
+
+```clojure
+(defroutes myapp
+ (GET "/hello/:name" [name] (str "Hello " name)))
+```
+
+You can match entire paths with *
+
+```clojure
+(defroutes myapp
+ (GET "/file/*.*" [*] (str *)))
+```
+
+Handlers may utilize query parameters:
+
+```clojure
+(defroutes myapp
+ (GET "/posts" []
+ (fn [req]
+ (let [title (get (:params req) "title")
+ author (get (:params req) "title")]
+ " Do something with title and author"))))
+```
+
+Or, for POST and PUT requests, form parameters
+
+```clojure
+(defroutes myapp
+ (POST "/posts" []
+ (fn [req]
+ (let [title (get (:params req) "title")
+ author (get (:params req) "title")]
+ "Do something with title and author"))))
+```
+
+
+### Return values
+
+The return value of a route block determines at least 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 body](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:
+
+[Clojure for the Brave and True](http://www.braveclojure.com/)
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 4fa8deba..136f6c50 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -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)
{
}
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/go-de.html.markdown b/de-de/go-de.html.markdown
index 8c2f58dd..ca27fdc7 100644
--- a/de-de/go-de.html.markdown
+++ b/de-de/go-de.html.markdown
@@ -79,7 +79,7 @@ func learnTypes() {
Zeilenumbrüche beinhalten.` // Selber Zeichenketten-Typ
// nicht-ASCII Literal. Go Quelltext ist UTF-8 kompatibel.
- g := 'Σ' // Ein Runen-Typ, alias uint32, gebraucht für unicode code points.
+ 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
diff --git a/de-de/haskell-de.html.markdown b/de-de/haskell-de.html.markdown
new file mode 100644
index 00000000..df6267f9
--- /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/es-es/bash-es.html.markdown b/es-es/bash-es.html.markdown
new file mode 100644
index 00000000..489fd39e
--- /dev/null
+++ b/es-es/bash-es.html.markdown
@@ -0,0 +1,195 @@
+---
+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
+---
+
+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/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..3865126c
--- /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 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/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/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/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/git.html.markdown b/git.html.markdown
index 65e57f05..618d1906 100644
--- a/git.html.markdown
+++ b/git.html.markdown
@@ -395,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 4ea6861b..bedc3042 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -9,9 +9,10 @@ contributors:
- ["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.
@@ -25,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.
@@ -33,87 +34,102 @@ 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.
+ s := "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)
-
- learnFlowControl() // Back in the flow.
+ // 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 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.
+
+ // 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.
+ _, _, _, _, _, _, _, _, _ = 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.
}
// It is possible, unlike in many other languages for functions in go
@@ -122,240 +138,257 @@ can include line breaks.` // Same string type.
// 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.
+ 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:
- learnFunctionFactory() // func returning func is fun(3)(3)
- 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!"))
+ // 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!"))
+ 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
- }
+ 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.
- // The underbar here is ignoring the index argument of the array.
- 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.
- go func() {
- 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();
+ 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))
+ 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))
}
```
@@ -364,13 +397,15 @@ func requestServer() {
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/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..3e6621f5
--- /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コマンドを呼び出すこともできます
+
+
+```python
+# コメント行は、#で開始します
+
+
+# 複数行をまとめてコメントにすることはできないので、
+# コメントを複数の行に分けたい場合、このように、単に毎行をコメントにしてください
+
+
+# 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 \ No newline at end of file
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 c59a90c3..7c869b28 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -460,8 +460,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/ko-kr/go-kr.html.markdown b/ko-kr/go-kr.html.markdown
index e4eaee56..3012c04f 100644
--- a/ko-kr/go-kr.html.markdown
+++ b/ko-kr/go-kr.html.markdown
@@ -79,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 타입으로 표현됨
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/learntmux.html.markdown b/learntmux.html.markdown
new file mode 100644
index 00000000..eaf3fd25
--- /dev/null
+++ b/learntmux.html.markdown
@@ -0,0 +1,71 @@
+---
+category: tool
+tool: tmux
+contributors:
+ - ["kaernyk", "http://github.com/kaernyk"]
+filename: LearnTmux.txt
+---
+
+
+ tmux 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.
+
+ Once you feel comfortable manipulating tmux to suit your needs, I strongly
+suggest you read the man pages.
+
+
+
+```
+# Session Management
+
+ tmux new Create new session
+ -s "Session" Create named session
+ -n "Window" Create named Window
+ -c "/dir" Start in target directory
+
+ C^b $ Rename current session
+ C^b d Detach current session
+ C^b D Select session to detach
+
+ tmux attach Attach last/available session
+ -t "#" Attach target session
+ -d Detach the session from other instances
+
+ tmux ls List open sessions
+ C^b s Select new session for attached client interactively
+
+ kill-session Kill current session
+ -t "#" Kill target session
+ -a Kill all sessions
+ -a -t "#" Kill all sessions but the target
+
+
+# Window Management
+
+ C^b c Create another window
+ C^b " Split Horizontally
+ C^b % Split Vertically
+ C^b M-(1-5) 1) Tile vertically
+ 2) Tile horizontally
+ 3) Tile Vertically /w large horizontal
+ 4) Tile horizontally /w large vertical
+ 5) Tile all windows evenly
+
+ C^b q Briefly display pane indexes
+ C^# Choose current window by #
+ C^b w Choose current window interactively
+ C^b n Change to next window
+ C^b p Change to previous window
+ C^b Up, Right Change to pane in selected direction
+ Down, left
+ C^b { Swap current/previous window
+ C^b } Swap current/next window
+
+ C^b C-Up, Right Resize in steps of one cell
+ Down, left
+ C^b M-Up, Right resize in steps of five cells
+ Down, left
+
+ exit or C^b x Kill the current window
+```
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/perl6.html.markdown b/perl6.html.markdown
new file mode 100644
index 00000000..fe5b197c
--- /dev/null
+++ b/perl6.html.markdown
@@ -0,0 +1,1344 @@
+---
+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
+
+## * Arrays. They represent multiple values. Their name start with `@`.
+
+my @array = 1, 2, 3;
+my @array = 'a', 'b', 'c';
+# equivalent to :
+my @array = <a b c>; # array of words, delimited by space.
+ # Similar to perl5's qw, or Ruby's %w.
+
+say @array[2]; # Array indices start at 0 -- This is the third element
+
+say "Interpolate an array using [] : @array[]";
+#=> Interpolate an array using [] : a b c
+
+## * 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";
+}
+
+### 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 arrays,
+# using the Whatever Star:
+my @array = 1..*; # 1 to Infinite !
+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.
+
+## * 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`
+ }
+}
+
+# You can throw an exception using `die`:
+die X::AdHoc.new(payload => 'Error !');
+# TODO warn
+# TODO fail
+# TODO CONTROL
+
+### 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.
+
+# - `**` - "Quantify It Yourself".
+# 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)
+
+## 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 any `**`, 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).
+
+# If you're wondering how the captures are numbered, here's an explanation:
+TODO use graphs from s05
+
+
+## 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 ...
+
+### 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, you !" }
+# 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 get `--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/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 32c8fbdd..c7339831 100644
--- a/pt-br/go-pt.html.markdown
+++ b/pt-br/go-pt.html.markdown
@@ -75,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
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..cac4a13e
--- /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 é 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/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 210c9619..9057dde2 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -45,6 +45,15 @@ 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
+
# Enforce precedence with parentheses
(1 + 3) * 2 # => 8
@@ -327,6 +336,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 +393,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 +441,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 +528,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 +549,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
index 778076f8..f6babaff 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -2,6 +2,7 @@
language: python3
contributors:
- ["Louie Dinh", "http://pythonpracticeprojects.com"]
+ - ["Steven Basart", "http://github.com/xksteven"]
filename: learnpython3.py
---
@@ -37,13 +38,21 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
# 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
+
# Enforce precedence with parentheses
(1 + 3) * 2 # => 8
-
# Boolean values are primitives
True
False
@@ -52,7 +61,6 @@ False
not True # => False
not False # => True
-
# Equality is ==
1 == 1 # => True
2 == 1 # => False
@@ -71,7 +79,6 @@ not False # => True
1 < 2 < 3 # => True
2 < 3 < 2 # => False
-
# Strings are created with " or '
"This is a string."
'This is also a string.'
@@ -86,10 +93,16 @@ not False # => True
"{} 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"
+"{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
@@ -284,7 +297,7 @@ prints:
mouse is a mammal
"""
for animal in ["dog", "cat", "mouse"]:
- # You can use % to interpolate formatted strings
+ # You can use format() to interpolate formatted strings
print("{} is a mammal".format(animal))
"""
@@ -318,9 +331,12 @@ 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
-
-# Python's offers a fundamental abstraction called the Iterable.
+# 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.
@@ -328,7 +344,7 @@ 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
-i We can loop over it.
+# We can loop over it.
for i in our_iterable:
print(i) # Prints one, two, three
@@ -406,6 +422,24 @@ 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):
@@ -438,14 +472,17 @@ 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
# An instance method. All methods take "self" as the first argument
def say(self, msg):
- return "{name}: {message}" % (name=self.name, message=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
@@ -524,9 +561,11 @@ def double_numbers(iterable):
# 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)
+# 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):
+for i in double_numbers(range_):
print(i)
if i >= 30:
break
@@ -539,10 +578,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/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/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/scala.html.markdown b/scala.html.markdown
index 432933c2..379c092c 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -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
index f24b1592..e7f2f9a2 100644
--- a/swift.html.markdown
+++ b/swift.html.markdown
@@ -2,131 +2,164 @@
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.
```js
//
-// Basics
+// 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")
+
var myVariable = 42
+let øπΩ = "value" // unicode variable names
let myConstant = 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 label = "some text " + String(myVariable) // Casting
-let piText = "Pi = \(myConstant)" // String interpolation
-var optionalString: String? = "optional" // Can be nil
+let intValue = 0007 // 7
+let largeIntValue = 77_000 // 77000
+let label = "some text " + String(myVariable) // Casting
+let piText = "Pi = \(myConstant), Pi 2 = \(myConstant * 2)" // String interpolation
+var optionalString: String? = "optional" // Can be nil
optionalString = nil
+/*
+Comment here
+ /*
+ Nested comments are also supported
+ */
+*/
//
-// Arrays and Dictionaries
+// MARK: Collections
//
// Array
var shoppingList = ["catfish", "water", "lemons"]
shoppingList[1] = "bottle of water"
-let emptyArray = String[]()
+let emptyArray = [String]()
// Dictionary
var occupations = [
- "Malcolm": "Captain",
- "kaylee": "Mechanic"
+ "Malcolm": "Captain",
+ "kaylee": "Mechanic"
]
occupations["Jayne"] = "Public Relations"
-let emptyDictionary = Dictionary<String, Float>()
+let emptyDictionary = [String: Float]()
//
-// Control Flow
+// 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!")
- }
+ 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)")
+ println("\(key): \(value)")
}
// for loop (range)
for i in -1...1 { // [-1, 0, 1]
- println(i)
+ println(i)
}
-// use .. to exclude the last number
+// use ..< to exclude the last number
// while loop
var i = 1
while i < 1000 {
- i *= 2
+ i *= 2
}
// do-while loop
do {
- println("hello")
+ 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."
+ let vegetableComment = "Add some raisins and make ants on a log."
case "cucumber", "watercress":
- let vegetableComment = "That would make a good tea sandwich."
+ let vegetableComment = "That would make a good tea sandwich."
case let x where x.hasSuffix("pepper"):
- let vegetableComment = "Is it a spicy \(x)?"
+ let vegetableComment = "Is it a spicy \(x)?"
default: // required (in order to cover all possible input)
- let vegetableComment = "Everything tastes good in soup."
+ let vegetableComment = "Everything tastes good in soup."
}
//
-// Functions
+// MARK: Functions
//
// Functions are a first-class type, meaning they can be nested
// in functions and can be passed around
-// Function
+// 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)."
+ 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)
+ return (3.59, 3.69, 3.79)
}
-// Args
+// Variadic Args
func setup(numbers: Int...) {}
// Passing and returning functions
func makeIncrementer() -> (Int -> Int) {
- func addOne(number: Int) -> Int {
- return 1 + number
- }
- return addOne
+ func addOne(number: Int) -> Int {
+ return 1 + number
+ }
+ return addOne
}
var increment = makeIncrementer()
increment(7)
//
-// Closures
+// MARK: Closures
//
+var numbers = [1, 2, 6]
// Functions are special case closures ({})
@@ -134,91 +167,243 @@ increment(7)
// `->` 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
- })
+ (number: Int) -> Int in
+ let result = 3 * number
+ return result
+})
// When the type is known, like above, we can do this
-var numbers = [1, 2, 6]
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]
//
-// Classes
+// 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`
-// A simple class `Square` extends `Shape`
-class Rect: Shape {
- var sideLength: Int = 1
+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
+ }
+ }
- // Custom getter and setter property
- var perimeter: Int {
- get {
- return 4 * sideLength
+ // 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)
+ }
}
- set {
- sideLength = newValue / 4
+
+ init(sideLength: Int) {
+ super.init()
+ self.sideLength = sideLength
}
- }
-
- init(sideLength: Int) {
- super.init()
- self.sideLength = sideLength
- }
-
- func shrink() {
- if sideLength > 0 {
- --sideLength
+
+ func shrink() {
+ if sideLength > 0 {
+ --sideLength
+ }
+ }
+
+ override func getArea() -> Int {
+ return sideLength * 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 = new Square(sideLength: 5)
+
+var mySquare = Square()
print(mySquare.getArea()) // 25
mySquare.shrink()
print(mySquare.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`
+// compare instances, not the same as == which compares objects (equal to)
+if mySquare === mySquare {
+ println("Yep, it's mySquare")
+}
//
-// Enums
+// 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 "♧"
+ case Spades, Hearts, Diamonds, Clubs
+ func getIcon() -> String {
+ switch self {
+ case .Spades: return "♤"
+ case .Hearts: return "♡"
+ case .Diamonds: return "♢"
+ case .Clubs: return "♧"
+ }
}
- }
}
//
-// Other
+// 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
//
-// `protocol`: Similar to Java interfaces.
-// `extension`s: Add extra functionality to an already created type
+// `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. Use the `where` keyword to specify the
// requirements of the generics.
-``` \ No newline at end of file
+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/typescript.html.markdown b/typescript.html.markdown
new file mode 100644
index 00000000..8173aac8
--- /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.
+
+```ts
+//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/whip.html.markdown b/whip.html.markdown
index dc5a0b39..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"
@@ -159,12 +159,12 @@ undefined ; user to indicate a value that hasn't been set
; | | 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/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/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/julia-cn.html.markdown b/zh-cn/julia-cn.html.markdown
new file mode 100644
index 00000000..7afc9043
--- /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
+ #
+```