summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--common-lisp.html.markdown605
-rw-r--r--csharp.html.markdown549
-rw-r--r--haskell.html.markdown2
-rw-r--r--ko-kr/javascript-kr.html.markdown435
-rw-r--r--ko-kr/lua-kr.html.markdown424
-rw-r--r--php.html.markdown5
-rw-r--r--ruby-ecosystem.html.markdown6
-rw-r--r--ruby.html.markdown28
-rw-r--r--zh-cn/racket-cn.html.markdown608
-rw-r--r--zh-cn/ruby-cn.html.markdown5
10 files changed, 2653 insertions, 14 deletions
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/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/ko-kr/javascript-kr.html.markdown b/ko-kr/javascript-kr.html.markdown
new file mode 100644
index 00000000..79f5d88b
--- /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") // will open a popup with "Hello, Adam!" in 5s
+
+///////////////////////////////////
+// 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){ // don't overwrite it if it exists
+ 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)을 참고했습니다. \ No newline at end of file
diff --git a/ko-kr/lua-kr.html.markdown b/ko-kr/lua-kr.html.markdown
new file mode 100644
index 00000000..2badf734
--- /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 = {}
+ -- set up 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/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/ruby-ecosystem.html.markdown b/ruby-ecosystem.html.markdown
index a31f552d..cae55cd3 100644
--- a/ruby-ecosystem.html.markdown
+++ b/ruby-ecosystem.html.markdown
@@ -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..68c5b524 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -5,6 +5,7 @@ contributors:
- ["David Underwood", "http://theflyingdeveloper.com"]
- ["Joel Walden", "http://joelwalden.net"]
- ["Luke Holder", "http://twitter.com/lukeholder"]
+ - ["Tristan Hume", "http://thume.ca/"]
---
```ruby
@@ -158,11 +159,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}
@@ -191,9 +187,14 @@ 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 +205,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}"
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