summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--c.html.markdown675
-rw-r--r--clojure.html.markdown2
-rw-r--r--common-lisp.html.markdown605
-rw-r--r--csharp.html.markdown549
-rw-r--r--es-es/c-es.html.markdown2
-rw-r--r--es-es/coffeescript-es.html.markdown57
-rw-r--r--fr-fr/ruby-fr.html.markdown407
-rw-r--r--go.html.markdown301
-rw-r--r--haskell.html.markdown2
-rw-r--r--java.html.markdown4
-rw-r--r--javascript.html.markdown246
-rw-r--r--ko-kr/javascript-kr.html.markdown435
-rw-r--r--ko-kr/lua-kr.html.markdown424
-rw-r--r--ko-kr/python-kr.html.markdown484
-rw-r--r--objective-c.html.markdown310
-rw-r--r--php.html.markdown5
-rw-r--r--pt-br/elisp-pt.html.markdown359
-rw-r--r--pt-br/python-pt.html.markdown2
-rw-r--r--ru-ru/clojure-ru.html.markdown426
-rw-r--r--ruby-ecosystem.html.markdown8
-rw-r--r--ruby.html.markdown44
-rw-r--r--zh-cn/go-zh.html.markdown279
-rwxr-xr-xzh-cn/python-cn.html.markdown277
-rw-r--r--zh-cn/racket-cn.html.markdown608
-rw-r--r--zh-cn/ruby-cn.html.markdown5
25 files changed, 5950 insertions, 566 deletions
diff --git a/c.html.markdown b/c.html.markdown
index d243b19d..8e16837c 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -1,23 +1,25 @@
---
-name: c
-category: language
-language: c
-filename: learnc.c
-contributors:
- - ["Adam Bard", "http://adambard.com/"]
+- name: c
+- category: language
+- language: c
+- filename: learnc.c
+- contributors:
+ - [Adam Bard](http://adambard.com/)
+ - [Árpád Goretity](http://twitter.com/H2CO3_iOS)
+
---
-Ah, C. Still the language of modern high-performance computing.
+Ah, C. Still **the** language of modern high-performance computing.
C is the lowest-level language most programmers will ever use, but
it more than makes up for it with raw speed. Just be aware of its manual
memory management and C will take you as far as you need to go.
```c
-// Single-line comments start with //
+// Single-line comments start with // - only available in C99 and later.
/*
-Multi-line comments look like this.
+Multi-line comments look like this. They work in C89 as well.
*/
// Import headers with #include
@@ -25,6 +27,17 @@ Multi-line comments look like this.
#include <stdio.h>
#include <string.h>
+// file names between <angle brackets> are headers from the C standard library.
+// They are searched for by the preprocessor in the system include paths
+// (usually /usr/lib on Unices, can be controlled with the -I<dir> option if you are using GCC or clang.)
+// For your own headers, use double quotes instead of angle brackets:
+#include "my_header.h"
+
+// The C preprocessor introduces an almost fully-featured macro language. It's useful, but
+// it can be confusing (and what's even worse, it can be misused). Read the
+// Wikipedia article on the C preprocessor for further information:
+// http://en.wikipedia.org/wiki/C_preprocessor
+
// Declare function signatures in advance in a .h file, or at the top of
// your .c file.
void function_1();
@@ -33,261 +46,347 @@ void function_2();
// 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
-///////////////////////////////////////
-
-// You have to declare variables before using them. A variable declaration
-// requires you to specify its type; a variable's type determines its size
-// in bytes.
-
-// 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. This means they can't be negative, but
-// the maximum value of an unsigned variable is greater than the maximum
-// signed value of the same size.
-unsigned char ux_char;
-unsigned short ux_short;
-unsigned int ux_int;
-unsigned long long ux_long_long;
-
-// Other than char, which is always 1 byte, these types vary in size depending
-// on your machine. sizeof(T) gives you the size of a variable with type T in
-// bytes so you can express the size of these types in a portable way.
-// For example,
-printf("%lu\n", sizeof(int)); // => 4 (on machines with 4-byte words)
-
-// 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
-
-// Strings are just arrays of chars terminated by a NUL (0x00) byte,
-// represented in strings as the special character '\0'.
-// (We don't have to include the NUL byte in string literals; the compiler
-// inserts it at the end of the array for us.)
-char a_string[20] = "This is a string";
-printf("%s\n", a_string); // %s formats a string
-
-/*
-You may have noticed that a_string is only 16 chars long.
-Char #17 is the NUL byte.
-Chars #18, 19 and 20 have undefined values.
-*/
-
-printf("%d\n", a_string[16]); // => 0
-
-///////////////////////////////////////
-// Operators
-///////////////////////////////////////
-
-int i1 = 1, i2 = 2; // Shorthand for multiple declaration
-float f1 = 1.0, f2 = 2.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
-
-// 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.
-// 0 is false, anything else is true. (The comparison
-// operators always return 0 or 1.)
-3 == 2; // => 0 (false)
-3 != 2; // => 1 (true)
-3 > 2; // => 1
-3 < 2; // => 0
-2 <= 2; // => 1
-2 >= 2; // => 1
-
-// 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
-
-// Bitwise operators!
-~0x0F; // => 0xF0 (bitwise negation)
-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))
-
-///////////////////////////////////////
-// 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) {
- printf("%d, ", ii++); // ii++ increments ii in-place, after using its 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 in-place, before using its 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");
-
-///////////////////////////////////////
-// Typecasting
-///////////////////////////////////////
-
-// Every value in C has a type, but you can cast one value into another type
-// if you want.
-
-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", (char) 257); // => 1 (Max char = 255)
-
-// 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", &x); // Use & to retrieve the address of a variable
-// (%p formats a pointer)
-// => Prints some address in memory;
-
-// Pointer types end with * in their declaration
-int* px; // px is a pointer to an int
-px = &x; // Stores the address of x in px
-printf("%p\n", px); // => Prints some address in memory
-
-// To retreive the value at the address a pointer is pointing to,
-// put * in front to de-reference it.
-printf("%d\n", *px); // => Prints 0, the value of x, which is what px is pointing to the address of
-
-// You can also change the value the pointer is pointing to.
-// We'll have to wrap the de-reference in parenthesis because
-// ++ has a higher precedence than *.
-(*px)++; // Increment the value px is pointing to by 1
-printf("%d\n", *px); // => Prints 1
-printf("%d\n", x); // => Prints 1
-
-int x_array[20]; // Arrays are a good way to allocate a contiguous block of memory
-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 are actually just pointers to their first element.
-
-// Arrays are pointers to their first element
-printf("%d\n", *(x_ptr)); // => Prints 20
-printf("%d\n", x_array[0]); // => Prints 20
-
-// Pointers are incremented and decremented based on their type
-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 integer argument
-// representing the number of bytes to allocate from the heap.
-int* my_ptr = (int*) malloc(sizeof(int) * 20);
-for (xx=0; xx<20; xx++) {
- *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx would also work here
-} // Initialize memory to 20, 19, 18, 17... 2, 1 (as ints)
-
-// Dereferencing memory that you haven't allocated gives
-// unpredictable results
-printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what?
-
-// 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
-free(my_ptr);
-
-// Strings can be char arrays, but are usually represented as char
-// pointers:
-char* my_str = "This is my very own string";
-
-printf("%c\n", *my_str); // => 'T'
-
-function_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
+ ///////////////////////////////////////
+
+ // You have to declare variables before using them. A variable declaration
+ // requires you to specify its type; a variable's type determines its size
+ // in bytes.
+
+ // 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. This means they can't be negative, but
+ // the maximum value of an unsigned variable is greater than the maximum
+ // signed value of the same size.
+ unsigned char ux_char;
+ unsigned short ux_short;
+ unsigned int ux_int;
+ unsigned long long ux_long_long;
+
+ // Other than char, which is always 1 byte (but not necessarily 8 bits!),
+ // these types vary in size depending on your machine and compiler.
+ // sizeof(T) gives you the size of a variable with type T in
+ // bytes so you can express the size of these types in a portable way.
+ // sizeof(obj) yields the size of an actual expression (variable, literal, etc.).
+ // For example,
+ printf("%zu\n", sizeof(int)); // => 4 (on most machines with 4-byte words)
+
+
+ // It's worth noting that if the argument of the `sizeof` operator is not a type but an expression,
+ // then its argument is not evaluated except VLAs (see below). Also, `sizeof()` is an operator, not a function,
+ // furthermore, the value it yields is a compile-time constant (except when used on VLAs, again.)
+ int a = 1;
+ size_t size = sizeof(a++); // a++ is not evaluated
+ printf("sizeof(a++) = %zu where a = %d\n", size, a);
+ // the above code prints "sizeof(a++) = 4 where a = 1" (on a usual 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);
+ size_t size = strtoul(buf, NULL, 10); // strtoul parses a string to an unsigned integer
+ int var_length_array[size]; // declare the VLA
+ printf("sizeof array = %zu\n", sizeof var_length_array);
+
+ // A possible outcome of this program may be:
+ Enter the array size: 10
+ sizeof array = 40
+
+ // Strings are just arrays of chars terminated by a NUL (0x00) byte,
+ // represented in strings as the special character '\0'.
+ // (We don't have to include the NUL byte in string literals; the compiler
+ // inserts it at the end of the array for us.)
+ char a_string[20] = "This is a string";
+ printf("%s\n", a_string); // %s formats a string
+
+ /*
+ You may have noticed that a_string is only 16 chars long.
+ Char #17 is the NUL byte.
+ Chars #18, 19 and 20 are 0 as well - if an initializer list (in this case, the string literal)
+ has less elements than the array it is initializing, then excess array elements are implicitly
+ initialized to zero. This is why int ar[10] = { 0 } works as expected intuitively.
+ */
+
+ printf("%d\n", a_string[16]); // => 0
+
+ // So string literals are strings enclosed within double quotes, but 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 - truncation)
+
+ ///////////////////////////////////////
+ // Operators
+ ///////////////////////////////////////
+
+ int i1 = 1, i2 = 2; // Shorthand for multiple declaration
+ float f1 = 1.0, f2 = 2.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
+
+ // 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 all undefined behavior:
+ // - 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 more than or equal to 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) {
+ printf("%d, ", ii++); // ii++ increments ii in-place, after yielding its value ("postincrement").
+ } // => 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 in-place, and yields the already incremented value ("preincrement")
+ // => 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");
+
+ // branching with multiple choices: switch()
+ switch (some_integral_expression) {
+ case 0: // labels need to be integral *constant* epxressions
+ do_stuff();
+ break; // if you don't break, control flow falls over labels - you usually don't want that.
+ 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)
+ // printf("%d\n", (unsigned char) 257); would be undefined behavior - `char' is usually signed
+ // on most modern systems, and signed integer overflow invokes UB.
+ // Also, for determining the maximal value of a `char`, a `signed char` and an `unisigned char`,
+ // respectively, use the CHAR_MAX, SCHAR_MAX and UCHAR_MAX macros from <limits.h>
+
+ // Integral types can be cast to floating-point types, and vice-versa.
+ printf("%f\n", (float)100); // %f formats a float
+ printf("%lf\n", (double)100); // %lf formats a double
+ printf("%d\n", (char)100.0);
+
+ ///////////////////////////////////////
+ // Pointers
+ ///////////////////////////////////////
+
+ // A pointer is a variable declared to store a memory address. Its declaration will
+ // also tell you the type of data it points to. You can retrieve the memory address
+ // of your variables, then mess with them.
+
+ int x = 0;
+ printf("%p\n", (void *)&x); // Use & to retrieve the address of a variable
+ // (%p formats an object pointer of type void *)
+ // => Prints some address in memory;
+
+
+ // Pointers start with * in their declaration
+ int *px, not_a_pointer; // px is a pointer to an int
+ px = &x; // Stores the address of x in px
+ printf("%p\n", (void *)px); // => Prints some address in memory
+ printf("%zu, %zu\n", sizeof(px), sizeof(not_a_pointer));
+ // => Prints "8, 4" on a typical 64-bit system
+
+ // To retreive the value at the address a pointer is pointing to,
+ // put * in front to de-reference it.
+ // Note: yes, it may be confusing that '*' is used for _both_ declaring a pointer and dereferencing it.
+ printf("%d\n", *px); // => Prints 0, the value of x, which is what px is pointing to the address of
+
+ // You can also change the value the pointer is pointing to.
+ // We'll have to wrap the de-reference in parenthesis because
+ // ++ has a higher precedence than *.
+ (*px)++; // Increment the value px is pointing to by 1
+ printf("%d\n", *px); // => Prints 1
+ printf("%d\n", x); // => Prints 1
+
+ int x_array[20]; // Arrays are a good way to allocate a contiguous block of memory
+ int xx;
+ for (xx = 0; xx < 20; xx++) {
+ x_array[xx] = 20 - xx;
+ } // Initialize x_array to 20, 19, 18,... 2, 1
+
+ // Declare a pointer of type int and initialize it to point to x_array
+ int* x_ptr = x_array;
+ // x_ptr now points to the first element in the array (the integer 20).
+ // This works because arrays often decay into pointers to their first element.
+ // For example, when an array is passed to a function or is assigned to a pointer,
+ // it decays into (implicitly converted to) a pointer.
+ // Exceptions: when the array is the argument of the `&` (address-od) operator:
+ int arr[10];
+ int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`! It's of type "pointer to array" (of ten `int`s).
+ // or when the array is a string literal used for initializing a char array:
+ char arr[] = "foobarbazquirk";
+ // or when it's the argument of the `sizeof` or `alignof` operator:
+ int arr[10];
+ int *ptr = arr; // equivalent with int *ptr = &arr[0];
+ printf("%zu %zu\n", sizeof arr, sizeof ptr); // probably prints "40, 4" or "40, 8"
+
+
+ // Pointers are incremented and decremented based on their type
+ // (this is called pointer arithmetic)
+ printf("%d\n", *(x_ptr + 1)); // => Prints 19
+ printf("%d\n", x_array[1]); // => Prints 19
+
+ // You can also dynamically allocate contiguous blocks of memory with the
+ // standard library function malloc, which takes one argument of type size_t
+ // representing the number of bytes to allocate (usually from the heap, although this
+ // may not be true on e. g. embedded systems - the C standard says nothing about it).
+ int *my_ptr = malloc(sizeof(*my_ptr) * 20);
+ for (xx = 0; xx < 20; xx++) {
+ *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx would also work here, and it's also more readable
+ } // 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();
} // end main function
///////////////////////////////////////
@@ -297,7 +396,8 @@ function_1();
// Function declaration syntax:
// <return type> <function name>(<args>)
-int add_two_ints(int x1, int x2){
+int add_two_ints(int x1, int x2)
+{
return x1 + x2; // Use return to return a value
}
@@ -309,10 +409,12 @@ Example: in-place string reversal
*/
// A void function returns no value
-void str_reverse(char* str_in){
+void str_reverse(char *str_in)
+{
char tmp;
- int ii=0, len = strlen(str_in); // Strlen is part of the c standard library
- for(ii=0; ii<len/2; ii++){
+ 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;
@@ -333,15 +435,20 @@ printf("%s\n", c); // => ".tset a si sihT"
typedef int my_type;
my_type my_type_var = 0;
-// Structs are just collections of data
+// Structs are just collections of data, the members are allocated sequentially, in the order they are written:
struct rectangle {
int width;
int height;
};
+// it's generally not true that sizeof(struct rectangle) == sizeof(int) + sizeof(int) due to
+// potential padding between the structure members (this is for alignment reasons. Probably won't
+// happen if all members are of the same type, but watch out!
+// See http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member
+// for further information.
-void function_1(){
-
+void function_1()
+{
struct rectangle my_rec;
// Access struct members with .
@@ -349,22 +456,29 @@ void function_1(){
my_rec.height = 20;
// You can declare pointers to structs
- struct rectangle* my_rec_ptr = &my_rec;
+ struct rectangle *my_rec_ptr = &my_rec;
// Use dereferencing to set struct pointer members...
(*my_rec_ptr).width = 30;
- // ... or use the -> shorthand
+ // ... 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
typedef struct rectangle rect;
-int area(rect r){
+int area(rect r)
+{
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)
+{
+ return r->width * r->height;
+}
+
///////////////////////////////////////
// Function pointers
///////////////////////////////////////
@@ -376,10 +490,11 @@ However, definition syntax may be initially confusing.
Example: use str_reverse from a pointer
*/
-void str_reverse_through_pointer(char * str_in) {
+void str_reverse_through_pointer(char *str_in) {
// Define a function pointer variable, named f.
void (*f)(char *); // Signature should exactly match the target function.
f = &str_reverse; // Assign the address for the actual function (determined at runtime)
+ // f = str_reverse; would work as well - functions decay into pointers, similar to arrays
(*f)(str_in); // Just calling the function through the pointer
// f(str_in); // That's an alternative but equally valid syntax for calling it.
}
@@ -400,7 +515,15 @@ typedef void (*my_fnp_type)(char *);
## Further Reading
Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language)
+It is *the* book about C, written by the creators of C. Be careful, though - it's ancient and it contains some
+inaccuracies (well, ideas that are not considered good anymore) or now-changed practices.
+
+Another good resource is [Learn C the hard way](http://c.learncodethehardway.org/book/).
+
+If you have a question, read the [compl.lang.c Frequently Asked Questions](http://c-faq.com).
-Another good resource is [Learn C the hard way](http://c.learncodethehardway.org/book/)
+It's very important to use proper spacing, indentation and to be consistent with your coding style in general.
+Readable code is better than clever code and fast code. For a good, sane coding style to adopt, see the
+[Linux kernel coding stlye](https://www.kernel.org/doc/Documentation/CodingStyle).
Other than that, Google is your friend.
diff --git a/clojure.html.markdown b/clojure.html.markdown
index 6baae0ce..a502a95c 100644
--- a/clojure.html.markdown
+++ b/clojure.html.markdown
@@ -365,7 +365,7 @@ my-atom ;=> Atom<#...> (Returns the Atom object)
### Further Reading
-This is far from exhaustive, but hopefully it's enought o get you on your feet.
+This is far from exhaustive, but hopefully it's enough to get you on your feet.
Clojure.org has lots of articles:
[http://clojure.org/](http://clojure.org/)
diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown
new file mode 100644
index 00000000..a917304c
--- /dev/null
+++ b/common-lisp.html.markdown
@@ -0,0 +1,605 @@
+---
+
+language: "Common Lisp"
+filename: commonlisp.lisp
+contributors:
+ - ["Paul Nathan", "https://github.com/pnathan"]
+---
+
+ANSI Common Lisp is a general purpose, multi-paradigm programming
+language suited for a wide variety of industry applications. It is
+frequently referred to a programmable programming language.
+
+The classic starting point is [Practical Common Lisp and freely available.](http://www.gigamonkeys.com/book/)
+
+Another popular and recent book is
+[Land of Lisp](http://landoflisp.com/).
+
+
+
+```scheme
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; 0. Syntax
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; General form.
+
+;; Lisp has two fundamental pieces of syntax: the ATOM and the
+;; S-expression. Typically, grouped S-expressions are called `forms`.
+
+10 ; an atom; it evaluates to itself
+
+:THING ;Another atom; evaluating to the symbol :thing.
+
+t ; another atom, denoting true.
+
+(+ 1 2 3 4) ; an s-expression
+
+'(4 :foo t) ;another one
+
+
+;;; Comments
+
+;; Single line comments start with a semicolon; use two for normal
+;; comments, three for section comments, and four for file-level
+;; comments.
+
+#| Block comments
+ can span multiple lines and...
+ #|
+ they can be nested!
+ |#
+|#
+
+;;; Environment.
+
+;; A variety of implementations exist; most are
+;; standard-conformant. CLISP is a good starting one.
+
+;; Libraries are managed through Quicklisp.org's Quicklisp system.
+
+;; Common Lisp is usually developed with a text editor and a REPL
+;; (Read Evaluate Print Loop) running at the same time. The REPL
+;; allows for interactive exploration of the program as it is "live"
+;; in the system.
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; 1. Primitive Datatypes and Operators
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Symbols
+
+'foo ; => FOO Notice that the symbol is upper-cased automatically.
+
+;; Intern manually creates a symbol from a string.
+
+(intern "AAAA") ; => AAAA
+
+(intern "aaa") ; => |aaa|
+
+;;; Numbers
+9999999999999999999999 ; integers
+#b111 ; binary => 7
+#o111 ; octal => 73
+#x111 ; hexadecimal => 273
+3.14159s0 ; single
+3.14159d0 ; double
+1/2 ; ratios
+#C(1 2) ; complex numbers
+
+
+;; Function application is written (f x y z ...)
+;; where f is a function and x, y, z, ... are operands
+;; If you want to create a literal list of data, use ' to stop it from
+;; being evaluated - literally, "quote" the data.
+'(+ 1 2) ; => (+ 1 2)
+;; You can also call a function manually:
+(funcall #'+ 1 2 3) ; => 6
+;; Some arithmetic operations
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(expt 2 3) ; => 8
+(mod 5 2) ; => 1
+(/ 35 5) ; => 7
+(/ 1 3) ; => 1/3
+(+ #C(1 2) #C(6 -4)) ; => #C(7 -2)
+
+ ;;; Booleans
+t ; for true (any not-nil value is true)
+nil ; for false - and the empty list
+(not nil) ; => t
+(and 0 t) ; => t
+(or 0 nil) ; => 0
+
+ ;;; Characters
+#\A ; => #\A
+#\λ ; => #\GREEK_SMALL_LETTER_LAMDA
+#\u03BB ; => #\GREEK_SMALL_LETTER_LAMDA
+
+;;; Strings are fixed-length arrays of characters.
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; backslash is an escaping character
+
+;; Strings can be concatenated too!
+(concatenate 'string "Hello " "world!") ; => "Hello world!"
+
+;; A string can be treated like a sequence of characters
+(elt "Apple" 0) ; => #\A
+
+;; format can be used to format strings:
+(format nil "~a can be ~a" "strings" "formatted")
+
+;; Printing is pretty easy; ~% is the format specifier for newline.
+(format t "Common Lisp is groovy. Dude.~%")
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. Variables
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; You can create a global (dynamically scoped) using defparameter
+;; a variable name can use any character except: ()[]{}",'`;#|\
+
+;; Dynamically scoped variables should have earmuffs in their name!
+
+(defparameter *some-var* 5)
+*some-var* ; => 5
+
+;; You can also use unicode characters.
+(defparameter *AΛB* nil)
+
+
+;; Accessing a previously unbound variable is an
+;; undefined behavior (but possible). Don't do it.
+
+
+;; Local binding: `me` is bound to "dance with you" only within the
+;; (let ...). Let always returns the value of the last `form` in the
+;; let form.
+
+(let ((me "dance with you"))
+ me)
+;; => "dance with you"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Structs and Collections
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Structs
+(defstruct dog name breed age)
+(defparameter *rover*
+ (make-dog :name "rover"
+ :breed "collie"
+ :age 5))
+*rover* ; => #S(DOG :NAME "rover" :BREED "collie" :AGE 5)
+
+(dog-p *rover*) ; => t ;; ewww)
+(dog-name *rover*) ; => "rover"
+
+;; Dog-p, make-dog, and dog-name are all created by defstruct!
+
+;;; Pairs
+;; `cons' constructs pairs, `car' and `cdr' extract the first
+;; and second elements
+(cons 'SUBJECT 'VERB) ; => '(SUBJECT . VERB)
+(car (cons 'SUBJECT 'VERB)) ; => SUBJECT
+(cdr (cons 'SUBJECT 'VERB)) ; => VERB
+
+;;; Lists
+
+;; Lists are linked-list data structures, made of `cons' pairs and end
+;; with a `nil' (or '()) to mark the end of the list
+(cons 1 (cons 2 (cons 3 nil))) ; => '(1 2 3)
+;; `list' is a convenience variadic constructor for lists
+(list 1 2 3) ; => '(1 2 3)
+;; and a quote can also be used for a literal list value
+'(1 2 3) ; => '(1 2 3)
+
+;; Can still use `cons' to add an item to the beginning of a list
+(cons 4 '(1 2 3)) ; => '(4 1 2 3)
+
+;; Use `append' to - surprisingly - append lists together
+(append '(1 2) '(3 4)) ; => '(1 2 3 4)
+
+;; Or use concatenate -
+
+(concatenate
+
+;; Lists are a very central type, so there is a wide variety of functionality for
+;; them, a few examples:
+(mapcar #'1+ '(1 2 3)) ; => '(2 3 4)
+(mapcar #'+ '(1 2 3) '(10 20 30)) ; => '(11 22 33)
+(remove-if-not #'evenp '(1 2 3 4)) ; => '(2 4)
+(every #'evenp '(1 2 3 4)) ; => nil
+(some #'oddp '(1 2 3 4)) ; => T
+(butlast '(subject verb object)) ; => (SUBJECT VERB)
+
+
+;;; Vectors
+
+;; Vectors are fixed-length arrays
+#(1 2 3) ; => #(1 2 3)
+
+;; Use concatenate to add vectors together
+(concatenate 'vector #(1 2 3) #(4 5 6)) ; => #(1 2 3 4 5 6)
+
+;;; Arrays
+
+;; Both vectors and strings are special-cases of arrays.
+
+;; 2D arrays
+
+(make-array (list 2 2))
+
+;; (make-array '(2 2)) works as well.
+
+; => #2A((0 0) (0 0))
+
+(make-array (list 2 2 2))
+
+; => #3A(((0 0) (0 0)) ((0 0) (0 0)))
+
+;; Caution- the default initial values are
+;; implementation-defined. Here's how to define them:
+
+(make-array '(2) :initial-element 'unset)
+
+; => #(UNSET UNSET)
+
+;; And, to access the element at 1,1,1 -
+(aref (make-array (list 2 2 2)) 1 1 1)
+
+; => 0
+
+;;; Naively, sets are just lists:
+
+(set-difference '(1 2 3 4) '(4 5 6 7)) ; => (3 2 1)
+(intersection '(1 2 3 4) '(4 5 6 7)) ; => 4
+(union '(1 2 3 4) '(4 5 6 7)) ; => (3 2 1 4 5 6 7)
+(adjoin 4 '(1 2 3 4)) ; => (1 2 3 4)
+
+;; But you'll want to use a better data structure than a linked list
+;; for performant work!
+
+;;; Dictionaries are implemented as hash tables.
+
+;; Create a hash table
+(defparameter *m* (make-hash-table))
+
+;; set a value
+(setf (gethash 'a *m*) 1)
+
+;; Retrieve a value
+(gethash 'a *m*) ; => 1, t
+
+;; Detail - Common Lisp has multiple return values possible. gethash
+;; returns t in the second value if anything was found, and nil if
+;; not.
+
+;; Retrieving a non-present value returns nil
+ (gethash *m* 'd) ;=> nil, nil
+
+;; You can provide a default value for missing keys
+(gethash *m* 'd :not-found) ; => :NOT-FOUND
+
+;; Let's handle the multiple return values here in code.
+
+(multiple-value-bind
+ (a b)
+ (gethash 'd *m*)
+ (list a b))
+; => (NIL NIL)
+
+(multiple-value-bind
+ (a b)
+ (gethash 'a *m*)
+ (list a b))
+; => (1 T)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `lambda' to create anonymous functions.
+;; A function always returns the value of its last expression.
+;; The exact printable representation of a function will vary...
+
+(lambda () "Hello World") ; => #<FUNCTION (LAMBDA ()) {1004E7818B}>
+
+;; Use funcall to call lambda functions
+(funcall (lambda () "Hello World")) ; => "Hello World"
+
+;; Or Apply
+(apply (lambda () "Hello World") nil) ; => "Hello World"
+
+;; De-anonymize the function
+(defun hello-world ()
+ "Hello World")
+(hello-world) ; => "Hello World"
+
+;; The () in the above is the list of arguments for the function
+(defun hello (name)
+ (format nil "Hello, ~a " name))
+
+(hello "Steve") ; => "Hello, Steve"
+
+;; Functions can have optional arguments; they default to nil
+
+(defun hello (name &optional from)
+ (if from
+ (format t "Hello, ~a, from ~a" name from)
+ (format t "Hello, ~a" name)))
+
+ (hello "Jim" "Alpacas") ;; => Hello, Jim, from Alpacas
+
+;; And the defaults can be set...
+(defun hello (name &optional (from "The world"))
+ (format t "Hello, ~a, from ~a" name from))
+
+(hello "Steve")
+; => Hello, Steve, from The world
+
+(hello "Steve" "the alpacas")
+; => Hello, Steve, from the alpacas
+
+
+;; And of course, keywords are allowed as well... usually more
+;; flexible than &optional.
+
+(defun generalized-greeter (name &key (from "the world") (honorific "Mx"))
+ (format t "Hello, ~a ~a, from ~a" honorific name from))
+
+(generalized-greeter "Jim") ; => Hello, Mx Jim, from the world
+
+(generalized-greeter "Jim" :from "the alpacas you met last summer" :honorific "Mr")
+; => Hello, Mr Jim, from the alpacas you met last summer
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. Equality
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Common Lisp has a sophisticated equality system. A couple are covered yere.
+
+;; for numbers use `='
+(= 3 3.0) ; => t
+(= 2 1) ; => nil
+
+;; for object identity (approximately) use `eql`
+(eql 3 3) ; => t
+(eql 3 3.0) ; => nil
+(eql (list 3) (list 3)) ; => nil
+
+;; for lists, strings, and bit-vectors use `equal'
+(equal (list 'a 'b) (list 'a 'b)) ; => t
+(equal (list 'a 'b) (list 'b 'a)) ; => nil
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. Control Flow
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Conditionals
+
+(if t ; test expression
+ "this is true" ; then expression
+ "this is false") ; else expression
+; => "this is true"
+
+;; In conditionals, all non-nil values are treated as true
+(member 'Groucho '(Harpo Groucho Zeppo)) ; => '(GROUCHO ZEPPO)
+(if (member 'Groucho '(Harpo Groucho Zeppo))
+ 'yep
+ 'nope)
+; => 'YEP
+
+;; `cond' chains a series of tests to select a result
+(cond ((> 2 2) (error "wrong!"))
+ ((< 2 2) (error "wrong again!"))
+ (t 'ok)) ; => 'OK
+
+;; Typecase switches on the type of the value
+(typecase 1
+ (string :string)
+ (integer :int))
+
+; => :int
+
+;;; Iteration
+
+;; Of course recursion is supported:
+
+(defun walker (n)
+ (if (zerop n)
+ :walked
+ (walker (1- n))))
+
+(walker) ; => :walked
+
+;; Most of the time, we use DOLIST or LOOP
+
+
+(dolist (i '(1 2 3 4))
+ (format t "~a" i))
+
+; => 1234
+
+(loop for i from 0 below 10
+ collect i)
+
+; => (0 1 2 3 4 5 6 7 8 9)
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. Mutation
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `setf' to assign a new value to an existing variable. This was
+;; demonstrated earlier in the hash table example.
+
+(let ((variable 10))
+ (setf variable 2))
+ ; => 2
+
+
+;; Good Lisp style is to minimize destructive functions and to avoid
+;; mutation when reasonable.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. Classes and Objects
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; No more Animal classes, let's have Human-Powered Mechanical
+;; Conveyances.
+
+(defclass human-powered-conveyance ()
+ ((velocity
+ :accessor velocity
+ :initarg :velocity)
+ (average-efficiency
+ :accessor average-efficiency)
+ :initarg :average-efficiency)
+ (:documentation "A human powered conveyance"))
+
+;; defclass, followed by name, followed by the superclass list,
+;; followed by slot list, followed by optional qualities such as
+;; :documentation.
+
+;; When no superclass list is set, the empty list defaults to the
+;; standard-object class. This *can* be changed, but not until you
+;; know what you're doing. Look up the Art of the Metaobject Protocol
+;; for more information.
+
+(defclass bicycle (human-powered-conveyance)
+ ((wheel-size
+ :accessor wheel-size
+ :initarg :wheel-size
+ :documentation "Diameter of the wheel.")
+ (height
+ :accessor height
+ :initarg :height)))
+
+(defclass recumbent (bicycle)
+ ((chain-type
+ :accessor chain-type
+ :initarg :chain-type)))
+
+(defclass unicycle (human-powered-conveyance) nil)
+
+(defclass canoe (human-powered-conveyance)
+ ((number-of-rowers
+ :accessor number-of-rowers
+ :initarg :number-of-rowers)))
+
+
+;; Calling DESCRIBE on the human-powered-conveyance class in the REPL gives:
+
+(describe 'human-powered-conveyance)
+
+; COMMON-LISP-USER::HUMAN-POWERED-CONVEYANCE
+; [symbol]
+;
+; HUMAN-POWERED-CONVEYANCE names the standard-class #<STANDARD-CLASS
+; HUMAN-POWERED-CONVEYANCE>:
+; Documentation:
+; A human powered conveyance
+; Direct superclasses: STANDARD-OBJECT
+; Direct subclasses: UNICYCLE, BICYCLE, CANOE
+; Not yet finalized.
+(defparameter *foo#\u03BBooo* nil) ; Direct slots:
+; VELOCITY
+; Readers: VELOCITY
+; Writers: (SETF VELOCITY)
+; AVERAGE-EFFICIENCY
+; Readers: AVERAGE-EFFICIENCY
+; Writers: (SETF AVERAGE-EFFICIENCY)
+
+;; Note the reflective behavior available to you! Common Lisp is
+;; designed to be an interactive system
+
+;; To define a method, let's find out what our circumference of the
+;; bike wheel turns out to be using the equation: C = d * pi
+
+(defmethod circumference ((object bicycle))
+ (* pi (wheel-size object)))
+
+;; pi is defined in Lisp already for us!
+
+;; Let's suppose we find out that the efficiency value of the number
+;; of rowers in a canoe is roughly logarithmic. This should probably be set
+;; in the constructor/initializer.
+
+;; Here's how to initialize your instance after Common Lisp gets done
+;; constructing it:
+
+(defmethod initialize-instance :after ((object canoe) &rest args)
+ (setf (average-efficiency object) (log (1+ (number-of-rowers object)))))
+
+;; Then to construct an instance and check the average efficiency...
+
+(average-efficiency (make-instance 'canoe :number-of-rowers 15))
+; => 2.7725887
+
+
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 8. Macros
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Macros let you extend the syntax of the language
+
+;; Common Lisp doesn't come with a WHILE loop- let's add one.
+;; If we obey our assembler instincts, we wind up with:
+
+(defmacro while (condition &body body)
+ "While `condition` is true, `body` is executed.
+
+`condition` is tested prior to each execution of `body`"
+ (let ((block-name (gensym)))
+ `(tagbody
+ (unless ,condition
+ (go ,block-name))
+ (progn
+ ,@body)
+ ,block-name)))
+
+;; Let's look at the high-level version of this:
+
+
+(defmacro while (condition &body body)
+ "While `condition` is true, `body` is executed.
+
+`condition` is tested prior to each execution of `body`"
+ `(loop while ,condition
+ do
+ (progn
+ ,@body)))
+
+;; However, with a modern compiler, this is not required; the LOOP
+;; form compiles equally well and is easier to read.
+
+;; Note that ``` is used, as well as `,` and `@`. ``` is a quote-type operator
+;; known as quasiquote; it allows the use of `,` . `,` allows "unquoting"
+;; variables. @ interpolates lists.
+
+;; Gensym creates a unique symbol guaranteed to not exist elsewhere in
+;; the system. This is because macros are expanded at compile time and
+;; variables declared in the macro can collide with variables used in
+;; regular code.
+
+;; See Practical Common Lisp for more information on macros.
+```
+
+
+## Further Reading
+
+[Keep moving on to the Practical Common Lisp book.](http://www.gigamonkeys.com/book/)
+
+
+## Credits.
+
+Lots of thanks to the Scheme people for rolling up a great starting
+point which could be easily moved to Common Lisp.
+
+- [Paul Khoung](https://github.com/pkhuong) for some great reviewing.
diff --git a/csharp.html.markdown b/csharp.html.markdown
new file mode 100644
index 00000000..c254b5a9
--- /dev/null
+++ b/csharp.html.markdown
@@ -0,0 +1,549 @@
+---
+
+language: c#
+contributors:
+ - ["Irfan Charania", "https://github.com/irfancharania"]
+filename: LearnCSharp.cs
+
+---
+
+C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the .NET Framework.
+
+[Read more here.](http://msdn.microsoft.com/en-us/library/vstudio/z1zx9t92.aspx)
+
+```c#
+// Single-line comments start with //
+/*
+Multi-line comments look like this
+*/
+/// <summary>
+/// This is an XML documentation comment
+/// </summary>
+
+// Specify namespaces application will be using
+using System;
+using System.Collections.Generic;
+
+
+// defines scope to organize code into "packages"
+namespace Learning
+{
+ // Each .cs file should at least contain a class with the same name as the file
+ // you're allowed to do otherwise, but shouldn't for sanity.
+ public class LearnCSharp
+ {
+ // A console application must have a main method as an entry point
+ public static void Main(string[] args)
+ {
+ // Use Console.WriteLine to print lines
+ Console.WriteLine("Hello World");
+ Console.WriteLine(
+ "Integer: " + 10 +
+ " Double: " + 3.14 +
+ " Boolean: " + true);
+
+ // To print without a new line, use Console.Write
+ Console.Write("Hello ");
+ Console.Write("World");
+
+
+ ///////////////////////////////////////////////////
+ // Types & Variables
+ //
+ // Declare a variable using <type> <name>
+ ///////////////////////////////////////////////////
+
+ // Sbyte - Signed 8-bit integer
+ // (-128 <= sbyte <= 127)
+ sbyte fooSbyte = 100;
+
+ // Byte - Unsigned 8-bit integer
+ // (0 <= byte <= 255)
+ byte fooByte = 100;
+
+ // Short - Signed 16-bit integer
+ // (-32,768 <= short <= 32,767)
+ short fooShort = 10000;
+
+ // Ushort - Unsigned 16-bit integer
+ // (0 <= ushort <= 65,535)
+ ushort fooUshort = 10000;
+
+ // Integer - Signed 32-bit integer
+ // (-2,147,483,648 <= int <= 2,147,483,647)
+ int fooInt = 1;
+
+ // Uinteger - Unsigned 32-bit integer
+ // (0 <= uint <= 4,294,967,295)
+ uint fooUint = 1;
+
+ // Long - Signed 64-bit integer
+ // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
+ long fooLong = 100000L;
+ // L is used to denote that this variable value is of type long or ulong
+ // anything without is treated as int or uint depending on size.
+
+ // Ulong - Unsigned 64-bit integer
+ // (0 <= ulong <= 18,446,744,073,709,551,615)
+ ulong fooUlong = 100000L;
+
+ // Float - Single-precision 32-bit IEEE 754 Floating Point
+ // Precision: 7 digits
+ float fooFloat = 234.5f;
+ // f is used to denote that this variable value is of type float;
+ // otherwise it is treated as double.
+
+ // Double - Double-precision 64-bit IEEE 754 Floating Point
+ // Precision: 15-16 digits
+ double fooDouble = 123.4;
+
+ // Bool - true & false
+ bool fooBoolean = true;
+ bool barBoolean = false;
+
+ // Char - A single 16-bit Unicode character
+ char fooChar = 'A';
+
+ // Strings
+ string fooString = "My string is here!";
+ Console.WriteLine(fooString);
+
+ // formatting
+ string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2);
+ Console.WriteLine(fooFormattedString);
+
+ // formatting dates
+ DateTime fooDate = DateTime.Now;
+ Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
+
+ // \n is an escaped character that starts a new line
+ string barString = "Printing on a new line?\nNo Problem!";
+ Console.WriteLine(barString);
+
+ // it can be written prettier by using the @ symbol
+ string bazString = @"Here's some stuff
+ on a new line!";
+ Console.WriteLine(bazString);
+
+ // quotes need to be escaped
+ // use \" normally
+ string quotedString = "some \"quoted\" stuff";
+ Console.WriteLine(quotedString);
+
+ // use "" when strings start with @
+ string quotedString2 = @"some MORE ""quoted"" stuff";
+ Console.WriteLine(quotedString2);
+
+ // Use const or read-only to make a variable immutable
+ // const values are calculated at compile time
+ const int HOURS_I_WORK_PER_WEEK = 9001;
+
+ // Nullable types
+ // any type can be made nullable by suffixing a ?
+ // <type>? <var name> = <value>
+ int? nullable = null;
+ Console.WriteLine("Nullable variable: " + nullable);
+
+ // ?? is syntactic sugar for specifying default value
+ // in case variable is null
+ int notNullable = nullable ?? 0;
+ Console.WriteLine("Not nullable variable: " + notNullable);
+
+ // Var - compiler will choose the most appropriate type based on value
+ var fooImplicit = true;
+
+ ///////////////////////////////////////////////////
+ // Data Structures
+ ///////////////////////////////////////////////////
+ Console.WriteLine("\n->Data Structures");
+
+ // Arrays
+ // The array size must be decided upon declaration
+ // The format for declaring an array is follows:
+ // <datatype>[] <var name> = new <datatype>[<array size>];
+ int[] intArray = new int[10];
+ string[] stringArray = new string[1];
+ bool[] boolArray = new bool[100];
+
+ // Another way to declare & initialize an array
+ int[] y = { 9000, 1000, 1337 };
+
+ // Indexing an array - Accessing an element
+ Console.WriteLine("intArray @ 0: " + intArray[0]);
+
+ // Arrays are zero-indexed and mutable.
+ intArray[1] = 1;
+ Console.WriteLine("intArray @ 1: " + intArray[1]); // => 1
+
+ // Lists
+ // Lists are used more frequently than arrays as they are more flexible
+ // The format for declaring a list is follows:
+ // List<datatype> <var name> = new List<datatype>();
+ List<int> intList = new List<int>();
+ List<string> stringList = new List<string>();
+
+ // Another way to declare & initialize a list
+ List<int> z = new List<int> { 9000, 1000, 1337 };
+
+ // Indexing a list - Accessing an element
+ // Lists are zero-indexed and mutable.
+ Console.WriteLine("z @ 0: " + z[2]);
+
+ // Lists don't default to a value;
+ // A value must be added before accessing the index
+ intList.Add(1);
+ Console.WriteLine("intList @ 0: " + intList[0]);
+
+
+ // Others data structures to check out:
+ //
+ // Stack/Queue
+ // Dictionary
+ // Read-only Collections
+ // Tuple (.Net 4+)
+
+
+ ///////////////////////////////////////
+ // Operators
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Operators");
+
+ int i1 = 1, i2 = 2; // Shorthand for multiple declarations
+
+ // Arithmetic is straightforward
+ Console.WriteLine("1+2 = " + (i1 + i2)); // => 3
+ Console.WriteLine("2-1 = " + (i2 - i1)); // => 1
+ Console.WriteLine("2*1 = " + (i2 * i1)); // => 2
+ Console.WriteLine("1/2 = " + (i1 / i2)); // => 0 (0.5 truncated down)
+
+ // Modulo
+ Console.WriteLine("11%3 = " + (11 % 3)); // => 2
+
+ // Comparison operators
+ Console.WriteLine("3 == 2? " + (3 == 2)); // => false
+ Console.WriteLine("3 != 2? " + (3 != 2)); // => true
+ Console.WriteLine("3 > 2? " + (3 > 2)); // => true
+ Console.WriteLine("3 < 2? " + (3 < 2)); // => false
+ Console.WriteLine("2 <= 2? " + (2 <= 2)); // => true
+ Console.WriteLine("2 >= 2? " + (2 >= 2)); // => true
+
+ // Bitwise operators!
+ /*
+ ~ Unary bitwise complement
+ << Signed left shift
+ >> Signed right shift
+ >>> Unsigned right shift
+ & Bitwise AND
+ ^ Bitwise exclusive OR
+ | Bitwise inclusive OR
+ */
+
+ // Incrementations
+ int i = 0;
+ Console.WriteLine("\n->Inc/Dec-rementation");
+ Console.WriteLine(i++); //i = 1. Post-Incrementation
+ Console.WriteLine(++i); //i = 2. Pre-Incrementation
+ Console.WriteLine(i--); //i = 1. Post-Decrementation
+ Console.WriteLine(--i); //i = 0. Pre-Decrementation
+
+
+ ///////////////////////////////////////
+ // Control Structures
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Control Structures");
+
+ // If statements are c-like
+ int j = 10;
+ if (j == 10)
+ {
+ Console.WriteLine("I get printed");
+ }
+ else if (j > 10)
+ {
+ Console.WriteLine("I don't");
+ }
+ else
+ {
+ Console.WriteLine("I also don't");
+ }
+
+ // Ternary operators
+ // A simple if/else can be written as follows
+ // <condition> ? <true> : <false>
+ string isTrue = (true) ? "True" : "False";
+ Console.WriteLine("Ternary demo: " + isTrue);
+
+
+ // While loop
+ int fooWhile = 0;
+ while (fooWhile < 100)
+ {
+ //Console.WriteLine(fooWhile);
+ //Increment the counter
+ //Iterated 99 times, fooWhile 0->99
+ fooWhile++;
+ }
+ Console.WriteLine("fooWhile Value: " + fooWhile);
+
+ // Do While Loop
+ int fooDoWhile = 0;
+ do
+ {
+ //Console.WriteLine(fooDoWhile);
+ //Increment the counter
+ //Iterated 99 times, fooDoWhile 0->99
+ fooDoWhile++;
+ } while (fooDoWhile < 100);
+ Console.WriteLine("fooDoWhile Value: " + fooDoWhile);
+
+ // For Loop
+ int fooFor;
+ //for loop structure => for(<start_statement>; <conditional>; <step>)
+ for (fooFor = 0; fooFor < 10; fooFor++)
+ {
+ //Console.WriteLine(fooFor);
+ //Iterated 10 times, fooFor 0->9
+ }
+ Console.WriteLine("fooFor Value: " + fooFor);
+
+ // Switch Case
+ // A switch works with the byte, short, char, and int data types.
+ // It also works with enumerated types (discussed in Enum Types),
+ // the String class, and a few special classes that wrap
+ // primitive types: Character, Byte, Short, and Integer.
+ int month = 3;
+ string monthString;
+ switch (month)
+ {
+ case 1:
+ monthString = "January";
+ break;
+ case 2:
+ monthString = "February";
+ break;
+ case 3:
+ monthString = "March";
+ break;
+ default:
+ monthString = "Some other month";
+ break;
+ }
+ Console.WriteLine("Switch Case Result: " + monthString);
+
+
+ ///////////////////////////////////////
+ // Converting Data Types And Typcasting
+ ///////////////////////////////////////
+
+ // Converting data
+
+ // Convert String To Integer
+ // this will throw an Exception on failure
+ int.Parse("123");//returns an integer version of "123"
+
+ // try parse will default to type default on failure
+ // in this case: 0
+ int tryInt;
+ int.TryParse("123", out tryInt);
+
+ // Convert Integer To String
+ // Convert class has a number of methods to facilitate conversions
+ Convert.ToString(123);
+
+ ///////////////////////////////////////
+ // Classes And Functions
+ ///////////////////////////////////////
+
+ Console.WriteLine("\n->Classes & Functions");
+
+ // (definition of the Bicycle class follows)
+
+ // Use new to instantiate a class
+ Bicycle trek = new Bicycle();
+
+ // Call object methods
+ trek.speedUp(3); // You should always use setter and getter methods
+ trek.setCadence(100);
+
+ // ToString is a convention to display the value of this Object.
+ Console.WriteLine("trek info: " + trek.ToString());
+
+ // Instantiate another new Bicycle
+ Bicycle octo = new Bicycle(5, 10);
+ Console.WriteLine("octo info: " + octo.ToString());
+
+ // Instantiate a new Penny Farthing
+ PennyFarthing funbike = new PennyFarthing(1, 10);
+ Console.WriteLine("funbike info: " + funbike.ToString());
+
+ Console.Read();
+ } // End main method
+
+
+ } // End LearnCSharp class
+
+ // You can include other classes in a .cs file
+
+
+ // Class Declaration Syntax:
+ // <public/private/protected> class <class name>{
+ // //data fields, constructors, functions all inside.
+ // //functions are called as methods in Java.
+ // }
+
+ public class Bicycle
+ {
+ // Bicycle's Fields/Variables
+ public int cadence; // Public: Can be accessed from anywhere
+ private int _speed; // Private: Only accessible from within the class
+ protected int gear; // Protected: Accessible from the class and subclasses
+ internal int wheels; // Internal: Accessible from within the assembly
+ string name; // default: Only accessible from within this class
+
+ // readonly values are set at run time
+ // they can only be assigned upon declaration or in a constructor
+ readonly bool hasCardsInSpokes = false; // read-only private
+
+ // Constructors are a way of creating classes
+ // This is a default constructor
+ public Bicycle()
+ {
+ gear = 1;
+ cadence = 50;
+ _speed = 5;
+ name = "Bontrager";
+ }
+
+ // This is a specified constructor (it contains arguments)
+ public Bicycle(int startCadence, int startSpeed, int startGear,
+ string name, bool hasCardsInSpokes)
+ {
+ this.gear = startGear;
+ this.cadence = startCadence;
+ this._speed = startSpeed;
+ this.name = name;
+ this.hasCardsInSpokes = hasCardsInSpokes;
+ }
+
+ // Constructors can be chained
+ public Bicycle(int startCadence, int startSpeed) :
+ this(startCadence, startSpeed, 0, "big wheels", true)
+ {
+ }
+
+ // Function Syntax:
+ // <public/private/protected> <return type> <function name>(<args>)
+
+ // classes can implement getters and setters for their fields
+ // or they can implement properties
+
+ // Method declaration syntax:
+ // <scope> <return type> <method name>(<args>)
+ public int getCadence()
+ {
+ return cadence;
+ }
+
+ // void methods require no return statement
+ public void setCadence(int newValue)
+ {
+ cadence = newValue;
+ }
+
+ // virtual keyword indicates this method can be overridden
+ public virtual void setGear(int newValue)
+ {
+ gear = newValue;
+ }
+
+ public void speedUp(int increment)
+ {
+ _speed += increment;
+ }
+
+ public void slowDown(int decrement)
+ {
+ _speed -= decrement;
+ }
+
+ // properties get/set values
+ // when only data needs to be accessed, consider using properties.
+ // properties may have either get or set, or both
+ private bool _hasTassles; // private variable
+ public bool hasTassles // public accessor
+ {
+ get { return _hasTassles; }
+ set { _hasTassles = value; }
+ }
+
+ private int _frameSize;
+ public int FrameSize
+ {
+ get { return _frameSize; }
+ // you are able to specify access modifiers for either get or set
+ // this means only Bicycle class can call set on Framesize
+ private set { _frameSize = value; }
+ }
+
+ //Method to display the attribute values of this Object.
+ public override string ToString()
+ {
+ return "gear: " + gear +
+ " cadence: " + cadence +
+ " speed: " + _speed +
+ " name: " + name +
+ " cards in spokes: " + (hasCardsInSpokes ? "yes" : "no") +
+ "\n------------------------------\n"
+ ;
+ }
+ } // end class Bicycle
+
+ // PennyFarthing is a subclass of Bicycle
+ class PennyFarthing : Bicycle
+ {
+ // (Penny Farthings are those bicycles with the big front wheel.
+ // They have no gears.)
+
+ // calling parent constructor
+ public PennyFarthing(int startCadence, int startSpeed) :
+ base(startCadence, startSpeed, 0, "PennyFarthing", true)
+ {
+ }
+
+ public override void setGear(int gear)
+ {
+ gear = 0;
+ }
+ }
+} // End Namespace
+
+```
+
+## Topics Not Covered
+
+ * Enums, Flags
+ * Attributes
+ * Generics (T), Delegates, Func, Actions, lambda expressions
+ * Exceptions, Interfaces, Abstraction
+ * LINQ
+ * ASP.NET (Web Forms/MVC/WebMatrix)
+ * Winforms
+ * Windows Presentation Foundation (WPF)
+
+
+
+## Further Reading
+
+ * [DotNetPerls](http://www.dotnetperls.com)
+ * [C# in Depth](http://manning.com/skeet2)
+ * [Programming C#](http://shop.oreilly.com/product/0636920024064.do)
+ * [LINQ](http://shop.oreilly.com/product/9780596519254.do)
+ * [MSDN Library](http://msdn.microsoft.com/en-us/library/618ayhy6.aspx)
+ * [ASP.NET MVC Tutorials](http://www.asp.net/mvc/tutorials)
+ * [ASP.NET Web Matrix Tutorials](http://www.asp.net/web-pages/tutorials)
+ * [ASP.NET Web Forms Tutorials](http://www.asp.net/web-forms/tutorials)
+ * [Windows Forms Programming in C#](http://www.amazon.com/Windows-Forms-Programming-Chris-Sells/dp/0321116208)
+
+
+
+[C# Coding Conventions](http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx)
diff --git a/es-es/c-es.html.markdown b/es-es/c-es.html.markdown
index b109f761..5d3aae0c 100644
--- a/es-es/c-es.html.markdown
+++ b/es-es/c-es.html.markdown
@@ -284,7 +284,7 @@ for (xx=0; xx<20; xx++) {
// impredecibles
printf("%d\n", *(my_ptr + 21)); // => Prints who-knows-what?
-// Cuando hallas acabado con el bloque de memoría malloc, necesitas
+// Cuando hayas acabado con el bloque de memoría malloc, necesitas
// liberarlo o sino nadie más podrá usarlo hasta que tu programa se cierre
free(my_ptr);
diff --git a/es-es/coffeescript-es.html.markdown b/es-es/coffeescript-es.html.markdown
new file mode 100644
index 00000000..78bb9be5
--- /dev/null
+++ b/es-es/coffeescript-es.html.markdown
@@ -0,0 +1,57 @@
+---
+language: coffeescript
+lang: es-es
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+translators:
+ - ["Pablo Elices", "http://github.com/pabloelices"]
+filename: coffeescript-es.coffee
+---
+
+``` coffeescript
+# CoffeeScript es un lenguaje hipster.
+# Tiene convenciones de muchos lenguajes modernos.
+# Los comentarios son como en Ruby y Python, usan almohadillas.
+
+###
+Los comentarios en bloque son como estos, y se traducen directamente a '/*' y '*/'
+para el código JavaScript resultante.
+
+Deberías entender la mayor parte de la semántica de JavaScript antes de continuar.
+###
+
+# Asignación:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# Condiciones:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# Funciones:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+# Rangos:
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# Objetos:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Símbolos:
+race = (winner, runners...) ->
+ print winner, runners
+
+# Existencia:
+alert "I knew it!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
+
+# Colecciones por comprensión:
+cubes = (math.cube num for num in list) #=> ...
+```
diff --git a/fr-fr/ruby-fr.html.markdown b/fr-fr/ruby-fr.html.markdown
new file mode 100644
index 00000000..5efb2f3c
--- /dev/null
+++ b/fr-fr/ruby-fr.html.markdown
@@ -0,0 +1,407 @@
+---
+language: ruby
+filename: learnruby-fr.rb
+contributors:
+ - ["David Underwood", "http://theflyingdeveloper.com"]
+ - ["Joel Walden", "http://joelwalden.net"]
+ - ["Luke Holder", "http://twitter.com/lukeholder"]
+ - ["Tristan Hume", "http://thume.ca/"]
+ - ["Nick LaMuro", "https://github.com/NickLaMuro"]
+translators:
+ - ["Geoffrey Roguelon", "https://github.com/GRoguelon"]
+ - ["Nami-Doc", "https://github.com/Nami-Doc"]
+lang: fr-fr
+---
+
+```ruby
+# Ceci est un commentaire
+
+=begin
+Ceci est un commentaire multiligne
+Personne ne les utilise
+Vous devriez en faire de même
+=end
+
+# Tout d'abord : Tout est un objet.
+
+# Les nombres sont des objets
+
+3.class #=> Fixnum
+
+3.to_s #=> "3"
+
+# Les opérateurs de base
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+35 / 5 #=> 7
+
+# Les opérateurs sont juste des raccourcis
+# pour appeler une méthode sur un objet
+1.+(3) #=> 4
+10.* 5 #=> 50
+
+# Les valeurs spéciales sont des objets
+nil # Nul
+true # Vrai
+false # Faux
+
+nil.class #=> NilClass
+true.class #=> TrueClass
+false.class #=> FalseClass
+
+# Égalité
+1 == 1 #=> true
+2 == 1 #=> false
+
+# Inégalité
+1 != 1 #=> false
+2 != 1 #=> true
+!true #=> false
+!false #=> true
+
+# à part false lui-même, nil est la seule autre valeur 'false'
+
+!nil #=> true
+!false #=> true
+!0 #=> false
+
+# Plus de comparaisons
+1 < 10 #=> true
+1 > 10 #=> false
+2 <= 2 #=> true
+2 >= 2 #=> true
+
+# Les chaînes de caractères sont des objets
+
+'Je suis une chaîne de caractères'.class #=> String
+"Je suis également une chaîne de caractères".class #=> String
+
+placeholder = "utiliser l'interpolation de chaîne de caractères"
+"Je peux #{placeholder} quand j'utilise les guillemets"
+#=> "Je peux utiliser l'interpolation de chaîne de caractères quand j'utilise les guillemets"
+
+# Affichez un message
+puts "J'affiche à l'écran!"
+
+# Variables
+x = 25 #=> 25
+x #=> 25
+
+# Notez que l'affectation retourne la valeur affectée.
+# Cela signifie que vous pouvez affecter plusieurs fois de suite :
+
+x = y = 10 #=> 10
+x #=> 10
+y #=> 10
+
+# Par convention, utilisez la notation underscore
+# pour nommer les variables
+snake_case = true
+
+# Utilisez des noms de variable explicites
+path_to_project_root = '/nom/correct/'
+path = '/mauvais/nom/'
+
+# Symboles (aussi des objets)
+# Les symboles sont immuables, constants,
+# réutilisables et représentés en interne
+# par une valeur entière. Ils sont souvent
+# utilisés à la place des chaînes de caractères
+# pour transmettre efficacement des valeurs
+# spécifiques ou significatives
+
+:pending.class #=> Symbol
+
+status = :pending
+
+status == :pending #=> true
+
+status == 'pending' #=> false
+
+status == :approved #=> false
+
+# Tableaux
+
+# Ceci est un tableau
+array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
+
+# Les tableaux contiennent différents types d'élément.
+
+[1, "hello", false] #=> [1, "hello", false]
+
+# Les tableaux peuvent être indexés
+# Du début
+array[0] #=> 1
+array[12] #=> nil
+
+# Comme les opérateurs, la syntaxe [var] est juste un raccourci
+# pour appeler la méthode [] d'un objet
+array.[] 0 #=> 1
+array.[] 12 #=> nil
+
+# Depuis la fin
+array[-1] #=> 5
+
+# Avec un index de début et de fin
+array[2, 4] #=> [3, 4, 5]
+
+# Ou avec un intervalle
+array[1..3] #=> [2, 3, 4]
+
+# Ajoutez un élément au tableau comme ceci
+array << 6 #=> [1, 2, 3, 4, 5, 6]
+
+# Les Hash sont des dictionnaires Ruby contenant des paires de clé/valeur.
+# Les Hash sont délimitées par des accolades :
+hash = {'color' => 'green', 'number' => 5}
+
+hash.keys #=> ['color', 'number']
+
+# Les Hash retournent la valeur
+# en utilisant la clé associée à la valeur :
+hash['color'] #=> 'green'
+hash['number'] #=> 5
+
+# Recherchez une clé inexistante dans une Hash retourne nil :
+hash['nothing here'] #=> nil
+
+# Depuis Ruby 1.9, Une syntaxe spécifique est apparue en utilisant les symboles comme clés :
+
+new_hash = { defcon: 3, action: true}
+
+new_hash.keys #=> [:defcon, :action]
+
+# Astuce : Les tableaux et les Hash sont dénombrables
+# Ils partagent un certain nombre de méthodes pratiques
+# telle que each, map, count, etc...
+
+# Structures de contrôle
+
+if true
+ "si instruction"
+elsif false
+ "autrement si, facultatif"
+else
+ "autrement, également facultatif"
+end
+
+for compteur in 1..5
+ puts "itération #{compteur}"
+end
+#=> itération 1
+#=> itération 2
+#=> itération 3
+#=> itération 4
+#=> itération 5
+
+# CEPENDANT, l'usage de la boucle for est très rare.
+# À la place, utilisez la méthode "each"
+# et passez lui un bloc de code.
+# Un bloc de code est un ensemble d'instructions que vous pouvez passer à une methode comme "each".
+# Les blocs sont similaires aux lambdas, les fonctions anonymes ou les closures dans d'autres langages.
+#
+# La méthode "each" exécute le bloc de code pour chaque élément de l'intervalle d'éléments.
+# Le bloc de code passe un paramètre compteur.
+# Appelez la méthode "each" avec un bloc de code comme ceci :
+
+(1..5).each do |compteur|
+ puts "itération #{compteur}"
+end
+#=> itération 1
+#=> itération 2
+#=> itération 3
+#=> itération 4
+#=> itération 5
+
+# Vous pouvez également mettre un bloc de code entre accolades :
+(1..5).each {|compteur| puts "itération #{compteur}"}
+
+# Le contenu des structures de données peut être parcouru
+# en utilisant la méthode each.
+array.each do |element|
+ puts "#{element} est une partie du tableau"
+end
+hash.each do |cle, valeur|
+ puts "#{cle} est #{valeur}"
+end
+
+compteur = 1
+while compteur <= 5 do
+ puts "itération #{compteur}"
+ compteur += 1
+end
+#=> itération 1
+#=> itération 2
+#=> itération 3
+#=> itération 4
+#=> itération 5
+
+grade = 'B'
+
+case grade
+when 'A'
+ puts "Excellent"
+when 'B'
+ puts "Plus de chance la prochaine fois"
+when 'C'
+ puts "Vous pouvez faire mieux"
+when 'D'
+ puts "C'est pas terrible"
+when 'F'
+ puts "Vous avez échoué!"
+else
+ puts "Sytème de notation alternatif"
+end
+
+# Fonctions
+
+def double(x)
+ x * 2
+end
+
+# Les fonctions (et tous les blocs de code) retournent
+# implicitement la valeur de la dernière instruction évaluée
+double(2) #=> 4
+
+# Les paranthèses sont facultative
+# lorsqu'il n'y a pas d'ambiguïté sur le résultat
+double 3 #=> 6
+
+double double 3 #=> 12
+
+def sum(x,y)
+ x + y
+end
+
+# Les paramètres de méthode sont séparés par des virgules
+sum 3, 4 #=> 7
+
+sum sum(3,4), 5 #=> 12
+
+# yield
+# Toutes les méthodes ont un argument facultatif et implicite
+# de type bloc de code
+# il peut être appelé avec le mot clé 'yield'
+
+def surround
+ puts "{"
+ yield
+ puts "}"
+end
+
+surround { puts 'Bonjour tout le monde' }
+
+# {
+# Bonjour tout le monde
+# }
+
+
+# Définissez une classe avec le mot clé 'class'
+class Humain
+
+ # Une variable de classe
+ # est partagée par toutes les instances de cette classe.
+ @@espece = "H. sapiens"
+
+ # Constructeur de classe
+ def initialize(nom, age = 0)
+ # Affectez l'argument à la variable d'instance 'nom'
+ # pour la durée de vie de l'instance de cette classe
+ @nom = nom
+ # Si le paramètre 'age' est absent,
+ # la valeur par défaut définie dans la liste des arguments sera utilisée.
+ @age = age
+ end
+
+ # Une simple méthode setter
+ def nom=(nom)
+ @nom = nom
+ end
+
+ # Une simple méthode getter
+ def nom
+ @nom
+ end
+
+ # Une méthode de classe utilise le mot clé 'self'
+ # pour se distinguer de la méthode d'instance.
+ # La méthode sera alors accessible à partir de la classe
+ # et non pas de l'instance.
+ def self.say(msg)
+ puts "#{msg}"
+ end
+
+ def species
+ @@species
+ end
+
+end
+
+
+# Instanciez une classe
+jim = Humain.new("Jim Halpert")
+
+dwight = Humain.new("Dwight K. Schrute")
+
+# Appelez quelques méthodes
+jim.espece #=> "H. sapiens"
+jim.nom #=> "Jim Halpert"
+jim.nom = "Jim Halpert II" #=> "Jim Halpert II"
+jim.nom #=> "Jim Halpert II"
+dwight.espece #=> "H. sapiens"
+dwight.nom #=> "Dwight K. Schrute"
+
+# Appelez la méthode de classe
+Humain.say("Hi") #=> "Hi"
+
+# Les classes sont également des objets en Ruby.
+# Par conséquent, les classes peuvent avoir des variables d'instance.
+# Les variables de classe sont partagées parmi
+# la classe et ses descendants.
+
+# Classe parente
+class Humain
+ @@foo = 0
+
+ def self.foo
+ @@foo
+ end
+
+ def self.foo=(valeur)
+ @@foo = valeur
+ end
+end
+
+# Classe fille
+class Travailleur < Humain
+end
+
+Humain.foo # 0
+Travailleur.foo # 0
+
+Humain.foo = 2 # 2
+Travailleur.foo # 2
+
+# Les variables d'instance de classe ne sont pas partagées
+# avec les classes héritées.
+
+class Humain
+ @bar = 0
+
+ def self.bar
+ @bar
+ end
+
+ def self.bar=(valeur)
+ @bar = valeur
+ end
+end
+
+class Docteur < Humain
+end
+
+Humain.bar # 0
+Docteur.bar # nil
+
+```
diff --git a/go.html.markdown b/go.html.markdown
new file mode 100644
index 00000000..e7b35926
--- /dev/null
+++ b/go.html.markdown
@@ -0,0 +1,301 @@
+---
+name: Go
+category: language
+language: Go
+filename: learngo.go
+contributors:
+ - ["Sonia Keys", "https://github.com/soniakeys"]
+---
+
+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.
+
+It has familiar concepts of imperative languages with static typing.
+It's fast to compile and fast to execute, it adds easy-to-understand
+concurrency to leverage today's multi-core CPUs, and has features to
+help with large-scale programming.
+
+Go comes with a great standard library and an enthusiastic community.
+
+```Go
+// Single line comment
+/* Multi-
+ line comment */
+
+// A package clause starts every source file.
+// Main is a special name declaring an executable rather than a library.
+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
+)
+
+// 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!")
+
+ // Call another function within this package.
+ beyondHello()
+}
+
+// Functions have parameters in parentheses.
+// If there are no parameters, empty parens 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!
+}
+
+// Functions can have parameters and (multiple!) return values.
+func learnMultiple(x, y int) (sum, prod int) {
+ 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
+
+ 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 UTF-8 code point
+
+ f := 3.14195 // float64, an IEEE-754 64-bit floating point number
+ c := 3 + 4i // complex128, represented internally with two float64s
+
+ // 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
+}
+
+// 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.
+}
+
+func expensiveComputation() int {
+ return 1e6
+}
+
+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 := 1
+ switch x {
+ case 0:
+ case 1:
+ // cases don't "fall through"
+ case 2:
+ // unreached
+ }
+ // Like if, for doesn't use parens either.
+ for x := 0; x < 3; x++ { // ++ is a statement
+ fmt.Println("iteration", x)
+ }
+ // x == 1 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 > 100 // references x declared above switch statement.
+ }
+ fmt.Println("xBig:", xBig()) // true (we last assigned 1e6 to x)
+ x /= 1e5 // this makes it == 10
+ fmt.Println("xBig:", xBig()) // false now
+
+ // When you need it, you'll love it.
+ goto love
+love:
+
+ learnInterfaces() // Good stuff coming up!
+}
+
+// Define Stringer as an interface type with one method, String.
+type Stringer interface {
+ String() string
+}
+
+// Define pair as a struct with two fields, ints named x and y.
+type pair struct {
+ x, y int
+}
+
+// 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)
+}
+
+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
+
+ 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()
+}
+
+// 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.
+}
+
+// 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.
+ cc := make(chan chan string) // a channel of 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.Println("it's a", i)
+ case <-cs: // or the value received can be discarded
+ fmt.Println("it's a string")
+ case <-cc: // 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() {
+ // ListenAndServe first parameter is TCP address to listen at.
+ // Second parameter is an interface, specifically http.Handler.
+ err := http.ListenAndServe(":8080", pair{})
+ fmt.Println(err) // don't ignore errors
+}
+
+// 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!"))
+}
+```
+
+## Further Reading
+
+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
+and amazingly short (as language definitions go these days.)
+
+On the reading list for students of Go is the source code to the standard
+library. Comprehensively documented, it demonstrates the best of readable
+and understandable Go, Go style, and Go idioms. Click on a function name
+in the documentation and the source code comes up!
+
diff --git a/haskell.html.markdown b/haskell.html.markdown
index 9847ef2a..e3ec3f38 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -84,7 +84,7 @@ not False -- True
-- rest of the elements of this "infinite" list don't exist yet! Haskell won't
-- actually evaluate them until it needs to.
-- joining two lists
+-- joining two lists
[1..5] ++ [6..10]
-- adding to the head of a list
diff --git a/java.html.markdown b/java.html.markdown
index b4531635..cdcf620c 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -405,3 +405,7 @@ Other Topics To Research:
* [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html)
* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html)
+
+Books:
+
+* [Head First Java] (http://www.headfirstlabs.com/books/hfjava/)
diff --git a/javascript.html.markdown b/javascript.html.markdown
index cc279b9a..fb79949e 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -30,83 +30,84 @@ doStuff();
// wherever there's a newline, except in certain cases.
doStuff()
-// We'll leave semicolons off here; whether you do or not will depend on your
-// personal preference or your project's style guide.
+// So that we don't have to worry about those certain cases (for now), we'll
+// leave them on.
///////////////////////////////////
// 1. Numbers, Strings and Operators
// Javascript has one number type (which is a 64-bit IEEE 754 double).
-3 // = 3
-1.5 // = 1.5
+3; // = 3
+1.5; // = 1.5
// All the basic arithmetic works as you'd expect.
-1 + 1 // = 2
-8 - 1 // = 7
-10 * 2 // = 20
-35 / 5 // = 7
+1 + 1; // = 2
+8 - 1; // = 7
+10 * 2; // = 20
+35 / 5; // = 7
// Including uneven division.
-5 / 2 // = 2.5
+5 / 2; // = 2.5
// Bitwise operations also work; when you perform a bitwise operation your float
// is converted to a signed int *up to* 32 bits.
-1 << 2 // = 4
+1 << 2; // = 4
// Precedence is enforced with parentheses.
-(1 + 3) * 2 // = 8
+(1 + 3) * 2; // = 8
// There are three special not-a-real-number values:
-Infinity // result of e.g. 1/0
--Infinity // result of e.g. -1/0
-NaN // result of e.g. 0/0
+Infinity; // result of e.g. 1/0
+-Infinity; // result of e.g. -1/0
+NaN; // result of e.g. 0/0
// There's also a boolean type.
-true
-false
+true;
+false;
// Strings are created with ' or ".
-'abc'
-"Hello, world"
+'abc';
+"Hello, world";
// Negation uses the ! symbol
-!true // = false
-!false // = true
+!true; // = false
+!false; // = true
// Equality is ==
-1 == 1 // = true
-2 == 1 // = false
+1 == 1; // = true
+2 == 1; // = false
// Inequality is !=
-1 != 1 // = false
-2 != 1 // = true
+1 != 1; // = false
+2 != 1; // = true
// More comparisons
-1 < 10 // = true
-1 > 10 // = false
-2 <= 2 // = true
-2 >= 2 // = true
+1 < 10; // = true
+1 > 10; // = false
+2 <= 2; // = true
+2 >= 2; // = true
// Strings are concatenated with +
-"Hello " + "world!" // = "Hello world!"
+"Hello " + "world!"; // = "Hello world!"
// and are compared with < and >
-"a" < "b" // = true
+"a" < "b"; // = true
// Type coercion is performed for comparisons...
-"5" == 5 // = true
+"5" == 5; // = true
// ...unless you use ===
-"5" === 5 // = false
+"5" === 5; // = false
// You can access characters in a string with charAt
-"This is a string".charAt(0)
+"This is a string".charAt(0);
// There's also null and undefined
-null // used to indicate a deliberate non-value
-undefined // used to indicate a value that hasn't been set yet
+null; // used to indicate a deliberate non-value
+undefined; // used to indicate a value is not currently present (although undefined
+ // is actually a value itself)
-// null, undefined, NaN, 0 and "" are falsy, and everything else is truthy.
+// false, null, undefined, NaN, 0 and "" are falsy, and everything else is truthy.
// Note that 0 is falsy and "0" is truthy, even though 0 == "0".
///////////////////////////////////
@@ -114,57 +115,57 @@ undefined // used to indicate a value that hasn't been set yet
// Variables are declared with the var keyword. Javascript is dynamically typed,
// so you don't need to specify type. Assignment uses a single = character.
-var someVar = 5
+var someVar = 5;
// if you leave the var keyword off, you won't get an error...
-someOtherVar = 10
+someOtherVar = 10;
// ...but your variable will be created in the global scope, not in the scope
// you defined it in.
// Variables declared without being assigned to are set to undefined.
-var someThirdVar // = undefined
+var someThirdVar; // = undefined
// There's shorthand for performing math operations on variables:
-someVar += 5 // equivalent to someVar = someVar + 5; someVar is 10 now
-someVar *= 10 // now someVar is 100
+someVar += 5; // equivalent to someVar = someVar + 5; someVar is 10 now
+someVar *= 10; // now someVar is 100
// and an even-shorter-hand for adding or subtracting 1
-someVar++ // now someVar is 101
-someVar-- // back to 100
+someVar++; // now someVar is 101
+someVar--; // back to 100
// Arrays are ordered lists of values, of any type.
-var myArray = ["Hello", 45, true]
+var myArray = ["Hello", 45, true];
// Their members can be accessed using the square-brackets subscript syntax.
// Array indices start at zero.
-myArray[1] // = 45
+myArray[1]; // = 45
// JavaScript's objects are equivalent to 'dictionaries' or 'maps' in other
// languages: an unordered collection of key-value pairs.
-{key1: "Hello", key2: "World"}
+var myObj = {key1: "Hello", key2: "World"};
// Keys are strings, but quotes aren't required if they're a valid
// JavaScript identifier. Values can be any type.
-var myObj = {myKey: "myValue", "my other key": 4}
+var myObj = {myKey: "myValue", "my other key": 4};
// Object attributes can also be accessed using the subscript syntax,
-myObj["my other key"] // = 4
+myObj["my other key"]; // = 4
// ... or using the dot syntax, provided the key is a valid identifier.
-myObj.myKey // = "myValue"
+myObj.myKey; // = "myValue"
// Objects are mutable; values can be changed and new keys added.
-myObj.myThirdKey = true
+myObj.myThirdKey = true;
// If you try to access a value that's not yet set, you'll get undefined.
-myObj.myFourthKey // = undefined
+myObj.myFourthKey; // = undefined
///////////////////////////////////
// 3. Logic and Control Structures
// The if structure works as you'd expect.
-var count = 1
+var count = 1;
if (count == 3){
// evaluated if count is 3
} else if (count == 4) {
@@ -181,10 +182,10 @@ while (true) {
// Do-while loops are like while loops, except they always run at least once.
var input
do {
- input = getInput()
+ input = getInput();
} while (!isValid(input))
-// the for loop is the same as C and Java:
+// the for loop is the same as C and Java:
// initialisation; continue condition; iteration.
for (var i = 0; i < 5; i++){
// will run 5 times
@@ -192,29 +193,23 @@ for (var i = 0; i < 5; i++){
// && is logical and, || is logical or
if (house.size == "big" && house.colour == "blue"){
- house.contains = "bear"
+ house.contains = "bear";
}
if (colour == "red" || colour == "blue"){
// colour is either red or blue
}
// && and || "short circuit", which is useful for setting default values.
-var name = otherName || "default"
+var name = otherName || "default";
///////////////////////////////////
// 4. Functions, Scope and Closures
// JavaScript functions are declared with the function keyword.
function myFunction(thing){
- return thing.toUpperCase()
+ return thing.toUpperCase();
}
-myFunction("foo") // = "FOO"
-
-// Functions can also be defined "anonymously" - without a name:
-function(thing){
- return thing.toLowerCase()
-}
-// (we can't call our function, since we don't have a name to refer to it with)
+myFunction("foo"); // = "FOO"
// JavaScript functions are first class objects, so they can be reassigned to
// different variable names and passed to other functions as arguments - for
@@ -222,52 +217,49 @@ function(thing){
function myFunction(){
// this code will be called in 5 seconds' time
}
-setTimeout(myFunction, 5000)
-
-// You can even write the function statement directly in the call to the other
-// function.
+setTimeout(myFunction, 5000);
-setTimeout(function myFunction(){
+// Function objects don't even have to be declared with a name - you can write
+// an anonymous function definition directly into the arguments of another.
+setTimeout(function(){
// this code will be called in 5 seconds' time
-}, 5000)
+}, 5000);
// JavaScript has function scope; functions get their own scope but other blocks
// do not.
if (true){
- var i = 5
+ var i = 5;
}
-i // = 5 - not undefined as you'd expect in a block-scoped language
+i; // = 5 - not undefined as you'd expect in a block-scoped language
// This has led to a common pattern of "immediately-executing anonymous
// functions", which prevent temporary variables from leaking into the global
// scope.
(function(){
- var temporary = 5
+ var temporary = 5;
// We can access the global scope by assiging to the 'global object', which
// in a web browser is always 'window'. The global object may have a
// different name in non-browser environments such as Node.js.
- window.permanent = 10
- // Or, as previously mentioned, we can just leave the var keyword off.
- permanent2 = 15
-})()
-temporary // raises ReferenceError
-permanent // = 10
-permanent2 // = 15
+ window.permanent = 10;
+})();
+temporary; // raises ReferenceError
+permanent; // = 10
// One of JavaScript's most powerful features is closures. If a function is
// defined inside another function, the inner function has access to all the
-// outer function's variables.
+// outer function's variables, even after the outer function exits.
function sayHelloInFiveSeconds(name){
- var prompt = "Hello, " + name + "!"
+ var prompt = "Hello, " + name + "!";
function inner(){
- alert(prompt)
+ alert(prompt);
}
- setTimeout(inner, 5000)
- // setTimeout is asynchronous, so this function will finish without waiting
- // 5 seconds. However, once the 5 seconds is up, inner will still have
- // access to the value of prompt.
+ setTimeout(inner, 5000);
+ // setTimeout is asynchronous, so the sayHelloInFiveSeconds function will
+ // exit immediately, and setTimeout will call inner afterwards. However,
+ // because inner is "closed over" sayHelloInFiveSeconds, inner still has
+ // access to the 'prompt' variable when it is finally called.
}
-sayHelloInFiveSeconds("Adam") // will open a popup with "Hello, Adam!" in 5s
+sayHelloInFiveSeconds("Adam"); // will open a popup with "Hello, Adam!" in 5s
///////////////////////////////////
// 5. More about Objects; Constructors and Prototypes
@@ -275,44 +267,44 @@ sayHelloInFiveSeconds("Adam") // will open a popup with "Hello, Adam!" in 5s
// Objects can contain functions.
var myObj = {
myFunc: function(){
- return "Hello world!"
+ return "Hello world!";
}
-}
-myObj.myFunc() // = "Hello world!"
+};
+myObj.myFunc(); // = "Hello world!"
// When functions attached to an object are called, they can access the object
// they're attached to using the this keyword.
myObj = {
myString: "Hello world!",
myFunc: function(){
- return this.myString
+ return this.myString;
}
-}
-myObj.myFunc() // = "Hello world!"
+};
+myObj.myFunc(); // = "Hello world!"
// What this is set to has to do with how the function is called, not where
// it's defined. So, our function doesn't work if it isn't called in the
// context of the object.
-var myFunc = myObj.myFunc
-myFunc() // = undefined
+var myFunc = myObj.myFunc;
+myFunc(); // = undefined
// Inversely, a function can be assigned to the object and gain access to it
// through this, even if it wasn't attached when it was defined.
var myOtherFunc = function(){
- return this.myString.toUpperCase()
+ return this.myString.toUpperCase();
}
-myObj.myOtherFunc = myOtherFunc
-myObj.myOtherFunc() // = "HELLO WORLD!"
+myObj.myOtherFunc = myOtherFunc;
+myObj.myOtherFunc(); // = "HELLO WORLD!"
// When you call a function with the new keyword, a new object is created, and
// made available to the function via this. Functions designed to be called
// like this are called constructors.
var MyConstructor = function(){
- this.myNumber = 5
+ this.myNumber = 5;
}
-myNewObj = new MyConstructor() // = {myNumber: 5}
-myNewObj.myNumber // = 5
+myNewObj = new MyConstructor(); // = {myNumber: 5}
+myNewObj.myNumber; // = 5
// Every JavaScript object has a 'prototype'. When you go to access a property
// on an object that doesn't exist on the actual object, the interpreter will
@@ -323,31 +315,31 @@ myNewObj.myNumber // = 5
// part of the standard; we'll get to standard ways of using prototypes later.
var myObj = {
myString: "Hello world!",
-}
+};
var myPrototype = {
meaningOfLife: 42,
myFunc: function(){
return this.myString.toLowerCase()
}
-}
-myObj.__proto__ = myPrototype
-myObj.meaningOfLife // = 42
+};
+myObj.__proto__ = myPrototype;
+myObj.meaningOfLife; // = 42
// This works for functions, too.
-myObj.myFunc() // = "hello world!"
+myObj.myFunc(); // = "hello world!"
// Of course, if your property isn't on your prototype, the prototype's
// prototype is searched, and so on.
myPrototype.__proto__ = {
myBoolean: true
-}
-myObj.myBoolean // = true
+};
+myObj.myBoolean; // = true
// There's no copying involved here; each object stores a reference to its
// prototype. This means we can alter the prototype and our changes will be
// reflected everywhere.
-myPrototype.meaningOfLife = 43
-myObj.meaningOfLife // = 43
+myPrototype.meaningOfLife = 43;
+myObj.meaningOfLife; // = 43
// We mentioned that __proto__ was non-standard, and there's no standard way to
// change the prototype of an existing object. However, there's two ways to
@@ -355,8 +347,8 @@ myObj.meaningOfLife // = 43
// The first is Object.create, which is a recent addition to JS, and therefore
// not available in all implementations yet.
-var myObj = Object.create(myPrototype)
-myObj.meaningOfLife // = 43
+var myObj = Object.create(myPrototype);
+myObj.meaningOfLife; // = 43
// The second way, which works anywhere, has to do with constructors.
// Constructors have a property called prototype. This is *not* the prototype of
@@ -366,20 +358,20 @@ myConstructor.prototype = {
getMyNumber: function(){
return this.myNumber
}
-}
-var myNewObj2 = new myConstructor()
-myNewObj2.getMyNumber() // = 5
+};
+var myNewObj2 = new myConstructor();
+myNewObj2.getMyNumber(); // = 5
// Built-in types like strings and numbers also have constructors that create
// equivalent wrapper objects.
-var myNumber = 12
-var myNumberObj = new Number(12)
-myNumber == myNumberObj // = true
+var myNumber = 12;
+var myNumberObj = new Number(12);
+myNumber == myNumberObj; // = true
// Except, they aren't exactly equivalent.
-typeof(myNumber) // = 'number'
-typeof(myNumberObj) // = 'object'
-myNumber === myNumberObj // = false
+typeof(myNumber); // = 'number'
+typeof(myNumberObj); // = 'object'
+myNumber === myNumberObj; // = false
if (0){
// This code won't execute, because 0 is falsy.
}
@@ -390,9 +382,9 @@ if (Number(0)){
// However, the wrapper objects and the regular builtins share a prototype, so
// you can actually add functionality to a string, for instance.
String.prototype.firstCharacter = function(){
- return this.charAt(0)
+ return this.charAt(0);
}
-"abc".firstCharacter() // = "a"
+"abc".firstCharacter(); // = "a"
// This fact is often used in "polyfilling", which is implementing newer
// features of JavaScript in an older subset of JavaScript, so that they can be
@@ -403,10 +395,10 @@ String.prototype.firstCharacter = function(){
if (Object.create === undefined){ // don't overwrite it if it exists
Object.create = function(proto){
// make a temporary constructor with the right prototype
- var Constructor = function(){}
- Constructor.prototype = proto
+ var Constructor = function(){};
+ Constructor.prototype = proto;
// then use it to create a new, appropriately-prototyped object
- return new Constructor()
+ return new Constructor();
}
}
```
diff --git a/ko-kr/javascript-kr.html.markdown b/ko-kr/javascript-kr.html.markdown
new file mode 100644
index 00000000..e5517aa8
--- /dev/null
+++ b/ko-kr/javascript-kr.html.markdown
@@ -0,0 +1,435 @@
+---
+language: javascript
+category: language
+contributors:
+ - ["Adam Brenecki", "http://adam.brenecki.id.au"]
+translators:
+ - ["wikibook", "http://wikibook.co.kr"]
+lang: ko-kr
+---
+
+자바스크립트는 넷스케이프의 브렌던 아이크(Brendan Eich)가 1995년에 만들었습니다.
+원래 자바스크립트는 웹사이트를 위한 단순한 스크립트 언어를 목표로 만들어졌는데,
+좀 더 복잡한 웹 애플리케이션을 만들기 위해 자바를 보완하는 역할이었지만
+웹 페이지와의 긴밀한 상호작용과 브라우저에 대한 지원 기능 덕분에 웹 프론트엔드에서
+자바보다 훨씬 더 보편적으로 쓰이게 됐습니다.
+
+그렇지만 자바스크립트는 웹 브라우저에만 국한되지 않습니다. 구글 크롬의 V8 자바스크립트
+엔진을 위한 독립형 런타임을 제공하는 Node.js는 점점 인기를 얻고 있습니다.
+
+피드백 주시면 대단히 감사하겠습니다! [@adambrenecki](https://twitter.com/adambrenecki)나
+[adam@brenecki.id.au](mailto:adam@brenecki.id.au)를 통해 저와 만나실 수 있습니다.
+
+```js
+// 주석은 C와 비슷합니다. 한 줄짜리 주석은 두 개의 슬래시로 시작하고,
+/* 여러 줄 주석은 슬래시 별표로 시작해서
+ 별표 슬래시로 끝납니다. */
+
+// 구문은 세미콜론(;)으로 끝낼 수 있습니다.
+doStuff();
+
+// 하지만 꼭 그럴 필요는 없는데, 특정 경우를 제외하고
+// 새 줄이 시작할 때마다 세미콜론이 자동으로 삽입되기 때문입니다.
+doStuff()
+
+// 여기서는 세미콜론을 생략하겠습니다. 세미콜론을 생략할지 여부는
+// 개인적인 취향이나 프로젝트의 스타일 가이드를 따릅니다.
+
+///////////////////////////////////
+// 1. 숫자, 문자열, 연산자
+
+// 자바스크립트에는 단 하나의 숫자 타입(64비트 IEEE 754 배정도 숫자)만이
+// 있습니다.
+3 // = 3
+1.5 // = 1.5
+
+// 모든 기초 산술 연산은 기대한 대로 동작합니다.
+1 + 1 // = 2
+8 - 1 // = 7
+10 * 2 // = 20
+35 / 5 // = 7
+
+// 나누어 떨어지지 않는 나눗셈도 포함됩니다.
+5 / 2 // = 2.5
+
+// 비트 연산도 지원됩니다. float을 대상으로 비트 연산을 수행하면
+// 32비트까지 부호가 있는 int로 변환됩니다.
+1 << 2 // = 4
+
+// 괄호를 이용하면 우선순위를 지정할 수 있습니다.
+(1 + 3) * 2 // = 8
+
+// 실제 숫자가 아닌 특별한 세 가지 값이 있습니다.
+Infinity // 1/0 1/0과 같은 연산의 결과
+-Infinity // -1/0과 같은 연산의 결과
+NaN // 0/0과 같은 연산의 결과
+
+// 불린 타입도 있습니다.
+true
+false
+
+// 문자열은 '나 "로 생성합니다.
+'abc'
+"Hello, world"
+
+// 부정 연산에는 ! 기호를 이용합니다.
+!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
+
+// 문자열은 +로 연결할 수 있습니다.
+"Hello " + "world!" // = "Hello world!"
+
+// 그리고 <와 >로 비교할 수 있습니다.
+"a" < "b" // = true
+
+// 비교 시 타입 강제변환이 수행됩니다.
+"5" == 5 // = true
+
+// ===를 쓰지 않는다면 말이죠.
+"5" === 5 // = false
+
+// charAt을 이용하면 문자열 내의 문자에 접근할 수 있습니다.
+"This is a string".charAt(0)
+
+// null과 undefined도 있습니다.
+null // 의도적으로 값이 아님을 나타내는 데 사용합니다.
+undefined // 값이 아직 설정되지 않음을 나타내는 데 사용합니다.
+
+// null, undefinded, NaN, 0, ""은 거짓이며, 그 밖의 다른 모든 값은 참입니다.
+// 참고로 0은 거짓이며, "0"은 참입니다(심지어 0 == "0"이더라도).
+
+///////////////////////////////////
+// 2. 변수, 배열, 객체
+
+// 변수는 var 키워드로 선언합니다. 자바스크립트는 동적 타입 언어라서
+// 타입을 지정할 필요가 없습니다. 값을 할당할 때는 = 문자 하나를 사용합니다.
+var someVar = 5
+
+// var 키워드를 지정하지 않아도 오류는 발생하지 않습니다.
+someOtherVar = 10
+
+// 그렇지만 변수가 여러분이 정의한 유효범위가 아니라
+// 전역 유효범위에 생성됩니다.
+
+// 값을 할당하지 않은 채로 선언한 변수는 undefined로 설정됩니다.
+var someThirdVar // = undefined
+
+// 변수에 수학 연산을 수행하는 축약형 표현은 다음과 같습니다.
+someVar += 5 // someVar = someVar + 5;와 같음. 이제 someVar는 10.
+someVar *= 10 // somVar는 100
+
+// 1을 더하거나 빼는 훨씬 더 짧은 표현도 있습니다.
+someVar++ // 이제 someVar는 101
+someVar-- // 다시 100으로 되돌아감
+
+// 배열은 순차적인 임의 타입 값의 목록입니다.
+var myArray = ["Hello", 45, true]
+
+// 배열의 멤버는 대괄호로 둘러싼 인덱스를 이용해 접근할 수 있습니다.
+// 배열의 인덱스는 0부터 시작합니다.
+myArray[1] // = 45
+
+// 자바스크립트의 객체는 다른 언어의 '사전'이나 '맵'과 같습니다.
+// 즉, 키-값 쌍으로 구성된 비순차 컬렉션입니다.
+{key1: "Hello", key2: "World"}
+
+// 키는 문자열이지만 유효한 자바스크립트 식별자일 경우
+// 작은따옴표는 필요하지 않습니다. 값은 어떤 타입이든 사용할 수 있습니다.
+var myObj = {myKey: "myValue", "my other key": 4}
+
+// 객체 속성에도 인덱스를 이용해 접근할 수 있습니다.
+myObj["my other key"] // = 4
+
+// 또는 키가 유효한 식별자일 경우 점 표기법을 이용해 접근할 수 있습니다.
+myObj.myKey // = "myValue"
+
+// 객체는 변경 가능합니다. 즉, 값을 변경하거나 새 키를 추가할 수 있습니다.
+myObj.myThirdKey = true
+
+// 설정되지 않은 값에 접근하려고 하면 undefined가 반환됩니다.
+myObj.myFourthKey // = undefined
+
+///////////////////////////////////
+// 3. 로직과 제어 구조
+
+// if 구조는 여러분이 예상한 대로 동작합니다.
+var count = 1
+if (count == 3){
+ // count가 3일 경우 평가됨
+} else if (count == 4) {
+ // count가 4일 경우 평가됨
+} else {
+ // count가 3이나 4가 아닌 경우에 평가됨
+}
+
+// while도 마찬가지입니다.
+while (true) {
+ // 무한 루프!
+}
+
+// do-while 문은 항상 최소 한 번은 실행된다는 점을 제외하면
+// while 문과 비슷합니다.
+var input
+do {
+ input = getInput()
+} while (!isValid(input))
+
+// for 문은 C와 자바의 for 문과 같습니다.
+// 초기화식; 지속 조건; 증감식
+for (var i = 0; i < 5; i++){
+ // 5번 실행됨
+}
+
+// &&는 논리 and이고 ||는 논리 or입니다.
+if (house.size == "big" && house.colour == "blue"){
+ house.contains = "bear"
+}
+if (colour == "red" || colour == "blue"){
+ // 색은 빨강이거나 파랑
+}
+
+// &&와 ||은 "단축 평가"를 수행하는데, 기본값을 설정할 때 유용합니다.
+var name = otherName || "default"
+
+///////////////////////////////////
+// 4. 함수, 유효범위, 클로저
+
+// 자바스크립트 함수는 function 키워드로 선언합니다.
+function myFunction(thing){
+ return thing.toUpperCase()
+}
+myFunction("foo") // = "FOO"
+
+// 함수는 "익명"으로, 즉 이름 없이 정의할 수도 있습니다.
+function(thing){
+ return thing.toLowerCase()
+}
+// (함수를 가리키는 이름이 없기 때문에 함수를 호출할 수 없습니다)
+
+// 자바스크립트 함수는 일급 객체이므로 다른 변수에 재할당하고
+// 다른 함수에 인자로 전달할 수 있습니다. 가령, 이벤트 핸들러를 만들 경우
+function myFunction(){
+ // 이 코드는 5초 내에 호출됨
+}
+setTimeout(myFunction, 5000)
+
+// 다른 함수를 호출할 때 직접적으로 함수 구문을 작성할 수도 있습니다.
+
+setTimeout(function myFunction(){
+ // 이 코드는 5초 내에 호출됨
+}, 5000)
+
+// 자바스크립트에는 함수 유효범위가 있습니다.
+// 함수는 자체적인 유효범위를 가지지만 다른 블록은 유효범위를 가지지 않습니다.
+if (true){
+ var i = 5
+}
+i // = 5 - 블록 유효범위를 지원하는 언어에서는 undefined가 아닙니다.
+
+// 이것은 "즉시 실행되는 익명 함수"라는 공통 패턴으로 이어지는데,
+// 이 패턴은 임시 변수가 전역 유효범위로 유출되는 것을 방지합니다.
+(function(){
+ var temporary = 5
+ // '전역 객체'에 할당하는 식으로 전역 유효범위에 접근할 수 있는데,
+ // 브라우저에서 전역 객체는 항상 'window'입니다. 전역 객체는
+ // Node.js와 같은 브라우저가 아닌 환경에서는 다른 이름일 수도 있습니다.
+ window.permanent = 10
+ // 또는 앞에서 언급했다시피 var 키워드를 뺄 수도 있습니다.
+ permanent2 = 15
+})()
+temporary // ReferenceError 발생
+permanent // = 10
+permanent2 // = 15
+
+// 자바스크립트의 강력한 기능 중 하나는 클로저(closure)입니다.
+// 함수가 다른 함수 안에서 정의되면 안쪽에 정의된 함수는 바깥 함수의
+// 모든 변수에 접근할 수 있습니다.
+function sayHelloInFiveSeconds(name){
+ var prompt = "Hello, " + name + "!"
+ function inner(){
+ alert(prompt)
+ }
+ setTimeout(inner, 5000)
+ // setTimeout은 비동기적으로 동작하므로 이 함수는 5초 동안
+ // 기다리지 않고 실행을 마칩니다. 하지만 5초가 지나면 inner에서도
+ // prompt의 값에 접근할 수 있습니다.
+}
+sayHelloInFiveSeconds("Adam") // 5초 내로 "Hello, Adam!"이라고 적힌 팝업이 표시됨
+
+///////////////////////////////////
+// 5. 객체 심화; 생성자와 프로토타입
+
+// 객체는 함수를 포함할 수 있습니다.
+var myObj = {
+ myFunc: function(){
+ return "Hello world!"
+ }
+}
+myObj.myFunc() // = "Hello world!"
+
+// 객체에 포함된 함수가 호출되면 함수에서는 this 키워드를 이용해
+// 해당 함수가 포함된 객체에 접근할 수 있습니다.
+myObj = {
+ myString: "Hello world!",
+ myFunc: function(){
+ return this.myString
+ }
+}
+myObj.myFunc() // = "Hello world!"
+
+// 여기서 설정한 것은 함수가 정의된 곳이 아닌 함수가 호출되는
+// 방식과 관련이 있습니다. 그래서 아래 함수는 객체 컨텍스트에서
+// 호출되지 않으면 동작하지 않습니다.
+var myFunc = myObj.myFunc
+myFunc() // = undefined
+
+// 반대로 함수는 객체에 할당하고 this를 통해 해당 객체에 접근할 수 있습니다.
+// 함수를 정의할 때 객체에 추가되지 않았더라도 마찬가지입니다.
+var myOtherFunc = function(){
+ return this.myString.toUpperCase()
+}
+myObj.myOtherFunc = myOtherFunc
+myObj.myOtherFunc() // = "HELLO WORLD!"
+
+// new 키워드로 함수를 호출하면 새로운 객체가 생성되고 this를 통해
+// 함수에서 사용할 수 있게 됩니다. 이런 식으로 설계된 함수를 생성자라 합니다.
+
+var MyConstructor = function(){
+ this.myNumber = 5
+}
+myNewObj = new MyConstructor() // = {myNumber: 5}
+myNewObj.myNumber // = 5
+
+// 모든 자바스크립트 객체는 'prototype'을 가지고 있습니다. 어떤 객체에 대해
+// 실제 객체에는 존재하지 않는 프로퍼티에 접근하면 인터프리터는 프로로타입에서
+// 해당 프로퍼티를 찾습니다.
+
+// 일부 자바스크립트 구현체에서는 __proto__라는 마법의 프로퍼티로
+// 객체의 프로토타입에 접근하는 것을 허용하기도 합니다. 프로토타입을
+// 설명하기에는 이런 내용도 도움되겠지만 __proto__는 표준에 포함돼
+// 있지 않습니다. 나중에 프로토타입을 사용하는 표준 방법을 살펴보겠습니다.
+var myObj = {
+ myString: "Hello world!",
+}
+var myPrototype = {
+ meaningOfLife: 42,
+ myFunc: function(){
+ return this.myString.toLowerCase()
+ }
+}
+myObj.__proto__ = myPrototype
+myObj.meaningOfLife // = 42
+
+// 이 방법은 함수에도 통합니다.
+myObj.myFunc() // = "hello world!"
+
+// 물론 프로퍼티가 프로토타입에 존재하지 않으면
+// 프로토타입의 프로토타입을 찾는 식으로 진행됩니다.
+myPrototype.__proto__ = {
+ myBoolean: true
+}
+myObj.myBoolean // = true
+
+// 여기서 복사는 일어나지 않습니다. 각 객체에는 프로토타입에 대한
+// 참조가 보관돼 있습니다. 이는 프로토타입을 변경하면 변경사항이
+// 모든 곳에 반영된다는 의미입니다.
+myPrototype.meaningOfLife = 43
+myObj.meaningOfLife // = 43
+
+// 앞에서 __proto__가 표준에 포함돼 있지 않다고 이야기했는데,
+// 기존 객체의 프로토타입을 변경하는 표준 방법은 없습니다.
+// 하지만 특정 프로토타입을 가지고 새로운 객체를 생성하는 두 가지
+// 방법이 있습니다.
+
+// 첫 번째 방법은 Object.create를 이용하는 것인데,
+// Object.create는 최근에 자바스크립트에 추가된 것이라서 아직까지
+// 모든 구현체에서 이용할 수 있는 것은 아닙니다.
+var myObj = Object.create(myPrototype)
+myObj.meaningOfLife // = 43
+
+// 두 번째 방법은 어디서나 통하는 방법인데, 생성자와 관련이 있습니다.
+// 생성자에는 prototype이라는 프로퍼티가 있습니다. 이 프로퍼티는
+// 생성자 함수 자체의 프로토타입이 *아니고* 생성자와 new 키워드를 이용해
+// 객체가 생성될 때 새로운 객체가 받는 프로토타입입니다.
+myConstructor.prototype = {
+ getMyNumber: function(){
+ return this.myNumber
+ }
+}
+var myNewObj2 = new myConstructor()
+myNewObj2.getMyNumber() // = 5
+
+// 문자열과 숫자와 같은 내장 타입에도 동등한 래퍼 객체를
+// 생성하는 생성자가 있습니다.
+var myNumber = 12
+var myNumberObj = new Number(12)
+myNumber == myNumberObj // = true
+
+// 하지만 정확히 같지는 않습니다.
+typeof(myNumber) // = 'number'
+typeof(myNumberObj) // = 'object'
+myNumber === myNumberObj // = false
+if (0){
+ // 0은 거짓이라서 이 코드는 실행되지 않습니다.
+}
+if (Number(0)){
+ // Number(0)은 참이라서 이 코드는 *실행됩니다*.
+}
+
+// 하지만 래퍼 객체와 일반 내장 함수는 프로토타입을 공유하기 때문에
+// 가령 문자열에 실제로 기능을 추가할 수 있습니다.
+String.prototype.firstCharacter = function(){
+ return this.charAt(0)
+}
+"abc".firstCharacter() // = "a"
+
+// 이러한 사실은 기존 자바스크립트 버전에서 자바스크립트의
+// 새로운 기능을 구현하는 "폴리필(polyfilling)"에 자주 이용되므로
+// 오래된 버전의 브라우저와 같이 기존 환경에서 사용될 수 있습니다.
+
+// 예를 들어, Object.create가 모든 구현체에서 사용 가능한 것은 아니라고
+// 했지만 아래의 폴리필을 이용해 Object.create를 여전히 사용할 수 있습니다.
+if (Object.create === undefined){ // 이미 존재하면 덮어쓰지 않음
+ Object.create = function(proto){
+ // 올바른 프로토타입을 가지고 임시 생성자를 만듬
+ var Constructor = function(){}
+ Constructor.prototype = proto
+ // 그런 다음 임시 생성자를 이용해 새로운 적절한 프로토타입을
+ // 포함한 객체를 생성
+ return new Constructor()
+ }
+}
+```
+
+## 기타 참고 자료
+
+[모질라 개발자 네트워크](https://developer.mozilla.org/en-US/docs/Web/JavaScript)에서는
+자바스크립트에 대한 훌륭한 문서를 제공합니다. 더불어 위키 형식이라서 좀 더 많은 사항을
+배우게 되면 여러분만의 지식을 공유함으로써 다른 사람들에게 도움을 줄 수도 있습니다.
+
+MDN의 ['자바스크립트 재입문'](https://developer.mozilla.org/ko/docs/A_re-introduction_to_JavaScript)에서는
+여기서 다룬 개념의 상당수를 더욱 자세히 다루고 있습니다. 이 자료에서는 자바스크립트 언어 자체에
+대해서만 상당히 신중하게 다뤘습니다. 웹 페이지에서 자바스크립트를 사용하는 방법을 배우고 싶다면
+[문서 객체 모델(Document Object Model)](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core)에
+관해 배우는 것으로 시작하길 바랍니다.
+
+[자바스크립트 가든](http://bonsaiden.github.io/JavaScript-Garden/)에서는 자바스크립트 언어에서
+직관에 어긋나는 모든 부분들을 심도 있게 다룹니다.
+
+더불어 이 글에 직접적으로 기여한 분들로, 내용 중 일부는 이 사이트에 있는
+루이 딘(Louie Dihn)의 파이썬 튜토리얼과 모질라 개발자 네트워크에 있는
+[자바스크립트 튜토리얼](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)을 참고했습니다.
diff --git a/ko-kr/lua-kr.html.markdown b/ko-kr/lua-kr.html.markdown
new file mode 100644
index 00000000..04d119c4
--- /dev/null
+++ b/ko-kr/lua-kr.html.markdown
@@ -0,0 +1,424 @@
+---
+language: lua
+category: language
+contributors:
+ - ["Tyler Neylon", "http://tylerneylon.com/"]
+translators:
+ - ["wikibook", "http://wikibook.co.kr"]
+lang: ko-kr
+---
+
+```lua
+-- 대시 두 개는 한 줄짜리 주석을 의미합니다.
+
+--[[
+ [와 ]를 두 개씩 추가하면 여러 줄 주석이 됩니다.
+--]]
+
+----------------------------------------------------
+-- 1. 변수와 흐름 제어
+----------------------------------------------------
+
+num = 42 -- 모든 숫자는 double입니다.
+-- 놀랄 필요는 없습니다. 64비트 double은
+-- 정확한 int 값을 저장하기 위해 52비트로 구성돼
+-- 있습니다. 52비트 이하의 int 값에 대해서는
+-- 장비 정밀도와 관련된 문제가 생기지 않습니다.
+
+s = 'walternate' -- 파이썬과 같은 불변 문자열
+t = "큰따옴표를 써도 됩니다"
+u = [[ 이중 대괄호는
+ 여러 줄 문자열을
+ 나타냅니다.]]
+t = nil -- 미정의 t. 루아는 가비지 컬렉션을 지원합니다.
+
+-- 블록은 do/end와 같은 키워드로 나타냅니다:
+while num < 50 do
+ num = num + 1 -- ++나 += 유형의 연산자는 쓸 수 없습니다.
+end
+
+-- If 절:
+if num > 40 then
+ print('40 이상')
+elseif s ~= 'walternate' then -- ~=은 '같지 않다'입니다.
+ -- 동일성 검사는 파이썬과 마찬가지로 ==입니다.
+ -- 문자열에도 쓸 수 있습니다.
+ io.write('not over 40\n') -- 기본적으로 stdout에 씁니다.
+else
+ -- 변수는 기본적으로 전역 변수입니다.
+ thisIsGlobal = 5 -- 낙타 표기법이 일반적입니다.
+
+ -- 변수를 지역 변수로 만드는 방법은 다음과 같습니다:
+ local line = io.read() -- 다음 stdin 줄을 읽습니다
+
+ -- 문자열 연결에는 .. 연산자를 씁니다:
+ print('겨울이 오고 있습니다, ' .. line)
+end
+
+-- 미정의 변수는 nil을 반환합니다.
+-- 다음 코드를 실행해도 오류가 나지 않습니다:
+foo = anUnknownVariable -- 이제 foo는 nil입니다.
+
+aBoolValue = false
+
+-- nil과 false만이 거짓값입니다; 0과 ''은 참입니다!
+if not aBoolValue then print('twas false') end
+
+-- 'or'와 'and'는 단축 평가(short-circuit)됩니다.
+-- 다음 코드는 C/자바스크립트의 a?b:c 연산자와 비슷합니다:
+ans = aBoolValue and 'yes' or 'no' --> 'no'
+
+karlSum = 0
+for i = 1, 100 do -- 범위에는 마지막 요소도 포함됩니다.
+ karlSum = karlSum + i
+end
+
+-- 카운트 다운을 할 때는 "100, 1, -1"을 범위로 씁니다.
+fredSum = 0
+for j = 100, 1, -1 do fredSum = fredSum + j end
+
+-- 일반적으로 범위는 begin, end[, step]입니다.
+
+-- 또 다른 반복문 구문은 다음과 같습니다:
+repeat
+ print('미래의 방식')
+ num = num - 1
+until num == 0
+
+
+----------------------------------------------------
+-- 2. 함수
+----------------------------------------------------
+
+function fib(n)
+ if n < 2 then return n end
+ return fib(n - 2) + fib(n - 1)
+end
+
+-- 클로저와 익명 함수도 사용할 수 있습니다:
+function adder(x)
+ -- 반환된 함수는 adder가 호출될 때 생성되고 x의
+ -- 값이 유지됩니다:
+ return function (y) return x + y end
+end
+a1 = adder(9)
+a2 = adder(36)
+print(a1(16)) --> 25
+print(a2(64)) --> 100
+
+-- 반환문, 함수 호출, 할당문은 길이가 다른
+-- 값의 리스트에 대해서도 모두 동작합니다.
+-- 리스트에 값이 더 적을 때는 nil이 할당/반환되고
+-- 리스트에 값이 더 많을 때는 나머지 값은 버려집니다.
+
+x, y, z = 1, 2, 3, 4
+-- 이제 x = 1, y = 2, z = 3이고 4는 버려집니다.
+
+function bar(a, b, c)
+ print(a, b, c)
+ return 4, 8, 15, 16, 23, 42
+end
+
+x, y = bar('zaphod') --> "zaphod nil nil"가 출력
+-- 이제 x = 4, y = 8이고 15~42의 값은 버려집니다.
+
+-- 함수는 일급 객체이고, 지역/전역 유효범위를 가질
+-- 수 있습니다. 아래의 두 함수는 같습니다:
+function f(x) return x * x end
+f = function (x) return x * x end
+
+-- 그리고 아래의 두 함수도 마찬가지입니다:
+local function g(x) return math.sin(x) end
+local g; g = function (x) return math.sin(x) end
+-- 'local g'라고 선언하면 g를 지역 함수로 만듭니다.
+
+-- 그나저나 삼각 함수는 라디안 단위로 동작합니다.
+
+-- 함수를 호출할 때 문자열 매개변수를 하나만 전달한다면
+-- 괄호를 쓰지 않아도 됩니다:
+print 'hello' -- 잘 동작합니다.
+
+
+----------------------------------------------------
+-- 3. 테이블
+----------------------------------------------------
+
+-- 테이블 = 루아의 유일한 복합 자료구조로서, 연관 배열입니다.
+-- PHP의 배열이나 자바스크립트의 객체와 비슷하며,
+-- 리스트로도 사용할 수 있는 해시 기반의 딕셔너리입니다.
+
+-- 테이블을 딕셔너리/맵으로 사용하기:
+
+-- 딕셔너리 리터럴은 기본적으로 문자열 키를 가집니다:
+t = {key1 = 'value1', key2 = false}
+
+-- 문자열 키에는 자바스크립트와 유사한 점 표기법을 쓸 수 있습니다:
+print(t.key1) -- 'value1'을 출력.
+t.newKey = {} -- 새 키/값 쌍을 추가.
+t.key2 = nil -- 테이블에서 key2를 제거.
+
+-- (nil이 아닌) 값을 키로 사용하는 리터럴 표기법:
+u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'}
+print(u[6.28]) -- "tau"가 출력
+
+-- 키 매칭은 기본적으로 숫자와 문자열에 대해서는 값으로 하지만
+-- 테이블에 대해서는 식별자로 합니다.
+a = u['@!#'] -- Now a = 'qbert'.
+b = u[{}] -- We might expect 1729, but it's nil:
+a = u['@!#'] -- 이제 a는 'qbert'입니다.
+b = u[{}] -- 1729를 예상했겠지만 nil입니다:
+-- 탐색이 실패하기 때문에 b는 nil입니다. 탐색이 실패하는 이유는
+-- 사용된 키가 원본 값을 저장할 때 사용한 키와 동일한 객체가 아니기
+-- 때문입니다. 따라서 문자열 및 숫자가 좀 더 이식성 있는 키입니다.
+
+-- 테이블 하나를 매개변수로 취하는 함수를 호출할 때는 괄호가 필요하지 않습니다:
+function h(x) print(x.key1) end
+h{key1 = 'Sonmi~451'} -- 'Sonmi~451'를 출력.
+
+for key, val in pairs(u) do -- 테이블 순회
+ print(key, val)
+end
+
+-- _G는 모든 전역 멤버에 대한 특별한 테이블입니다.
+print(_G['_G'] == _G) -- 'true'가 출력
+
+-- 테이블을 리스트/배열로 사용하기:
+
+-- 리스트 리터럴은 암묵적으로 int 키로 설정됩니다:
+v = {'value1', 'value2', 1.21, 'gigawatts'}
+for i = 1, #v do -- #v는 리스트 v의 크기입니다.
+ print(v[i]) -- 인덱스가 1에서 시작합니다!! 제정신이 아닙니다!
+end
+-- 'list'는 실제 타입이 아닙니다. v는 연속된 정수형 키가 포함된
+-- 테이블이고 리스트로 취급될 뿐입니다.
+
+----------------------------------------------------
+-- 3.1 메타테이블과 메타메서드
+----------------------------------------------------
+
+-- 테이블은 테이블에 연산자 오버로딩을 가능하게 하는 메타테이블을
+-- 가질 수 있습니다. 나중에 메타테이블이 어떻게 자바스크립트
+-- 프로토타입과 같은 행위를 지원하는지 살펴보겠습니다.
+
+f1 = {a = 1, b = 2} -- 분수 a/b를 표현
+f2 = {a = 2, b = 3}
+
+-- 다음 코드는 실패합니다:
+-- s = f1 + f2
+
+metafraction = {}
+function metafraction.__add(f1, f2)
+ sum = {}
+ sum.b = f1.b * f2.b
+ sum.a = f1.a * f2.b + f2.a * f1.b
+ return sum
+end
+
+setmetatable(f1, metafraction)
+setmetatable(f2, metafraction)
+
+s = f1 + f2 -- f1의 메타테이블을 대상으로 __add(f1, f2)를 호출
+
+-- f1과 f2는 자바스크립트의 프로토타입과 달리 각 메타테이블에 대한
+-- 키가 없어서 getmetatable(f1)과 같이 받아와야 합니다.
+-- 메타테이블은 __add 같은 루아가 알고 있는 키가 지정된 일반 테이블입니다.
+
+-- 그렇지만 다음 줄은 s가 메타테이블을 가지고 있지 않기 때문에 실패합니다.
+-- t = s + s
+-- 아래와 같이 클래스와 유사한 패턴은 이러한 문제가 발생하지 않습니다.
+
+-- 메타테이블에 대한 __index는 점을 이용한 탐색을 오버로드합니다:
+defaultFavs = {animal = 'gru', food = 'donuts'}
+myFavs = {food = 'pizza'}
+setmetatable(myFavs, {__index = defaultFavs})
+eatenBy = myFavs.animal -- 동작합니다! 고마워요, 메타테이블!
+
+-- 직접적인 메타테이블 탐색이 실패할 경우 메타테이블의 __index 값을 이용해
+-- 재시도하고, 이런 과정이 반복됩니다.
+
+-- __index 값은 좀 더 세분화된 탐색을 위해 function(tbl, key)가
+-- 될 수도 있습니다.
+
+-- __index, __add, ...의 값을 메타메서드라고 합니다.
+-- 다음은 메타메서드를 가진 테이블의 전체 목록입니다.
+
+-- __add(a, b) for a + b
+-- __sub(a, b) for a - b
+-- __mul(a, b) for a * b
+-- __div(a, b) for a / b
+-- __mod(a, b) for a % b
+-- __pow(a, b) for a ^ b
+-- __unm(a) for -a
+-- __concat(a, b) for a .. b
+-- __len(a) for #a
+-- __eq(a, b) for a == b
+-- __lt(a, b) for a < b
+-- __le(a, b) for a <= b
+-- __index(a, b) <fn이나 테이블> for a.b
+-- __newindex(a, b, c) for a.b = c
+-- __call(a, ...) for a(...)
+
+----------------------------------------------------
+-- 3.2 클래스 형태의 테이블과 상속
+----------------------------------------------------
+
+-- 루아에는 클래스가 내장돼 있지 않으며, 테이블과 메타테이블을
+-- 이용해 클래스를 만드는 다양한 방법이 있습니다.
+
+-- 다음 예제에 대한 설명은 하단을 참조합니다.
+
+Dog = {} -- 1.
+
+function Dog:new() -- 2.
+ newObj = {sound = 'woof'} -- 3.
+ self.__index = self -- 4.
+ return setmetatable(newObj, self) -- 5.
+end
+
+function Dog:makeSound() -- 6.
+ print('I say ' .. self.sound)
+end
+
+mrDog = Dog:new() -- 7.
+mrDog:makeSound() -- 'I say woof' -- 8.
+
+-- 1. Dog는 클래스처럼 동작합니다. 실제로는 테이블입니다.
+-- 2. function 테이블명:fn(...)은
+-- function 테이블명.fn(self, ...)과 같습니다.
+-- :는 self라는 첫 번째 인자를 추가할 뿐입니다.
+-- self가 값을 어떻게 얻는지 궁금하다면 아래의 7과 8을 읽어보세요.
+-- 3. newObj는 Dog 클래스의 인스턴스가 됩니다.
+-- 4. self = 인스턴스화되는 클래스.
+-- 주로 self = Dog이지만 상속을 이용하면 이것을 바꿀 수 있습니다.
+-- newObj의 메타테이블과 self의 __index를 모두 self에 설정하면
+-- newObj가 self의 함수를 갖게 됩니다.
+-- 5. 참고: setmetatable은 첫 번째 인자를 반환합니다.
+-- 6. :는 2에서 설명한 것과 같이 동작하지만 이번에는 self가
+-- 클래스가 아닌 인스턴스라고 예상할 수 있습니다.
+-- 7. Dog.new(Dog)과 같으므로 new()에서는 self = Dog입니다.
+-- 8. mrDog.makeSound(mrDog)과 같으므로 self = mrDog입니다.
+
+----------------------------------------------------
+
+-- 상속 예제:
+
+LoudDog = Dog:new() -- 1.
+
+function LoudDog:makeSound()
+ s = self.sound .. ' ' -- 2.
+ print(s .. s .. s)
+end
+
+seymour = LoudDog:new() -- 3.
+seymour:makeSound() -- 'woof woof woof' -- 4.
+
+-- 1. LoudDog은 Dog의 메서드와 변수를 갖게 됩니다.
+-- 2. self는 new()에서 'sound' 키를 가집니다. 3을 참고하세요.
+-- 3. LoudDog.new(LoudDog)과 같고, LoudDog은 'new' 키가 없지만
+-- 메타테이블에서 __index = Dog이기 때문에 Dog.new(LoudDog)으로
+-- 변환됩니다.
+-- 결과: seymour의 메타테이블은 LoudDog이고 LoudDog.__index는
+-- LoudDog입니다. 따라서 seymour.key는 seymour.key,
+-- LoudDog.key, Dog.key와 같을 것이며, 지정한 키에 어떤 테이블이
+-- 오든 상관없을 것입니다.
+-- 4. 'makeSound' 키는 LoudDog에서 발견할 수 있습니다.
+-- 이것은 LoudDog.makeSound(seymour)와 같습니다.
+
+-- 필요할 경우, 하위 클래스의 new()는 기반 클래스의 new()와 유사합니다.
+function LoudDog:new()
+ newObj = {}
+ -- newObj를 구성
+ self.__index = self
+ return setmetatable(newObj, self)
+end
+
+----------------------------------------------------
+-- 4. 모듈
+----------------------------------------------------
+
+
+--[[ 여기서 주석을 제거하면 이 스크립트의 나머지 부분은
+-- 실행 가능한 상태가 됩니다.
+```
+
+```lua
+-- mod.lua 파일의 내용이 다음과 같다고 가정해 봅시다.
+local M = {}
+
+local function sayMyName()
+ print('이소룡')
+end
+
+function M.sayHello()
+ print('안녕하세요')
+ sayMyName()
+end
+
+return M
+
+-- 또 다른 파일에서는 mod.lua의 기능을 이용할 수 있습니다.
+local mod = require('mod') -- mod.lua 파일을 실행
+
+-- require는 모듈을 포함시키는 표준화된 방법입니다.
+-- require는 다음과 같이 동작합니다: (캐싱돼 있지 않을 경우. 하단 참조)
+local mod = (function ()
+ <mod.lua의 내용>
+end)()
+-- mod.lua가 함수의 본문처럼 되므로 mod.lua 안의 지역 멤버는
+-- 밖에서 볼 수 없습니다.
+
+-- 다음 코드가 동작하는 것은 mod가 mod.lua의 M과 같기 때문입니다.
+mod.sayHello() -- 이소룡 씨에게 인사를 건넵니다.
+
+-- 다음 코드를 실행하면 오류가 발생합니다.
+-- sayMyName는 mod.lua 안에서만 존재하기 때문입니다:
+mod.sayMyName() -- 오류
+
+-- require의 반환값은 캐싱되므로 require를 여러 번 실행해도
+-- 파일은 최대 한 번만 실행됩니다.
+
+-- mod2.lua에 "print('Hi')"가 들어 있다고 가정해 봅시다.
+local a = require('mod2') -- Hi!를 출력
+local b = require('mod2') -- print를 실행하지 않음. a=b
+
+-- dofile은 require와 비슷하지만 캐싱을 하지 않습니다:
+dofile('mod2') --> Hi!
+dofile('mod2') --> Hi! (require와 달리 다시 한번 실행됨)
+
+-- loadfile은 루아 파일을 읽어들이지만 실행하지는 않습니다
+f = loadfile('mod2') -- f()를 호출해야 mod2.lua가 실행됩니다.
+
+-- loadstring은 문자열에 대한 loadfile입니다.
+g = loadstring('print(343)') -- 함수를 반환합니다.
+g() -- 343이 출력됩니다. 그전까지는 아무것도 출력되지 않습니다.
+
+--]]
+
+```
+
+## 참고자료
+
+루아를 배우는 일이 흥미진진했던 이유는 <a href="http://love2d.org/">Love 2D 게임 엔진</a>을 이용해
+게임을 만들 수 있었기 때문입니다. 이것이 제가 루아를 배운 이유입니다.
+
+저는 <a href="http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/">BlackBulletIV의 "프로그래머를 위한 루아"</a>로
+시작했습니다. 그다음으로 공식 <a href="http://www.lua.org/pil/contents.html">"프로그래밍 루아"</a> 책을 읽었습니다.
+그렇게 루아를 배웠습니다.
+
+lua-users.org에 있는 <a href="http://lua-users.org/files/wiki_insecure/users/thomasl/luarefv51.pdf">짧은 루아 레퍼런스</a>를
+읽어두면 도움될지도 모르겠습니다.
+
+여기서는 표준 라이브러리에 관해서는 다루지 않았습니다.
+
+* <a href="http://lua-users.org/wiki/StringLibraryTutorial">string 라이브러리</a>
+* <a href="http://lua-users.org/wiki/TableLibraryTutorial">table 라이브러리</a>
+* <a href="http://lua-users.org/wiki/MathLibraryTutorial">math 라이브러리</a>
+* <a href="http://lua-users.org/wiki/IoLibraryTutorial">io 라이브러리</a>
+* <a href="http://lua-users.org/wiki/OsLibraryTutorial">os 라이브러리</a>
+
+그나저나 이 파일 전체는 유효한 루아 프로그램입니다. 이 파일을
+learn.lua로 저장한 후 "lua learn.lua"를 실행해 보세요!
+
+이 글은 tylerneylon.com에 처음으로 써본 글이며,
+<a href="https://gist.github.com/tylerneylon/5853042">Github의 Gist</a>에서도 확인할 수 있습니다.
+루아로 즐거운 시간을 보내세요!
diff --git a/ko-kr/python-kr.html.markdown b/ko-kr/python-kr.html.markdown
new file mode 100644
index 00000000..a131e9a2
--- /dev/null
+++ b/ko-kr/python-kr.html.markdown
@@ -0,0 +1,484 @@
+---
+language: python
+category: language
+contributors:
+ - ["Louie Dinh", "http://ldinh.ca"]
+filename: learnpython.py
+translators:
+ - ["wikibook", "http://wikibook.co.kr"]
+lang: ko-kr
+---
+
+파이썬은 귀도 반 로섬이 90년대에 만들었습니다. 파이썬은 현존하는 널리 사용되는 언어 중 하나입니다.
+저는 문법적 명료함에 반해 파이썬을 사랑하게 됐습니다. 파이썬은 기본적으로 실행 가능한 의사코드입니다.
+
+피드백 주시면 정말 감사하겠습니다! [@louiedinh](http://twitter.com/louiedinh)나
+louiedinh [at] [구글의 이메일 서비스]를 통해 저에게 연락하시면 됩니다.
+
+참고: 이 글은 구체적으로 파이썬 2.7에 해당하는 내용을 담고 있습니다만
+파이썬 2.x에도 적용할 수 있을 것입니다. 파이썬 3을 다룬 튜토리얼도 곧 나올 테니 기대하세요!
+
+```python
+# 한 줄짜리 주석은 해시로 시작합니다.
+""" 여러 줄 문자열은 "를 세 개 써서 시작할 수 있고,
+ 주석으로 자주 사용됩니다.
+"""
+
+####################################################
+## 1. 기본 자료형과 연산자
+####################################################
+
+# 숫자
+3 #=> 3
+
+# 수학 연산은 예상하신 대로입니다.
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+35 / 5 #=> 7
+
+# 나눗셈은 약간 까다롭습니다. 정수로 나눈 다음 결과값을 자동으로 내림합니다.
+5 / 2 #=> 2
+
+# 나눗셈 문제를 해결하려면 float에 대해 알아야 합니다.
+2.0 # 이것이 float입니다.
+11.0 / 4.0 #=> 2.75 훨씬 낫네요
+
+# 괄호를 이용해 연산자 우선순위를 지정합니다.
+(1 + 3) * 2 #=> 8
+
+# 불린(Boolean) 값은 기본형입니다.
+True
+False
+
+# not을 이용해 부정합니다.
+not True #=> False
+not False #=> True
+
+# 동일성 연산자는 ==입니다.
+1 == 1 #=> True
+2 == 1 #=> False
+
+# 불일치 연산자는 !=입니다.
+1 != 1 #=> False
+2 != 1 #=> True
+
+# 그밖의 비교 연산자는 다음과 같습니다.
+1 < 10 #=> True
+1 > 10 #=> False
+2 <= 2 #=> True
+2 >= 2 #=> True
+
+# 비교 연산을 연결할 수도 있습니다!
+1 < 2 < 3 #=> True
+2 < 3 < 2 #=> False
+
+# 문자열은 "나 '로 생성합니다.
+"This is a string."
+'This is also a string.'
+
+# 문자열도 연결할 수 있습니다!
+"Hello " + "world!" #=> "Hello world!"
+
+# 문자열은 문자로 구성된 리스트로 간주할 수 있습니다.
+"This is a string"[0] #=> 'T'
+
+# %는 다음과 같이 문자열을 형식화하는 데 사용할 수 있습니다:
+"%s can be %s" % ("strings", "interpolated")
+
+# 문자열을 형식화하는 새로운 방법은 format 메서드를 이용하는 것입니다.
+# 이 메서드를 이용하는 방법이 더 선호됩니다.
+"{0} can be {1}".format("strings", "formatted")
+# 자릿수를 세기 싫다면 키워드를 이용해도 됩니다.
+"{name} wants to eat {food}".format(name="Bob", food="lasagna")
+
+# None은 객체입니다.
+None #=> None
+
+# 객체와 None을 비교할 때는 동일성 연산자인 `==`를 사용해서는 안 됩니다.
+# 대신 `is`를 사용하세요.
+"etc" is None #=> False
+None is None #=> True
+
+# 'is' 연산자는 객체의 식별자를 검사합니다.
+# 기본형 값을 다룰 때는 이 연산자가 그다지 유용하지 않지만
+# 객체를 다룰 때는 매우 유용합니다.
+
+# None, 0, 빈 문자열/리스트는 모두 False로 평가됩니다.
+# 그밖의 다른 값은 모두 True입니다
+0 == False #=> True
+"" == False #=> True
+
+
+####################################################
+## 2. 변수와 컬렉션
+####################################################
+
+# 뭔가를 출력하는 것은 상당히 쉽습니다.
+print "I'm Python. Nice to meet you!"
+
+
+# 변수에 값을 할당하기 전에 변수를 반드시 선언하지 않아도 됩니다.
+some_var = 5 # 명명관례는 '밑줄이_포함된_소문자'입니다.
+some_var #=> 5
+
+# 미할당된 변수에 접근하면 예외가 발생합니다.
+# 예외 처리에 관해서는 '제어 흐름'을 참고하세요.
+some_other_var # 이름 오류가 발생
+
+# 표현식으로도 사용할 수 있습니다.
+"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
+
+# 리스트는 순차 항목을 저장합니다.
+li = []
+# 미리 채워진 리스트로 시작할 수도 있습니다.
+other_li = [4, 5, 6]
+
+# append를 이용해 리스트 끝에 항목을 추가합니다.
+li.append(1) #li는 이제 [1]입니다.
+li.append(2) #li는 이제 [1, 2]입니다.
+li.append(4) #li는 이제 [1, 2, 4]입니다.
+li.append(3) #li는 이제 [1, 2, 4, 3]입니다.
+# pop을 이용해 끝에서부터 항목을 제거합니다.
+li.pop() #=> 3이 반환되고 li는 이제 [1, 2, 4]입니다.
+# 다시 넣어봅시다
+li.append(3) # li는 이제 다시 [1, 2, 4, 3]가 됩니다.
+
+# 배열에서 했던 것처럼 리스트에도 접근할 수 있습니다.
+li[0] #=> 1
+# 마지막 요소를 봅시다.
+li[-1] #=> 3
+
+# 범위를 벗어나서 접근하면 IndexError가 발생합니다.
+li[4] # IndexError가 발생
+
+# 슬라이스 문법을 통해 범위를 지정해서 값을 조회할 수 있습니다.
+# (이 문법을 통해 간편하게 범위를 지정할 수 있습니다.)
+li[1:3] #=> [2, 4]
+# 앞부분을 생략합니다.
+li[2:] #=> [4, 3]
+# 끝부분을 생략합니다.
+li[:3] #=> [1, 2, 4]
+
+# del로 임의의 요소를 제거할 수 있습니다.
+del li[2] # li is now [1, 2, 3]
+
+# 리스트를 추가할 수도 있습니다.
+li + other_li #=> [1, 2, 3, 4, 5, 6] - 참고: li와 other_li는 그대로 유지됩니다.
+
+# extend로 리스트를 연결합니다.
+li.extend(other_li) # 이제 li는 [1, 2, 3, 4, 5, 6]입니다.
+
+# in으로 리스트 안에서 특정 요소가 존재하는지 확인합니다.
+1 in li #=> True
+
+# len으로 길이를 검사합니다.
+len(li) #=> 6
+
+# 튜플은 리스트와 비슷하지만 불변성을 띱니다.
+tup = (1, 2, 3)
+tup[0] #=> 1
+tup[0] = 3 # TypeError가 발생
+
+# 튜플에 대해서도 리스트에서 할 수 있는 일들을 모두 할 수 있습니다.
+len(tup) #=> 3
+tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tup[:2] #=> (1, 2)
+2 in tup #=> True
+
+# 튜플(또는 리스트)을 변수로 풀 수 있습니다.
+a, b, c = (1, 2, 3) # 이제 a는 1, b는 2, c는 3입니다
+# 괄호를 빼면 기본적으로 튜플이 만들어집니다.
+d, e, f = 4, 5, 6
+# 이제 두 값을 바꾸는 게 얼마나 쉬운지 확인해 보세요.
+e, d = d, e # 이제 d는 5이고 e는 4입니다.
+
+# 딕셔너리는 매핑을 저장합니다.
+empty_dict = {}
+# 다음은 값을 미리 채운 딕셔너리입니다.
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# []를 이용해 값을 조회합니다.
+filled_dict["one"] #=> 1
+
+# 모든 키를 리스트로 구합니다.
+filled_dict.keys() #=> ["three", "two", "one"]
+# 참고 - 딕셔너리 키의 순서는 보장되지 않습니다.
+# 따라서 결과가 이와 정확히 일치하지 않을 수도 있습니다.
+
+# 모든 값을 리스트로 구합니다.
+filled_dict.values() #=> [3, 2, 1]
+# 참고 - 키 순서와 관련해서 위에서 설명한 내용과 같습니다.
+
+# in으로 딕셔너리 안에 특정 키가 존재하는지 확인합니다.
+"one" in filled_dict #=> True
+1 in filled_dict #=> False
+
+# 존재하지 않는 키를 조회하면 KeyError가 발생합니다.
+filled_dict["four"] # KeyError
+
+# get 메서드를 이용하면 KeyError가 발생하지 않습니다.
+filled_dict.get("one") #=> 1
+filled_dict.get("four") #=> None
+# get 메서드는 값이 누락된 경우 기본 인자를 지원합니다.
+filled_dict.get("one", 4) #=> 1
+filled_dict.get("four", 4) #=> 4
+
+# setdefault 메서드는 딕셔너리에 새 키-값 쌍을 추가하는 안전한 방법입니다.
+filled_dict.setdefault("five", 5) #filled_dict["five"]는 5로 설정됩니다.
+filled_dict.setdefault("five", 6) #filled_dict["five"]는 여전히 5입니다.
+
+
+# 세트는 집합을 저장합니다.
+empty_set = set()
+# 다수의 값으로 세트를 초기화합니다.
+some_set = set([1,2,2,3,4]) # 이제 some_set는 set([1, 2, 3, 4])입니다.
+
+# 파이썬 2.7부터는 {}를 세트를 선언하는 데 사용할 수 있습니다.
+filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
+
+# 세트에 항목을 추가합니다.
+filled_set.add(5) # 이제 filled_set는 {1, 2, 3, 4, 5}입니다.
+
+# &을 이용해 교집합을 만듭니다.
+other_set = {3, 4, 5, 6}
+filled_set & other_set #=> {3, 4, 5}
+
+# |를 이용해 합집합을 만듭니다.
+filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+
+# -를 이용해 차집합을 만듭니다.
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# in으로 세트 안에 특정 요소가 존재하는지 검사합니다.
+2 in filled_set #=> True
+10 in filled_set #=> False
+
+
+####################################################
+## 3. 제어 흐름
+####################################################
+
+# 변수를 만들어 봅시다.
+some_var = 5
+
+# 다음은 if 문입니다. 파이썬에서는 들여쓰기가 대단히 중요합니다!
+# 다음 코드를 실행하면 "some_var is smaller than 10"가 출력됩니다.
+if some_var > 10:
+ print "some_var is totally bigger than 10."
+elif some_var < 10: # elif 절은 선택사항입니다.
+ print "some_var is smaller than 10."
+else: # 이 부분 역시 선택사항입니다.
+ print "some_var is indeed 10."
+
+
+"""
+for 루프는 리스트를 순회합니다.
+아래 코드는 다음과 같은 내용을 출력합니다:
+ dog is a mammal
+ cat is a mammal
+ mouse is a mammal
+"""
+for animal in ["dog", "cat", "mouse"]:
+ # %로 형식화된 문자열에 값을 채워넣을 수 있습니다.
+ print "%s is a mammal" % animal
+
+"""
+`range(number)`는 숫자 리스트를 반환합니다.
+이때 숫자 리스트의 범위는 0에서 지정한 숫자까지입니다.
+아래 코드는 다음과 같은 내용을 출력합니다:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print i
+
+"""
+while 루프는 조건이 더는 충족되지 않을 때까지 진행됩니다.
+prints:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print x
+ x += 1 # x = x + 1의 축약형
+
+# try/except 블록을 이용한 예외 처리
+
+# 파이썬 2.6 및 상위 버전에서 동작하는 코드
+try:
+ # raise를 이용해 오류를 발생시킵니다
+ raise IndexError("This is an index error")
+except IndexError as e:
+ pass # pass는 단순 no-op 연산입니다. 보통 이곳에 복구 코드를 작성합니다.
+
+
+####################################################
+## 4. 함수
+####################################################
+
+# 새 함수를 만들 때 def를 사용합니다.
+def add(x, y):
+ print "x is %s and y is %s" % (x, y)
+ return x + y # return 문을 이용해 값을 반환합니다.
+
+# 매개변수를 전달하면서 함수를 호출
+add(5, 6) #=> "x is 5 and y is 6"가 출력되고 11이 반환됨
+
+# 함수를 호출하는 또 다른 방법은 키워드 인자를 지정하는 방법입니다.
+add(y=6, x=5) # 키워드 인자는 순서에 구애받지 않습니다.
+
+# 위치 기반 인자를 임의 개수만큼 받는 함수를 정의할 수 있습니다.
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# 키워드 인자를 임의 개수만큼 받는 함수 또한 정의할 수 있습니다.
+def keyword_args(**kwargs):
+ return kwargs
+
+# 이 함수를 호출해서 어떤 일이 일어나는지 확인해 봅시다.
+keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+
+# 원한다면 한 번에 두 가지 종류의 인자를 모두 받는 함수를 정의할 수도 있습니다.
+def all_the_args(*args, **kwargs):
+ print args
+ print kwargs
+"""
+all_the_args(1, 2, a=3, b=4)를 실행하면 다음과 같은 내용이 출력됩니다:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# 함수를 호출할 때 varargs/kwargs와 반대되는 일을 할 수 있습니다!
+# *를 이용해 튜플을 확장하고 **를 이용해 kwargs를 확장합니다.
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # foo(1, 2, 3, 4)와 같음
+all_the_args(**kwargs) # foo(a=3, b=4)와 같음
+all_the_args(*args, **kwargs) # foo(1, 2, 3, 4, a=3, b=4)와 같음
+
+# 파이썬에는 일급 함수가 있습니다
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) #=> 13
+
+# 게다가 익명 함수도 있습니다.
+(lambda x: x > 2)(3) #=> True
+
+# 내장된 고차 함수(high order function)도 있습니다.
+map(add_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# 맵과 필터에 리스트 조건 제시법(list comprehensions)을 사용할 수 있습니다.
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. 클래스
+####################################################
+
+# 클래스를 하나 만들기 위해 특정 객체의 하위 클래스를 만들 수 있습니다.
+class Human(object):
+
+ # 클래스 속성은 이 클래스의 모든 인스턴스에서 공유합니다.
+ species = "H. sapiens"
+
+ # 기본 초기화자
+ def __init__(self, name):
+ # 인자를 인스턴스의 name 속성에 할당합니다.
+ self.name = name
+
+ # 모든 인스턴스 메서드에서는 self를 첫 번째 인자로 받습니다.
+ def say(self, msg):
+ return "%s: %s" % (self.name, msg)
+
+ # 클래스 메서드는 모든 인스턴스에서 공유합니다.
+ # 클래스 메서드는 호출하는 클래스를 첫 번째 인자로 호출됩니다.
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # 정적 메서드는 클래스나 인스턴스 참조 없이도 호출할 수 있습니다.
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# 클래스 인스턴스화
+i = Human(name="Ian")
+print i.say("hi") # "Ian: hi"가 출력됨
+
+j = Human("Joel")
+print j.say("hello") # "Joel: hello"가 출력됨
+
+# 클래스 메서드를 호출
+i.get_species() #=> "H. sapiens"
+
+# 공유 속성을 변경
+Human.species = "H. neanderthalensis"
+i.get_species() #=> "H. neanderthalensis"
+j.get_species() #=> "H. neanderthalensis"
+
+# 정적 메서드를 호출
+Human.grunt() #=> "*grunt*"
+
+
+####################################################
+## 6. 모듈
+####################################################
+
+# 다음과 같이 모듈을 임포트할 수 있습니다.
+import math
+print math.sqrt(16) #=> 4
+
+# 모듈의 특정 함수를 호출할 수 있습니다.
+from math import ceil, floor
+print ceil(3.7) #=> 4.0
+print floor(3.7) #=> 3.0
+
+# 모듈의 모든 함수를 임포트할 수 있습니다.
+# Warning: this is not recommended
+from math import *
+
+# 모듈 이름을 축약해서 쓸 수 있습니다.
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# 파이썬 모듈은 평범한 파이썬 파일에 불과합니다.
+# 직접 모듈을 작성해서 그것들을 임포트할 수 있습니다.
+# 모듈의 이름은 파일의 이름과 같습니다.
+
+# 다음과 같은 코드로 모듈을 구성하는 함수와 속성을 확인할 수 있습니다.
+import math
+dir(math)
+
+
+```
+
+## 더 배울 준비가 되셨습니까?
+
+### 무료 온라인 참고자료
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [The Official Docs](http://docs.python.org/2.6/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/2/)
+
+### 파이썬 관련 도서
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20) \ No newline at end of file
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
new file mode 100644
index 00000000..b92e3218
--- /dev/null
+++ b/objective-c.html.markdown
@@ -0,0 +1,310 @@
+---
+
+language: Objective-C
+contributors:
+ - ["Eugene Yagrushkin", "www.about.me/yagrushkin"]
+ - ["Yannick Loriot", "https://github.com/YannickL"]
+filename: LearnObjectiveC.m
+
+---
+
+Objective-C is the main programming language used by Apple for the OS X and iOS operating systems and their respective frameworks, Cocoa and Cocoa Touch.
+It is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.
+
+```cpp
+// Single-line comments start with //
+
+/*
+Multi-line comments look like this.
+*/
+
+// Imports the Foundation headers with #import
+#import <Foundation/Foundation.h>
+#import "MyClass.h"
+
+// Your program's entry point is a function called
+// main with an integer return type.
+int main (int argc, const char * argv[])
+{
+ // Create an autorelease pool to manage the memory into the program
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+
+ // Use NSLog to print lines to the console
+ NSLog(@"Hello World!"); // Print the string "Hello World!"
+
+ ///////////////////////////////////////
+ // Types & Variables
+ ///////////////////////////////////////
+
+ // Primitive declarations
+ int myPrimitive1 = 1;
+ long myPrimitive2 = 234554664565;
+
+ // Object declarations
+ // Put the * in front of the variable names for strongly-typed object declarations
+ MyClass *myObject1 = nil; // Strong typing
+ id myObject2 = nil; // Weak typing
+ // %@ is an object
+ // 'description' is a convention to display the value of the Objects
+ NSLog(@"%@ and %@", myObject1, [myObject2 description]); // Print "(null) and (null)"
+
+ // String
+ NSString *worldString = @"World";
+ NSLog(@"Hello %@!", worldString); // Print "Hello World!"
+
+ // Character literals
+ NSNumber *theLetterZNumber = @'Z';
+ char theLetterZ = [theLetterZNumber charValue];
+ NSLog(@"%c", theLetterZ);
+
+ // Integral literals
+ NSNumber *fortyTwoNumber = @42;
+ int fortyTwo = [fortyTwoNumber intValue];
+ NSLog(@"%i", fortyTwo);
+
+ NSNumber *fortyTwoUnsignedNumber = @42U;
+ unsigned int fortyTwoUnsigned = [fortyTwoUnsignedNumber unsignedIntValue];
+ NSLog(@"%u", fortyTwoUnsigned);
+
+ NSNumber *fortyTwoShortNumber = [NSNumber numberWithShort:42];
+ short fortyTwoShort = [fortyTwoShortNumber shortValue];
+ NSLog(@"%hi", fortyTwoShort);
+
+ NSNumber *fortyTwoLongNumber = @42L;
+ long fortyTwoLong = [fortyTwoLongNumber longValue];
+ NSLog(@"%li", fortyTwoLong);
+
+ // Floating point literals
+ NSNumber *piFloatNumber = @3.141592654F;
+ float piFloat = [piFloatNumber floatValue];
+ NSLog(@"%f", piFloat);
+
+ NSNumber *piDoubleNumber = @3.1415926535;
+ piDouble = [piDoubleNumber doubleValue];
+ NSLog(@"%f", piDouble);
+
+ // BOOL literals
+ NSNumber *yesNumber = @YES;
+ NSNumber *noNumber = @NO;
+
+ // Array object
+ NSArray *anArray = @[@1, @2, @3, @4];
+ NSNumber *thirdNumber = anArray[2];
+ NSLog(@"Third number = %@", thirdObject); // Print "Third number = 3"
+
+ // Dictionary object
+ NSDictionary *aDictionary = @{ @"key1" : @"value1", @"key2" : @"value2" };
+ NSObject *valueObject = aDictionary[@"A Key"];
+ NSLog(@"Object = %@", valueObject); // Print "Object = (null)"
+
+ ///////////////////////////////////////
+ // Operators
+ ///////////////////////////////////////
+
+ // The operators works like in the C language
+ // For example:
+ 2 + 5; // => 7
+ 4.2f + 5.1f; // => 9.3f
+ 3 == 2; // => 0 (NO)
+ 3 != 2; // => 1 (YES)
+ 1 && 1; // => 1 (Logical and)
+ 0 || 1; // => 1 (Logical or)
+ ~0x0F; // => 0xF0 (bitwise negation)
+ 0x0F & 0xF0; // => 0x00 (bitwise AND)
+ 0x01 << 1; // => 0x02 (bitwise left shift (by 1))
+
+ ///////////////////////////////////////
+ // Control Structures
+ ///////////////////////////////////////
+
+ // If-Else statement
+ if (NO)
+ {
+ NSLog(@"I am never run");
+ } else if (0)
+ {
+ NSLog(@"I am also never run");
+ } else
+ {
+ NSLog(@"I print");
+ }
+
+ // Switch statement
+ switch (2)
+ {
+ case 0:
+ {
+ NSLog(@"I am never run");
+ } break;
+ case 1:
+ {
+ NSLog(@"I am also never run");
+ } break;
+ default:
+ {
+ NSLog(@"I print");
+ } break;
+ }
+
+ // While loops statements
+ int ii = 0;
+ while (ii < 4)
+ {
+ NSLog(@"%d,", ii++); // ii++ increments ii in-place, after using its value.
+ } // => prints "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // For loops statements
+ int jj;
+ for (jj=0; jj < 4; jj++)
+ {
+ NSLog(@"%d,", jj++);
+ } // => prints "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // Foreach statements
+ NSArray *values = @[@0, @1, @2, @3];
+ for (NSNumber *value in values)
+ {
+ NSLog(@"%@,", value);
+ } // => prints "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // Try-Catch-Finally statements
+ @try
+ {
+ // Your statements here
+ @throw [NSException exceptionWithName:@"FileNotFoundException"
+ reason:@"File Not Found on System" userInfo:nil];
+ } @catch (NSException * e)
+ {
+ NSLog(@"Exception: %@", e);
+ } @finally
+ {
+ NSLog(@"Finally");
+ } // => prints "Exception: File Not Found on System"
+ // "Finally"
+
+ ///////////////////////////////////////
+ // Objects
+ ///////////////////////////////////////
+
+ // Create an object instance by allocating memory and initializing it.
+ // An object is not fully functional until both steps have been completed.
+ MyClass *myObject = [[MyClass alloc] init];
+
+ // The Objective-C model of object-oriented programming is based on message
+ // passing to object instances.
+ // In Objective-C one does not simply call a method; one sends a message.
+ [myObject instanceMethodWithParameter:@"Steve Jobs"];
+
+ // Clean up the memory you used into your program
+ [pool drain];
+
+ // End the program
+ return 0;
+}
+
+///////////////////////////////////////
+// Classes And Functions
+///////////////////////////////////////
+
+// Declare your class in a header(MyClass.h) file:
+// Class Declaration Syntax:
+// @interface ClassName : ParentClassName <ImplementedProtocols>
+// {
+// Member variable declarations;
+// }
+// -/+ (type) Method declarations;
+// @end
+@interface MyClass : NSObject <MyCustomProtocol>
+{
+ int count;
+ id data;
+ NSString *name;
+}
+// Convenience notation to auto generate public getter and setter
+@property int count;
+@property (copy) NSString *name; // Copy the object during assignment.
+@property (readonly) id data; // Declare only a getter method.
+
+// Methods
++/- (return type)methodSignature:(Parameter Type *)parameterName;
+
+// + for class method
++ (NSString *)classMethod;
+
+// - for instance method
+- (NSString *)instanceMethodWithParmeter:(NSString *)string;
+- (NSNumber *)methodAParameterAsString:(NSString*)string andAParameterAsNumber:(NSNumber *)number;
+
+@end
+
+// Implement the methods in an implementation (MyClass.m) file:
+
+@implementation UserObject
+
+// Call when the object is releasing
+- (void)dealloc
+{
+}
+
+// Constructors are a way of creating classes
+// This is a default constructor which is called when the object is creating
+- (id)init
+{
+ if ((self = [super init]))
+ {
+ self.count = 1;
+ }
+ return self;
+}
+
++ (NSString *)classMethod
+{
+ return [[self alloc] init];
+}
+
+- (NSString *)instanceMethodWithParmeter:(NSString *)string
+{
+ return @"New string";
+}
+
+- (NSNumber *)methodAParameterAsString:(NSString*)string andAParameterAsNumber:(NSNumber *)number
+{
+ return @42;
+}
+
+// Methods declared into MyProtocol
+- (void)myProtocolMethod
+{
+ // statements
+}
+
+@end
+
+/*
+ * A protocol declares methods that can be implemented by any class.
+ * Protocols are not classes themselves. They simply define an interface
+ * that other objects are responsible for implementing.
+ */
+@protocol MyProtocol
+ - (void)myProtocolMethod;
+@end
+
+
+
+```
+## Further Reading
+
+[Wikipedia Objective-C](http://en.wikipedia.org/wiki/Objective-C)
+
+[Learning Objective-C](http://developer.apple.com/library/ios/referencelibrary/GettingStarted/Learning_Objective-C_A_Primer/)
+
+[iOS For High School Students: Getting Started](http://www.raywenderlich.com/5600/ios-for-high-school-students-getting-started)
diff --git a/php.html.markdown b/php.html.markdown
index ce228870..083574ee 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -440,6 +440,11 @@ class MyClass
static $staticVar = 'static';
+ // Static variables and their visibility
+ public static $publicStaticVar = 'publicStatic';
+ private static $privateStaticVar = 'privateStatic'; // Accessible within the class only
+ protected static $protectedStaticVar = 'protectedStatic'; // Accessible from the class and subclasses
+
// Properties must declare their visibility
public $property = 'public';
public $instanceProp;
diff --git a/pt-br/elisp-pt.html.markdown b/pt-br/elisp-pt.html.markdown
new file mode 100644
index 00000000..9031cad9
--- /dev/null
+++ b/pt-br/elisp-pt.html.markdown
@@ -0,0 +1,359 @@
+---
+language: elisp
+contributors:
+ - ["Bastien Guerry", "http://bzg.fr"]
+translators:
+ - ["Lucas Tadeu Teixeira", "http://ltt.me"]
+lang: pt-br
+filename: learn-emacs-lisp-pt.el
+---
+
+```scheme
+;; Introdução ao Emacs Lisp em 15 minutos (v0.2d)
+;;
+;; Autor: Bastien / @bzg2 / http://bzg.fr
+;;
+;; Antes de começar, leia este texto escrito Peter Norvig:
+;; http://norvig.com/21-days.html
+;;
+;; Agora instale GNU Emacs 24.3:
+;;
+;; Debian: apt-get install emacs (ou veja as instruções da sua distribuição)
+;; OSX: http://emacsformacosx.com/emacs-builds/Emacs-24.3-universal-10.6.8.dmg
+;; Windows: http://ftp.gnu.org/gnu/windows/emacs/emacs-24.3-bin-i386.zip
+;;
+;; Informações mais gerais podem ser encontradas em:
+;; http://www.gnu.org/software/emacs/#Obtaining
+
+;; Aviso importante:
+;;
+;; Realizar este tutorial não danificará seu computador, a menos
+;; que você fique tão irritado a ponto de jogá-lo no chão. Neste caso,
+;; me abstenho de qualquer responsabilidade. Divirta-se!
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; Abra o Emacs.
+;;
+;; Aperte a tecla `q' para ocultar a mensagem de boas vindas.
+;;
+;; Agora olhe para a linha cinza na parte inferior da janela:
+;;
+;; "*scratch*" é o nome do espaço de edição em que você se encontra.
+;; Este espaço de edição é chamado "buffer".
+;;
+;; O buffer de rascunho (i.e., "scratch") é o buffer padrão quando
+;; o Emacs é aberto. Você nunca está editando arquivos: você está
+;; editando buffers que você pode salvar em um arquivo.
+;;
+;; "Lisp interaction" refere-se a um conjunto de comandos disponíveis aqui.
+;;
+;; O Emacs possui um conjunto de comandos embutidos (disponíveis em
+;; qualquer buffer) e vários subconjuntos de comandos disponíveis
+;; quando você ativa um modo específico. Aqui nós utilizamos
+;; `lisp-interaction-mode', que possui comandos para interpretar e navegar
+;; em código Elisp.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; Pontos e vírgulas iniciam comentários em qualquer parte de uma linha.
+;;
+;; Programas codificados em Elisp são compostos por expressões simbólicas
+;; (conhecidas também por "sexps"):
+(+ 2 2)
+
+;; Esta expressão simbólica significa "Some 2 e 2".
+
+;; "Sexps" são envoltas em parêntese, possivelmente aninhados:
+(+ 2 (+ 1 1))
+
+;; Uma expressão simbólica contém átomos ou outras expressões
+;; simbólicas. Nos exemplos acima, 1 e 2 são átomos;
+;; (+ 2 (+ 1 1)) e (+ 1 1) são expressões simbólicas.
+
+;; No modo `lisp-interaction-mode' você pode interpretar "sexps".
+;; Posicione o cursor logo após o parêntese de fechamento e,
+;; então, segure apertado Ctrl e aperte a tecla j ("C-j", em resumo).
+
+(+ 3 (+ 1 2))
+;; ^ posicione o cursor aqui
+;; `C-j' => 6
+
+;; `C-j' insere o resultado da interpretação da expressão no buffer.
+
+;; `C-xC-e' exibe o mesmo resultado na linha inferior do Emacs,
+;; chamada de "mini-buffer". Nós geralmente utilizaremos `C-xC-e',
+;; já que não queremos poluir o buffer com texto desnecessário.
+
+;; `setq' armazena um valor em uma variável:
+(setq my-name "Bastien")
+;; `C-xC-e' => "Bastien" (texto exibido no mini-buffer)
+
+;; `insert' insere "Hello!" na posição em que se encontra seu cursor:
+(insert "Hello!")
+;; `C-xC-e' => "Hello!"
+
+;; Nós executamos `insert' com apenas um argumento ("Hello!"), mas
+;; mais argumentos podem ser passados -- aqui utilizamos dois:
+
+(insert "Hello" " world!")
+;; `C-xC-e' => "Hello world!"
+
+;; Você pode utilizar variávies no lugar de strings:
+(insert "Hello, I am " my-name)
+;; `C-xC-e' => "Hello, I am Bastien"
+
+;; Você pode combinar "sexps" em funções:
+(defun hello () (insert "Hello, I am " my-name))
+;; `C-xC-e' => hello
+
+;; Você pode interpretar chamadas de funções:
+(hello)
+;; `C-xC-e' => Hello, I am Bastien
+
+;; Os parêntesis vazios na definição da função significam que ela
+;; não aceita argumentos. Mas sempre utilizar `my-name' é um tédio!
+;; Vamos dizer à função para aceitar um argumento (o argumento é
+;; chamado "name"):
+
+(defun hello (name) (insert "Hello " name))
+;; `C-xC-e' => hello
+
+;; Agora vamos executar a função com a string "you" como o valor
+;; para seu único parâmetro:
+(hello "you")
+;; `C-xC-e' => "Hello you"
+
+;; Aí sim!
+
+;; Respire um pouco.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; Agora mude para um novo buffer chamado "*test*":
+
+(switch-to-buffer-other-window "*test*")
+;; `C-xC-e'
+;; => [a tela exibirá duas janelas e o cursor estará no buffer *test*]
+
+;; Posicione o mouse sobre a janela superior e clique com o botão
+;; esquerdo para voltar. Ou você pode utilizar `C-xo' (i.e. segure
+;; ctrl-x e aperte o) para voltar para a outra janela, de forma interativa.
+
+;; Você pode combinar várias "sexps" com `progn':
+(progn
+ (switch-to-buffer-other-window "*test*")
+ (hello "you"))
+;; `C-xC-e'
+;; => [A tela exibirá duas janelas e o cursor estará no buffer *test*]
+
+;; Agora, se você não se importar, pararei de pedir que você aperte
+;; `C-xC-e': faça isso para cada "sexp" que escrevermos.
+
+;; Sempre volte para o buffer *scratch* com o mouse ou `C-xo'.
+
+;; Frequentemente, é útil apagar o conteúdo do buffer:
+(progn
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ (hello "there"))
+
+;; Ou voltar para a outra janela:
+(progn
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ (hello "you")
+ (other-window 1))
+
+;; Você pode armazenar um valor em uma variável local utilizando `let':
+(let ((local-name "you"))
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ (hello local-name)
+ (other-window 1))
+
+;; Neste caso, não é necessário utilizar `progn' já que `let' combina
+;; várias "sexps".
+
+;; Vamos formatar uma string:
+(format "Hello %s!\n" "visitor")
+
+;; %s é um espaço reservado para uma string, substituído por "visitor".
+;; \n é um caractere de nova linha.
+
+;; Vamos refinar nossa função utilizando `format':
+(defun hello (name)
+ (insert (format "Hello %s!\n" name)))
+
+(hello "you")
+
+;; Vamos criar outra função que utilize `let':
+(defun greeting (name)
+ (let ((your-name "Bastien"))
+ (insert (format "Hello %s!\n\nI am %s."
+ name ; the argument of the function
+ your-name ; the let-bound variable "Bastien"
+ ))))
+
+;; E executá-la:
+(greeting "you")
+
+;; Algumas funções são interativas:
+(read-from-minibuffer "Enter your name: ")
+
+;; Ao ser interpretada, esta função retorna o que você digitou no prompt.
+
+;; Vamos fazer nossa função `greeting' pedir pelo seu nome:
+(defun greeting (from-name)
+ (let ((your-name (read-from-minibuffer "Enter your name: ")))
+ (insert (format "Hello!\n\nI am %s and you are %s."
+ from-name ; the argument of the function
+ your-name ; the let-bound var, entered at prompt
+ ))))
+
+(greeting "Bastien")
+
+;; Vamos finalizá-la fazendo-a exibir os resultados em outra janela:
+(defun greeting (from-name)
+ (let ((your-name (read-from-minibuffer "Enter your name: ")))
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ (insert (format "Hello %s!\n\nI am %s." your-name from-name))
+ (other-window 1)))
+
+;; Agora teste-a:
+(greeting "Bastien")
+
+;; Respire um pouco.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; Vamos armazenar uma lista de nomes:
+(setq list-of-names '("Sarah" "Chloe" "Mathilde"))
+
+;; Pegue o primeiro elemento desta lista utilizando `car':
+(car list-of-names)
+
+;; Pegue uma lista de todos os elementos, exceto o primeiro, utilizando
+;; `cdr':
+(cdr list-of-names)
+
+;; Adicione um elemento ao início da lista com `push':
+(push "Stephanie" list-of-names)
+
+;; NOTA: `car' e `cdr' não modificam a lista, `push' sim.
+;; Esta é uma diferença importante: algumas funções não têm qualquer
+;; efeito colateral (como `car'), enquanto outras sim (como `push').
+
+;; Vamos executar `hello' para cada elemento em `list-of-names':
+(mapcar 'hello list-of-names)
+
+;; Refine `greeting' para saudar todos os nomes em `list-of-names':
+(defun greeting ()
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ (mapcar 'hello list-of-names)
+ (other-window 1))
+
+(greeting)
+
+;; Você se lembra da função `hello' que nós definimos lá em cima? Ela
+;; recebe um argumento, um nome. `mapcar' executa `hello', sucessivamente,
+;; utilizando cada elemento de `list-of-names' como argumento para `hello'.
+
+;; Agora vamos arrumar, um pouco, o que nós temos escrito no buffer:
+
+(defun replace-hello-by-bonjour ()
+ (switch-to-buffer-other-window "*test*")
+ (goto-char (point-min))
+ (while (search-forward "Hello")
+ (replace-match "Bonjour"))
+ (other-window 1))
+
+;; (goto-char (point-min)) vai para o início do buffer.
+;; (search-forward "Hello") busca pela string "Hello".
+;; (while x y) interpreta a(s) sexp(s) y enquanto x retornar algo.
+;; Se x retornar `nil' (nada), nós saímos do laço.
+
+(replace-hello-by-bonjour)
+
+;; Você deveria ver todas as ocorrências de "Hello" no buffer *test*
+;; substituídas por "Bonjour".
+
+;; Você deveria, também, receber um erro: "Search failed: Hello".
+;;
+;; Para evitar este erro, você precisa dizer ao `search-forward' se ele
+;; deveria parar de buscar em algum ponto no buffer, e se ele deveria
+;; falhar de forma silenciosa quando nada fosse encontrado:
+
+;; (search-forward "Hello" nil t) dá conta do recado:
+
+;; O argumento `nil' diz: a busca não está limitada a uma posição.
+;; O argumento `t' diz: falhe silenciosamente quando nada for encontrado.
+
+;; Nós utilizamos esta "sexp" na função abaixo, que não gera um erro:
+
+(defun hello-to-bonjour ()
+ (switch-to-buffer-other-window "*test*")
+ (erase-buffer)
+ ;; Say hello to names in `list-of-names'
+ (mapcar 'hello list-of-names)
+ (goto-char (point-min))
+ ;; Replace "Hello" by "Bonjour"
+ (while (search-forward "Hello" nil t)
+ (replace-match "Bonjour"))
+ (other-window 1))
+
+(hello-to-bonjour)
+
+;; Vamos colorir os nomes:
+
+(defun boldify-names ()
+ (switch-to-buffer-other-window "*test*")
+ (goto-char (point-min))
+ (while (re-search-forward "Bonjour \\(.+\\)!" nil t)
+ (add-text-properties (match-beginning 1)
+ (match-end 1)
+ (list 'face 'bold)))
+ (other-window 1))
+
+;; Esta função introduz `re-search-forward': ao invés de buscar
+;; pela string "Bonjour", você busca por um padrão utilizando uma
+;; "expressão regular" (abreviada pelo prefixo "re-").
+
+;; A expressão regular é "Bonjour \\(.+\\)!" e lê-se:
+;; a string "Bonjour ", e
+;; um grupo de | que é o \\( ... \\)
+;; quaisquer caracteres | que é o .
+;; possivelmente repetidos | que é o +
+;; e a string "!".
+
+;; Preparado? Teste!
+
+(boldify-names)
+
+;; `add-text-properties' adiciona... propriedades de texto, como uma fonte.
+
+;; OK, terminamos por aqui. Feliz Hacking!
+
+;; Se você quiser saber mais sobre uma variável ou função:
+;;
+;; C-h v uma-variável RET
+;; C-h f uma-função RET
+;;
+;; Para ler o manual de Emacs Lisp que vem com o Emacs:
+;;
+;; C-h i m elisp RET
+;;
+;; Para ler uma introdução online ao Emacs Lisp:
+;; https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html
+
+;; Agradecimentos a estas pessoas por seu feedback e sugestões:
+;; - Wes Hardaker
+;; - notbob
+;; - Kevin Montuori
+;; - Arne Babenhauserheide
+;; - Alan Schmitt
+;; - LinXitoW
+;; - Aaron Meurer
+```
diff --git a/pt-br/python-pt.html.markdown b/pt-br/python-pt.html.markdown
index e08bb5a8..5afd46d0 100644
--- a/pt-br/python-pt.html.markdown
+++ b/pt-br/python-pt.html.markdown
@@ -4,7 +4,7 @@ contributors:
- ["Louie Dinh", "http://ldinh.ca"]
translators:
- ["Vilson Vieira", "http://automata.cc"]
-lang: pt-bf
+lang: pt-br
filename: learnpython-pt.py
---
diff --git a/ru-ru/clojure-ru.html.markdown b/ru-ru/clojure-ru.html.markdown
new file mode 100644
index 00000000..48c16192
--- /dev/null
+++ b/ru-ru/clojure-ru.html.markdown
@@ -0,0 +1,426 @@
+---
+language: clojure
+filename: learnclojure-ru.clj
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+ - ["Alexey Pirogov", "http://twitter.com/alex_pir"]
+
+---
+
+Clojure, это представитель семейства Lisp-подобных языков, разработанный
+для Java Virtual Machine. Язык идейно гораздо ближе к чистому
+[функциональному программированию](https://ru.wikipedia.org/wiki/%D0%A4%D1%83%D0%BD%D0%BA%D1%86%D0%B8%D0%BE%D0%BD%D0%B0%D0%BB%D1%8C%D0%BD%D0%BE%D0%B5_%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5) чем его прародитель Common Lisp, но в то же время обладает набором инструментов для работы с состоянием,
+таких как [STM](https://ru.wikipedia.org/wiki/Software_transactional_memory).
+
+Благодаря такому сочетанию технологий в одном языке, разработка программ,
+предполагающих конкурентное выполнение, значительно упрощается
+и даже может быть автоматизирована.
+
+(Последующие примеры кода предполагают выполнение в Clojure версии 1.2 и выше)
+
+
+```clojure
+; Комментарии начинаются символом ";".
+
+; Код на языке Clojure записывается в виде "форм",
+; которые представляют собой обычные списки элементов, разделенных пробелами,
+; заключённые в круглые скобки
+;
+; Clojure Reader (инструмент языка, отвечающий за чтение исходного кода),
+; анализируя форму, предполагает, что первым элементом формы (т.е. списка)
+; является функция или макрос, который следует вызвать, передав ему
+; в качестве аргументов остальные элементы списка-формы.
+
+; Первым вызовом в файле должен быть вызов функции ns,
+; которая отвечает за выбор текущего пространства имен (namespace)
+(ns learnclojure-ru)
+
+; Несколько простых примеров:
+
+; str объединяет в единую строку все свои аргументы
+(str "Hello" " " "World") ; => "Hello World"
+
+; Арифметика тоже выглядит несложно
+(+ 1 1) ; => 2
+(- 2 1) ; => 1
+(* 1 2) ; => 2
+(/ 2 1) ; => 2
+
+; Проверка на равенство (Equality)
+(= 1 1) ; => true
+(= 2 1) ; => false
+
+; Для булевой логики вам может понадобиться not
+(not true) ; => false
+
+; Вложенные формы, конечно же, допустимы и работают вполне предсказуемо
+(+ 1 (- 3 2)) ; = 1 + (3 - 2) => 2
+
+; Типы
+;;;;;;;;;;;;;
+
+; Clojure использует типы Java для представления булевых значений,
+; строк и чисел
+; Узнать тип мы можем, использую функцию `class
+(class 1) ; Целочисленные литералы типа по-умолчанию являются java.lang.Long
+(class 1.) ; Числа с плавающей точкой, это java.lang.Double
+(class "") ; Строки всегда заключаются в двойные кавычки
+ ; и представляют собой java.lang.String
+(class false) ; Булевы значения, это экземпляры java.lang.Boolean
+(class nil) ; "Пустое" значение называется "nil"
+
+; Если Вы захотите создать список из чисел, вы можете просто
+; предварить форму списка символом "'", который подскажет Reader`у,
+; что эта форма не требует вычисления
+'(+ 1 2) ; => (+ 1 2)
+; ("'", это краткая запись формы (quote (+ 1 2))
+
+; "Квотированный" список можно вычислить, передав его функции eval
+(eval '(+ 1 2)) ; => 3
+
+; Коллекции и Последовательности
+;;;;;;;;;;;;;;;;;;;
+
+; Списки (Lists) в clojure структурно представляют собой "связанные списки",
+; тогда как Векторы (Vectors), устроены как массивы.
+; Векторы и Списки тоже являются классами Java!
+(class [1 2 3]); => clojure.lang.PersistentVector
+(class '(1 2 3)); => clojure.lang.PersistentList
+
+; Список может быть записан, как (1 2 3), но в этом случае
+; он будет воспринят reader`ом, как вызов функции.
+; Есть два способа этого избежать:
+; '(1 2 3) - квотирование,
+; (list 1 2 3) - явное конструирование списка с помощью функции list.
+
+; "Коллекции", это некие наборы данных
+; И списки, и векторы являются коллекциями:
+(coll? '(1 2 3)) ; => true
+(coll? [1 2 3]) ; => true
+
+; "Последовательности" (seqs), это абстракция над наборами данных,
+; элементы которых "упакованы" последовательно.
+; Списки - последовательности, а вектора - нет.
+(seq? '(1 2 3)) ; => true
+(seq? [1 2 3]) ; => false
+
+; Любая seq предоставляет доступ только к началу последовательности данных,
+; не предоставляя информацию о её длине.
+; При этом последовательности могут быть и бесконечными,
+; т.к. являются ленивыми и предоставляют данные только по требованию!
+(range 4) ; => (0 1 2 3)
+(range) ; => (0 1 2 3 4 ...) (бесконечная последовательность!)
+(take 4 (range)) ; (0 1 2 3)
+
+; Добавить элемент в начало списка или вектора можно с помощью функции cons
+(cons 4 [1 2 3]) ; => (4 1 2 3)
+(cons 4 '(1 2 3)) ; => (4 1 2 3)
+
+; Функция conj добавляет элемент в коллекцию
+; максимально эффективным для неё способом.
+; Для списков эффективно добавление в начло, а для векторов - в конец.
+(conj [1 2 3] 4) ; => [1 2 3 4]
+(conj '(1 2 3) 4) ; => (4 1 2 3)
+
+; Функция concat объединяет несколько списков и векторов в единый список
+(concat [1 2] '(3 4)) ; => (1 2 3 4)
+
+; Работать с коллекциями удобно с помощью функций filter и map
+(map inc [1 2 3]) ; => (2 3 4)
+(filter even? [1 2 3]) ; => (2)
+
+; reduce поможет "свернуть" коллекцию
+(reduce + [1 2 3 4])
+; = (+ (+ (+ 1 2) 3) 4)
+; => 10
+
+; Вызывая reduce, мы можем указать начальное значение
+(reduce conj [] '(3 2 1))
+; = (conj (conj (conj [] 3) 2) 1)
+; => [3 2 1]
+
+; Функции
+;;;;;;;;;;;;;;;;;;;;;
+
+; Функция создается специальной формой fn.
+; "Тело"" функции может состоять из нескольких форм,
+; но результатом вызова функции всегда будет результат вычисления
+; последней из них.
+(fn [] "Hello World") ; => fn
+
+; (Вызов функции требует "оборачивания" fn-формы в форму вызова)
+((fn [] "Hello World")) ; => "Hello World"
+
+; Назначить значению имя можно специальной формой def
+(def x 1)
+x ; => 1
+
+; Назначить имя можно любому значению, в т.ч. и функции:
+(def hello-world (fn [] "Hello World"))
+(hello-world) ; => "Hello World"
+
+; Поскольку именование функций - очень частая операция,
+; clojure позволяет, сделать это проще:
+(defn hello-world [] "Hello World")
+
+; Вектор [] в форме описания функции, следующий сразу за именем,
+; описывает параметры функции:
+(defn hello [name]
+ (str "Hello " name))
+(hello "Steve") ; => "Hello Steve"
+
+; Одна функция может иметь сразу несколько наборов аргументов:
+(defn hello3
+ ([] "Hello World")
+ ([name] (str "Hello " name)))
+(hello3 "Jake") ; => "Hello Jake"
+(hello3) ; => "Hello World"
+
+; Также функция может иметь набор аргументов переменной длины
+(defn count-args [& args] ; args будет содержать seq аргументов
+ (str "You passed " (count args) " args: " args))
+(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)"
+
+; Можно комбинировать оба подхода задания аргументов
+(defn hello-count [name & args]
+ (str "Hello " name ", you passed " (count args) " extra args"))
+(hello-count "Finn" 1 2 3)
+; => "Hello Finn, you passed 3 extra args"
+
+; Для создания анонимных функций есть специальный синтаксис:
+; функциональные литералы
+(def hello2 #(str "Hello " %1))
+(hello2 "Fanny") ; => "Hello Fanny"
+
+; такие функциональные литералы удобно использовать с map, filter и reduce
+(map #(* 10 %1) [1 2 3 5]) ; => (10 20 30 50)
+(filter #(> %1 3) [1 2 3 4 5 6 7]) ; => (4 5 6 7)
+(reduce #(str %1 "," %2) [1 2 3 4]) ; => "1,2,3,4"
+
+; Отображения (Maps)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; Hash maps и array maps имеют одинаковый интерфейс.
+; Hash maps производят поиск по ключу быстрее, но не сохраняют порядок ключей
+(class {:a 1 :b 2 :c 3}) ; => clojure.lang.PersistentArrayMap
+(class (hash-map :a 1 :b 2 :c 3)) ; => clojure.lang.PersistentHashMap
+
+; Array maps автоматически преобразуются в hash maps,
+; как только разрастутся до определенного размера
+
+; Отображения могут использовать в качестве ключей любые хэшируемые значения,
+; однако предпочтительными являются ключи,
+; являющиеся "ключевыми словами" (keywords)
+(class :a) ; => clojure.lang.Keyword
+
+(def stringmap {"a" 1, "b" 2, "c" 3})
+stringmap ; => {"a" 1, "b" 2, "c" 3}
+
+(def keymap {:a 1, :b 2, :c 3})
+keymap ; => {:a 1, :c 3, :b 2}
+
+; Предыдущий пример содержит запятые в коде, однако reader не использует их,
+; при обработке литералов - запятые просто воспринимаются,
+; как "пробельные символы" (whitespaces)
+
+; Отображение может выступать в роли функции, возвращающей значение по ключу
+(stringmap "a") ; => 1
+(keymap :a) ; => 1
+
+; При попытке получить отсутствующее значение, будет возвращён nil
+(stringmap "d") ; => nil
+
+; Иногда бывает удобно указать конкретное значение по-умолчанию:
+({:a 1 :b 2} :c "Oops!") ; => "Oops!"
+
+; Keywords тоже могут использоваться в роли функций!
+(:b keymap) ; => 2
+
+; Однако этот фокус не пройдёт со строками.
+;("a" stringmap)
+; => Exception: java.lang.String cannot be cast to clojure.lang.IFn
+
+; Добавить пару ключ-значение в отображение можно функцией assoc
+(def newkeymap (assoc keymap :d 4))
+newkeymap ; => {:a 1, :b 2, :c 3, :d 4}
+
+; Но всегда следует помнить, что значения в Clojure - неизменяемые!
+keymap ; => {:a 1, :b 2, :c 3} - оригинал не был затронут
+
+; dissoc позволяет исключить значение по ключу
+(dissoc keymap :a :b) ; => {:c 3}
+
+; Множества (Sets)
+;;;;;;;;;;;;;;;;;;
+
+(class #{1 2 3}) ; => clojure.lang.PersistentHashSet
+(set [1 2 3 1 2 3 3 2 1 3 2 1]) ; => #{1 2 3}
+
+; Добавляются элементы посредством conj
+(conj #{1 2 3} 4) ; => #{1 2 3 4}
+
+; Исключаются - посредством disj
+(disj #{1 2 3} 1) ; => #{2 3}
+
+; Вызов множества, как функции, позволяет проверить
+; принадлежность элемента этому множеству:
+(#{1 2 3} 1) ; => 1
+(#{1 2 3} 4) ; => nil
+
+; В пространстве имен clojure.sets
+; содержится множество функций для работы с множествами
+
+; Полезные формы
+;;;;;;;;;;;;;;;;;
+
+; Конструкции ветвления в clojure, это обычные макросы
+; и подобны их собратьям в других языках:
+(if false "a" "b") ; => "b"
+(if false "a") ; => nil
+
+; Специальная форма let позволяет присвоить имена значениям локально.
+; При этом все изменения будут видны только вложенным формам:
+(def a 10)
+(let [a 1 b 2]
+ (> a b)) ; => false
+
+; Несколько форм можно объединить в одну форму посредством do
+; Значением do-формы будет значение последней формы из списка вложенных в неё:
+(do
+ (print "Hello")
+ "World") ; => "World" (prints "Hello")
+
+; Множество макросов содержит внутри себя неявную do-форму.
+; Пример - макрос определения функции:
+(defn print-and-say-hello [name]
+ (print "Saying hello to " name)
+ (str "Hello " name))
+(print-and-say-hello "Jeff") ;=> "Hello Jeff" (prints "Saying hello to Jeff")
+
+; Ещё один пример - let:
+(let [name "Urkel"]
+ (print "Saying hello to " name)
+ (str "Hello " name)) ; => "Hello Urkel" (prints "Saying hello to Urkel")
+
+; Модули
+;;;;;;;;;
+
+; Форма "use" позволяет добавить в текущее пространство имен
+; все имена (вместе со значениями) из указанного модуля:
+(use 'clojure.set)
+
+; Теперь нам доступны операции над множествами:
+(intersection #{1 2 3} #{2 3 4}) ; => #{2 3}
+(difference #{1 2 3} #{2 3 4}) ; => #{1}
+
+; use позволяет указать, какие конкретно имена
+; должны быть импортированы из модуля:
+(use '[clojure.set :only [intersection]])
+
+; Также модуль может быть импортирован формой require
+(require 'clojure.string)
+
+; После этого модуль становится доступе в текущем пространстве имен,
+; а вызов его функций может быть осуществлен указанием полного имени функции:
+(clojure.string/blank? "") ; => true
+
+; Импортируемому модулю можно назначить короткое имя:
+(require '[clojure.string :as str])
+(str/replace "This is a test." #"[a-o]" str/upper-case) ; => "THIs Is A tEst."
+; (Литерал вида #"" обозначает регулярное выражение)
+
+; Вместо отдельной формы require (и use, хотя это и не приветствуется) можно
+; указать необходимые модули прямо в форме ns:
+(ns test
+ (:require
+ [clojure.string :as str] ; Внимание: при указании внутри формы ns
+ [clojure.set :as set])) ; имена пакетов не квотируются!
+
+; Java
+;;;;;;;
+
+; Стандартная библиотека Java очень богата,
+; и всё это богатство доступно и для Clojure!
+
+; import позволяет импортировать модули Java
+(import java.util.Date)
+
+; В том числе и из ns
+(ns test
+ (:import java.util.Date
+ java.util.Calendar))
+
+; Имя класса, сопровождаемое символом "." позволяет
+; инстанцировать объекты Java-классов:
+(Date.) ; <a date object>
+
+; форма . позволяет вызывать методы:
+(. (Date.) getTime) ; <a timestamp>
+(.getTime (Date.)) ; а можно и так
+
+; Статические методы вызываются как функции модуля:
+(System/currentTimeMillis) ; <a timestamp> (Модуль system всегда доступен!)
+
+; doto позволяет удобно работать с объектами, изменяющими свое состояние
+(import java.util.Calendar)
+(doto (Calendar/getInstance)
+ (.set 2000 1 1 0 0 0)
+ .getTime) ; => A Date. set to 2000-01-01 00:00:00
+
+; Работа с изменяемым сотоянием
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; Clojure предоставляет набор инструментов
+; для работы с изменяемым состоянием: Software Transactional Memory.
+; Структуры STM представлены тремя типами:
+; - атомы (atoms)
+; - агенты (agents)
+; - ссылки (references)
+
+; Самые простые хранители состояния - атомы:
+(def my-atom (atom {})) ; {} - начальное состояние атома
+
+; Обновляется атом посредством swap!.
+; swap! применяет функцию аргумент к текущему значению
+; атома и помещает в атом результат
+(swap! my-atom assoc :a 1) ; Обновляет my-atom, помещая в него (assoc {} :a 1)
+(swap! my-atom assoc :b 2) ; Обновляет my-atom, помещая в него (assoc {:a 1} :b 2)
+
+; Получить значение атома можно посредством '@'
+; (провести так называемую операцию dereference)
+my-atom ;=> Atom<#...> (Возвращает объект типа Atom)
+@my-atom ; => {:a 1 :b 2}
+
+; Пример реализации счётчика на атоме
+(def counter (atom 0))
+(defn inc-counter []
+ (swap! counter inc))
+
+(inc-counter)
+(inc-counter)
+(inc-counter)
+(inc-counter)
+(inc-counter)
+
+@counter ; => 5
+
+; С другими STM-конструкциями - refs и agents - можно ознакомиться тут:
+; Refs: http://clojure.org/refs
+; Agents: http://clojure.org/agents
+```
+
+### Для будущего чтения
+
+Это руководство не претендует на полноту, но мы смеем надеяться, способно вызвать интерес к дальнейшему изучению языка.
+
+Clojure.org - сайт содержит большое количество статей по языку:
+[http://clojure.org/](http://clojure.org/)
+
+Clojuredocs.org - сайт документации языка с примерами использования функций:
+[http://clojuredocs.org/quickref/Clojure%20Core](http://clojuredocs.org/quickref/Clojure%20Core)
+
+4Clojure - отличный способ закрепить навыки программирования на clojure, решая задачи вместе с коллегами со всего мира:
+[http://www.4clojure.com/](http://www.4clojure.com/)
+
+Clojure-doc.org (да, именно) неплохой перечень статей для начинающих:
+[http://clojure-doc.org/](http://clojure-doc.org/)
diff --git a/ruby-ecosystem.html.markdown b/ruby-ecosystem.html.markdown
index a31f552d..54c1d178 100644
--- a/ruby-ecosystem.html.markdown
+++ b/ruby-ecosystem.html.markdown
@@ -81,7 +81,7 @@ development.
Less mature/compatible:
* Topaz - Written in RPython (using the PyPy toolchain), Topaz is fairly young
- and not yet compatable. It shows promise to be a high-performance ruby
+ 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
to have stopped since Microsoft pulled their support.
@@ -93,13 +93,13 @@ 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.
## RubyGems
-(RubyGems)[http://rubygems.org/] is a community-run package manager for ruby.
+[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
@@ -108,7 +108,7 @@ things like version, dependencies, author(s), and license(s).
## Bundler
-(Bundler)[http://bundler.io/] is a gem dependency resolver. It uses a project's
+[Bundler](http://bundler.io/) is a gem dependency resolver. It uses a project's
Gemfile to find dependencies, and then fetches those dependencies' dependencies
recursively. It does this until all dependencies are resolved and downloaded, or
it will stop if a conflict has been found.
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 861a94ad..3a233d98 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -5,6 +5,8 @@ contributors:
- ["David Underwood", "http://theflyingdeveloper.com"]
- ["Joel Walden", "http://joelwalden.net"]
- ["Luke Holder", "http://twitter.com/lukeholder"]
+ - ["Tristan Hume", "http://thume.ca/"]
+ - ["Nick LaMuro", "https://github.com/NickLaMuro"]
---
```ruby
@@ -34,7 +36,7 @@ You shouldn't either
# Arithmetic is just syntactic sugar
# for calling a method on an object
1.+(3) #=> 4
-10.* 5 #=> 50
+10.* 5 #=> 50
# Special values are objects
nil # Nothing to see here
@@ -116,11 +118,11 @@ status == :approved #=> false
# Arrays
# This is an array
-[1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
+array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
# Arrays can contain different types of items
-array = [1, "hello", false] #=> => [1, "hello", false]
+[1, "hello", false] #=> [1, "hello", false]
# Arrays can be indexed
# From the front
@@ -158,11 +160,6 @@ hash['number'] #=> 5
# Asking a hash for a key that doesn't exist returns nil:
hash['nothing here'] #=> nil
-# Iterate over hashes with the #each method:
-hash.each do |k, v|
- puts "#{k} is #{v}"
-end
-
# Since Ruby 1.9, there's a special syntax when using symbols as keys:
new_hash = { defcon: 3, action: true}
@@ -177,9 +174,9 @@ new_hash.keys #=> [:defcon, :action]
if true
"if statement"
elsif false
- "else if, optional"
+ "else if, optional"
else
- "else, also optional"
+ "else, also optional"
end
for counter in 1..5
@@ -191,9 +188,15 @@ end
#=> iteration 4
#=> iteration 5
-# HOWEVER
-# No-one uses for loops
-# Use `each` instead, like this:
+# HOWEVER, No-one uses for loops.
+# Instead you should use the "each" method and pass it a block.
+# A block is a bunch of code that you can pass to a method like "each".
+# It is analogous to lambdas, anonymous functions or closures in other
+# programming languages.
+#
+# The "each" method of a range runs the block once for each element of the range.
+# The block is passed a counter as a parameter.
+# Calling the "each" method with a block looks like this:
(1..5).each do |counter|
puts "iteration #{counter}"
@@ -204,6 +207,17 @@ end
#=> iteration 4
#=> iteration 5
+# You can also surround blocks in curly brackets:
+(1..5).each {|counter| puts "iteration #{counter}"}
+
+# The contents of data structures can also be iterated using each.
+array.each do |element|
+ puts "#{element} is part of the array"
+end
+hash.each do |key, value|
+ puts "#{key} is #{value}"
+end
+
counter = 1
while counter <= 5 do
puts "iteration #{counter}"
@@ -228,7 +242,7 @@ when 'D'
puts "Scraping through"
when 'F'
puts "You failed!"
-else
+else
puts "Alternative grading system, eh?"
end
@@ -238,7 +252,7 @@ def double(x)
x * 2
end
-# Functions (and all blocks) implcitly return the value of the last statement
+# Functions (and all blocks) implicitly return the value of the last statement
double(2) #=> 4
# Parentheses are optional where the result is unambiguous
diff --git a/zh-cn/go-zh.html.markdown b/zh-cn/go-zh.html.markdown
new file mode 100644
index 00000000..25fd1f03
--- /dev/null
+++ b/zh-cn/go-zh.html.markdown
@@ -0,0 +1,279 @@
+---
+名字:Go
+分类:编程语言
+文件名:learngo.go
+贡献者:
+ - ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["pantaovay", "https://github.com/pantaovay"]
+---
+
+发明Go语言是出于更好地完成工作的需要。Go不是计算机科学的最新发展潮流,但它却提供了解决现实问题的最新最快的方法。
+
+Go拥有命令式语言的静态类型,编译很快,执行也很快,同时加入了对于目前多核CPU的并发计算支持,也有相应的特性来实现大规模编程。
+
+Go语言有非常棒的标准库,还有一个充满热情的社区。
+
+```Go
+// 单行注释
+/* 多行
+ 注释 */
+
+// 导入包的子句在每个源文件的开头。
+// Main比较特殊,它用来声明可执行文件,而不是一个库。
+package main
+
+// Import语句声明了当前文件引用的包。
+import (
+ "fmt" // Go语言标准库中的包
+ "net/http" // 一个web服务器包
+ "strconv" // 字符串转换
+)
+
+//函数声明:Main是程序执行的入口。不管你喜欢还是不喜欢,反正G就用了花括号来包住函数体。
+func main() {
+ // 往标准输出打印一行。
+ // 用包名fmt限制打印函数。
+ fmt.Println("Hello world!")
+
+ // 调用当前包的另一个函数。
+ beyondHello()
+}
+
+// 函数可以在括号里加参数。
+// 如果没有参数的话,也需要一个空括号。
+func beyondHello() {
+ var x int // 变量声明,变量必须在使用之前声明。
+ x = 3 // 变量赋值。
+ // 可以用:=来偷懒,它自动把变量类型、声明和赋值都搞定了。
+ y := 4
+ sum, prod := learnMultiple(x, y) // 多个返回变量的函数
+ fmt.Println("sum:", sum, "prod:", prod) // 简单输出
+ learnTypes() // 少于y分钟,学的更多!
+}
+
+// 多变量和多返回值的函数
+func learnMultiple(x, y int) (sum, prod int) {
+ return x + y, x * y // 返回两个值
+}
+
+// 内置变量类型和关键词
+func learnTypes() {
+ // 短声明给你所想。
+ s := "Learn Go!" // String类型
+
+ s2 := `A "raw" string literal
+can include line breaks.` // 同样是String类型
+
+ // 非ascii字符。Go使用UTF-8编码。
+ g := 'Σ' // rune类型,uint32的别名,使用UTF-8编码
+
+ f := 3.14195 // float64类型,IEEE-754 64位浮点数
+ c := 3 + 4i // complex128类型,内部使用两个float64表示
+
+ // Var变量可以直接初始化。
+ var u uint = 7 // unsigned 无符号变量,但是实现依赖int型变量的长度
+ var pi float32 = 22. / 7
+
+ // 字符转换
+ n := byte('\n') // byte是uint8的别名
+
+ // 数组类型编译的时候大小固定。
+ var a4 [4] int // 有4个int变量的数组,初始为0
+ a3 := [...]int{3, 1, 5} // 有3个int变量的数组,同时进行了初始化
+
+ // Slice 有动态大小。Array和Slice各有千秋,但是使用slice的地方更多些。
+ s3 := []int{4, 5, 9} // 和a3相比,这里没有省略号
+ s4 := make([]int, 4) // 分配一个有4个int型变量的slice,全部被初始化为0
+
+ var d2 [][]float64 // 声明而已,什么都没有分配
+ bs := []byte("a slice") // 类型转换的语法
+
+ p, q := learnMemory() // 声明p,q为int型变量的指针
+ fmt.Println(*p, *q) // * 取值
+
+ // Map是动态可增长关联数组,和其他语言中的hash或者字典相似。
+ m := map[string]int{"three": 3, "four": 4}
+ m["one"] = 1
+
+ // 在Go语言中未使用的变量在编译的时候会报错,而不是warning。
+ // 下划线 _ 可以使你“使用”一个变量,但是丢弃它的值。
+ _,_,_,_,_,_,_,_,_ = s2, g, f, u, pi, n, a3, s4, bs
+ // 输出变量
+ fmt.Println(s, c, a4, s3, d2, m)
+
+ learnFlowControl() // 回到流程控制
+}
+
+// Go全面支持垃圾回收。Go有指针,但是不支持指针运算。
+// 你会因为空指针而犯错,但是不会因为增加指针而犯错。
+func learnMemory() (p, q *int) {
+ // 返回int型变量指针p和q
+ p = new(int) // 内置函数new分配内存
+ // 自动将分配的int赋值0,p不再是空的了。
+ s := make([]int, 20) // 给20个int变量分配一块内存
+ s[3] = 7 // 赋值
+ r := -2 // 声明另一个局部变量
+ return &s[3], &r // & 取址
+}
+
+func expensiveComputation() int {
+ return 1e6
+}
+
+func learnFlowControl() {
+ // If需要花括号,括号就免了
+ if true {
+ fmt.Println("told ya")
+ }
+ // 用go fmt 命令可以帮你格式化代码,所以不用怕被人吐槽代码风格了,也不用容忍被人的代码风格。
+ if false {
+ // pout
+ } else {
+ // gloat
+ }
+ // 如果太多嵌套的if语句,推荐使用switch
+ x := 1
+ switch x {
+ case 0:
+ case 1:
+ // 隐式调用break语句,匹配上一个即停止
+ case 2:
+ // 不会运行
+ }
+ // 和if一样,for也不用括号
+ for x := 0; x < 3; x++ { // ++ 自增
+ fmt.Println("iteration", x)
+ }
+ // x在这里还是1。为什么?
+
+ // for 是go里唯一的循环关键字,不过它有很多变种
+ for { // 无限循环
+ break // 骗你的
+ continue // 不会运行的
+ }
+ // 和for一样,if中的:=先给y赋值,然后再和x作比较。
+ if y := expensiveComputation(); y > x {
+ x = y
+ }
+ // 闭包函数
+ xBig := func() bool {
+ return x > 100 // x是上面声明的变量引用
+ }
+ fmt.Println("xBig:", xBig()) // true (上面把y赋给x了)
+ x /= 1e5 // x变成10
+ fmt.Println("xBig:", xBig()) // 现在是false
+
+ // 当你需要goto的时候,你会爱死它的!
+ goto love
+love:
+
+ learnInterfaces() // 好东西来了!
+}
+
+// 定义Stringer为一个接口类型,有一个方法String
+type Stringer interface {
+ String() string
+}
+
+// 定义pair为一个结构体,有x和y两个int型变量。
+type pair struct {
+ x, y int
+}
+
+// 定义pair类型的方法,实现Stringer接口。
+func (p pair) String() string { // p被叫做“接收器”
+ // Sprintf是fmt包中的另一个公有函数。
+ // 用 . 调用p中的元素。
+ return fmt.Sprintf("(%d, %d)", p.x, p.y)
+}
+
+func learnInterfaces() {
+ // 花括号用来定义结构体变量,:=在这里将一个结构体变量赋值给p。
+ p := pair{3, 4}
+ fmt.Println(p.String()) // 调用pair类型p的String方法
+ var i Stringer // 声明i为Stringer接口类型
+ i = p // 有效!因为p实现了Stringer接口(类似java中的塑型)
+ // 调用i的String方法,输出和上面一样
+ fmt.Println(i.String())
+
+ // fmt包中的Println函数向对象要它们的string输出,实现了String方法就可以这样使用了。(类似java中的序列化)
+ fmt.Println(p) // 输出和上面一样,自动调用String函数。
+ fmt.Println(i) // 输出和上面一样。
+
+ learnErrorHandling()
+}
+
+func learnErrorHandling() {
+ // ", ok"用来判断有没有正常工作
+ m := map[int]string{3: "three", 4: "four"}
+ if x, ok := m[1]; !ok { // ok 为false,因为m中没有1
+ fmt.Println("no one there")
+ } else {
+ fmt.Print(x) // 如果x在map中的话,x就是那个值喽。
+ }
+ // 错误可不只是ok,它还可以给出关于问题的更多细节。
+ if _, err := strconv.Atoi("non-int"); err != nil { // _ discards value
+ // 输出"strconv.ParseInt: parsing "non-int": invalid syntax"
+ fmt.Println(err)
+ }
+ // 待会再说接口吧。同时,
+ learnConcurrency()
+}
+
+// c是channel类型,一个并发安全的通信对象。
+func inc(i int, c chan int) {
+ c <- i + 1 // <-把右边的发送到左边的channel。
+}
+
+// 我们将用inc函数来并发地增加一些数字。
+func learnConcurrency() {
+ // 用make来声明一个slice,make会分配和初始化slice,map和channel。
+ c := make(chan int)
+ // 用go关键字开始三个并发的goroutine,如果机器支持的话,还可能是并行执行。三个都被发送到同一个channel。
+ go inc(0, c) // go is a statement that starts a new goroutine.
+ go inc(10, c)
+ go inc(-805, c)
+ // 从channel中独处结果并打印。
+ // 打印出什么东西是不可预知的。
+ fmt.Println(<-c, <-c, <-c) // channel在右边的时候,<-是接收操作。
+
+ cs := make(chan string) // 操作string的channel
+ cc := make(chan chan string) // 操作channel的channel
+ go func() { c <- 84 }() // 开始一个goroutine来发送一个新的数字
+ go func() { cs <- "wordy" }() // 发送给cs
+ // Select类似于switch,但是每个case包括一个channel操作。它随机选择一个准备好通讯的case。
+ select {
+ case i := <-c: // 从channel接收的值可以赋给其他变量
+ fmt.Println("it's a", i)
+ case <-cs: // 或者直接丢弃
+ fmt.Println("it's a string")
+ case <-cc: // 空的,还没作好通讯的准备
+ fmt.Println("didn't happen.")
+ }
+ // 上面c或者cs的值被取到,其中一个goroutine结束,另外一个保持阻塞。
+
+ learnWebProgramming() // Go很适合web编程,我知道你也想学!
+}
+
+// http包中的一个简单的函数就可以开启web服务器。
+func learnWebProgramming() {
+ // ListenAndServe第一个参数指定了监听端口,第二个参数是一个接口,特定是http.Handler。
+ err := http.ListenAndServe(":8080", pair{})
+ fmt.Println(err) // 不要无视错误。
+}
+
+// 使pair实现http.Handler接口的ServeHTTP方法。
+func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ // 使用http.ResponseWriter返回数据
+ w.Write([]byte("You learned Go in Y minutes!"))
+}
+```
+
+## 更进一步
+
+Go的根源在[Go官方网站](http://golang.org/)。
+在那里你可以学习入门教程,通过浏览器交互式地学习,而且可以读到很多东西。
+
+强烈推荐阅读语言定义部分,很简单而且很简洁!(as language definitions go these days.)
+
+学习Go还要阅读Go标准库的源代码,全部文档化了,可读性非常好,可以学到go,go style和go idioms。在文档中点击函数名,源代码就出来了!
diff --git a/zh-cn/python-cn.html.markdown b/zh-cn/python-cn.html.markdown
index 764eed54..51efaac3 100755
--- a/zh-cn/python-cn.html.markdown
+++ b/zh-cn/python-cn.html.markdown
@@ -17,6 +17,7 @@ Python 由 Guido Van Rossum 在90年代初创建。 它现在是最流行的语
如果是Python 3,请在网络上寻找其他教程
```python
+
# 单行注释
""" 多行字符串可以用
三个引号包裹,不过这也可以被当做
@@ -28,84 +29,84 @@ Python 由 Guido Van Rossum 在90年代初创建。 它现在是最流行的语
####################################################
# 数字类型
-3 #=> 3
+3 # => 3
# 简单的算数
-1 + 1 #=> 2
-8 - 1 #=> 7
-10 * 2 #=> 20
-35 / 5 #=> 7
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+35 / 5 # => 7
# 整数的除法会自动取整
-5 / 2 #=> 2
+5 / 2 # => 2
# 要做精确的除法,我们需要引入浮点数
2.0 # 浮点数
-11.0 / 4.0 #=> 2.75 好多了
+11.0 / 4.0 # => 2.75 精确多了
# 括号具有最高优先级
-(1 + 3) * 2 #=> 8
+(1 + 3) * 2 # => 8
-# 布尔值也是原始数据类型
+# 布尔值也是基本的数据类型
True
False
-# 用not来取非
-not True #=> False
-not False #=> True
+# 用 not 来取非
+not True # => False
+not False # => True
# 相等
-1 == 1 #=> True
-2 == 1 #=> False
+1 == 1 # => True
+2 == 1 # => False
# 不等
-1 != 1 #=> False
-2 != 1 #=> True
+1 != 1 # => False
+2 != 1 # => True
# 更多的比较操作符
-1 < 10 #=> True
-1 > 10 #=> False
-2 <= 2 #=> True
-2 >= 2 #=> True
+1 < 10 # => True
+1 > 10 # => False
+2 <= 2 # => True
+2 >= 2 # => True
# 比较运算可以连起来写!
-1 < 2 < 3 #=> True
-2 < 3 < 2 #=> False
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
-# 字符串通过"或'括起来
+# 字符串通过 " 或 ' 括起来
"This is a string."
'This is also a string.'
# 字符串通过加号拼接
-"Hello " + "world!" #=> "Hello world!"
+"Hello " + "world!" # => "Hello world!"
# 字符串可以被视为字符的列表
-"This is a string"[0] #=> 'T'
+"This is a string"[0] # => 'T'
# % 可以用来格式化字符串
"%s can be %s" % ("strings", "interpolated")
-# 也可以用format方法来格式化字符串
+# 也可以用 format 方法来格式化字符串
# 推荐使用这个方法
"{0} can be {1}".format("strings", "formatted")
# 也可以用变量名代替数字
"{name} wants to eat {food}".format(name="Bob", food="lasagna")
# None 是对象
-None #=> None
+None # => None
# 不要用相等 `==` 符号来和None进行比较
-# 要用 `is`
-"etc" is None #=> False
-None is None #=> True
+# 要用 `is`
+"etc" is None # => False
+None is None # => True
# 'is' 可以用来比较对象的相等性
# 这个操作符在比较原始数据时没多少用,但是比较对象时必不可少
-# None, 0, 和空字符串都被算作False
-# 其他的均为True
-0 == False #=> True
-"" == False #=> True
+# None, 0, 和空字符串都被算作 False
+# 其他的均为 True
+0 == False # => True
+"" == False # => True
####################################################
@@ -116,16 +117,16 @@ None is None #=> True
print "I'm Python. Nice to meet you!"
-# 给变量赋值前不需要事先生命
-some_var = 5 # 规范用小写字母和下划线来做为变量名
-some_var #=> 5
+# 给变量赋值前不需要事先声明
+some_var = 5 # 一般建议使用小写字母和下划线组合来做为变量名
+some_var # => 5
-# 访问之前为赋值的变量会抛出异常
-# 查看控制流程一节来了解异常处理
-some_other_var # 抛出命名异常
+# 访问未赋值的变量会抛出异常
+# 可以查看控制流程一节来了解如何异常处理
+some_other_var # 抛出 NameError
-# if语句可以作为表达式来使用
-"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
+# if 语句可以作为表达式来使用
+"yahoo!" if 3 > 2 else 2 # => "yahoo!"
# 列表用来保存序列
li = []
@@ -133,64 +134,64 @@ li = []
other_li = [4, 5, 6]
# 在列表末尾添加元素
-li.append(1) #li 现在是 [1]
-li.append(2) #li 现在是 [1, 2]
-li.append(4) #li 现在是 [1, 2, 4]
-li.append(3) #li 现在是 [1, 2, 4, 3]
+li.append(1) # li 现在是 [1]
+li.append(2) # li 现在是 [1, 2]
+li.append(4) # li 现在是 [1, 2, 4]
+li.append(3) # li 现在是 [1, 2, 4, 3]
# 移除列表末尾元素
-li.pop() #=> 3 and li is now [1, 2, 4]
-# 放回来
+li.pop() # => 3 li 现在是 [1, 2, 4]
+# 重新加进去
li.append(3) # li is now [1, 2, 4, 3] again.
# 像其他语言访问数组一样访问列表
-li[0] #=> 1
+li[0] # => 1
# 访问最后一个元素
-li[-1] #=> 3
+li[-1] # => 3
# 越界会抛出异常
-li[4] # 抛出越界异常
+li[4] # 抛出越界异常
# 切片语法需要用到列表的索引访问
# 可以看做数学之中左闭右开区间
-li[1:3] #=> [2, 4]
+li[1:3] # => [2, 4]
# 省略开头的元素
-li[2:] #=> [4, 3]
+li[2:] # => [4, 3]
# 省略末尾的元素
-li[:3] #=> [1, 2, 4]
+li[:3] # => [1, 2, 4]
# 删除特定元素
-del li[2] # li 现在是 [1, 2, 3]
+del li[2] # li 现在是 [1, 2, 3]
# 合并列表
-li + other_li #=> [1, 2, 3, 4, 5, 6] - 不改变这两个列表
+li + other_li # => [1, 2, 3, 4, 5, 6] - 并不会不改变这两个列表
-# 通过拼接合并列表
-li.extend(other_li) # li 是 [1, 2, 3, 4, 5, 6]
+# 通过拼接来合并列表
+li.extend(other_li) # li 是 [1, 2, 3, 4, 5, 6]
-# 用in来返回元素是否在列表中
-1 in li #=> True
+# 用 in 来返回元素是否在列表中
+1 in li # => True
# 返回列表长度
-len(li) #=> 6
+len(li) # => 6
-# 元组类似于列表,但是他是不可改变的
+# 元组类似于列表,但它是不可改变的
tup = (1, 2, 3)
-tup[0] #=> 1
+tup[0] # => 1
tup[0] = 3 # 类型错误
# 对于大多数的列表操作,也适用于元组
-len(tup) #=> 3
-tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
-tup[:2] #=> (1, 2)
-2 in tup #=> True
+len(tup) # => 3
+tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
+tup[:2] # => (1, 2)
+2 in tup # => True
# 你可以将元组解包赋给多个变量
-a, b, c = (1, 2, 3) # a是1,b是2,c是3
-# 如果不加括号,那么会自动视为元组
+a, b, c = (1, 2, 3) # a 是 1,b 是 2,c 是 3
+# 如果不加括号,将会被自动视为元组
d, e, f = 4, 5, 6
# 现在我们可以看看交换两个数字是多么容易的事
-e, d = d, e # d是5,e是4
+e, d = d, e # d 是 5,e 是 4
# 字典用来储存映射关系
@@ -199,59 +200,59 @@ empty_dict = {}
filled_dict = {"one": 1, "two": 2, "three": 3}
# 字典也用中括号访问元素
-filled_dict["one"] #=> 1
+filled_dict["one"] # => 1
# 把所有的键保存在列表中
-filled_dict.keys() #=> ["three", "two", "one"]
+filled_dict.keys() # => ["three", "two", "one"]
# 键的顺序并不是唯一的,得到的不一定是这个顺序
# 把所有的值保存在列表中
-filled_dict.values() #=> [3, 2, 1]
+filled_dict.values() # => [3, 2, 1]
# 和键的顺序相同
# 判断一个键是否存在
-"one" in filled_dict #=> True
-1 in filled_dict #=> False
+"one" in filled_dict # => True
+1 in filled_dict # => False
-# 查询一个不存在的键会抛出键异常
-filled_dict["four"] # 键异常
+# 查询一个不存在的键会抛出 KeyError
+filled_dict["four"] # KeyError
-# 用get方法来避免键异常
-filled_dict.get("one") #=> 1
-filled_dict.get("four") #=> None
-# get方法支持在不存在的时候返回一个默认值
-filled_dict.get("one", 4) #=> 1
-filled_dict.get("four", 4) #=> 4
+# 用 get 方法来避免 KeyError
+filled_dict.get("one") # => 1
+filled_dict.get("four") # => None
+# get 方法支持在不存在的时候返回一个默认值
+filled_dict.get("one", 4) # => 1
+filled_dict.get("four", 4) # => 4
-# Setdefault是一个更安全的添加字典元素的方法
-filled_dict.setdefault("five", 5) #filled_dict["five"] 的值为 5
-filled_dict.setdefault("five", 6) #filled_dict["five"] 的值仍然是 5
+# setdefault 是一个更安全的添加字典元素的方法
+filled_dict.setdefault("five", 5) # filled_dict["five"] 的值为 5
+filled_dict.setdefault("five", 6) # filled_dict["five"] 的值仍然是 5
# 集合储存无顺序的元素
empty_set = set()
-# 出事话一个集合
-some_set = set([1,2,2,3,4]) # filled_set 现在是 set([1, 2, 3, 4])
+# 初始化一个集合
+some_set = set([1, 2, 2, 3, 4]) # filled_set 现在是 set([1, 2, 3, 4])
# Python 2.7 之后,大括号可以用来表示集合
-filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
+filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
-# 为集合添加元素
-filled_set.add(5) # filled_set 现在是 {1, 2, 3, 4, 5}
+# 向集合添加元素
+filled_set.add(5) # filled_set 现在是 {1, 2, 3, 4, 5}
-# 用&来实现集合的交
+# 用 & 来计算集合的交
other_set = {3, 4, 5, 6}
-filled_set & other_set #=> {3, 4, 5}
+filled_set & other_set # => {3, 4, 5}
-# 用|来实现集合的并
-filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+# 用 | 来计算集合的并
+filled_set | other_set # => {1, 2, 3, 4, 5, 6}
-# 用-来实现集合的差
-{1,2,3,4} - {2,3,5} #=> {1, 4}
+# 用 - 来计算集合的差
+{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}
-# 用in来判断元素是否存在于集合中
-2 in filled_set #=> True
-10 in filled_set #=> False
+# 用 in 来判断元素是否存在于集合中
+2 in filled_set # => True
+10 in filled_set # => False
####################################################
@@ -261,13 +262,13 @@ filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
# 新建一个变量
some_var = 5
-# 这是个if语句,在python中缩进是很重要的。
-# 会输出 "some var is smaller than 10"
+# 这是个 if 语句,在 python 中缩进是很重要的。
+# 下面的代码片段将会输出 "some var is smaller than 10"
if some_var > 10:
print "some_var is totally bigger than 10."
elif some_var < 10: # 这个 elif 语句是不必须的
print "some_var is smaller than 10."
-else: # 也不是必须的
+else: # 这个 else 也不是必须的
print "some_var is indeed 10."
@@ -281,7 +282,7 @@ else: # 也不是必须的
for animal in ["dog", "cat", "mouse"]:
# 你可以用 % 来格式化字符串
print "%s is a mammal" % animal
-
+
"""
`range(number)` 返回从0到给定数字的列表
输出:
@@ -294,7 +295,7 @@ for i in range(4):
print i
"""
-While循环
+while 循环
输出:
0
1
@@ -304,29 +305,29 @@ While循环
x = 0
while x < 4:
print x
- x += 1 # Shorthand for x = x + 1
+ x += 1 # x = x + 1 的简写
-# 用 try/except块来处理异常
+# 用 try/except 块来处理异常
# Python 2.6 及以上适用:
try:
- # 用raise来抛出异常
+ # 用 raise 来抛出异常
raise IndexError("This is an index error")
except IndexError as e:
- pass # Pass就是什么都不做,不过通常这里会做一些恢复工作
+ pass # pass 就是什么都不做,不过通常这里会做一些恢复工作
####################################################
## 4. 函数
####################################################
-# 用def来新建函数
+# 用 def 来新建函数
def add(x, y):
print "x is %s and y is %s" % (x, y)
- return x + y # Return values with a return statement
+ return x + y # 通过 return 来返回值
# 调用带参数的函数
-add(5, 6) #=> 输出 "x is 5 and y is 6" 返回 11
+add(5, 6) # => 输出 "x is 5 and y is 6" 返回 11
# 通过关键字赋值来调用函数
add(y=6, x=5) # 顺序是无所谓的
@@ -335,7 +336,7 @@ add(y=6, x=5) # 顺序是无所谓的
def varargs(*args):
return args
-varargs(1, 2, 3) #=> (1,2,3)
+varargs(1, 2, 3) # => (1,2,3)
# 我们也可以定义接受多个变量的函数,这些变量是按照关键字排列的
@@ -343,7 +344,7 @@ def keyword_args(**kwargs):
return kwargs
# 实际效果:
-keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"}
# 你也可以同时将一个函数定义成两种形式
def all_the_args(*args, **kwargs):
@@ -355,38 +356,38 @@ all_the_args(1, 2, a=3, b=4) prints:
{"a": 3, "b": 4}
"""
-# 当调用函数的时候,我们也可以和之前所做的相反,把元组和字典展开为参数
+# 当调用函数的时候,我们也可以进行相反的操作,把元组和字典展开为参数
args = (1, 2, 3, 4)
kwargs = {"a": 3, "b": 4}
-all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
-all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
-all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+all_the_args(*args) # 等价于 foo(1, 2, 3, 4)
+all_the_args(**kwargs) # 等价于 foo(a=3, b=4)
+all_the_args(*args, **kwargs) # 等价于 foo(1, 2, 3, 4, a=3, b=4)
-# Python 有一等函数:
+# 函数在 python 中是一等公民
def create_adder(x):
def adder(y):
return x + y
return adder
add_10 = create_adder(10)
-add_10(3) #=> 13
+add_10(3) # => 13
# 匿名函数
-(lambda x: x > 2)(3) #=> True
+(lambda x: x > 2)(3) # => True
# 内置高阶函数
-map(add_10, [1,2,3]) #=> [11, 12, 13]
-filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+map(add_10, [1, 2, 3]) # => [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# 可以用列表方法来对高阶函数进行更巧妙的引用
-[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
-[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
####################################################
## 5. 类
####################################################
-# 我们新建的类是从object类中继承的
+# 我们新建的类是从 object 类中继承的
class Human(object):
# 类属性,由所有类的对象共享
@@ -397,9 +398,9 @@ class Human(object):
# 将参数赋给对象成员属性
self.name = name
- # 成员方法,参数要有self
+ # 成员方法,参数要有 self
def say(self, msg):
- return "%s: %s" % (self.name, msg)
+ return "%s: %s" % (self.name, msg)
# 类方法由所有类的对象共享
# 这类方法在调用时,会把类本身传给第一个参数
@@ -421,15 +422,15 @@ j = Human("Joel")
print j.say("hello") # 输出 "Joel: hello"
# 访问类的方法
-i.get_species() #=> "H. sapiens"
+i.get_species() # => "H. sapiens"
# 改变共享属性
Human.species = "H. neanderthalensis"
-i.get_species() #=> "H. neanderthalensis"
-j.get_species() #=> "H. neanderthalensis"
+i.get_species() # => "H. neanderthalensis"
+j.get_species() # => "H. neanderthalensis"
# 访问静态变量
-Human.grunt() #=> "*grunt*"
+Human.grunt() # => "*grunt*"
####################################################
@@ -438,12 +439,12 @@ Human.grunt() #=> "*grunt*"
# 我们可以导入其他模块
import math
-print math.sqrt(16) #=> 4
+print math.sqrt(16) # => 4
-# 我们也可以从一个模块中特定的函数
+# 我们也可以从一个模块中导入特定的函数
from math import ceil, floor
-print ceil(3.7) #=> 4.0
-print floor(3.7) #=> 3.0
+print ceil(3.7) # => 4.0
+print floor(3.7) # => 3.0
# 从模块中导入所有的函数
# 警告:不推荐使用
@@ -451,13 +452,13 @@ from math import *
# 简写模块名
import math as m
-math.sqrt(16) == m.sqrt(16) #=> True
+math.sqrt(16) == m.sqrt(16) # => True
# Python的模块其实只是普通的python文件
# 你也可以创建自己的模块,并且导入它们
# 模块的名字就和文件的名字相同
-# 以可以通过下面的信息找找要成为模块需要什么属性或方法
+# 也可以通过下面的方法查看模块中有什么属性和方法
import math
dir(math)
diff --git a/zh-cn/racket-cn.html.markdown b/zh-cn/racket-cn.html.markdown
new file mode 100644
index 00000000..d43511ea
--- /dev/null
+++ b/zh-cn/racket-cn.html.markdown
@@ -0,0 +1,608 @@
+---
+
+language: racket
+lang: zh-cn
+filename: learnracket.rkt
+contributors:
+ - ["th3rac25", "https://github.com/voila"]
+ - ["Eli Barzilay", "https://github.com/elibarzilay"]
+ - ["Gustavo Schmidt", "https://github.com/gustavoschmidt"]
+translators:
+ - ["lyuehh", "https://github.com/lyuehh"]
+---
+
+Racket是Lisp/Scheme家族中的一个通用的,多范式的编程语言。
+非常期待您的反馈!你可以通过[@th3rac25](http://twitter.com/th3rac25)或以用户名为 th3rac25 的Google邮箱服务和我取得联系
+
+```racket
+#lang racket ; 声明我们使用的语言
+
+;;; 注释
+
+;; 单行注释以分号开始
+
+#| 块注释
+ 可以横跨很多行而且...
+ #|
+ 可以嵌套
+ |#
+|#
+
+;; S表达式注释忽略剩下的表达式
+;; 在调试的时候会非常有用
+#; (被忽略的表达式)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 1. 原始数据类型和操作符
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 数字
+9999999999999999999999 ; 整数
+#b111 ; 二进制数字 => 7
+#o111 ; 八进制数字 => 73
+#x111 ; 十六进制数字 => 273
+3.14 ; 实数
+6.02e+23
+1/2 ; 有理数
+1+2i ; 复数
+
+;; 函数调用写作(f x y z ...)
+;; 在这里 f 是一个函数, x, y, z, ... 是参数
+;; 如果你想创建一个列表数据的字面量, 使用 ' 来阻止它们
+;; 被求值
+'(+ 1 2) ; => (+ 1 2)
+;; 接下来,是一些数学运算
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(expt 2 3) ; => 8
+(quotient 5 2) ; => 2
+(remainder 5 2) ; => 1
+(/ 35 5) ; => 7
+(/ 1 3) ; => 1/3
+(exact->inexact 1/3) ; => 0.3333333333333333
+(+ 1+2i 2-3i) ; => 3-1i
+
+;;; 布尔类型
+#t ; 为真
+#f ; 为假,#f 之外的任何值都是真
+(not #t) ; => #f
+(and 0 #f (error "doesn't get here")) ; => #f
+(or #f 0 (error "doesn't get here")) ; => 0
+
+;;; 字符
+#\A ; => #\A
+#\λ ; => #\λ
+#\u03BB ; => #\λ
+
+;;; 字符串是字符组成的定长数组
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; \是转义字符
+"Foo\tbar\41\x21\u0021\a\r\n" ; 包含C语言的转义字符,和Unicode
+"λx:(μα.α→α).xx" ; 字符串可以包含Unicode字符
+
+;; 字符串可以相加
+(string-append "Hello " "world!") ; => "Hello world!"
+
+;; 一个字符串可以看做是一个包含字符的列表
+(string-ref "Apple" 0) ; => #\A
+
+;; format 可以用来格式化字符串
+(format "~a can be ~a" "strings" "formatted")
+
+;; 打印字符串非常简单
+(printf "I'm Racket. Nice to meet you!\n")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. 变量
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 你可以使用 define 定义一个变量
+;; 变量的名字可以使用任何字符除了: ()[]{}",'`;#|\
+(define some-var 5)
+some-var ; => 5
+
+;; 你也可以使用Unicode字符
+(define ⊆ subset?)
+(⊆ (set 3 2) (set 1 2 3)) ; => #t
+
+;; 访问未赋值的变量会引发一个异常
+; x ; => x: undefined ...
+
+;; 本地绑定: `me' 被绑定到 "Bob",并且只在 let 中生效
+(let ([me "Bob"])
+ "Alice"
+ me) ; => "Bob"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 结构和集合
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 结构体
+(struct dog (name breed age))
+(define my-pet
+ (dog "lassie" "collie" 5))
+my-pet ; => #<dog>
+(dog? my-pet) ; => #t
+(dog-name my-pet) ; => "lassie"
+
+;;; 对 (不可变的)
+;; `cons' 返回对, `car' 和 `cdr' 从对中提取第1个
+;; 和第2个元素
+(cons 1 2) ; => '(1 . 2)
+(car (cons 1 2)) ; => 1
+(cdr (cons 1 2)) ; => 2
+
+;;; 列表
+
+;; 列表由链表构成, 由 `cons' 的结果
+;; 和一个 `null' (或者 '()) 构成,后者标记了这个列表的结束
+(cons 1 (cons 2 (cons 3 null))) ; => '(1 2 3)
+;; `list' 给列表提供了一个非常方便的可变参数的生成器
+(list 1 2 3) ; => '(1 2 3)
+;; 一个单引号也可以用来表示一个列表字面量
+'(1 2 3) ; => '(1 2 3)
+
+;; 仍然可以使用 `cons' 在列表的开始处添加一项
+(cons 4 '(1 2 3)) ; => '(4 1 2 3)
+
+;; `append' 函数可以将两个列表合并
+(append '(1 2) '(3 4)) ; => '(1 2 3 4)
+
+;; 列表是非常基础的类型,所以有*很多*操作列表的方法
+;; 下面是一些例子:
+(map add1 '(1 2 3)) ; => '(2 3 4)
+(map + '(1 2 3) '(10 20 30)) ; => '(11 22 33)
+(filter even? '(1 2 3 4)) ; => '(2 4)
+(count even? '(1 2 3 4)) ; => 2
+(take '(1 2 3 4) 2) ; => '(1 2)
+(drop '(1 2 3 4) 2) ; => '(3 4)
+
+;;; 向量
+
+;; 向量是定长的数组
+#(1 2 3) ; => '#(1 2 3)
+
+;; 使用 `vector-append' 方法将2个向量合并
+(vector-append #(1 2 3) #(4 5 6)) ; => #(1 2 3 4 5 6)
+
+;;; Set(翻译成集合也不太合适,所以不翻译了..)
+
+;; 从一个列表创建一个Set
+(list->set '(1 2 3 1 2 3 3 2 1 3 2 1)) ; => (set 1 2 3)
+
+;; 使用 `set-add' 增加一个成员
+;; (函数式特性: 这里会返回一个扩展后的Set,而不是修改输入的值)
+(set-add (set 1 2 3) 4) ; => (set 1 2 3 4)
+
+;; 使用 `set-remove' 移除一个成员
+(set-remove (set 1 2 3) 1) ; => (set 2 3)
+
+;; 使用 `set-member?' 测试成员是否存在
+(set-member? (set 1 2 3) 1) ; => #t
+(set-member? (set 1 2 3) 4) ; => #f
+
+;;; 散列表
+
+;; 创建一个不变的散列表 (可变散列表的例子在下面)
+(define m (hash 'a 1 'b 2 'c 3))
+
+;; 根据键取得值
+(hash-ref m 'a) ; => 1
+
+;; 获取一个不存在的键是一个异常
+; (hash-ref m 'd) => 没有找到元素
+
+;; 你可以给不存在的键提供一个默认值
+(hash-ref m 'd 0) ; => 0
+
+;; 使用 `hash-set' 来扩展一个不可变的散列表
+;; (返回的是扩展后的散列表而不是修改它)
+(define m2 (hash-set m 'd 4))
+m2 ; => '#hash((b . 2) (a . 1) (d . 4) (c . 3))
+
+;; 记住,使用 `hash` 创建的散列表是不可变的
+m ; => '#hash((b . 2) (a . 1) (c . 3)) <-- no `d'
+
+;; 使用 `hash-remove' 移除一个键值对 (函数式特性,m并不变)
+(hash-remove m 'a) ; => '#hash((b . 2) (c . 3))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 函数
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 使用 `lambda' 创建函数
+;; 函数总是返回它最后一个表达式的值
+(lambda () "Hello World") ; => #<procedure>
+;; 也可以使用 Unicode 字符 `λ'
+(λ () "Hello World") ; => 同样的函数
+
+;; 使用括号调用一个函数,也可以直接调用一个 lambda 表达式
+((lambda () "Hello World")) ; => "Hello World"
+((λ () "Hello World")) ; => "Hello World"
+
+;; 将函数赋值为一个变量
+(define hello-world (lambda () "Hello World"))
+(hello-world) ; => "Hello World"
+
+;; 你可以使用函数定义的语法糖来简化代码
+(define (hello-world2) "Hello World")
+
+;; `()`是函数的参数列表
+(define hello
+ (lambda (name)
+ (string-append "Hello " name)))
+(hello "Steve") ; => "Hello Steve"
+;; 同样的,可以使用语法糖来定义:
+(define (hello2 name)
+ (string-append "Hello " name))
+
+;; 你也可以使用可变参数, `case-lambda'
+(define hello3
+ (case-lambda
+ [() "Hello World"]
+ [(name) (string-append "Hello " name)]))
+(hello3 "Jake") ; => "Hello Jake"
+(hello3) ; => "Hello World"
+;; ... 或者给参数指定一个可选的默认值
+(define (hello4 [name "World"])
+ (string-append "Hello " name))
+
+;; 函数可以将多余的参数放到一个列表里
+(define (count-args . args)
+ (format "You passed ~a args: ~a" (length args) args))
+(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)"
+;; ... 也可以使用不带语法糖的 `lambda' 形式:
+(define count-args2
+ (lambda args
+ (format "You passed ~a args: ~a" (length args) args)))
+
+;; 你可以混用两种用法
+(define (hello-count name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args)))
+(hello-count "Finn" 1 2 3)
+; => "Hello Finn, you passed 3 extra args"
+;; ... 不带语法糖的形式:
+(define hello-count2
+ (lambda (name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args))))
+
+;; 使用关键字
+(define (hello-k #:name [name "World"] #:greeting [g "Hello"] . args)
+ (format "~a ~a, ~a extra args" g name (length args)))
+(hello-k) ; => "Hello World, 0 extra args"
+(hello-k 1 2 3) ; => "Hello World, 3 extra args"
+(hello-k #:greeting "Hi") ; => "Hi World, 0 extra args"
+(hello-k #:name "Finn" #:greeting "Hey") ; => "Hey Finn, 0 extra args"
+(hello-k 1 2 3 #:greeting "Hi" #:name "Finn" 4 5 6)
+ ; => "Hi Finn, 6 extra args"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. 判断是否相等
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 判断数字使用 `='
+(= 3 3.0) ; => #t
+(= 2 1) ; => #f
+
+;; 判断对象使用 `eq?'
+(eq? 3 3) ; => #t
+(eq? 3 3.0) ; => #f
+(eq? (list 3) (list 3)) ; => #f
+
+;; 判断集合使用 `equal?'
+(equal? (list 'a 'b) (list 'a 'b)) ; => #t
+(equal? (list 'a 'b) (list 'b 'a)) ; => #f
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. 控制结构
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 条件判断
+
+(if #t ; 测试表达式
+ "this is true" ; 为真的表达式
+ "this is false") ; 为假的表达式
+; => "this is true"
+
+;; 注意, 除 `#f` 之外的所有值都认为是真
+(member 'Groucho '(Harpo Groucho Zeppo)) ; => '(Groucho Zeppo)
+(if (member 'Groucho '(Harpo Groucho Zeppo))
+ 'yep
+ 'nope)
+; => 'yep
+
+;; `cond' 会进行一系列的判断来选择一个结果
+(cond [(> 2 2) (error "wrong!")]
+ [(< 2 2) (error "wrong again!")]
+ [else 'ok]) ; => 'ok
+
+;;; 模式匹配
+
+(define (fizzbuzz? n)
+ (match (list (remainder n 3) (remainder n 5))
+ [(list 0 0) 'fizzbuzz]
+ [(list 0 _) 'fizz]
+ [(list _ 0) 'buzz]
+ [_ #f]))
+
+(fizzbuzz? 15) ; => 'fizzbuzz
+(fizzbuzz? 37) ; => #f
+
+;;; 循环
+
+;; 循环可以使用递归(尾递归)
+(define (loop i)
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i))))
+(loop 5) ; => i=5, i=6, ...
+
+;; 类似的,可以使用 `let` 定义
+(let loop ((i 0))
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i)))) ; => i=0, i=1, ...
+
+;; 看上面的例子怎么增加一个新的 `loop' 形式, 但是 Racket 已经有了一个非常
+;; 灵活的 `for' 了:
+(for ([i 10])
+ (printf "i=~a\n" i)) ; => i=0, i=1, ...
+(for ([i (in-range 5 10)])
+ (printf "i=~a\n" i)) ; => i=5, i=6, ...
+
+;;; 其他形式的迭代
+;; `for' 允许在很多数据结构中迭代:
+;; 列表, 向量, 字符串, Set, 散列表, 等...
+
+(for ([i (in-list '(l i s t))])
+ (displayln i))
+
+(for ([i (in-vector #(v e c t o r))])
+ (displayln i))
+
+(for ([i (in-string "string")])
+ (displayln i))
+
+(for ([i (in-set (set 'x 'y 'z))])
+ (displayln i))
+
+(for ([(k v) (in-hash (hash 'a 1 'b 2 'c 3 ))])
+ (printf "key:~a value:~a\n" k v))
+
+;;; 更多复杂的迭代
+
+;; 并行扫描多个序列 (遇到长度小的就停止)
+(for ([i 10] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x 1:y 2:z
+
+;; 嵌套循环
+(for* ([i 2] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x, 0:y, 0:z, 1:x, 1:y, 1:z
+
+;; 带有条件判断的 `for`
+(for ([i 1000]
+ #:when (> i 5)
+ #:unless (odd? i)
+ #:break (> i 10))
+ (printf "i=~a\n" i))
+; => i=6, i=8, i=10
+
+;;; 更多的例子帮助你加深理解..
+;; 和 `for' 循环非常像 -- 收集结果
+
+(for/list ([i '(1 2 3)])
+ (add1 i)) ; => '(2 3 4)
+
+(for/list ([i '(1 2 3)] #:when (even? i))
+ i) ; => '(2)
+
+(for/list ([i 10] [j '(x y z)])
+ (list i j)) ; => '((0 x) (1 y) (2 z))
+
+(for/list ([i 1000] #:when (> i 5) #:unless (odd? i) #:break (> i 10))
+ i) ; => '(6 8 10)
+
+(for/hash ([i '(1 2 3)])
+ (values i (number->string i)))
+; => '#hash((1 . "1") (2 . "2") (3 . "3"))
+
+;; 也有很多其他的内置方法来收集循环中的值:
+(for/sum ([i 10]) (* i i)) ; => 285
+(for/product ([i (in-range 1 11)]) (* i i)) ; => 13168189440000
+(for/and ([i 10] [j (in-range 10 20)]) (< i j)) ; => #t
+(for/or ([i 10] [j (in-range 0 20 2)]) (= i j)) ; => #t
+;; 如果需要合并计算结果, 使用 `for/fold'
+(for/fold ([sum 0]) ([i '(1 2 3 4)]) (+ sum i)) ; => 10
+;; (这个函数可以在大部分情况下替代普通的命令式循环)
+
+;;; 异常
+
+;; 要捕获一个异常,使用 `with-handlers' 形式
+(with-handlers ([exn:fail? (lambda (exn) 999)])
+ (+ 1 "2")) ; => 999
+(with-handlers ([exn:break? (lambda (exn) "no time")])
+ (sleep 3)
+ "phew") ; => "phew", 如果你打断了它,那么结果 => "no time"
+
+;; 使用 `raise' 抛出一个异常后者其他任何值
+(with-handlers ([number? ; 捕获抛出的数字类型的值
+ identity]) ; 将它们作为普通值
+ (+ 1 (raise 2))) ; => 2
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. 可变的值
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 使用 `set!' 给一个已经存在的变量赋一个新值
+(define n 5)
+(set! n (add1 n))
+n ; => 6
+
+;; 给那些明确地需要变化的值使用 `boxes` (在其他语言里类似指针
+;; 或者引用)
+(define n* (box 5))
+(set-box! n* (add1 (unbox n*)))
+(unbox n*) ; => 6
+
+;; 很多 Racket 诗句类型是不可变的 (对,列表,等),有一些既是可变的
+;; 又是不可变的 (字符串,向量,散列表
+;; 等...)
+
+;; 使用 `vector' 或者 `make-vector' 创建一个可变的向量
+(define vec (vector 2 2 3 4))
+(define wall (make-vector 100 'bottle-of-beer))
+;; 使用 `vector-set!` 更新一项
+(vector-set! vec 0 1)
+(vector-set! wall 99 'down)
+vec ; => #(1 2 3 4)
+
+;; 创建一个空的可变散列表,然后操作它
+(define m3 (make-hash))
+(hash-set! m3 'a 1)
+(hash-set! m3 'b 2)
+(hash-set! m3 'c 3)
+(hash-ref m3 'a) ; => 1
+(hash-ref m3 'd 0) ; => 0
+(hash-remove! m3 'a)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. 模块
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 模块让你将你的代码组织为多个文件,成为可重用的模块,
+;; 在这里,我们使用嵌套在本文的整个大模块
+;; 里的子模块(从 "#lang" 这一行开始)
+
+(module cake racket/base ; 基于 racket/base 定义一个 `cake` 模块
+
+ (provide print-cake) ; 这个模块导出的函数
+
+ (define (print-cake n)
+ (show " ~a " n #\.)
+ (show " .-~a-. " n #\|)
+ (show " | ~a | " n #\space)
+ (show "---~a---" n #\-))
+
+ (define (show fmt n ch) ; 内部函数
+ (printf fmt (make-string n ch))
+ (newline)))
+
+;; 使用 `require` 从模块中得到所有 `provide` 的函数
+(require 'cake) ; 这里的 `'`表示是本地的子模块
+(print-cake 3)
+; (show "~a" 1 #\A) ; => 报错, `show' 没有被导出,不存在
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 8. 类和对象
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 创建一个 fish% 类(%是给类绑定用的)
+(define fish%
+ (class object%
+ (init size) ; 初始化的参数
+ (super-new) ; 父类的初始化
+ ;; 域
+ (define current-size size)
+ ;; 公共方法
+ (define/public (get-size)
+ current-size)
+ (define/public (grow amt)
+ (set! current-size (+ amt current-size)))
+ (define/public (eat other-fish)
+ (grow (send other-fish get-size)))))
+
+;; 创建一个 fish% 类的示例
+(define charlie
+ (new fish% [size 10]))
+
+;; 使用 `send' 调用一个对象的方法
+(send charlie get-size) ; => 10
+(send charlie grow 6)
+(send charlie get-size) ; => 16
+
+;; `fish%' 是一个普通的值,我们可以用它来混入
+(define (add-color c%)
+ (class c%
+ (init color)
+ (super-new)
+ (define my-color color)
+ (define/public (get-color) my-color)))
+(define colored-fish% (add-color fish%))
+(define charlie2 (new colored-fish% [size 10] [color 'red]))
+(send charlie2 get-color)
+;; 或者,不带名字
+(send (new (add-color fish%) [size 10] [color 'red]) get-color)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 9. 宏
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 宏让你扩展这门语言的语法
+
+;; 让我们定义一个while循环
+(define-syntax-rule (while condition body ...)
+ (let loop ()
+ (when condition
+ body ...
+ (loop))))
+
+(let ([i 0])
+ (while (< i 10)
+ (displayln i)
+ (set! i (add1 i))))
+
+;; 宏是安全的,你不能修改现有的变量
+(define-syntax-rule (swap! x y) ; !表示会修改
+ (let ([tmp x])
+ (set! x y)
+ (set! y tmp)))
+
+(define tmp 2)
+(define other 3)
+(swap! tmp other)
+(printf "tmp = ~a; other = ~a\n" tmp other)
+;; 变量 `tmp` 被重命名为 `tmp_1`
+;; 避免名字冲突
+;; (let ([tmp_1 tmp])
+;; (set! tmp other)
+;; (set! other tmp_1))
+
+;; 但它们仍然会导致错误代码,比如:
+(define-syntax-rule (bad-while condition body ...)
+ (when condition
+ body ...
+ (bad-while condition body ...)))
+;; 这个宏会挂掉,它产生了一个无限循环,如果你试图去使用它
+;; 编译器会进入死循环
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 10. 契约
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 契约限制变量从模块中导入
+
+(module bank-account racket
+ (provide (contract-out
+ [deposit (-> positive? any)] ; 数量一直是正值
+ [balance (-> positive?)]))
+
+ (define amount 0)
+ (define (deposit a) (set! amount (+ amount a)))
+ (define (balance) amount)
+ )
+
+(require 'bank-account)
+(deposit 5)
+
+(balance) ; => 5
+
+;; 客户端尝试存储一个负值时会出错
+;; (deposit -5) ; => deposit: contract violation
+;; expected: positive?
+;; given: -5
+;; more details....
+```
+
+## 进一步阅读
+
+想知道更多吗? 尝试 [Getting Started with Racket](http://docs.racket-lang.org/getting-started/)
diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown
index 6530b520..619e6e92 100644
--- a/zh-cn/ruby-cn.html.markdown
+++ b/zh-cn/ruby-cn.html.markdown
@@ -94,7 +94,7 @@ x = y = 10 #=> 10
x #=> 10
y #=> 10
-# 按照惯例,用snake_case 作为变量名
+# 按照惯例,用 snake_case 作为变量名
snake_case = true
# 使用具有描述性的运算符
@@ -102,7 +102,8 @@ path_to_project_root = '/good/name/'
path = '/bad/name/'
# 符号(Symbols,也是对象)
-# 符号是不可变的,内部用整数类型表示的可重用的值。通常用它代替字符串来有效地表达有意义的值
+# 符号是不可变的,内部用整数类型表示的可重用的值。
+# 通常用它代替字符串来有效地表示有意义的值。
:pending.class #=> Symbol