summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bash.html.markdown8
-rw-r--r--c.html.markdown32
-rw-r--r--clojure-macros.html.markdown152
-rw-r--r--coffeescript.html.markdown51
-rw-r--r--common-lisp.html.markdown4
-rw-r--r--csharp.html.markdown34
-rw-r--r--css.html.markdown26
-rw-r--r--de-de/bash-de.html.markdown2
-rw-r--r--de-de/css-de.html.markdown1
-rw-r--r--elisp.html.markdown14
-rw-r--r--elixir.html.markdown10
-rw-r--r--erlang.html.markdown39
-rw-r--r--es-es/go-es.html.markdown199
-rw-r--r--es-es/julia-es.html.markdown759
-rw-r--r--es-es/python-es.html.markdown4
-rw-r--r--es-es/python3-es.html.markdown570
-rw-r--r--fa-ir/javascript.html.markdown2
-rw-r--r--fr-fr/csharp-fr.html.markdown812
-rw-r--r--fr-fr/haskell.html.markdown1
-rw-r--r--fr-fr/objective-c-fr.html.markdown528
-rw-r--r--fr-fr/python-fr.html.markdown2
-rw-r--r--go.html.markdown148
-rw-r--r--haskell.html.markdown2
-rw-r--r--haxe.html.markdown2
-rw-r--r--hu-hu/go.html.markdown42
-rw-r--r--hy.html.markdown174
-rw-r--r--id-id/css-id.html.markdown246
-rw-r--r--it-it/brainfuck-it.html.markdown101
-rw-r--r--it-it/java-it.html.markdown502
-rw-r--r--java.html.markdown68
-rw-r--r--javascript.html.markdown53
-rw-r--r--json.html.markdown48
-rw-r--r--julia.html.markdown410
-rw-r--r--ko-kr/coffeescript-kr.html.markdown2
-rw-r--r--ko-kr/go-kr.html.markdown314
-rw-r--r--ko-kr/javascript-kr.html.markdown1
-rw-r--r--ko-kr/lua-kr.html.markdown1
-rw-r--r--ko-kr/php-kr.html.markdown2
-rw-r--r--ko-kr/racket-kr.html.markdown640
-rw-r--r--livescript.html.markdown2
-rw-r--r--lua.html.markdown151
-rw-r--r--markdown.html.markdown246
-rw-r--r--matlab.html.markdown2
-rw-r--r--objective-c.html.markdown394
-rw-r--r--paren.html.markdown193
-rw-r--r--perl.html.markdown2
-rw-r--r--php.html.markdown2
-rw-r--r--pt-br/go-pt.html.markdown4
-rw-r--r--pt-br/java-pt.html.markdown2
-rw-r--r--pt-br/ruby-pt.html.markdown4
-rw-r--r--pt-br/visualbasic-pt.html.markdown285
-rw-r--r--python.html.markdown247
-rw-r--r--python3.html.markdown578
-rw-r--r--r.html.markdown525
-rw-r--r--racket.html.markdown8
-rw-r--r--red.html.markdown219
-rw-r--r--ro-ro/bash-ro.html.markdown177
-rw-r--r--ro-ro/ruby-ro.html.markdown491
-rw-r--r--ru-ru/c-ru.html.markdown4
-rw-r--r--ru-ru/go-ru.html.markdown174
-rw-r--r--ru-ru/haskell-ru.html.markdown546
-rw-r--r--ru-ru/julia-ru.html.markdown750
-rw-r--r--ruby.html.markdown32
-rw-r--r--scala.html.markdown5
-rw-r--r--xml.html.markdown126
-rw-r--r--yaml.html.markdown139
-rw-r--r--zh-cn/bash-cn.html.markdown2
-rw-r--r--zh-cn/c-cn.html.markdown394
-rw-r--r--zh-cn/clojure-cn.html.markdown2
-rw-r--r--zh-cn/clojure-macro-cn.html.markdown152
-rw-r--r--zh-cn/coffeescript-cn.html.markdown101
-rw-r--r--zh-cn/common-lisp-cn.html.markdown12
-rw-r--r--zh-cn/csharp-cn.html.markdown798
-rw-r--r--zh-cn/css-cn.html.markdown212
-rw-r--r--zh-cn/elisp-cn.html.markdown4
-rw-r--r--zh-cn/elixir-cn.html.markdown399
-rw-r--r--zh-cn/erlang-cn.html.markdown259
-rw-r--r--zh-cn/json-cn.html.markdown51
-rw-r--r--zh-cn/lua-cn.html.markdown413
-rw-r--r--zh-cn/php-cn.html.markdown6
-rw-r--r--zh-cn/r-cn.html.markdown2
-rw-r--r--zh-cn/racket-cn.html.markdown2
-rw-r--r--zh-cn/scala-cn.html.markdown1
-rw-r--r--zh-cn/visualbasic-cn.html.markdown274
-rw-r--r--zh-cn/xml-cn.html.markdown127
-rw-r--r--zh-cn/yaml-cn.html.markdown136
86 files changed, 13636 insertions, 1025 deletions
diff --git a/bash.html.markdown b/bash.html.markdown
index a6bd2b7c..d5d08e9d 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -15,7 +15,7 @@ Nearly all examples below can be a part of a shell script or executed directly i
[Read more here.](http://www.gnu.org/software/bash/manual/bashref.html)
```bash
-#!/bin/sh
+#!/bin/bash
# First line of the script is shebang which tells the system how to execute
# the script: http://en.wikipedia.org/wiki/Shebang_(Unix)
# As you already figured, comments start with #. Shebang is also a comment.
@@ -46,11 +46,15 @@ echo '$VARIABLE'
echo ${VARIABLE/Some/A}
# This will substitute the first occurance of "Some" with "A"
+# Substring from a variable
+echo ${VARIABLE:0:7}
+# This will return only the first 7 characters of the value
+
# Default value for variable
echo ${FOO:-"DefaultValueIfFOOIsMissingOrEmpty"}
# This works for null (FOO=), empty string (FOO=""), zero (FOO=0) returns 0
-# Bultin variables:
+# Builtin variables:
# There are some useful builtin variables, like
echo "Last program return value: $?"
echo "Script's PID: $$"
diff --git a/c.html.markdown b/c.html.markdown
index 84856b32..c89f2b88 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -92,7 +92,7 @@ int main() {
printf("%zu\n", sizeof(int)); // => 4 (on most machines with 4-byte words)
- // If the argument of the `sizeof` operator an expression, then its argument
+ // If the argument of the `sizeof` operator is an expression, then its argument
// is not evaluated (except VLAs (see below)).
// The value it yields in this case is a compile-time constant.
int a = 1;
@@ -154,7 +154,7 @@ int main() {
int multi_array[2][5] = {
{1, 2, 3, 4, 5},
{6, 7, 8, 9, 0}
- }
+ };
//access elements:
int array_int = multi_array[0][2]; // => 3
@@ -215,7 +215,7 @@ int main() {
z = (a > b) ? a : b; // => 10 "if a > b return a, else return b."
//Increment and decrement operators:
- char *s = "iLoveC"
+ char *s = "iLoveC";
int j = 0;
s[j++]; // => "i". Returns the j-th item of s THEN increments value of j.
j = 0;
@@ -251,7 +251,7 @@ int main() {
// While loops exist
int ii = 0;
while (ii < 10) { //ANY value not zero is true.
- printf("%d, ", ii++); // ii++ increments ii AFTER using it's current value.
+ printf("%d, ", ii++); // ii++ increments ii AFTER using its current value.
} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
printf("\n");
@@ -259,7 +259,7 @@ int main() {
int kk = 0;
do {
printf("%d, ", kk);
- } while (++kk < 10); // ++kk increments kk BEFORE using it's current value.
+ } while (++kk < 10); // ++kk increments kk BEFORE using its current value.
// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
printf("\n");
@@ -367,7 +367,7 @@ int main() {
// 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:
+ // Exceptions: when the array is the argument of the `&` (address-of) operator:
int arr[10];
int (*ptr_to_arr)[10] = &arr; // &arr is NOT of type `int *`!
// It's of type "pointer to array" (of ten `int`s).
@@ -376,7 +376,7 @@ int main() {
// 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"
+ printf("%zu, %zu\n", sizeof arr, sizeof ptr); // probably prints "40, 4" or "40, 8"
// Pointers are incremented and decremented based on their type
@@ -387,7 +387,7 @@ int main() {
// 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).
+ // 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
@@ -405,7 +405,7 @@ int main() {
// 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.)
+ // 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'
@@ -454,6 +454,12 @@ void str_reverse(char *str_in)
}
}
+/*
+char c[] = "This is a test.";
+str_reverse(c);
+printf("%s\n", c); // => ".tset a si sihT"
+*/
+
//if referring to external variables outside function, must use extern keyword.
int i = 0;
void testFunc() {
@@ -467,11 +473,7 @@ void testFunc() {
}
//**You may also declare functions as static to make them private**
-/*
-char c[] = "This is a test.";
-str_reverse(c);
-printf("%s\n", c); // => ".tset a si sihT"
-*/
+
///////////////////////////////////////
// User-defined types and structs
@@ -567,7 +569,7 @@ typedef void (*my_fnp_type)(char *);
'\b' // backspace character
'\0' // null character. Usually put at end of strings in C lang.
// hello\n\0. \0 used by convention to mark end of string.
-'\\' // backspace
+'\\' // backslash
'\?' // question mark
'\'' // single quote
'\"' // double quote
diff --git a/clojure-macros.html.markdown b/clojure-macros.html.markdown
new file mode 100644
index 00000000..8e671936
--- /dev/null
+++ b/clojure-macros.html.markdown
@@ -0,0 +1,152 @@
+---
+language: "clojure macros"
+filename: learnclojuremacros.clj
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+---
+
+As with all Lisps, Clojure's inherent [homoiconicity](https://en.wikipedia.org/wiki/Homoiconic)
+gives you access to the full extent of the language to write code-generation routines
+called "macros". Macros provide a powerful way to tailor the language to your needs.
+
+Be careful though. It's considered bad form to write a macro when a function will do.
+Use a macro only when you need control over when or if the arguments to a form will
+be evaluated.
+
+You'll want to be familiar with Clojure. Make sure you understand everything in
+[Clojure in Y Minutes](/docs/clojure/).
+
+```clojure
+;; Define a macro using defmacro. Your macro should output a list that can
+;; be evaluated as clojure code.
+;;
+;; This macro is the same as if you wrote (reverse "Hello World")
+(defmacro my-first-macro []
+ (list reverse "Hello World"))
+
+;; Inspect the result of a macro using macroexpand or macroexpand-1.
+;;
+;; Note that the call must be quoted.
+(macroexpand '(my-first-macro))
+;; -> (#<core$reverse clojure.core$reverse@xxxxxxxx> "Hello World")
+
+;; You can eval the result of macroexpand directly:
+(eval (macroexpand '(my-first-macro)))
+; -> (\d \l \o \r \W \space \o \l \l \e \H)
+
+;; But you should use this more succinct, function-like syntax:
+(my-first-macro) ; -> (\d \l \o \r \W \space \o \l \l \e \H)
+
+;; You can make things easier on yourself by using the more succinct quote syntax
+;; to create lists in your macros:
+(defmacro my-first-quoted-macro []
+ '(reverse "Hello World"))
+
+(macroexpand '(my-first-quoted-macro))
+;; -> (reverse "Hello World")
+;; Notice that reverse is no longer function object, but a symbol.
+
+;; Macros can take arguments.
+(defmacro inc2 [arg]
+ (list + 2 arg))
+
+(inc2 2) ; -> 4
+
+;; But, if you try to do this with a quoted list, you'll get an error, because
+;; the argument will be quoted too. To get around this, clojure provides a
+;; way of quoting macros: `. Inside `, you can use ~ to get at the outer scope
+(defmacro inc2-quoted [arg]
+ `(+ 2 ~arg))
+
+(inc2-quoted 2)
+
+;; You can use the usual destructuring args. Expand list variables using ~@
+(defmacro unless [arg & body]
+ `(if (not ~arg)
+ (do ~@body))) ; Remember the do!
+
+(macroexpand '(unless true (reverse "Hello World")))
+;; ->
+;; (if (clojure.core/not true) (do (reverse "Hello World")))
+
+;; (unless) evaluates and returns its body if the first argument is false.
+;; Otherwise, it returns nil
+
+(unless true "Hello") ; -> nil
+(unless false "Hello") ; -> "Hello"
+
+;; Used without care, macros can do great evil by clobbering your vars
+(defmacro define-x []
+ '(do
+ (def x 2)
+ (list x)))
+
+(def x 4)
+(define-x) ; -> (2)
+(list x) ; -> (2)
+
+;; To avoid this, use gensym to get a unique identifier
+(gensym 'x) ; -> x1281 (or some such thing)
+
+(defmacro define-x-safely []
+ (let [sym (gensym 'x)]
+ `(do
+ (def ~sym 2)
+ (list ~sym))))
+
+(def x 4)
+(define-x-safely) ; -> (2)
+(list x) ; -> (4)
+
+;; You can use # within ` to produce a gensym for each symbol automatically
+(defmacro define-x-hygenically []
+ `(do
+ (def x# 2)
+ (list x#)))
+
+(def x 4)
+(define-x-hygenically) ; -> (2)
+(list x) ; -> (4)
+
+;; It's typical to use helper functions with macros. Let's create a few to
+;; help us support a (dumb) inline arithmatic syntax
+(declare inline-2-helper)
+(defn clean-arg [arg]
+ (if (seq? arg)
+ (inline-2-helper arg)
+ arg))
+
+(defn apply-arg
+ "Given args [x (+ y)], return (+ x y)"
+ [val [op arg]]
+ (list op val (clean-arg arg)))
+
+(defn inline-2-helper
+ [[arg1 & ops-and-args]]
+ (let [ops (partition 2 ops-and-args)]
+ (reduce apply-arg (clean-arg arg1) ops)))
+
+;; We can test it immediately, without creating a macro
+(inline-2-helper '(a + (b - 2) - (c * 5))) ; -> (- (+ a (- b 2)) (* c 5))
+
+; However, we'll need to make it a macro if we want it to be run at compile time
+(defmacro inline-2 [form]
+ (inline-2-helper form)))
+
+(macroexpand '(inline-2 (1 + (3 / 2) - (1 / 2) + 1)))
+; -> (+ (- (+ 1 (/ 3 2)) (/ 1 2)) 1)
+
+(inline-2 (1 + (3 / 2) - (1 / 2) + 1))
+; -> 3 (actually, 3N, since the number got cast to a rational fraction with /)
+```
+
+### Further Reading
+
+Writing Macros from [Clojure for the Brave and True](http://www.braveclojure.com/)
+[http://www.braveclojure.com/writing-macros/](http://www.braveclojure.com/writing-macros/)
+
+Official docs
+[http://clojure.org/macros](http://clojure.org/macros)
+
+When to use macros?
+[http://dunsmor.com/lisp/onlisp/onlisp_12.html](http://dunsmor.com/lisp/onlisp/onlisp_12.html)
diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown
index 429f10b5..d96eed39 100644
--- a/coffeescript.html.markdown
+++ b/coffeescript.html.markdown
@@ -2,13 +2,19 @@
language: coffeescript
contributors:
- ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
filename: coffeescript.coffee
---
+CoffeeScript is a little language that compiles one-to-one into the equivalent JavaScript, and there is no interpretation at runtime.
+As one of the succeeders of JavaScript, CoffeeScript tries its best to output readable, pretty-printed and smooth-running JavaScript codes working well in every JavaScript runtime.
+
+See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript.
+
``` coffeescript
# CoffeeScript is a hipster language.
# It goes with the trends of many modern languages.
-# So comments are like Ruby and Python, they use hashes.
+# So comments are like Ruby and Python, they use number symbols.
###
Block comments are like these, and they translate directly to '/ *'s and '* /'s
@@ -28,6 +34,17 @@ number = -42 if opposite #=> if(opposite) { number = -42; }
# Functions:
square = (x) -> x * x #=> var square = function(x) { return x * x; }
+fill = (container, liquid = "coffee") ->
+ "Filling the #{container} with #{liquid}..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "coffee";
+# }
+# return "Filling the " + container + " with " + liquid + "...";
+#};
+
# Ranges:
list = [1..5] #=> var list = [1, 2, 3, 4, 5];
@@ -45,11 +62,41 @@ math =
# Splats:
race = (winner, runners...) ->
print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
# Existence:
alert "I knew it!" if elvis?
#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
# Array comprehensions:
-cubes = (math.cube num for num in list) #=> ...
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['broccoli', 'spinach', 'chocolate']
+eat food for food in foods when food isnt 'chocolate'
+#=>foods = ['broccoli', 'spinach', 'chocolate'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'chocolate') {
+# eat(food);
+# }
+#}
```
+
+## Additional resources
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown
index dda60797..8de81549 100644
--- a/common-lisp.html.markdown
+++ b/common-lisp.html.markdown
@@ -8,7 +8,7 @@ contributors:
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.
+frequently referred to as a programmable programming language.
The classic starting point is [Practical Common Lisp and freely available.](http://www.gigamonkeys.com/book/)
@@ -140,7 +140,7 @@ nil ; for false - and the empty list
;; 2. Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; You can create a global (dynamically scoped) using defparameter
-;; a variable name can use any character except: ()[]{}",'`;#|\
+;; a variable name can use any character except: ()",'`;#|\
;; Dynamically scoped variables should have earmuffs in their name!
diff --git a/csharp.html.markdown b/csharp.html.markdown
index dad0c26b..4fa8deba 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -30,6 +30,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Threading.Tasks;
+using System.IO;
// defines scope to organize code into "packages"
namespace Learning
@@ -105,7 +106,7 @@ namespace Learning
Console.WriteLine(fooString);
// You can access each character of the string with an indexer:
- char charFromString = fooString[1]; // 'y'
+ char charFromString = fooString[1]; // => 'e'
// Strings are immutable: you can't do fooString[1] = 'X';
// Compare strings with current culture, ignoring case
@@ -173,7 +174,7 @@ on a new line! ""Wow!"", the masses cried";
int i1 = 1, i2 = 2; // Shorthand for multiple declarations
// Arithmetic is straightforward
- Console.WriteLine(i1 + i2 - i1 * 3 / 7); //
+ Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
// Modulo
Console.WriteLine("11%3 = " + (11 % 3)); // => 2
@@ -241,7 +242,7 @@ on a new line! ""Wow!"", the masses cried";
int fooDoWhile = 0;
do
{
- //Iterated 99 times, fooDoWhile 0->99
+ //Iterated 100 times, fooDoWhile 0->99
fooDoWhile++;
} while (fooDoWhile < 100);
@@ -306,7 +307,7 @@ on a new line! ""Wow!"", the masses cried";
// try parse will default to type default on failure
// in this case: 0
int tryInt;
- if (int.TryParse("123", out tryInt)) // Funciton is boolean
+ if (int.TryParse("123", out tryInt)) // Function is boolean
Console.WriteLine(tryInt); // 123
// Convert Integer To String
@@ -434,6 +435,17 @@ on a new line! ""Wow!"", the masses cried";
Func<int, int> square = (x) => x * x; // Last T item is the return value
Console.WriteLine(square(3)); // 9
+ // DISPOSABLE RESOURCES MANAGEMENT - let you handle unmanaged resources easily.
+ // Most of objects that access unmanaged resources (file handle, device contexts, etc.)
+ // implement the IDisposable interface. The using statement takes care of
+ // cleaning those IDisposable objects for you.
+ using (StreamWriter writer = new StreamWriter("log.txt"))
+ {
+ writer.WriteLine("Nothing suspicious here");
+ // At the end of scope, resources will be released.
+ // Even if an exception is thrown.
+ }
+
// PARALLEL FRAMEWORK
// http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx
var websites = new string[] {
@@ -499,11 +511,11 @@ on a new line! ""Wow!"", the masses cried";
var db = new BikeRespository();
// execution is delayed, which is great when querying a database
- var fitler = db.Bikes.Where(b => b.HasTassles); // no query run
+ var filter = db.Bikes.Where(b => b.HasTassles); // no query run
if (42 > 6) // You can keep adding filters, even conditionally - great for "advanced search" functionality
- fitler = fitler.Where(b => b.IsBroken); // no query run
+ filter = filter.Where(b => b.IsBroken); // no query run
- var query = fitler
+ var query = filter
.OrderBy(b => b.Wheels)
.ThenBy(b => b.Name)
.Select(b => b.Name); // still no query run
@@ -546,7 +558,7 @@ on a new line! ""Wow!"", the masses cried";
}
set // set - define a method to set a proprety
{
- _cadence = value; // Value is the value passed in to to the setter
+ _cadence = value; // Value is the value passed in to the setter
}
}
private int _cadence;
@@ -564,7 +576,7 @@ on a new line! ""Wow!"", the masses cried";
}
int _speed; // Everything is private by default: Only accessible from within this class.
- // can also use keyword privatee
+ // can also use keyword private
public string Name { get; set; }
// Enum is a value type that consists of a set of named constants
@@ -576,7 +588,7 @@ on a new line! ""Wow!"", the masses cried";
AIST,
BMC,
Electra = 42, //you can explicitly set a value to a name
- Gitane
+ Gitane // 43
}
// We defined this type inside a Bicycle class, so it is a nested type
// Code outside of this class should reference this type as Bicycle.Brand
@@ -596,7 +608,7 @@ on a new line! ""Wow!"", the masses cried";
// This is a default constructor
public Bicycle()
{
- this.Gear = 1; // you can access mmebers of the object with the keyword this
+ this.Gear = 1; // you can access members of the object with the keyword this
Cadence = 50; // but you don't always need it
_speed = 5;
Name = "Bontrager";
diff --git a/css.html.markdown b/css.html.markdown
index b16b364d..cdef50cc 100644
--- a/css.html.markdown
+++ b/css.html.markdown
@@ -2,6 +2,8 @@
language: css
contributors:
- ["Mohammad Valipour", "https://github.com/mvalipour"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+filename: learncss.css
---
In early days of web there was no visual elements, just pure text. But with the
@@ -42,16 +44,16 @@ Given an element like this on the page:
<div class='some-class class2' id='someId' attr='value' />
*/
-/* you can target it by it's class name */
+/* you can target it by its name */
.some-class { }
/*or by both classes! */
.some-class.class2 { }
-/* or by it's tag name */
+/* or by its element name */
div { }
-/* or it's id */
+/* or its id */
#someId { }
/* or by the fact that it has an attribute! */
@@ -75,12 +77,12 @@ any spaaace between different parts because that makes it to have another
meaning.*/
div.some-class[attr$='ue'] { }
-/* you can also select an element based on how it's parent is.*/
+/* you can also select an element based on its parent.*/
/*an element which is direct child of an element (selected the same way) */
div.some-parent > .class-name {}
-/* or any of it's parents in the tree */
+/* or any of its parents in the tree */
/* the following basically means any element that has class "class-name"
and is child of a div with class name "some-parent" IN ANY DEPTH */
div.some-parent .class-name {}
@@ -89,7 +91,7 @@ div.some-parent .class-name {}
can you say what? */
div.some-parent.class-name {}
-/* you also might choose to select an element based on it's direct
+/* you also might choose to select an element based on its direct
previous sibling */
.i-am-before + .this-element { }
@@ -97,7 +99,7 @@ previous sibling */
.i-am-any-before ~ .this-element {}
/* There are some pseudo classes that allows you to select an element
-based on it's page behaviour (rather than page structure) */
+based on its page behaviour (rather than page structure) */
/* for example for when an element is hovered */
:hover {}
@@ -128,11 +130,11 @@ selector {
width: 5in; /* in inches */
/* Colors */
- background-color: #F6E /* in short hex */
- background-color: #F262E2 /* in long hex format */
- background-color: tomato /* can be a named color */
- background-color: rgb(255, 255, 255) /* in rgb */
- background-color: rgb(10%, 20%, 50%) /* in rgb percent */
+ background-color: #F6E; /* in short hex */
+ background-color: #F262E2; /* in long hex format */
+ background-color: tomato; /* can be a named color */
+ background-color: rgb(255, 255, 255); /* in rgb */
+ background-color: rgb(10%, 20%, 50%); /* in rgb percent */
background-color: rgba(255, 0, 0, 0.3); /* in semi-transparent rgb */
/* Images */
diff --git a/de-de/bash-de.html.markdown b/de-de/bash-de.html.markdown
index 7b60d79f..ad782e06 100644
--- a/de-de/bash-de.html.markdown
+++ b/de-de/bash-de.html.markdown
@@ -16,7 +16,7 @@ Beinahe alle der folgenden Beispiele können als Teile eines Shell-Skripts oder
[Weitere Informationen \(Englisch\)](http://www.gnu.org/software/bash/manual/bashref.html)
```bash
-#!/bin/sh
+#!/bin/bash
# Die erste Zeile des Scripts nennt sich Shebang in gibt dem System an, wie
# wie das Script ausgeführt werden soll: http://de.wikipedia.org/wiki/Shebang
# Du hast es bestimmt schon mitgekriegt, Kommentare fangen mit # an. Das Shebang ist auch ein Kommentar
diff --git a/de-de/css-de.html.markdown b/de-de/css-de.html.markdown
index e03b3174..8909b251 100644
--- a/de-de/css-de.html.markdown
+++ b/de-de/css-de.html.markdown
@@ -5,6 +5,7 @@ contributors:
translators:
- ["Kyr", "http://github.com/kyrami"]
lang: de-de
+filename: learncss-de.css
---
In den frühen Tagen des Internets gab es keine visuellen Elemente, alles war nur reiner Text. Aber mit der Weiterentwickliung von Browsern wurden auch vollständig visuelle Webseiten zu einem Standard.
diff --git a/elisp.html.markdown b/elisp.html.markdown
index d3910759..3208ffb8 100644
--- a/elisp.html.markdown
+++ b/elisp.html.markdown
@@ -280,10 +280,10 @@ filename: learn-emacs-lisp.el
;; should stop searching at some point in the buffer, and whether it
;; should silently fail when nothing is found:
-;; (search-forward "Hello" nil t) does the trick:
+;; (search-forward "Hello" nil 't) does the trick:
;; The `nil' argument says: the search is not bound to a position.
-;; The `t' argument says: silently fail when nothing is found.
+;; The `'t' argument says: silently fail when nothing is found.
;; We use this sexp in the function below, which doesn't throw an error:
@@ -294,7 +294,7 @@ filename: learn-emacs-lisp.el
(mapcar 'hello list-of-names)
(goto-char (point-min))
;; Replace "Hello" by "Bonjour"
- (while (search-forward "Hello" nil t)
+ (while (search-forward "Hello" nil 't)
(replace-match "Bonjour"))
(other-window 1))
@@ -305,7 +305,7 @@ filename: learn-emacs-lisp.el
(defun boldify-names ()
(switch-to-buffer-other-window "*test*")
(goto-char (point-min))
- (while (re-search-forward "Bonjour \\(.+\\)!" nil t)
+ (while (re-search-forward "Bonjour \\([^!]+\\)!" nil 't)
(add-text-properties (match-beginning 1)
(match-end 1)
(list 'face 'bold)))
@@ -317,9 +317,9 @@ filename: learn-emacs-lisp.el
;; The regular expression is "Bonjour \\(.+\\)!" and it reads:
;; the string "Bonjour ", and
-;; a group of | this is the \\( ... \\) construct
-;; any character | this is the .
-;; possibly repeated | this is the +
+;; a group of | this is the \\( ... \\) construct
+;; any character not ! | this is the [^!]
+;; possibly repeated | this is the +
;; and the "!" string.
;; Ready? Test it!
diff --git a/elixir.html.markdown b/elixir.html.markdown
index 8ea499ff..b27b2ee8 100644
--- a/elixir.html.markdown
+++ b/elixir.html.markdown
@@ -9,9 +9,9 @@ Elixir is a modern functional language built on top of the Erlang VM.
It's fully compatible with Erlang, but features a more standard syntax
and many more features.
-```ruby
+```elixir
-# Single line comments start with a hashtag.
+# Single line comments start with a number symbol.
# There's no multi-line comment,
# but you can stack multiple comments.
@@ -358,7 +358,7 @@ f = fn -> 2 * 2 end #=> #Function<erl_eval.20.80484245>
spawn(f) #=> #PID<0.40.0>
# `spawn` returns a pid (process identifier), you can use this pid to send
-# messages to the process. To do message passing we use the `<-` operator.
+# messages to the process. To do message passing we use the `send` operator.
# For all of this to be useful we need to be able to receive messages. This is
# achived with the `receive` mechanism:
defmodule Geometry do
@@ -378,11 +378,11 @@ end
pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0>
# Send a message to `pid` that will match a pattern in the receive statement
-pid <- {:rectangle, 2, 3}
+send pid, {:rectangle, 2, 3}
#=> Area = 6
# {:rectangle,2,3}
-pid <- {:circle, 2}
+send pid, {:circle, 2}
#=> Area = 12.56000000000000049738
# {:circle,2}
diff --git a/erlang.html.markdown b/erlang.html.markdown
index 065219ba..64b62f05 100644
--- a/erlang.html.markdown
+++ b/erlang.html.markdown
@@ -241,6 +241,45 @@ catcher(N) ->
% exception, it is converted into a tuple that describes the error.
catcher(N) -> catch generate_exception(N).
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 4. Concurrency
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Erlang relies on the actor model for concurrency. All we need to write
+% concurrent programs in erlang are three primitives: spawning processes,
+% sending messages and receiving messages.
+
+% To start a new process we use the `spawn` function, which takes a function
+% as argument.
+
+F = fun() -> 2 + 2 end. % #Fun<erl_eval.20.67289768>
+spawn(F). % <0.44.0>
+
+% `spawn` returns a pid (process identifier), you can use this pid to send
+% messages to the process. To do message passing we use the `!` operator.
+% For all of this to be useful we need to be able to receive messages. This is
+% achieved with the `receive` mechanism:
+
+-module(caculateGeometry).
+-compile(export_all).
+caculateAera() ->
+ receive
+ {rectangle, W, H} ->
+ W * H;
+ {circle, R} ->
+ 3.14 * R * R;
+ _ ->
+ io:format("We can only caculate area of rectangles or circles.")
+ end.
+
+% Compile the module and create a process that evaluates `caculateAera` in the shell
+c(caculateGeometry).
+CaculateAera = spawn(caculateGeometry, caculateAera, []).
+CaculateAera ! {circle, 2}. % 12.56000000000000049738
+
+% The shell is also a process, you can use `self` to get the current pid
+self(). % <0.41.0>
+
```
## References
diff --git a/es-es/go-es.html.markdown b/es-es/go-es.html.markdown
index 434f6713..e788e810 100644
--- a/es-es/go-es.html.markdown
+++ b/es-es/go-es.html.markdown
@@ -1,22 +1,24 @@
---
-name: Go
-category: language
language: Go
-filename: learngo.go
+lang: es-es
+filename: learngo-es.go
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
translators:
- ["Adrian Espinosa", "http://www.adrianespinosa.com"]
-lang: es-es
-
-
+ - ["Jesse Johnson", "https://github.com/holocronweaver"]
---
-Go fue creado por la necesidad de hacer el trabajo rápidamente. No es la última
-tendencia en informática, pero es la forma nueva y más rápida de resolver problemas reales.
+Go fue creado por la necesidad de hacer el trabajo rápidamente. No es
+la última tendencia en informática, pero es la forma nueva y más
+rápida de resolver problemas reales.
+
+Tiene conceptos familiares de lenguajes imperativos con tipado
+estático. Es rápido compilando y rápido al ejecutar, añade una
+concurrencia fácil de entender para las CPUs de varios núcleos de hoy
+en día, y tiene características que ayudan con la programación a gran
+escala.
-Tiene conceptos familiares de lenguajes imperativos con tipado estático.
-Es rápido compilando y rápido al ejecutar, añade una concurrencia fácil de entender para las CPUs de varios núcleos de hoy en día, y tiene características que ayudan con la programación a gran escala.
Go viene con una librería estándar muy buena y una comunidad entusiasta.
```go
@@ -28,15 +30,17 @@ Go viene con una librería estándar muy buena y una comunidad entusiasta.
// Main es un nombre especial que declara un ejecutable en vez de una librería.
package main
-// La declaración Import declara los paquetes de librerías referenciados en este archivo.
+// La declaración Import declara los paquetes de librerías
+// referenciados en este archivo.
import (
- "fmt" // Un paquete en la librería estándar de Go
+ "fmt" // Un paquete en la librería estándar de Go.
"net/http" // Sí, un servidor web!
- "strconv" // Conversiones de cadenas
+ "strconv" // Conversiones de cadenas.
+ m "math" // Librería matemáticas con alias local m.
)
-// Definición de una función. Main es especial. Es el punto de entrada para el ejecutable.
-// Te guste o no, Go utiliza llaves.
+// Definición de una función. Main es especial. Es el punto de
+// entrada para el ejecutable. Te guste o no, Go utiliza llaves.
func main() {
// Println imprime una línea a stdout.
// Cualificalo con el nombre del paquete, fmt.
@@ -49,19 +53,19 @@ func main() {
// Las funciones llevan parámetros entre paréntesis.
// Si no hay parámetros, los paréntesis siguen siendo obligatorios.
func beyondHello() {
- var x int // Declaración de una variable. Las variables se deben declarar antes de
- // utilizarlas.
+ var x int // Declaración de una variable.
+ // Las variables se deben declarar antes de utilizarlas.
x = 3 // Asignación de variables.
// Declaración "corta" con := para inferir el tipo, declarar y asignar.
y := 4
- sum, prod := learnMultiple(x, y) // función devuelve dos valores
- fmt.Println("sum:", sum, "prod:", prod) // simple salida
+ sum, prod := learnMultiple(x, y) // Función devuelve dos valores.
+ fmt.Println("sum:", sum, "prod:", prod) // Simple salida.
learnTypes() // < y minutes, learn more!
}
// Las funciones pueden tener parámetros y (múltiples!) valores de retorno.
func learnMultiple(x, y int) (sum, prod int) {
- return x + y, x * y // devolver dos valores
+ return x + y, x * y // Devolver dos valores.
}
// Algunos tipos incorporados y literales.
@@ -73,32 +77,33 @@ func learnTypes() {
saltos de línea.` // mismo tipo cadena
// Literal no ASCII. Los fuentes de Go son UTF-8.
- g := 'Σ' // tipo rune, un alias de uint32, alberga un punto unicode.
- f := 3.14195 // float64, el estándar IEEE-754 de coma flotante 64-bit
- c := 3 + 4i // complex128, representado internamente por dos float64
+ g := 'Σ' // Tipo rune, un alias de uint32, alberga un punto unicode.
+ f := 3.14195 // float64, el estándar IEEE-754 de coma flotante 64-bit.
+ c := 3 + 4i // complex128, representado internamente por dos float64.
// Sintaxis Var con inicializadores.
- var u uint = 7 // sin signo, pero la implementación depende del tamaño como en int
+ var u uint = 7 // Sin signo, pero la implementación depende del
+ // tamaño como en int.
var pi float32 = 22. / 7
// Sintáxis de conversión con una declaración corta.
- n := byte('\n') // byte es un alias de uint8
+ n := byte('\n') // byte es un alias de uint8.
// Los Arrays tienen un tamaño fijo a la hora de compilar.
- var a4 [4]int // un array de 4 ints, inicializados a 0
- a3 := [...]int{3, 1, 5} // un array de 3 ints, inicializados como se indica
+ var a4 [4]int // Un array de 4 ints, inicializados a 0.
+ a3 := [...]int{3, 1, 5} // Un array de 3 ints, inicializados como se indica.
// Los Slices tienen tamaño dinámico. Los arrays y slices tienen sus ventajas
// y desventajas pero los casos de uso para los slices son más comunes.
- s3 := []int{4, 5, 9} // Comparar con a3. No hay puntos suspensivos
- s4 := make([]int, 4) // Asigna slices de 4 ints, inicializados a 0
- var d2 [][]float64 // solo declaración, sin asignación
- bs := []byte("a slice") // sintaxis de conversión de tipo
+ s3 := []int{4, 5, 9} // Comparar con a3. No hay puntos suspensivos.
+ s4 := make([]int, 4) // Asigna slices de 4 ints, inicializados a 0.
+ var d2 [][]float64 // Solo declaración, sin asignación.
+ bs := []byte("a slice") // Sintaxis de conversión de tipo.
- p, q := learnMemory() // declara p, q para ser un tipo puntero a int.
+ p, q := learnMemory() // Declara p, q para ser un tipo puntero a int.
fmt.Println(*p, *q) // * sigue un puntero. Esto imprime dos ints.
- // Los Maps son arrays asociativos dinámicos, como los hash o diccionarios
- // de otros lenguajes
+ // Los Maps son arrays asociativos dinámicos, como los hash o
+ // diccionarios de otros lenguajes.
m := map[string]int{"three": 3, "four": 4}
m["one"] = 1
@@ -108,23 +113,24 @@ saltos de línea.` // mismo tipo cadena
// Esto cuenta como utilización de variables.
fmt.Println(s, c, a4, s3, d2, m)
- learnFlowControl() // vuelta al flujo
+ learnFlowControl() // Vuelta al flujo.
}
-// Go posee recolector de basura. Tiene puntero pero no aritmética de punteros.
-// Puedes cometer un errores con un puntero nil, pero no incrementando un puntero.
+// Go posee recolector de basura. Tiene puntero pero no aritmética de
+// punteros. Puedes cometer un errores con un puntero nil, pero no
+// incrementando un puntero.
func learnMemory() (p, q *int) {
// q y p tienen un tipo puntero a int.
- p = new(int) // función incorporada que asigna memoria.
+ p = new(int) // Función incorporada que asigna memoria.
// La asignación de int se inicializa a 0, p ya no es nil.
- s := make([]int, 20) // asigna 20 ints a un solo bloque de memoria.
- s[3] = 7 // asignar uno de ellos
- r := -2 // declarar otra variable local
+ s := make([]int, 20) // Asigna 20 ints a un solo bloque de memoria.
+ s[3] = 7 // Asignar uno de ellos.
+ r := -2 // Declarar otra variable local.
return &s[3], &r // & toma la dirección de un objeto.
}
-func expensiveComputation() int {
- return 1e6
+func expensiveComputation() float64 {
+ return m.Exp(10)
}
func learnFlowControl() {
@@ -134,29 +140,31 @@ func learnFlowControl() {
}
// El formato está estandarizado por el comando "go fmt."
if false {
- // pout
+ // Pout.
} else {
- // gloat
+ // Gloat.
}
// Utiliza switch preferiblemente para if encadenados.
- x := 1
+ x := 42.0
switch x {
case 0:
case 1:
- // los cases no se mezclan, no requieren de "break"
- case 2:
- // no llega
+ case 42:
+ // Los cases no se mezclan, no requieren de "break".
+ case 43:
+ // No llega.
}
// Como if, for no utiliza paréntesis tampoco.
- for x := 0; x < 3; x++ { // ++ es una sentencia
+ // Variables declaradas en for y if son locales de su ámbito local.
+ for x := 0; x < 3; x++ { // ++ es una sentencia.
fmt.Println("iteration", x)
}
- // x == 1 aqui.
+ // x == 42 aqui.
// For es la única sentencia de bucle en Go, pero tiene formas alternativas.
- for { // bucle infinito
- break // solo bromeaba!
- continue // no llega
+ for { // Bucle infinito.
+ break // Solo bromeaba!
+ continue // No llega.
}
// Como en for, := en una sentencia if significa declarar y asignar primero,
// luego comprobar y > x.
@@ -165,11 +173,11 @@ func learnFlowControl() {
}
// Los literales de funciones son "closures".
xBig := func() bool {
- return x > 100 // referencia a x declarada encima de la sentencia switch.
+ return x > 100 // Referencia a x declarada encima de la sentencia switch.
}
- fmt.Println("xBig:", xBig()) // verdadero (la última vez asignamos 1e6 a x)
- x /= 1e5 // esto lo hace == 10
- fmt.Println("xBig:", xBig()) // ahora es falso
+ fmt.Println("xBig:", xBig()) // verdadero (la última vez asignamos 1e6 a x).
+ x /= m.Exp(9) // Esto lo hace x == e.
+ fmt.Println("xBig:", xBig()) // Ahora es falso.
// Cuando lo necesites, te encantará.
goto love
@@ -199,16 +207,29 @@ func learnInterfaces() {
// La sintaxis de llaves es un "literal struct". Evalúa a un struct
// inicializado. La sintaxis := declara e inicializa p a este struct.
p := pair{3, 4}
- fmt.Println(p.String()) // llamar al método String de p, de tipo pair.
- var i Stringer // declarar i como interfaz tipo Stringer.
- i = p // válido porque pair implementa Stringer
- // Llamar al metodo String de i, de tipo Stringer. Misma salida que arriba
+ fmt.Println(p.String()) // Llamar al método String de p, de tipo pair.
+ var i Stringer // Declarar i como interfaz tipo Stringer.
+ i = p // Válido porque pair implementa Stringer.
+ // Llamar al metodo String de i, de tipo Stringer. Misma salida que arriba.
fmt.Println(i.String())
- // Las funciones en el paquete fmt llaman al método String para preguntar a un objeto
- // por una versión imprimible de si mismo
- fmt.Println(p) // salida igual que arriba. Println llama al método String.
- fmt.Println(i) // salida igual que arriba.
+ // Las funciones en el paquete fmt llaman al método String para
+ // preguntar a un objeto por una versión imprimible de si mismo.
+ fmt.Println(p) // Salida igual que arriba. Println llama al método String.
+ fmt.Println(i) // Salida igual que arriba.
+
+ learnVariadicParams("great", "learning", "here!")
+}
+
+// Las funciones pueden tener número variable de argumentos.
+func learnVariadicParams(myStrings ...interface{}) {
+ // Iterar cada valor de la variadic.
+ for _, param := range myStrings {
+ fmt.Println("param:", param)
+ }
+
+ // Pasar valor variadic como parámetro variadic.
+ fmt.Println("params:", fmt.Sprintln(myStrings...))
learnErrorHandling()
}
@@ -223,7 +244,7 @@ func learnErrorHandling() {
}
// Un valor de error comunica más información sobre el problema aparte de "ok".
if _, err := strconv.Atoi("non-int"); err != nil { // _ descarta el valor
- // imprime "strconv.ParseInt: parsing "non-int": invalid syntax"
+ // Imprime "strconv.ParseInt: parsing "non-int": invalid syntax".
fmt.Println(err)
}
// Revisarmeos las interfaces más tarde. Mientras tanto,
@@ -248,25 +269,28 @@ func learnConcurrency() {
go inc(-805, c)
// Leer los tres resultados del channel e imprimirlos.
// No se puede saber en que orden llegarán los resultados!
- fmt.Println(<-c, <-c, <-c) // channel a la derecha, <- es el operador "recibir".
-
- cs := make(chan string) // otro channel, este gestiona cadenas.
- cc := make(chan chan string) // un channel de cadenas de channels.
- go func() { c <- 84 }() // iniciar una nueva goroutine solo para enviar un valor.
- go func() { cs <- "wordy" }() // otra vez, para cs en esta ocasión
- // Select tiene una sintáxis parecida a la sentencia switch pero cada caso involucra
- // una operacion de channels. Selecciona un caso de forma aleatoria de los casos
- // que están listos para comunicarse.
+ fmt.Println(<-c, <-c, <-c) // Channel a la derecha, <- es el operador "recibir".
+
+ cs := make(chan string) // Otro channel, este gestiona cadenas.
+ ccs := make(chan chan string) // Un channel de cadenas de channels.
+ go func() { c <- 84 }() // Iniciar una nueva goroutine solo para
+ // enviar un valor.
+ go func() { cs <- "wordy" }() // Otra vez, para cs en esta ocasión.
+ // Select tiene una sintáxis parecida a la sentencia switch pero
+ // cada caso involucra una operacion de channels. Selecciona un caso
+ // de forma aleatoria de los casos que están listos para comunicarse.
select {
- case i := <-c: // el valor recibido puede ser asignado a una variable
+ case i := <-c: // El valor recibido puede ser asignado a una variable,
fmt.Printf("it's a %T", i)
- case <-cs: // o el valor puede ser descartado
+ case <-cs: // o el valor puede ser descartado.
fmt.Println("it's a string")
- case <-cc: // channel vacío, no está listo para la comunicación.
+ case <-ccs: // Channel vacío, no está listo para la comunicación.
fmt.Println("didn't happen.")
}
+
// En este punto un valor fue devuelvto de c o cs. Uno de las dos
- // goroutines que se iniciaron se ha completado, la otrá permancerá bloqueada.
+ // goroutines que se iniciaron se ha completado, la otrá permancerá
+ // bloqueada.
learnWebProgramming() // Go lo hace. Tu también quieres hacerlo.
}
@@ -281,7 +305,7 @@ func learnWebProgramming() {
// Haz pair un http.Handler implementando su único método, ServeHTTP.
func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- // Servir datos con un método de http.ResponseWriter
+ // Servir datos con un método de http.ResponseWriter.
w.Write([]byte("You learned Go in Y minutes!"))
}
```
@@ -291,11 +315,12 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
La raíz de todas las cosas de Go es la [web oficial de Go](http://golang.org/).
Ahí puedes seguir el tutorial, jugar interactivamente y leer mucho.
-La propia definición del lenguaje también está altamente recomendada. Es fácil de leer
-e increíblemente corta (como otras definiciones de lenguajes hoy en día)
+La propia definición del lenguaje también está altamente
+recomendada. Es fácil de leer e increíblemente corta (como otras
+definiciones de lenguajes hoy en día)
-En la lista de lectura de estudiantes de Go está el código fuente de la
-librería estándar. Muy bien documentada, demuestra lo mejor de Go leíble, comprendible,
-estilo Go y formas Go. Pincha en el nombre de una función en la documentación
-y te aparecerá el código fuente!
+En la lista de lectura de estudiantes de Go está el código fuente de
+la librería estándar. Muy bien documentada, demuestra lo mejor de Go
+leíble, comprendible, estilo Go y formas Go. Pincha en el nombre de
+una función en la documentación y te aparecerá el código fuente!
diff --git a/es-es/julia-es.html.markdown b/es-es/julia-es.html.markdown
new file mode 100644
index 00000000..41a7c68b
--- /dev/null
+++ b/es-es/julia-es.html.markdown
@@ -0,0 +1,759 @@
+---
+language: julia
+contributors:
+ - ["Leah Hanson", "http://leahhanson.us"]
+ - ["Guillermo Garza" ]
+filename: learnjulia-es.jl
+lang: es-es
+---
+
+Julia es un nuevo lenguaje funcional homoiconic enfocado en computación técnica.
+Aunque que tiene todo el poder de macros homoiconic, funciones de primera
+clase, y control de bajo nivel, Julia es tan fácil de aprender y utilizar como
+Python.
+
+Esto se basa en la versión de desarrollo actual de Julia, del 18 de octubre de
+2013.
+
+```ruby
+
+# Comentarios de una línea comienzan con una almohadilla (o signo gato)
+
+#= Commentarios multilinea pueden escribirse
+ usando '#=' antes de el texto y '=#'
+ después del texto. También se pueden anidar.
+=#
+
+####################################################
+## 1. Tipos de datos primitivos y operadores.
+####################################################
+
+# Todo en Julia es una expresión.
+
+# Hay varios tipos básicos de números.
+3 # => 3 (Int64)
+3.2 # => 3.2 (Float64)
+2 + 1im # => 2 + 1im (Complex{Int64})
+2//3 # => 2//3 (Rational{Int64})
+
+# Todos los operadores infijos normales están disponibles.
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+35 / 5 # => 7.0
+5/2 # => 2.5 # dividir un Int por un Int siempre resulta en un Float
+div (5, 2) # => 2 # para un resultado truncado, usa div
+5 \ 35 # => 7.0
+2 ^ 2 # => 4 # exponente, no es xor
+12 % 10 # => 2
+
+# Refuerza la precedencia con paréntesis
+(1 + 3) * 2 # => 8
+
+# Operadores a nivel de bit
+~2 # => -3 # bitwise not
+3 & 5 # => 1 # bitwise and
+2 | 4 # => 6 # bitwise or
+2 $ 4 # => 6 # bitwise xor
+2 >>> 1 # => 1 # logical shift right
+2 >> 1 # => 1 # arithmetic shift right
+2 << 1 # => 4 # logical/arithmetic shift left
+
+# Se puede utilizar la función bits para ver la representación binaria de un
+# número.
+bits(12345)
+# => "0000000000000000000000000000000000000000000000000011000000111001"
+bits(12345.0)
+# => "0100000011001000000111001000000000000000000000000000000000000000"
+
+# Valores 'boolean' (booleanos) son primitivos
+true
+false
+
+# Operadores Boolean (booleanos)
+!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
+# ¡Las comparaciones pueden ser concatenadas!
+1 < 2 < 3 # => true
+2 < 3 < 2 # => false
+
+# Strings se crean con "
+"Esto es un string."
+
+# Literales de caracteres se escriben con '
+'a'
+
+# Una string puede ser indexado como una array de caracteres
+"Esto es un string."[1] # => 'E' # Índices en Julia empiezen del 1
+# Sin embargo, esto no va a funcionar bien para strings UTF8,
+# Lo que se recomienda es la iteración (map, for, etc).
+
+# $ puede ser utilizado para la interpolación de strings:
+"2 + 2 = $(2 + 2)" # => "2 + 2 = 4"
+# Se puede poner cualquier expresión de Julia dentro los paréntesis.
+
+# Otro forma de formatear strings es el macro printf
+@printf "%d es menor de %f" 4.5 5.3 # 5 es menor de 5.300000
+
+# Imprimir es muy fácil
+println("Soy Julia. ¡Encantado de conocerte!")
+
+####################################################
+## 2. Variables y Colecciones
+####################################################
+
+# No hay necesidad de declarar las variables antes de asignarlas.
+una_variable = 5 # => 5
+una_variable # => 5
+
+# Acceder a variables no asignadas previamente es una excepción.
+try
+ otra_variable # => ERROR: some_other_var not defined
+catch e
+ println(e)
+end
+
+# Los nombres de variables comienzan con una letra.
+# Después de eso, puedes utilizar letras, dígitos, guiones y signos de
+# exclamación.
+OtraVariable123! = 6 # => 6
+
+# También puede utilizar caracteres unicode
+☃ = 8 # => 8
+# Estos son especialmente útiles para la notación matemática
+2 * π # => 6.283185307179586
+
+# Una nota sobre las convenciones de nomenclatura de Julia:
+#
+# * Los nombres de las variables aparecen en minúsculas, con separación de
+# palabra indicado por underscore ('\ _').
+#
+# * Los nombres de los tipos comienzan con una letra mayúscula y separación de
+# palabras se muestra con CamelCase en vez de underscore.
+#
+# * Los nombres de las funciones y los macros están en minúsculas, sin
+# underscore.
+#
+# * Funciones que modifican sus inputs tienen nombres que terminan en!. Estos
+# funciones a veces se llaman mutating functions o in-place functions.
+
+# Los Arrays almacenan una secuencia de valores indexados entre 1 hasta n
+a = Int64[] # => 0-element Int64 Array
+
+# Literales de arrays 1-dimensionales se pueden escribir con valores separados
+# por comas.
+b = [4, 5, 6] # => 3-element Int64 Array: [4, 5, 6]
+b[1] # => 4
+b[end] # => 6
+
+# Los arrays 2-dimensionales usan valores separados por espacios y filas
+# separados por punto y coma.
+matrix = [1 2; 3 4] # => 2x2 Int64 Array: [1 2; 3 4]
+
+# Añadir cosas a la final de una lista con push! y append!
+push!(a,1) # => [1]
+push!(a,2) # => [1,2]
+push!(a,4) # => [1,2,4]
+push!(a,3) # => [1,2,4,3]
+append!(a,b) # => [1,2,4,3,4,5,6]
+
+# Eliminar de la final con pop
+pop!(b) # => 6 y b ahora es [4,5]
+
+# Vamos a ponerlo de nuevo
+push!(b, 6) # b es ahora [4,5,6] de nuevo.
+
+a[1] # => 1 # recuerdan que los índices de Julia empiezan desde 1, no desde 0!
+
+# end es una abreviatura para el último índice. Se puede utilizar en cualquier
+# expresión de indexación
+a[end] # => 6
+
+# tambien hay shift y unshift
+shift!(a) # => 1 y a es ahora [2,4,3,4,5,6]
+unshift!(a,7) # => [7,2,4,3,4,5,6]
+
+# Nombres de funciónes que terminan en exclamaciones indican que modifican
+# su argumento.
+arr = [5,4,6] # => 3-element Int64 Array: [5,4,6]
+sort(arr) # => [4,5,6]; arr es todavía [5,4,6]
+sort!(arr) # => [4,5,6]; arr es ahora [4,5,6]
+
+# Buscando fuera de límites es un BoundsError
+try
+ a[0] # => ERROR: BoundsError() in getindex at array.jl:270
+ a[end+1] # => ERROR: BoundsError() in getindex at array.jl:270
+catch e
+ println(e)
+end
+
+# Errors dan la línea y el archivo de su procedencia, aunque sea en el standard
+# library. Si construyes Julia de source, puedes buscar en el source para
+# encontrar estos archivos.
+
+# Se puede inicializar arrays de un range
+a = [1:5] # => 5-element Int64 Array: [1,2,3,4,5]
+
+# Puedes mirar en ranges con sintaxis slice.
+a[1:3] # => [1, 2, 3]
+a[2:end] # => [2, 3, 4, 5]
+
+# Eliminar elementos de una array por índice con splice!
+arr = [3,4,5]
+splice!(arr,2) # => 4 ; arr es ahora [3,5]
+
+# Concatenar listas con append!
+b = [1,2,3]
+append!(a,b) # ahroa a es [1, 2, 3, 4, 5, 1, 2, 3]
+
+# Comprueba la existencia en una lista con in
+in(1, a) # => true
+
+# Examina la longitud con length
+length(a) # => 8
+
+# Tuples son immutable.
+tup = (1, 2, 3) # => (1,2,3) # un (Int64,Int64,Int64) tuple.
+tup[1] # => 1
+try:
+ tup[1] = 3 # => ERROR: no method setindex!((Int64,Int64,Int64),Int64,Int64)
+catch e
+ println(e)
+end
+
+# Muchas funciones de lista también trabajan en las tuples
+length(tup) # => 3
+tup[1:2] # => (1,2)
+in(2, tup) # => true
+
+# Se puede desempacar tuples en variables
+a, b, c = (1, 2, 3) # => (1,2,3) # a is now 1, b is now 2 and c is now 3
+
+# Los tuples se crean, incluso si se omite el paréntesis
+d, e, f = 4, 5, 6 # => (4,5,6)
+
+# Un tuple 1-elemento es distinto del valor que contiene
+(1,) == 1 # => false
+(1) == 1 # => true
+
+# Mira que fácil es cambiar dos valores
+e, d = d, e # => (5,4) # d is now 5 and e is now 4
+
+
+# Dictionaries almanecan mapeos
+dict_vacio = Dict() # => Dict{Any,Any}()
+
+# Se puede crear un dictionary usando un literal
+dict_lleno = ["one"=> 1, "two"=> 2, "three"=> 3]
+# => Dict{ASCIIString,Int64}
+
+# Busca valores con []
+dict_lleno["one"] # => 1
+
+# Obtén todas las claves
+keys(dict_lleno)
+# => KeyIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# Nota - claves del dictionary no están ordenados ni en el orden en que se
+# insertan.
+
+# Obtén todos los valores
+values(dict_lleno)
+# => ValueIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# Nota - Igual que el anterior en cuanto a ordenamiento de claves.
+
+# Compruebe si hay existencia de claves en un dictionary con in y haskey
+in(("uno", 1), dict_lleno) # => true
+in(("tres", 3), dict_lleno) # => false
+haskey(dict_lleno, "one") # => true
+haskey(dict_lleno, 1) # => false
+
+# Tratando de buscar una clave que no existe producirá un error
+try
+ dict_lleno["dos"] # => ERROR: key not found: dos in getindex at dict.jl:489
+catch e
+ println(e)
+end
+
+# Utilice el método get para evitar ese error proporcionando un valor
+# predeterminado
+# get(dictionary,key,default_value)
+get(dict_lleno,"one",4) # => 1
+get(dict_lleno,"four",4) # => 4
+
+# Usa Sets para representar colecciones (conjuntos) de valores únicos, no
+# ordenadas
+conjunto_vacio = Set() # => Set{Any}()
+# Iniciar una set de valores
+conjunto_lleno = Set(1,2,2,3,4) # => Set{Int64}(1,2,3,4)
+
+# Añadir más valores a un conjunto
+push!(conjunto_lleno,5) # => Set{Int64}(5,4,2,3,1)
+push!(conjunto_lleno,5) # => Set{Int64}(5,4,2,3,1)
+
+# Compruebe si los valores están en el conjunto
+in(2, conjunto_lleno) # => true
+in(10, conjunto_lleno) # => false
+
+# Hay funciones de intersección de conjuntos, la unión, y la diferencia.
+conjunto_otro= Set(3, 4, 5, 6) # => Set{Int64}(6,4,5,3)
+intersect(conjunto_lleno, conjunto_otro) # => Set{Int64}(3,4,5)
+union(conjunto_lleno, conjunto_otro) # => Set{Int64}(1,2,3,4,5,6)
+setdiff(Set(1,2,3,4),Set(2,3,5)) # => Set{Int64}(1,4)
+
+
+####################################################
+## 3. Control de Flujo
+####################################################
+
+# Hagamos una variable
+una_variable = 5
+
+# Aquí está una declaración de un 'if'. La indentación no es significativa en
+# Julia
+if una_variable > 10
+ println("una_variable es completamente mas grande que 10.")
+elseif una_variable < 10 # Este condición 'elseif' es opcional.
+ println("una_variable es mas chica que 10.")
+else # Esto también es opcional.
+ println("una_variable es de hecho 10.")
+end
+# => imprime "una_variable es mas chica que 10."
+
+# For itera sobre tipos iterables
+# Tipos iterables incluyen Range, Array, Set, Dict, y String.
+for animal=["perro", "gato", "raton"]
+ println("$animal es un mamifero")
+ # Se puede usar $ para interpolar variables o expresiónes en strings
+end
+# imprime:
+# perro es un mamifero
+# gato es un mamifero
+# raton es un mamifero
+
+for a in ["perro"=>"mamifero","gato"=>"mamifero","raton"=>"mamifero"]
+ println("$(a[1]) es un $(a[2])")
+end
+# imprime:
+# perro es un mamifero
+# gato es un mamifero
+# raton es un mamifero
+
+for (k,v) in ["perro"=>"mamifero", "gato"=>"mamifero", "raton"=>"mamifero"]
+ println("$k es un $v")
+end
+# imprime:
+# perro es un mamifero
+# gato es un mamifero
+# raton es un mamifero
+
+# While itera hasta que una condición no se cumple.
+x = 0
+while x < 4
+ println(x)
+ x += 1 # versión corta de x = x + 1
+end
+# imprime:
+# 0
+# 1
+# 2
+# 3
+
+# Maneja excepciones con un bloque try/catch
+try
+ error("ayuda")
+catch e
+ println("capturando $e")
+end
+# => capturando ErrorException("ayuda")
+
+
+####################################################
+## 4. Funciones
+####################################################
+
+# Usa 'function' para crear nuevas funciones
+
+#function nombre(arglist)
+# cuerpo...
+#end
+function suma(x, y)
+ println("x es $x e y es $y")
+
+ # Las funciones devuelven el valor de su última declaración
+ x + y
+end
+
+suma(5, 6) # => 11 # después de imprimir "x es 5 e y es de 6"
+
+# Puedes definir funciones que toman un número variable de
+# argumentos posicionales
+function varargs(args...)
+ return args
+ # Usa la palabra clave return para devolver en cualquier lugar de la función
+end
+# => varargs (generic function with 1 method)
+
+varargs(1,2,3) # => (1,2,3)
+
+# El ... se llama un splat.
+# Acabamos de utilizar lo en una definición de función.
+# También se puede utilizar en una llamada de función,
+# donde va splat un Array o el contenido de un Tuple en la lista de argumentos.
+Set([1,2,3]) # => Set{Array{Int64,1}}([1,2,3]) # Produce un Set de Arrays
+Set([1,2,3]...) # => Set{Int64}(1,2,3) # esto es equivalente a Set(1,2,3)
+
+x = (1,2,3) # => (1,2,3)
+Set(x) # => Set{(Int64,Int64,Int64)}((1,2,3)) # un Set de Tuples
+Set(x...) # => Set{Int64}(2,3,1)
+
+
+# Puede definir funciones con argumentos posicionales opcionales
+function defaults(a,b,x=5,y=6)
+ return "$a $b y $x $y"
+end
+
+defaults('h','g') # => "h g y 5 6"
+defaults('h','g','j') # => "h g y j 6"
+defaults('h','g','j','k') # => "h g y j k"
+try
+ defaults('h') # => ERROR: no method defaults(Char,)
+ defaults() # => ERROR: no methods defaults()
+catch e
+ println(e)
+end
+
+# Puedes definir funciones que toman argumentos de palabra clave
+function args_clave(;k1=4,nombre2="hola") # note the ;
+ return ["k1"=>k1,"nombre2"=>nombre2]
+end
+
+args_clave(nombre2="ness") # => ["nombre2"=>"ness","k1"=>4]
+args_clave(k1="mine") # => ["k1"=>"mine","nombre2"=>"hola"]
+args_clave() # => ["nombre2"=>"hola","k1"=>4]
+
+# Puedes combinar todo tipo de argumentos en la misma función
+function todos_los_args(arg_normal, arg_posicional_opcional=2; arg_clave="foo")
+ println("argumento normal: $arg_normal")
+ println("argumento optional: $arg_posicional_opcional")
+ println("argumento de clave: $arg_clave")
+end
+
+todos_los_args(1, 3, arg_clave=4)
+# imprime:
+# argumento normal: 1
+# argumento optional: 3
+# argumento de clave: 4
+
+# Julia tiene funciones de primera clase
+function crear_suma(x)
+ suma = function (y)
+ return x + y
+ end
+ return suma
+end
+
+# Esta es el sintaxis "stabby lambda" para crear funciones anónimas
+(x -> x > 2)(3) # => true
+
+# Esta función es idéntica a la crear_suma implementación anterior.
+function crear_suma(x)
+ y -> x + y
+end
+
+# También puedes nombrar la función interna, si quieres
+function crear_suma(x)
+ function suma(y)
+ x + y
+ end
+ suma
+end
+
+suma_10 = crear_suma(10)
+suma_10(3) # => 13
+
+
+# Hay funciones integradas de orden superior
+map(suma_10, [1,2,3]) # => [11, 12, 13]
+filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# Podemos usar listas por comprensión para mapeos
+[suma_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
+[suma_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+
+####################################################
+## 5. Tipos
+####################################################
+
+# Julia tiene sistema de tipos.
+# Cada valor tiene un tipo y las variables no tienen propios tipos.
+# Se puede utilizar la función `typeof` para obtener el tipo de un valor.
+typeof(5) # => Int64
+
+# Los tipos son valores de primera clase
+typeof(Int64) # => DataType
+typeof(DataType) # => DataType
+# DataType es el tipo que representa los tipos, incluyéndose a sí mismo.
+
+# Los tipos se usan para la documentación, optimizaciones, y envio.
+# No están comprobados estáticamente.
+
+# Los usuarios pueden definir tipos
+# Son como registros o estructuras en otros idiomas.
+# Nuevos tipos se definen utilizado la palabra clave `type`.
+
+# type Nombre
+# field::OptionalType
+# ...
+# end
+type Tigre
+ longituddecola::Float64
+ colordelpelaje # no incluyendo una anotación de tipo es el mismo que `::Any`
+end
+
+# Los argumentos del constructor por default son las propiedades
+# del tipo, en el orden en que están listados en la definición
+tigger = Tigre(3.5,"anaranjado") # => Tiger(3.5,"anaranjado")
+
+# El tipo funciona como la función constructora de valores de ese tipo
+sherekhan = typeof(tigger)(5.6,"fuego") # => Tiger(5.6,"fuego")
+
+
+# Este estilo de tipos son llamados tipos concrete
+# Se pueden crear instancias, pero no pueden tener subtipos.
+# La otra clase de tipos es tipos abstractos (abstract types).
+
+# abstract Nombre
+abstract Gato # sólo un nombre y un punto en la jerarquía de tipos
+
+# De los tipos Abstract no se pueden crear instancias, pero pueden tener
+# subtipos. Por ejemplo, Number es un tipo abstracto.
+subtypes(Number) # => 6-element Array{Any,1}:
+ # Complex{Float16}
+ # Complex{Float32}
+ # Complex{Float64}
+ # Complex{T<:Real}
+ # Real
+subtypes(Gato) # => 0-element Array{Any,1}
+
+# Cada tipo tiene un supertipo, utilice la función `súper` para conseguirlo.
+typeof(5) # => Int64
+super(Int64) # => Signed
+super(Signed) # => Real
+super(Real) # => Number
+super(Number) # => Any
+super(super(Signed)) # => Number
+super(Any) # => Any
+# Todo de estos tipos, a excepción de Int64, son abstractos.
+
+# <: es el operador de subtipos
+type Leon <: Gato # Leon es un subtipo de Gato
+ color_de_crin
+ rugido::String
+end
+
+# Se puede definir más constructores para su tipo.
+# Sólo defina una función del mismo nombre que el tipo
+# y llame a un constructor existente para obtener un valor del tipo correcto
+Leon(rugido::String) = Leon("verde",rugido)
+# Este es un constructor externo porque es fuera de la definición del tipo
+
+type Pantera <: Gato # Pantera tambien es un a subtipo de Cat
+ color_de_ojos
+ Pantera() = new("verde")
+ # Panteras sólo tendrán este constructor, y ningún constructor
+ # predeterminado.
+end
+# Utilizar constructores internos, como Panther hace, te da control sobre cómo
+# se pueden crear valores del tipo. Cuando sea posible, debes utilizar
+# constructores exteriores en lugar de los internos.
+
+####################################################
+## 6. Envio múltiple
+####################################################
+
+# En Julia, todas las funciones nombradas son funciones genéricas.
+# Esto significa que se construyen a partir de muchos métodos pequeños
+# Cada constructor de Leon es un método de la función genérica Leon.
+
+# Por ejemplo, vamos a hacer un maullar función:
+
+# Definiciones para Leon, Pantera, y Tigre
+function maullar(animal::Leon)
+ animal.rugido # acceso utilizando notación de puntos
+end
+
+function maullar(animal::Pantera)
+ "grrr"
+end
+
+function maullar(animal::Tigre)
+ "rawwwr"
+end
+
+# Prueba de la función maullar
+maullar(tigger) # => "rawwr"
+maullar(Leon("cafe","ROAAR")) # => "ROAAR"
+maullar(Pantera()) # => "grrr"
+
+# Revisar la jerarquía de tipos locales
+issubtype(Tigre,Gato) # => false
+issubtype(Leon,Gato) # => true
+issubtype(Pantera,Gato) # => true
+
+# Definición de una función que toma Gatos
+function mascota(gato::Gato)
+ println("El gato dice $(maullar(gato))")
+end
+
+mascota(Leon("42")) # => imprime "El gato dice 42"
+try
+ mascota(tigger) # => ERROR: no method mascota(Tigre))
+catch e
+ println(e)
+end
+
+# En los lenguajes orientados a objetos, expedición única es común. Esto
+# significa que el método se recogió basándose en el tipo del primer argumento.
+# En Julia, todos los tipos de argumentos contribuyen a seleccionar el mejor
+# método.
+
+# Vamos a definir una función con más argumentos, para que podamos ver la
+# diferencia
+function pelear(t::Tigre,c::Gato)
+ println("¡El tigre $(t.colordelpelaje) gana!")
+end
+# => pelear (generic function with 1 method)
+
+pelear(tigger,Pantera()) # => imprime ¡El tigre anaranjado gana!
+pelear(tigger,Leon("ROAR")) # => ¡El tigre anaranjado gana!
+
+# Vamos a cambiar el comportamiento cuando el Gato es específicamente un Leon
+pelear(t::Tigre,l::Leon) = println("El león con melena $(l.color_de_crin) gana")
+# => pelear (generic function with 2 methods)
+
+pelear(tigger,Pantera()) # => imprime ¡El tigre anaranjado gana!
+pelear(tigger,Leon("ROAR")) # => imprime El león con melena verde gana
+
+# No necesitamos un tigre para poder luchar
+pelear(l::Leon,c::Gato) = println("El gato victorioso dice $(maullar(c))")
+# => fight (generic function with 3 methods)
+
+pelear(Leon("balooga!"),Pantera()) # => imprime El gato victorioso dice grrr
+try
+ pelear(Pantera(),Leon("RAWR")) # => ERROR: no method pelear(Pantera, Leon))
+catch
+end
+
+# Un metodo con el gato primero
+pelear(c::Gato,l::Leon) = println("El gato le gana al León")
+# Warning: New definition
+# pelear(Gato,Leon) at none:1
+# is ambiguous with:
+# pelear(Leon,Gato) at none:1.
+# To fix, define
+# pelear(Leon,Leon)
+# before the new definition.
+# pelear (generic function with 4 methods)
+
+# Esta advertencia se debe a que no está claro que metodo de pelear será llamado
+# en:
+pelear(Leon("RAR"),Leon("cafe","rar")) # => imprime El gato victorioso dice rar
+# El resultado puede ser diferente en otras versiones de Julia
+
+pelear(l::Leon,l2::Leon) = println("Los leones llegan a un empate")
+pelear(Leon("GR"),Leon("cafe","rar")) # => imprime Los leones llegan a un empate
+
+
+# Un vistazo al nivel bajo
+# Se puede echar un vistazo a la LLVM y el código ensamblador generado.
+
+area_cuadrada(l) = l * l # area_cuadrada (generic function with 1 method)
+
+area_cuadrada(5) # => 25
+
+# ¿Qué sucede cuando damos area_cuadrada diferentes argumentos?
+code_native(area_cuadrada, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1 # Prologue
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # movsxd RAX, EDI # Fetch l from memory?
+ # imul RAX, RAX # Square l and store the result in RAX
+ # pop RBP # Restore old base pointer
+ # ret # Result will still be in RAX
+
+code_native(area_cuadrada, (Float32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiply (AVX)
+ # pop RBP
+ # ret
+
+code_native(area_cuadrada, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiply (AVX)
+ # pop RBP
+ # ret
+ #
+
+# Ten en cuenta que Julia usará instrucciones de "floating point" si alguno de
+# los argumentos son "floats"
+# Vamos a calcular el área de un círculo
+area_circulo(r) = pi * r * r # circle_area (generic function with 1 method)
+area_circulo(5) # 78.53981633974483
+
+code_native(area_circulo, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory
+ # movabs RAX, 4593140240 # Load pi
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r
+ # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r
+ # pop RBP
+ # ret
+ #
+
+code_native(area_circulo, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # movabs RAX, 4593140496
+ # Source line: 1
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX]
+ # vmulsd XMM0, XMM1, XMM0
+ # pop RBP
+ # ret
+ #
+```
+
+## ¿Listo para más?
+
+Puedes obtener muchos más detalles en [The Julia Manual](http://docs.julialang.org/en/latest/manual/)
+
+El mejor lugar para obtener ayuda con Julia es el (muy amable) [lista de correos](https://groups.google.com/forum/#!forum/julia-users).
+
diff --git a/es-es/python-es.html.markdown b/es-es/python-es.html.markdown
index f92f5cde..f7a0ec02 100644
--- a/es-es/python-es.html.markdown
+++ b/es-es/python-es.html.markdown
@@ -130,7 +130,7 @@ otra_variable # Levanta un error de nombre
# 'if' puede ser usado como una expresión
"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
-# Listas sobre secuencias
+# Listas almacenan secuencias
lista = []
# Puedes empezar con una lista prellenada
otra_lista = [4, 5, 6]
@@ -254,7 +254,7 @@ conjunto_lleno | otro_conjunto #=> {1, 2, 3, 4, 5, 6}
# Haz diferencia de conjuntos con -
{1,2,3,4} - {2,3,5} #=> {1, 4}
-# CHequea la existencia en un conjunto con 'in'
+# Chequea la existencia en un conjunto con 'in'
2 in conjunto_lleno #=> True
10 in conjunto_lleno #=> False
diff --git a/es-es/python3-es.html.markdown b/es-es/python3-es.html.markdown
new file mode 100644
index 00000000..1c69481a
--- /dev/null
+++ b/es-es/python3-es.html.markdown
@@ -0,0 +1,570 @@
+---
+language: python3
+contributors:
+ - ["Louie Dinh", "http://pythonpracticeprojects.com"]
+translators:
+ - ["Camilo Garrido", "http://twitter.com/hirohope"]
+lang: es-es
+filename: learnpython3-es.py
+---
+
+Python fue creado por Guido Van Rossum en el principio de los 90'. Ahora es uno
+de los lenguajes más populares en existencia. Me enamoré de Python por su claridad sintáctica.
+Es básicamente pseudocódigo ejecutable.
+
+¡Comentarios serán muy apreciados! Pueden contactarme en [@louiedinh](http://twitter.com/louiedinh) o louiedinh [at] [servicio de email de google]
+
+Nota: Este artículo aplica a Python 2.7 específicamente, pero debería ser aplicable a Python 2.x. ¡Pronto un recorrido por Python 3!
+
+```python
+
+# Comentarios de una línea comienzan con una almohadilla (o signo gato)
+
+""" Strings multilinea pueden escribirse
+ usando tres "'s, y comunmente son usados
+ como comentarios.
+"""
+
+####################################################
+## 1. Tipos de datos primitivos y operadores.
+####################################################
+
+# Tienes números
+3 #=> 3
+
+# Matemática es lo que esperarías
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+
+# Excepto la división la cual por defecto retorna un número 'float' (número de coma flotante)
+35 / 5 # => 7.0
+
+# Cuando usas un float, los resultados son floats
+3 * 2.0 # => 6.0
+
+# Refuerza la precedencia con paréntesis
+(1 + 3) * 2 # => 8
+
+
+# Valores 'boolean' (booleanos) son primitivos
+True
+False
+
+# Niega con 'not'
+not True # => False
+not False # => True
+
+
+# Igualdad es ==
+1 == 1 # => True
+2 == 1 # => False
+
+# Desigualdad es !=
+1 != 1 # => False
+2 != 1 # => True
+
+# Más comparaciones
+1 < 10 # => True
+1 > 10 # => False
+2 <= 2 # => True
+2 >= 2 # => True
+
+# ¡Las comparaciones pueden ser concatenadas!
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
+
+# Strings se crean con " o '
+"Esto es un string."
+'Esto también es un string'
+
+# ¡Strings también pueden ser sumados!
+"Hola " + "mundo!" #=> "Hola mundo!"
+
+# Un string puede ser tratado como una lista de caracteres
+"Esto es un string"[0] #=> 'E'
+
+# .format puede ser usaro para darle formato a los strings, así:
+"{} pueden ser {}".format("strings", "interpolados")
+
+# Puedes repetir los argumentos de formateo para ahorrar tipeos.
+"{0} sé ligero, {0} sé rápido, {0} brinca sobre la {1}".format("Jack", "vela") #=> "Jack sé ligero, Jack sé rápido, Jack brinca sobre la vela"
+# Puedes usar palabras claves si no quieres contar.
+"{nombre} quiere comer {comida}".format(nombre="Bob", food="lasaña") #=> "Bob quiere comer lasaña"
+
+
+# None es un objeto
+None # => None
+
+# No uses el símbolo de igualdad `==` para comparar objetos con None
+# Usa `is` en lugar de
+"etc" is None #=> False
+None is None #=> True
+
+# None, 0, y strings/listas/diccionarios vacíos(as) todos se evalúan como False.
+# Todos los otros valores son True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Variables y Colecciones
+####################################################
+
+# Python tiene una función para imprimir
+print("Soy Python. Encantado de conocerte")
+
+# No hay necesidad de declarar las variables antes de asignarlas.
+una_variable = 5 # La convención es usar guiones_bajos_con_minúsculas
+una_variable #=> 5
+
+# Acceder a variables no asignadas previamente es una excepción.
+# Ve Control de Flujo para aprender más sobre el manejo de excepciones.
+otra_variable # Levanta un error de nombre
+
+# Listas almacena secuencias
+lista = []
+# Puedes empezar con una lista prellenada
+otra_lista = [4, 5, 6]
+
+# Añadir cosas al final de una lista con 'append'
+lista.append(1) #lista ahora es [1]
+lista.append(2) #lista ahora es [1, 2]
+lista.append(4) #lista ahora es [1, 2, 4]
+lista.append(3) #lista ahora es [1, 2, 4, 3]
+# Remueve del final de la lista con 'pop'
+lista.pop() #=> 3 y lista ahora es [1, 2, 4]
+# Pongámoslo de vuelta
+lista.append(3) # Nuevamente lista ahora es [1, 2, 4, 3].
+
+# Accede a una lista como lo harías con cualquier arreglo
+lista[0] #=> 1
+# Mira el último elemento
+lista[-1] #=> 3
+
+# Mirar fuera de los límites es un error 'IndexError'
+lista[4] # Levanta la excepción IndexError
+
+# Puedes mirar por rango con la sintáxis de trozo.
+# (Es un rango cerrado/abierto para ustedes los matemáticos.)
+lista[1:3] #=> [2, 4]
+# Omite el inicio
+lista[2:] #=> [4, 3]
+# Omite el final
+lista[:3] #=> [1, 2, 4]
+# Selecciona cada dos elementos
+lista[::2] # =>[1, 4]
+# Invierte la lista
+lista[::-1] # => [3, 4, 2, 1]
+# Usa cualquier combinación de estos para crear trozos avanzados
+# lista[inicio:final:pasos]
+
+# Remueve elementos arbitrarios de una lista con 'del'
+del lista[2] # lista ahora es [1, 2, 3]
+
+# Puedes sumar listas
+lista + otra_lista #=> [1, 2, 3, 4, 5, 6] - Nota: lista y otra_lista no se tocan
+
+# Concatenar listas con 'extend'
+lista.extend(otra_lista) # lista ahora es [1, 2, 3, 4, 5, 6]
+
+# Chequea la existencia en una lista con 'in'
+1 in lista #=> True
+
+# Examina el largo de una lista con 'len'
+len(lista) #=> 6
+
+
+# Tuplas son como listas pero son inmutables.
+tupla = (1, 2, 3)
+tupla[0] #=> 1
+tupla[0] = 3 # Levanta un error TypeError
+
+# También puedes hacer todas esas cosas que haces con listas
+len(tupla) #=> 3
+tupla + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tupla[:2] #=> (1, 2)
+2 in tupla #=> True
+
+# Puedes desempacar tuplas (o listas) en variables
+a, b, c = (1, 2, 3) # a ahora es 1, b ahora es 2 y c ahora es 3
+# Tuplas son creadas por defecto si omites los paréntesis
+d, e, f = 4, 5, 6
+# Ahora mira que fácil es intercambiar dos valores
+e, d = d, e # d ahora es 5 y e ahora es 4
+
+
+# Diccionarios almacenan mapeos
+dicc_vacio = {}
+# Aquí está un diccionario prellenado
+dicc_lleno = {"uno": 1, "dos": 2, "tres": 3}
+
+# Busca valores con []
+dicc_lleno["uno"] #=> 1
+
+# Obtén todas las llaves como una lista con 'keys()'. Necesitamos envolver la llamada en 'list()' porque obtenemos un iterable. Hablaremos de eso luego.
+list(dicc_lleno.keys()) #=> ["tres", "dos", "uno"]
+# Nota - El orden de las llaves del diccionario no está garantizada.
+# Tus resultados podrían no ser los mismos del ejemplo.
+
+# Obtén todos los valores como una lista. Nuevamente necesitamos envolverlas en una lista para sacarlas del iterable.
+list(dicc_lleno.values()) #=> [3, 2, 1]
+# Nota - Lo mismo que con las llaves, no se garantiza el orden.
+
+# Chequea la existencia de una llave en el diccionario con 'in'
+"uno" in dicc_lleno #=> True
+1 in dicc_lleno #=> False
+
+# Buscar una llave inexistente deriva en KeyError
+dicc_lleno["cuatro"] # KeyError
+
+# Usa el método 'get' para evitar la excepción KeyError
+dicc_lleno.get("uno") #=> 1
+dicc_lleno.get("cuatro") #=> None
+# El método 'get' soporta un argumento por defecto cuando el valor no existe.
+dicc_lleno.get("uno", 4) #=> 1
+dicc_lleno.get("cuatro", 4) #=> 4
+
+# El método 'setdefault' inserta en un diccionario solo si la llave no está presente
+dicc_lleno.setdefault("cinco", 5) #dicc_lleno["cinco"] es puesto con valor 5
+dicc_lleno.setdefault("cinco", 6) #dicc_lleno["cinco"] todavía es 5
+
+
+# Remueve llaves de un diccionario con 'del'
+del dicc_lleno['uno'] # Remueve la llave 'uno' de dicc_lleno
+
+# Sets (conjuntos) almacenan ... bueno, conjuntos
+conjunto_vacio = set()
+# Inicializar un conjunto con montón de valores. Yeah, se ve un poco como un diccionario. Lo siento.
+un_conjunto = {1,2,2,3,4} # un_conjunto ahora es {1, 2, 3, 4}
+
+# Añade más valores a un conjunto
+conjunto_lleno.add(5) # conjunto_lleno ahora es {1, 2, 3, 4, 5}
+
+# Haz intersección de conjuntos con &
+otro_conjunto = {3, 4, 5, 6}
+conjunto_lleno & otro_conjunto #=> {3, 4, 5}
+
+# Haz unión de conjuntos con |
+conjunto_lleno | otro_conjunto #=> {1, 2, 3, 4, 5, 6}
+
+# Haz diferencia de conjuntos con -
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# Chequea la existencia en un conjunto con 'in'
+2 in conjunto_lleno #=> True
+10 in conjunto_lleno #=> False
+
+
+####################################################
+## 3. Control de Flujo
+####################################################
+
+# Let's just make a variable
+some_var = 5
+
+# Aquí está una declaración de un 'if'. ¡La indentación es significativa en Python!
+# imprime "una_variable es menor que 10"
+if una_variable > 10:
+ print("una_variable es completamente mas grande que 10.")
+elif una_variable < 10: # Este condición 'elif' es opcional.
+ print("una_variable es mas chica que 10.")
+else: # Esto también es opcional.
+ print("una_variable es de hecho 10.")
+
+"""
+For itera sobre listas
+imprime:
+ perro es un mamifero
+ gato es un mamifero
+ raton es un mamifero
+"""
+for animal in ["perro", "gato", "raton"]:
+ # Puedes usar % para interpolar strings formateados
+ print("{} es un mamifero".format(animal))
+
+"""
+`range(número)` retorna una lista de números
+desde cero hasta el número dado
+imprime:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+While itera hasta que una condición no se cumple.
+imprime:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # versión corta de x = x + 1
+
+# Maneja excepciones con un bloque try/except
+try:
+ # Usa raise para levantar un error
+ raise IndexError("Este es un error de indice")
+except IndexError as e:
+ pass # Pass no hace nada. Usualmente harias alguna recuperacion aqui.
+
+# Python oferce una abstracción fundamental llamada Iterable.
+# Un iterable es un objeto que puede ser tratado como una sequencia.
+# El objeto es retornado por la función 'range' es un iterable.
+
+dicc_lleno = {"uno": 1, "dos": 2, "tres": 3}
+nuestro_iterable = dicc_lleno.keys()
+print(nuestro_iterable) #=> range(1,10). Este es un objeto que implementa nuestra interfaz Iterable
+
+Podemos recorrerla.
+for i in nuestro_iterable:
+ print(i) # Imprime uno, dos, tres
+
+# Aunque no podemos selecionar un elemento por su índice.
+nuestro_iterable[1] # Genera un TypeError
+
+# Un iterable es un objeto que sabe como crear un iterador.
+nuestro_iterator = iter(nuestro_iterable)
+
+# Nuestro iterador es un objeto que puede recordar el estado mientras lo recorremos.
+# Obtenemos el siguiente objeto llamando la función __next__.
+nuestro_iterator.__next__() #=> "uno"
+
+# Mantiene el estado mientras llamamos __next__.
+nuestro_iterator.__next__() #=> "dos"
+nuestro_iterator.__next__() #=> "tres"
+
+# Después que el iterador ha retornado todos sus datos, da una excepción StopIterator.
+nuestro_iterator.__next__() # Genera StopIteration
+
+# Puedes obtener todos los elementos de un iterador llamando a list() en el.
+list(dicc_lleno.keys()) #=> Retorna ["uno", "dos", "tres"]
+
+
+
+####################################################
+## 4. Funciones
+####################################################
+
+# Usa 'def' para crear nuevas funciones
+def add(x, y):
+ print("x es {} y y es {}".format(x, y))
+ return x + y # Retorna valores con una la declaración return
+
+# Llamando funciones con parámetros
+add(5, 6) #=> imprime "x es 5 y y es 6" y retorna 11
+
+# Otra forma de llamar funciones es con argumentos de palabras claves
+add(y=6, x=5) # Argumentos de palabra clave pueden ir en cualquier orden.
+
+
+# Puedes definir funciones que tomen un número variable de argumentos
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# Puedes definir funciones que toman un número variable de argumentos
+# de palabras claves
+def keyword_args(**kwargs):
+ return kwargs
+
+# Llamémosla para ver que sucede
+keyword_args(pie="grande", lago="ness") #=> {"pie": "grande", "lago": "ness"}
+
+
+# You can do both at once, if you like# Puedes hacer ambas a la vez si quieres
+def todos_los_argumentos(*args, **kwargs):
+ print args
+ print kwargs
+"""
+todos_los_argumentos(1, 2, a=3, b=4) imprime:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# ¡Cuando llames funciones, puedes hacer lo opuesto a varargs/kwargs!
+# Usa * para expandir tuplas y usa ** para expandir argumentos de palabras claves.
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+todos_los_argumentos(*args) # es equivalente a foo(1, 2, 3, 4)
+todos_los_argumentos(**kwargs) # es equivalente a foo(a=3, b=4)
+todos_los_argumentos(*args, **kwargs) # es equivalente a foo(1, 2, 3, 4, a=3, b=4)
+
+# Python tiene funciones de primera clase
+def crear_suma(x):
+ def suma(y):
+ return x + y
+ return suma
+
+sumar_10 = crear_suma(10)
+sumar_10(3) #=> 13
+
+# También hay funciones anónimas
+(lambda x: x > 2)(3) #=> True
+
+# Hay funciones integradas de orden superior
+map(sumar_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# Podemos usar listas por comprensión para mapeos y filtros agradables
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. Classes
+####################################################
+
+
+# Heredamos de object para obtener una clase.
+class Humano(object):
+
+ # Un atributo de clase es compartido por todas las instancias de esta clase
+ especie = "H. sapiens"
+
+ # Constructor basico
+ def __init__(self, nombre):
+ # Asigna el argumento al atributo nombre de la instancia
+ self.nombre = nombre
+
+ # Un metodo de instancia. Todos los metodos toman self como primer argumento
+ def decir(self, msg):
+ return "%s: %s" % (self.nombre, msg)
+
+ # Un metodo de clase es compartido a través de todas las instancias
+ # Son llamados con la clase como primer argumento
+ @classmethod
+ def get_especie(cls):
+ return cls.especie
+
+ # Un metodo estatico es llamado sin la clase o instancia como referencia
+ @staticmethod
+ def roncar():
+ return "*roncar*"
+
+
+# Instancia una clase
+i = Humano(nombre="Ian")
+print i.decir("hi") # imprime "Ian: hi"
+
+j = Humano("Joel")
+print j.decir("hello") #imprime "Joel: hello"
+
+# Llama nuestro método de clase
+i.get_especie() #=> "H. sapiens"
+
+# Cambia los atributos compartidos
+Humano.especie = "H. neanderthalensis"
+i.get_especie() #=> "H. neanderthalensis"
+j.get_especie() #=> "H. neanderthalensis"
+
+# Llama al método estático
+Humano.roncar() #=> "*roncar*"
+
+
+####################################################
+## 6. Módulos
+####################################################
+
+# Puedes importar módulos
+import math
+print(math.sqrt(16)) #=> 4
+
+# Puedes obtener funciones específicas desde un módulo
+from math import ceil, floor
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7))#=> 3.0
+
+# Puedes importar todas las funciones de un módulo
+# Precaución: Esto no es recomendable
+from math import *
+
+# Puedes acortar los nombres de los módulos
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# Los módulos de Python son sólo archivos ordinarios de Python.
+# Puedes escribir tus propios módulos e importarlos. El nombre del módulo
+# es el mismo del nombre del archivo.
+
+# Puedes encontrar que funciones y atributos definen un módulo.
+import math
+dir(math)
+
+
+####################################################
+## 7. Avanzado
+####################################################
+
+# Los generadores te ayudan a hacer un código perezoso (lazy)
+def duplicar_numeros(iterable):
+ for i in iterable:
+ yield i + i
+
+# Un generador cera valores sobre la marcha.
+# En vez de generar y retornar todos los valores de una vez, crea uno en cada iteración.
+# Esto significa que valores más grandes que 15 no serán procesados en 'duplicar_numeros'.
+# Fíjate que 'range' es un generador. Crear una lista 1-900000000 tomaría mucho tiempo en crearse.
+_rango = range(1, 900000000)
+# Duplicará todos los números hasta que un resultado >= se encuentre.
+for i in duplicar_numeros(_rango):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decoradores
+# en este ejemplo 'pedir' envuelve a 'decir'
+# Pedir llamará a 'decir'. Si decir_por_favor es True entonces cambiará el mensaje a retornar
+from functools import wraps
+
+
+def pedir(_decir):
+ @wraps(_decir)
+ def wrapper(*args, **kwargs):
+ mensaje, decir_por_favor = _decir(*args, **kwargs)
+ if decir_por_favor:
+ return "{} {}".format(mensaje, "¡Por favor! Soy pobre :(")
+ return mensaje
+
+ return wrapper
+
+
+@pedir
+def say(decir_por_favor=False):
+ mensaje = "¿Puedes comprarme una cerveza?"
+ return mensaje, decir_por_favor
+
+
+print(decir()) # ¿Puedes comprarme una cerveza?
+print(decir(decir_por_favor=True)) # ¿Puedes comprarme una cerveza? ¡Por favor! Soy pobre :()
+```
+
+## ¿Listo para más?
+
+### Gratis y en línea
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+* [The Official Docs](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Encuadernados
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/fa-ir/javascript.html.markdown b/fa-ir/javascript.html.markdown
index f1beae87..922fe416 100644
--- a/fa-ir/javascript.html.markdown
+++ b/fa-ir/javascript.html.markdown
@@ -4,7 +4,7 @@ contributors:
- ["Adam Brenecki", "http://adam.brenecki.id.au"]
translators:
- ["Mohammad Valipour", "https://github.com/mvalipour"]
-filename: javascript.js
+filename: javascript-fa.js
lang: fa-ir
---
diff --git a/fr-fr/csharp-fr.html.markdown b/fr-fr/csharp-fr.html.markdown
new file mode 100644
index 00000000..c1641716
--- /dev/null
+++ b/fr-fr/csharp-fr.html.markdown
@@ -0,0 +1,812 @@
+---
+language: c#
+contributors:
+ - ["Irfan Charania", "https://github.com/irfancharania"]
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Melvyn Laïly", "http://x2a.yt"]
+ - ["Shaun McCarthy", "http://www.shaunmccarthy.com"]
+translators:
+ - ["Olivier Hoarau", "https://github.com/Olwaro"]
+filename: LearnCSharp.cs
+lang: fr-fr
+---
+
+C# est un langage de programmation orienté objet à typage fort qui permet aux développeurs de créer une grande variété d'applications fiables et robustes s'appuyant sur le framework .NET.
+
+[Plus d'infos](http://msdn.microsoft.com/fr-fr/library/67ef8sbd.aspx)
+
+```c#
+// Les commentaires sur une seule ligne commencent par //
+/*
+Les
+commentaires
+multi-lignes
+ressemblent
+ceci
+*/
+/// <summary>
+/// Ceci est un commentaire de documentation XML
+/// </summary>
+
+// Importez des namespaces avec l'instruction 'using'
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Dynamic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Net;
+using System.Threading.Tasks;
+
+// Définit la portée du code pour une meilleure organisation
+namespace Learning
+{
+ // Chaque fichier .cs devrait au moins contenir une classe avec le même nom
+ // que celui du fichier. Ce n'est pas une obligation mais c'est mieux !
+ public class LearnCSharp
+ {
+ // LES BASES - si vous avez déjà de l'expérience en Java ou C++
+ // passez directement à la partie FONCTIONNALITÉS INTERÉSSANTES
+ public static void Syntax()
+ {
+ // Utilisez Console.WriteLine pour écrire sur la sortie
+ Console.WriteLine("Hello World");
+ Console.WriteLine(
+ "Entier: " + 10 +
+ " Double: " + 3.14 +
+ " Booleen: " + true);
+
+ // Pour omettre le retour à la ligne : Console.Write
+ Console.Write("Hello ");
+ Console.Write("World");
+
+ ///////////////////////////////////////////////////
+ // Types et Variables
+ // Déclarez une variable avec la syntaxe <type> <nom>
+ ///////////////////////////////////////////////////
+
+ // Sbyte - Entier signé sur 8 bits
+ // (-128 <= sbyte <= 127)
+ sbyte fooSbyte = 100;
+
+ // Byte - Entier non-signé sur 8 bits
+ // (0 <= byte <= 255)
+ byte fooByte = 100;
+
+ // Short - Entier sur 16 bits
+ // Signé - (-32,768 <= short <= 32,767)
+ // Non-signé - (0 <= ushort <= 65,535)
+ short fooShort = 10000;
+ ushort fooUshort = 10000;
+
+ // Int - Entier sur 32 bits
+ int fooInt = 1; // (-2,147,483,648 <= int <= 2,147,483,647)
+ uint fooUint = 1; // (0 <= uint <= 4,294,967,295)
+
+ // Long - Entier sur 64 bits
+ long fooLong = 100000L; // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
+ ulong fooUlong = 100000L; // (0 <= ulong <= 18,446,744,073,709,551,615)
+ // Par défaut le type d'un littéral entier est int ou uint
+ // on ajoute 'L' pour spécifier la création d'un long
+
+ // Double - Réel sur 64 bits en virgule flottante (norme IEEE 754)
+ double fooDouble = 123.4; // Precision : 15-16 chiffres
+
+ // Float - Réel sur 32 bits en virgule flottante (norme IEEE 754)
+ float fooFloat = 234.5f; // Precision : 7 chiffres
+ // Par défaut le type d'un littéral réel est double
+ // on ajoute 'f' pour spécifier la création d'un float
+
+ // Decimal - Type de donnée numérique sur 128 bits, fournit une plus
+ // grande précision et une plage de valeurs réduite.
+ // Approprié aux calculs financiers et monétaires
+ decimal fooDecimal = 150.3m;
+
+ // Booléen - vrai / faux
+ bool fooBoolean = true; // ou false
+
+ // Char - Un unique caractère Unicode sur 16 bits
+ char fooChar = 'A';
+
+ // String -- contrairement aux types précédents qui sont des types valeurs,
+ // string est un type référence. Il peut donc avoir la valeur null
+ string fooString = "\"échappement\" de guillemets et ajout de \n (nouvelle ligne) et de \t (tabulation)";
+ Console.WriteLine(fooString);
+
+ // Il est possible d'accéder à chaque caractère d'une chaîne de caractères via son index
+ char charFromString = fooString[1]; // 'é'
+ // une chaîne de caractères est immuable : impossible de faire fooString[1] = 'X';
+
+ // Comparaison de chaînes de caractères avec la culture courrante en ignorant la casse
+ string.Compare(fooString, "x", StringComparison.CurrentCultureIgnoreCase);
+
+ // Formatage
+ string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2);
+
+ // Dates et formatage
+ DateTime fooDate = DateTime.Now;
+ Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
+
+ // Il est possible d'étaler une chaîne de caractères sur plusieurs lignes avec le symbole @.
+ // Pour échapper " utilisez ""
+ string bazString = @"Voici quelques trucs
+sur une nouvelle ligne! ""Wow!"", quel style";
+
+ // Utilisez const ou read-only pour rendre une variable immuable.
+ // Les valeurs constantes sont calculées au moment de la compilation
+ const int HOURS_I_WORK_PER_WEEK = 9001;
+
+ ///////////////////////////////////////////////////
+ // Structures de données
+ ///////////////////////////////////////////////////
+
+ // Tableaux - indexé à partir de zéro
+ // La taille d'un tableau doit être décidée à la déclaration
+ // La syntaxe pour déclarer un tableau est la suivante :
+ // <type>[] <nom> = new <type>[<taille>]
+ int[] intArray = new int[10];
+
+ // Une autre méthode de déclaration et d'initialisation
+ int[] y = { 9000, 1000, 1337 };
+
+ // Indexer un tableau - Accéder à un élément
+ Console.WriteLine("intArray à 0: " + intArray[0]);
+ // Les tableaux sont muables.
+ intArray[1] = 1;
+
+ // Listes
+ // Elles sont plus souvent utilisées que les tableaux car plus souples
+ // La syntaxe pour déclarer une liste est la suivante :
+ // List<type> <nom> = new List<type>();
+ List<int> intList = new List<int>();
+ List<string> stringList = new List<string>();
+ List<int> z = new List<int> { 9000, 1000, 1337 }; // intialisation
+ // Les <> indiquent un type générique
+ // Pus d'info dans la partie FONCTIONNALITÉS INTERÉSSANTES
+
+ // Les éléments d'une liste ne sont pas null par défaut
+ // Il faut ajouter une valeur avant d'y accéder par index
+ intList.Add(1);
+ Console.WriteLine("intList à 0: " + intList[0]);
+
+ // Autres structures de données à étudier :
+ // Stack/Queue (Pile/File)
+ // Dictionary (une implémentation de hash map)
+ // HashSet (représente un ensemble)
+ // Collections en lecture seule
+ // Tuple (.Net 4+)
+
+ ///////////////////////////////////////
+ // Opérateurs
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Opérateurs");
+
+ int i1 = 1, i2 = 2; // Raccourci pour des déclarations multiples
+
+ // Arithmétique classique
+ Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
+
+ // Modulo
+ Console.WriteLine("11%3 = " + (11 % 3)); // => 2
+
+ // Opérateurs de comparaison
+ 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
+
+ // Opérateurs bit à bit !
+ /*
+ ~ Compément unaire
+ << Décalage à gauche
+ >> Décalage à droite
+ & ET logique
+ ^ OU exclusif
+ | OU inclusif
+ */
+
+ // Incrémentations
+ int i = 0;
+ Console.WriteLine("\n->Inc/Dec-rementation");
+ Console.WriteLine(i++); //i = 1. Post-Incrémentation
+ Console.WriteLine(++i); //i = 2. Pre-Incrémentation
+ Console.WriteLine(i--); //i = 1. Post-Decrémentation
+ Console.WriteLine(--i); //i = 0. Pre-Decrémentation
+
+ ///////////////////////////////////////
+ // Structures de contrôle
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Structures de contrôle");
+
+ // Structure conditionnelle
+ int j = 10;
+ if (j == 10)
+ {
+ Console.WriteLine("Je serai affiché");
+ }
+ else if (j > 10)
+ {
+ Console.WriteLine("Pas moi");
+ }
+ else
+ {
+ Console.WriteLine("Moi non plus");
+ }
+
+ // Opérateur ternaire
+ // Un simple if/else peut s'écrire :
+ // <condition> ? <valeur si true> : <valeur si false>
+ string isTrue = (true) ? "True" : "False";
+
+ // Boucle while
+ int fooWhile = 0;
+ while (fooWhile < 100)
+ {
+ // 100 passages, de 0 à 99
+ fooWhile++;
+ }
+
+ // Boucle Do While
+ int fooDoWhile = 0;
+ do
+ {
+ // 100 passages, de 0 à 99
+ fooDoWhile++;
+ } while (fooDoWhile < 100);
+
+ // Boucle for
+ // Structure : for(<etat_initial>; <condition>; <pas>)
+ for (int fooFor = 0; fooFor < 10; fooFor++)
+ {
+ // 10 passages, de 0 à 9
+ }
+
+ // La boucle foreach
+ // Structure : foreach(<type_iterateur> <nom_iterateur> in <enumerable>)
+ // Cette boucle est utilisable sur des objets implémentant IEnumerable ou IEnumerable<T>
+ // Toutes les collections du framework .NET (Tableaux, Listes, ...) implémentent ces interfaces.
+ // (Notez que dans l'exemple suivant .ToCharArray() peut être omit car
+ // string implémente IEnumerable)
+ foreach (char character in "Hello World".ToCharArray())
+ {
+ //Itération sur chaque caractère
+ }
+
+ // La structure Switch Case
+ // Un switch fonctionne avec les types : byte, short, char et int.
+ // Les enums sont aussi supportés ainsi que les chaînes de caractères et quelques
+ // classes spéciales basées sur les types primitifs : Character, Byte, Short et Integer.
+ int mois = 3;
+ string moisString;
+ switch (mois)
+ {
+ case 1:
+ moisString = "Janvier";
+ break;
+ case 2:
+ moisString = "Février";
+ break;
+ case 3:
+ moisString = "Mars";
+ break;
+
+ // Vous pouvez assigner plus d'un 'case' à une action
+ // Mais vous ne pouvez pas ajouter une action sans 'break' avant un 'case'
+ // (pour ce faire, il faudrait ajouter explicitement un 'goto case x')
+ case 6:
+ case 7:
+ case 8:
+ moisString = "C'est l'été!";
+ break;
+ default:
+ moisString = "Un autre mois oO";
+ break;
+ }
+
+ ///////////////////////////////////////
+ // conversion de type de donnée et transtypage
+ ///////////////////////////////////////
+
+ // conversion de string vers int
+ // lève une exception en cas d'erreur
+ int.Parse("123"); //retourne la valeur entière de "123"
+
+ // TryParse affecte la valeur par défaut du type en cas d'erreur
+ // dans ce cas : 0
+ int tryInt;
+ if (int.TryParse("123", out tryInt)) // La fonction retourne un booléen
+ Console.WriteLine(tryInt); // => 123
+
+ // conversion d'un entier vers une chaîne de caractères
+ // La classe Convert possède plusieurs méthodes pour faciliter la conversion
+ Convert.ToString(123);
+ // ou
+ tryInt.ToString();
+ }
+
+ ///////////////////////////////////////
+ // CLASSES - voir les définitions à la fin du fichier
+ ///////////////////////////////////////
+
+ public static void Classes()
+ {
+ // voir les déclarations à la fin du fichier
+
+ // Utilisez 'new' pour instancier une classe
+ Bicycle trek = new Bicycle();
+
+ // Appel des méthodes de l'objet
+ trek.SpeedUp(3); // Il est toujours bon d'utiliser des accesseurs
+ trek.Cadence = 100;
+
+ // Affichage de la valeur de retour d'une méthode.
+ Console.WriteLine("trek info: " + trek.Info());
+
+ // Instanciation d'un nouveau PennyFarthing
+ PennyFarthing funbike = new PennyFarthing(1, 10);
+ Console.WriteLine("funbike info: " + funbike.Info());
+
+ Console.Read();
+ }
+
+ // POINT D'ENTRÉE - Une application console doit avoir une méthode main comme point d'entrée
+ public static void Main(string[] args)
+ {
+ OtherInterestingFeatures();
+ }
+
+ //
+ // FONCTIONNALITÉS INTÉRÉSSANTES
+ //
+
+ // SIGNATURE DE METHODE
+ public // Visibilité
+ static // Permet un appel direct par la classe (sans instanciation)
+ int // Type de retour,
+ MethodSignatures(
+ int maxCount, // Premier paramètre, de type int
+ int count = 0, // Valeur par défaut si aucun argument n'est passé
+ int another = 3,
+ params string[] otherParams // Capture tous les arguments passés à la méthode
+ )
+ {
+ return -1;
+ }
+
+ // Des méthodes peuvent avoir le même nom tant que leur signature est unique
+ public static void MethodSignature(string maxCount)
+ {
+ }
+
+ // TYPE GÉNÉRIQUE
+
+ // Les types TKey et TValue sont spécifiés par l'utilisateur lors de l'appel de la fonction
+ // Cette méthode émule SetDefaut de Python
+ public static TValue SetDefault<TKey, TValue>(
+ IDictionary<TKey, TValue> dictionary,
+ TKey key,
+ TValue defaultItem)
+ {
+ TValue result;
+ if (!dictionary.TryGetValue(key, out result))
+ return dictionary[key] = defaultItem;
+ return result;
+ }
+
+ // Vous pouvez limiter les types autorisés
+ public static void IterateAndPrint<T>(T toPrint) where T: IEnumerable<int>
+ {
+ // Nous sommes sûrs de pouvoir itérer, car T implémente IEnumerable<int>
+ foreach (var item in toPrint)
+ // Item sera de type int
+ Console.WriteLine(item.ToString());
+ }
+
+ public static void OtherInterestingFeatures()
+ {
+ // PARAMÈTERES OPTIONNELS
+ MethodSignatures(3, 1, 3, "Des", "Paramètres", "En plus");
+ MethodSignatures(3, another: 3); // affectation explicite, les autres
+ // paramètres ont la valeur par défaut
+
+ // MÉTHODE D'EXTENSION
+ int i = 3;
+ i.Print(); // Définit plus bas
+
+ // TYPES NULLABLE - idéal pour les interactions avec une base de données ou pour les valeurs de retour
+ // Tous les types valeurs peuvent être rendus nullable en les suffixant par '?'
+ // <type>? <nom> = <value>
+ int? nullable = null; // raccourci pour Nullable<int>
+ Console.WriteLine("Nullable variable: " + nullable);
+ bool hasValue = nullable.HasValue; // retourne vrai si la valeur n'est pas null
+
+ // ?? est un sucre syntaxique pour spécifier une valeur par défaut
+ // au cas ou une autre valeur serait nulle
+ int notNullable = nullable ?? 0; // 0
+
+ // VARIABLES IMPLICITEMENT TYPÉES - vous pouvez laisser le compilateur deviner le type d'une variable
+ var magic = "magic est de type string à la compilation. On a toujours un typage fort !";
+ // magic = 9; // ne fonctionnera pas car magic est désormais une chaîne de caractères
+
+ // TYPES GÉNÉRIQUES
+ var agenda = new Dictionary<string, string>() {
+ {"Sarah", "212 555 5555"} // Ajout d'une entrée à notre agenda
+ };
+
+ // Appel de la fonction SetDefault (définie plus haut)
+ Console.WriteLine(SetDefault<string,string>(agenda, "Shaun", "Pas de numéro")); // => Pas de numéro
+ // Notez que vous n'avez pas à spécifier TKey et TValue car le compilateur saura les inférer.
+ Console.WriteLine(SetDefault(agenda, "Sarah", "No Phone")); // => 212 555 5555
+
+ // EXPRESSION LAMBDA - permet d'écrire une fonction en tant qu'expression
+ Func<int, int> square = (x) => x * x; // La dernière expression est la valeur de retour
+ Console.WriteLine(square(3)); // => 9
+
+ // GESTION AUTOMATIQUE DES RESSOURCES - vous permet de manipuler facilement des resources non-managées
+ // La plus part des objets qui accèdent à des ressources non-managées (handle de fichier, périphérique, etc.)
+ // implémentent l'interface IDisposable. L'instruction using prend soin
+ // de libérer les objets IDisposable proprement à votre place.
+ using (StreamWriter writer = new StreamWriter("log.txt"))
+ {
+ writer.WriteLine("Rien à signaler");
+ // À la fin de cette portée les ressources seront libérées.
+ // Même si une exception est levée.
+ }
+
+ // BIBLIOTHÈQUE DE TÂCHES PARALLÈLES (TPL)
+ // http://msdn.microsoft.com/fr-fr/library/dd460717.aspx
+ var websites = new string[] {
+ "http://www.google.com", "http://www.reddit.com",
+ "http://www.shaunmccarthy.com"
+ };
+ var responses = new Dictionary<string, string>();
+
+ // L'exemple suivant exécutera chaque requête dans un thread séparé,
+ // et attendra la fin de chacun d'entre eux avant de continuer
+ Parallel.ForEach(websites,
+ new ParallelOptions() {MaxDegreeOfParallelism = 3}, // maximum de 3 threads
+ website =>
+ {
+ // Fait quelque chose de long
+ using (var r = WebRequest.Create(new Uri(website)).GetResponse())
+ {
+ responses[website] = r.ContentType;
+ }
+ });
+
+ // Ceci ne s'exécutera pas tant que les threads n'auront pas fini leur travail
+ foreach (var key in responses.Keys)
+ Console.WriteLine("{0}:{1}", key, responses[key]);
+
+ // TYPE DYNAMIQUE - idéal pour travailler avec d'autres langages
+ dynamic student = new ExpandoObject();
+ student.FirstName = "Mon prénom"; // Pas besoin de définir l'objet
+
+ // Vous pouvez même ajouter des méthodes (dans cet exemple : la méthode prend une chaîne de caractères et retourne une chaîne de caractères)
+ student.Introduce = new Func<string, string>(
+ (introduceTo) => string.Format("Hey {0}, c'est {1}", student.FirstName, introduceTo));
+ Console.WriteLine(student.Introduce("Beth"));
+
+ // IQUERYABLE<T> - quasiment toutes les collections implémentent cette interface
+ // ce qui permet d'utiliser des méthodes de style 'Filter' / 'Map' / 'Reduce'
+ var bikes = new List<Bicycle>();
+ bikes.Sort(); // Trie le tableau sur place
+ bikes.Sort((b1, b2) => b1.Wheels.CompareTo(b2.Wheels)); // Trie en se basant sur la propriété Wheels
+ var result = bikes
+ .Where(b => b.Wheels > 3) // 'Filter' - enchaînable (retourne un IQueryable du type précédent)
+ .Where(b => b.IsBroken && b.HasTassles)
+ .Select(b => b.ToString()); // 'Map' - on retourne le .ToString() de chaque élément filtré,
+ // le résultat est un IQueryable<string>
+
+ var sum = bikes.Sum(b => b.Wheels); // 'Reduce' - fait la somme de tous les Wheels de la liste
+
+ // Creation d'une liste d'objet anonymes basés sur des paramètres de la classe Bike
+ var bikeSummaries = bikes.Select(b=>new { Name = b.Name, IsAwesome = !b.IsBroken && b.HasTassles });
+ // Le compilateur peut inférer le type de ces objets anonymes, permettant à certains IDE d'effectuer
+ // des autos-complétion.
+ foreach (var bikeSummary in bikeSummaries.Where(b => b.IsAwesome))
+ Console.WriteLine(bikeSummary.Name);
+
+
+ // ASPARALLEL
+ // C'est ici que les choses se compliquent - un mélange de LINQ et de TPL
+ var threeWheelers = bikes.AsParallel().Where(b => b.Wheels == 3).Select(b => b.Name);
+ // La ligne précédente s'exécute en parallèle ! Des threads seront gérés automatiquement
+ // et les données y seront réparties. Idéal sur de grosses données (et si votre
+ // machine dispose de plusieurs coeurs)
+
+
+ // LINQ - lie une source de données à des objets IQueryable<T>
+ // ex : LindToSql => liaison avec une base de données, LinqToXml => liaison avec un document xml
+ var db = new BikeRespository();
+
+ // l'exécution est décalée, ce qui est préférable quand on travaille sur une base données
+ var filter = db.Bikes.Where(b => b.HasTassles); // pas de requête exécutée
+ if (42 > 6) // Vous pouvez continuer à affiner la recherche
+ filter = filter.Where(b => b.IsBroken); // pas de requête exécutée
+
+ var query = filter
+ .OrderBy(b => b.Wheels)
+ .ThenBy(b => b.Name)
+ .Select(b => b.Name); // toujours pas de requête exécutée
+
+ // Maintenant la requête est exécutée, mais retourne des données uniquement au fil de l'itération
+ foreach (string bike in query)
+ Console.WriteLine(result);
+
+ }
+
+ } // Fin de la classe LearnCSharp
+
+ // Il est possible d'inclure plusieurs classes dans un fichier .cs
+
+ public static class Extensions
+ {
+ // EXTENSION DE FONCTIONS
+ public static void Print(this object obj)
+ {
+ Console.WriteLine(obj.ToString());
+ }
+ }
+
+ // Syntaxe de déclaration de classe :
+ // <public/private/protected/internal> class <class name>{
+ // // champs, constructeurs, fonctions
+ // // tout est déclaré et implémenté à l'intérieur
+ // }
+
+ public class Bicycle
+ {
+ // Propriétés et variable de la classe
+ public int Cadence // Public : peut être accédé de partout
+ {
+ get // get - définit une méthode pour lire la propriété
+ {
+ return _cadence;
+ }
+ set // set - définit une méthode pour affecter une valeur à la propriété
+ {
+ _cadence = value; // 'value' est la valeur passée en argument au setteur
+ }
+ }
+ private int _cadence;
+
+ protected virtual int Gear // Protected : accessible depuis la classe et ses classes filles
+ {
+ get; // crée une propriété automatique, pas besoin de créer une variable de stockage
+ set;
+ }
+
+ internal int Wheels // Internal : accessible depuis l'assembly
+ {
+ get;
+ private set; // Il est possible de choisir la portée d'un accesseur
+ }
+
+ int _speed; // Par défaut tout est privé au sein d'une classe : accessible uniquement depuis la classe
+ // on peut ajouter explicitement le mot clé 'private'
+
+ public string Name { get; set; }
+
+
+ // Enum est un type valeur formé par un ensemble de constantes nommées
+ // C'est simplement une manière de mettre un nom sur une valeur (int par défaut).
+ // Les types compatibles pour un enum sont : byte, sbyte, short, ushort, int, uint, long et ulong.
+ // Un enum ne peut pas contenir deux fois la même valeur
+ public enum BikeBrand
+ {
+ AIST,
+ BMC,
+ Electra = 42, // il est possible de donner explicitement une valeur
+ Gitane // 43
+ }
+ // Nous avons défini cet enum à l'intérieur de la classe Bicycle, c'est donc un type imbriqué
+ // Pour le référencer à l'extérieur, il faudra utiliser Bicycle.BikeBrand
+
+ public BikeBrand Brand; // Après avoir déclaré notre type enum, on peut créer un champ de ce type
+
+ // Les membres statiques appartiennent à une classe plutôt qu'à une instance particulière
+ // Il est possible d'y accéder sans passer par un objet :
+ // ex : Console.WriteLine("Bicycles créés : " + Bicycle.bicyclesCreated);
+ static public int BicyclesCreated = 0;
+
+ // Les valeurs en lecture seule sont affectées lors de l'exécution
+ // Elles ne peuvent être assignées que lors de leur déclaration ou dans un constructeur
+ readonly bool _hasCardsInSpokes = false; // variable en lecture et privée
+
+ // Les constructeurs sont un moyen de créer des objets
+ // Voici un constructeur par défaut (pas d'arguments)
+ public Bicycle()
+ {
+ this.Gear = 1; // accès aux membres de la classe via le mot clé this
+ Cadence = 50; // qui est souvent implicite
+ _speed = 5;
+ Name = "Bontrager";
+ Brand = BikeBrand.AIST;
+ BicyclesCreated++;
+ }
+
+ // Voici un constructeur spécifique (qui prend des arguments)
+ public Bicycle(int startCadence, int startSpeed, int startGear,
+ string name, bool hasCardsInSpokes, BikeBrand brand)
+ : base() // possibilité d'appeler le constructeur de la classe mère (ici Object)
+ {
+ Gear = startGear;
+ Cadence = startCadence;
+ _speed = startSpeed;
+ Name = name;
+ _hasCardsInSpokes = hasCardsInSpokes;
+ Brand = brand;
+ }
+
+ // Les constructeurs peuvent s'enchaîner
+ public Bicycle(int startCadence, int startSpeed, BikeBrand brand) :
+ this(startCadence, startSpeed, 0, "big wheels", true, brand)
+ {
+ }
+
+ // Syntaxe de méthode :
+ // <public/private/protected> <type de retour> <nom de methode>(<args>)
+
+ // Les classes peuvent implémenter des accesseurs pour leurs champs
+ // ou implémenter des propriétés (c'est la méthode dominante en C#)
+
+ // Les paramètres de méthodes peuvent avoir des valeurs par défaut
+ // Dans ce cas, la méthode peut être appelée sans arguments
+ public void SpeedUp(int increment = 1)
+ {
+ _speed += increment;
+ }
+
+ public void SlowDown(int decrement = 1)
+ {
+ _speed -= decrement;
+ }
+
+ // Les propriétés se chargent de lire/modifier des valeurs
+ // elles peuvent être en lecture(get), en écriture(set) ou les deux
+ private bool _hasTassles; // variable privée
+ public bool HasTassles // propriété publique
+ {
+ get { return _hasTassles; }
+ set { _hasTassles = value; }
+ }
+
+ // Il est possible de définir une propriété automatique sur une ligne
+ // cette syntaxe créera une variable de stockage automatiquement.
+ // Il est possible de modifier l'accèsibilité des getter/setter pour limiter leur utilisation
+ public bool IsBroken { get; private set; }
+
+ // La même chose sur plusieurs lignes
+ public int FrameSize
+ {
+ get;
+ // Notez que seule la classe Bicycle peut changer la valeur de FrameSize
+ private set;
+ }
+
+ // Méthode qui affiche la valeur des champs de cet objet
+ public virtual string Info()
+ {
+ return "Gear: " + Gear +
+ " Cadence: " + Cadence +
+ " Speed: " + _speed +
+ " Name: " + Name +
+ " Cards in Spokes: " + (_hasCardsInSpokes ? "yes" : "no") +
+ "\n------------------------------\n"
+ ;
+ }
+
+ // Les méthodes peuvent aussi être statiques. Utile pour les méthodes d'aide.
+ public static bool DidWeCreateEnoughBycles()
+ {
+ // À l'intérieur d'une méthode statique on ne peut que référencer des membres statiques !
+ return BicyclesCreated > 9000;
+ } // Si votre classe n'a que des membres statiques, marquez la comme statique
+
+ } // fin de la classe Bicycle
+
+ // PennyFarthing est une classe dérivée de Bicycle
+ class PennyFarthing : Bicycle
+ {
+ // Appel au constructeur de la classe mère
+ public PennyFarthing(int startCadence, int startSpeed) :
+ base(startCadence, startSpeed, 0, "PennyFarthing", true, BikeBrand.Electra)
+ {
+ }
+
+ protected override int Gear
+ {
+ get
+ {
+ return 0;
+ }
+ set
+ {
+ // Lève une exception
+ throw new ArgumentException("Impossible de modifier Gear sur un PennyFarthing");
+ }
+ }
+
+ public override string Info()
+ {
+ string result = "PennyFarthing bicycle ";
+ result += base.ToString(); // Appel à la version de base de cette méthode
+ return result;
+ }
+ }
+
+ // Les interfaces contiennent uniquement la signature de leurs membres, sans implémentation.
+ interface IJumpable
+ {
+ void Jump(int meters); // Tous les membres d'interface sont publics par défaut
+ }
+
+ interface IBreakable
+ {
+ bool Broken { get; } // Les interfaces peuvent contenir des propriétés,
+ // des méthodes et des évènements
+ }
+
+ // Une classe ne peut hériter que d'une seule autre classe, mais peut implémenter plusieurs interfaces
+ class MountainBike : Bicycle, IJumpable, IBreakable
+ {
+ int damage = 0;
+
+ public void Jump(int meters)
+ {
+ damage += meters;
+ }
+
+ public bool Broken
+ {
+ get
+ {
+ return damage > 100;
+ }
+ }
+ }
+
+ /// <summary>
+ /// Utilisé pour illustrer la connexion à une base donnée dans l'exemple LinqToSql
+ /// L'approche code first d'EntityFramework est très pratique (un peu comme ActiveRecord de Ruby)
+ /// http://msdn.microsoft.com/fr-fr/data/jj193542.aspx
+ /// </summary>
+ public class BikeRespository : DbSet
+ {
+ public BikeRespository()
+ : base()
+ {
+ }
+
+ public DbSet<Bicycle> Bikes { get; set; }
+ }
+} // Fin du namespace
+```
+
+## Sujets non-abordés
+
+ * Flags
+ * Attribus
+ * Propriétés statiques
+ * Exceptions, Abstraction
+ * ASP.NET (Web Forms/MVC/WebMatrix)
+ * Winforms
+ * Windows Presentation Foundation (WPF)
+
+## Lectures Complémentaires
+
+ * [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)
+
+[Convention de codage C#](http://msdn.microsoft.com/library/vstudio/ff926074)
diff --git a/fr-fr/haskell.html.markdown b/fr-fr/haskell.html.markdown
index 9d0cec99..989db1d5 100644
--- a/fr-fr/haskell.html.markdown
+++ b/fr-fr/haskell.html.markdown
@@ -5,6 +5,7 @@ contributors:
translators:
- ["David Baumgartner", "http://davidbaumgartner.ch"]
lang: fr-fr
+filename: learnhaskell-fr.hs
---
Haskell a été conçu pour être un langage fonctionnel pur et maniable. Il est connu pour ses monades et son système de types, mais je n'ai cesse d'y revenir pour son élégance. Pour moi, Haskell fait de la programmation une joie.
diff --git a/fr-fr/objective-c-fr.html.markdown b/fr-fr/objective-c-fr.html.markdown
new file mode 100644
index 00000000..b98d161e
--- /dev/null
+++ b/fr-fr/objective-c-fr.html.markdown
@@ -0,0 +1,528 @@
+---
+
+language: Objective-C
+contributors:
+ - ["Eugene Yagrushkin", "www.about.me/yagrushkin"]
+ - ["Yannick Loriot", "https://github.com/YannickL"]
+ - ["Levi Bostian", "https://github.com/levibostian"]
+translators:
+ - ["Yannick Loriot", "https://github.com/YannickL"]
+filename: LearnObjectiveC-fr.m
+lang: fr-fr
+
+---
+
+L'Objective-C est un langage de programmation orienté objet réflexif principalement utilisé par Apple pour les systèmes d'exploitations Mac OS X et iOS et leurs frameworks respectifs, Cocoa et Cocoa Touch.
+
+```cpp
+// Les commentaires sur une seule ligne commencent par //
+
+/*
+Les
+commentaires
+multi-lignes
+ressemblent
+ceci
+*/
+
+// #import permet d'importer les en-têtes d'autres fichiers
+// Utilisez <> pour importer des fichiers globaux (en général des frameworks)
+// Utilisez "" pour importer des fichiers locaux (du projet)
+#import <Foundation/Foundation.h>
+#import "MaClasse.h"
+
+// Si vous activez les modules dans les projets iOS >= 7 ou Mac OS X >= 10.9
+// dans Xcode 5, vous pouvez importer les frameworks comme cela :
+@import Foundation;
+
+// Le point d'entrée de votre programme est une fonction qui s'appelle main
+// et qui retourne un entier comme type
+int main (int argc, const char * argv[])
+{
+ // Créer un groupe de libération automatique de la mémoire pour l'ensemble
+ // du programme
+ NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
+ // Si vous utilisez le comptage de référence automatique (ARC), utilisez
+ // @autoreleasepool à la place :
+ @autoreleasepool {
+
+ // NSLog() permet d'afficher une chaine de caractères dans la console
+ // Affiche la chaine de caractères "Bonjour Tous Le Monde !"
+ NSLog(@"Bonjour tous le Monde !");
+
+ ///////////////////////////////////////
+ // Les Types & Les Variables
+ ///////////////////////////////////////
+
+ // La déclaration de primitive
+ int maPrimitive1 = 1;
+ long maPrimitive2 = 234554664565;
+
+ // La déclaration d'objet
+ // Il faut mettre un astérisque devant la déclaration d'objet fortement typé
+ MaClasse *monObject1 = nil; // Typage fort
+ id monObject2 = nil; // Typage faible
+ // 'description' est une méthode qui permet de retourner un aperçut de l'objet sous forme textuelle
+ // La méthode 'description' est appelée par défaut quand on utilise le paramètre '%@'
+ NSLog(@"%@ and %@", monObject1, [monObject2 description]); // Affiche "(null) et (null)"
+
+ // Les chaines de caractères
+ NSString *chaineMonde = @"Monde";
+ NSLog(@"Bonjour tous le %@ !", chaineMonde); // affiche => "Bonjour Tous Le Monde !"
+ // NSMutableString est une chaine mutable
+ NSMutableString *chaineMutable = [NSMutableString stringWithString:@"Bonjour tous le"];
+ [chaineMutable appendString:@" Monde !"];
+ NSLog(@"%@", chaineMutable); // affiche => "Bonjour Tous Le Monde !"
+
+ // Les caractères
+ NSNumber *laLettreZSousFormeDeNombre = @'Z';
+ char laLettreZ = [laLettreZSousFormeDeNombre charValue]; // ou 'Z'
+ NSLog(@"%c", laLettreZ);
+
+ // Les nombres
+ NSNumber *nombreQuaranteDeux = @42;
+ int quaranteDeux = [nombreQuaranteDeux intValue]; // ou 42
+ NSLog(@"%i", quaranteDeux);
+
+ NSNumber *nombreQuaranteDeuxnonSigne = @42U;
+ unsigned int quaranteDeuxnonSigne = [nombreQuaranteDeuxnonSigne unsignedIntValue];
+ NSLog(@"%u", fortyTwoUnsigned);
+
+ NSNumber *nombreQuaranteDeuxCourt = [NSNumber numberWithShort:42];
+ short quaranteDeuxCourt = [nombreQuaranteDeuxCourt shortValue]; // ou 42
+ NSLog(@"%hi", fortyTwoShort);
+
+ NSNumber *nombreQuaranteDeuxLong = @42L;
+ long quaranteDeuxLong = [nombreQuaranteDeuxLong longValue]; // ou 42
+ NSLog(@"%li", fortyTwoLong);
+
+ // Les nombres flottants
+ NSNumber *nombrePiFlottant = @3.141592654F;
+ float piFlottant = [nombrePiFlottant floatValue]; // ou 3.141592654f
+ NSLog(@"%f", piFlottant); // affiche => 3.141592654
+ NSLog(@"%5.2f", piFlottant); // affiche => " 3.14"
+
+ NSNumber *nombrePiDouble = @3.1415926535;
+ double piDouble = [nombrePiDouble doubleValue]; // ou 3.1415926535
+ NSLog(@"%f", piDouble);
+ NSLog(@"%4.2f", piDouble); // affiche => "3.14"
+
+ // NSDecimalNumber est une classe pour avoir plus de précision sur les nombres
+ // flottants et les doubles
+ NSDecimalNumber *decNumUn = [NSDecimalNumber decimalNumberWithString:@"10.99"];
+ NSDecimalNumber *decNumDeux = [NSDecimalNumber decimalNumberWithString:@"5.002"];
+ // NSDecimalNumber ne permet pas d'utiliser les opérations standards (+, -, *, /)
+ // Il faut utiliser les méthodes suivantes à la place :
+ [decNumUn decimalNumberByAdding:decNumDeux];
+ [decNumUn decimalNumberBySubtracting:decNumDeux];
+ [decNumUn decimalNumberByMultiplyingBy:decNumDeux];
+ [decNumUn decimalNumberByDividingBy:decNumDeux];
+ NSLog(@"%@", decNumUn); // affiche => 10.99 comme NSDecimalNumber est immuable
+
+ // Les booléens
+ NSNumber *ouiNumber = @YES;
+ NSNumber *nonNumber = @NO;
+ // ou
+ BOOL ouiBool = YES;
+ BOOL nonBool = NO;
+ NSLog(@"%i", ouiBool); // affiche => 1
+
+ // Les listes
+ // Une liste peut contenir uniquement des objets
+ NSArray *uneListe = @[@1, @2, @3, @4];
+ NSNumber *troisiemeNombre = uneListe[2];
+ NSLog(@"Troisième nombre = %@", troisiemeNombre); // affiche "Troisième nombre = 3"
+ // NSMutableArray est une version mutable de NSArray
+ // Cela permet de modifier la liste en ajoutant de nouveaux éléments et en supprimant ou
+ // changeant de place des objets déjà présent
+ // C'est très pratique, mais pas aussi performant que l'utilisation de la classe NSArray
+ NSMutableArray *listeMutable = [NSMutableArray arrayWithCapacity:2];
+ [listeMutable addObject:@"Bonjour tous le"];
+ [listeMutable addObject:@"Monde"];
+ [listeMutable removeObjectAtIndex:0];
+ NSLog(@"%@", [listeMutable objectAtIndex:0]); // affiche => "Monde"
+
+ // Les dictionnaires
+ // Un dictionnaire est un ensemble de clés : valeurs
+ NSDictionary *unDictionnaire = @{ @"cle1" : @"valeur1", @"cle2" : @"valeur2" };
+ NSObject *valeur = unDictionnaire[@"Une clé"];
+ NSLog(@"Objet = %@", valeur); // affiche "Objet = (null)"
+ // NSMutableDictionary est un dictionnaire mutable, c-à-d que l'on peut modifier
+ NSMutableDictionary *dictionnaireMutable = [NSMutableDictionary dictionaryWithCapacity:2];
+ [dictionnaireMutable setObject:@"valeur1" forKey:@"cle1"];
+ [dictionnaireMutable setObject:@"valeur2" forKey:@"cle2"];
+ [dictionnaireMutable removeObjectForKey:@"cle1"];
+
+ // Les ensembles
+ // Un ensemble ne peut contenir de duplicatas contrairement aux NSArray
+ NSSet *ensemble = [NSSet setWithObjects:@"Salut", @"Salut", @"Monde", nil];
+ NSLog(@"%@", ensemble); // affiche => {(Salut, Monde)} (Pas forcément dans le même ordre)
+ // NSMutableSet est un ensemble mutable
+ NSMutableSet *ensembleMutable = [NSMutableSet setWithCapacity:2];
+ [ensembleMutable addObject:@"Salut"];
+ [ensembleMutable addObject:@"Salut"];
+ NSLog(@"%@", ensembleMutable); // affiche => {(Salut)}
+
+ ///////////////////////////////////////
+ // Les Operateurs
+ ///////////////////////////////////////
+
+ // Les opérateurs sont pareil qu'en C
+ // Par exemple :
+ 2 + 5; // => 7
+ 4.2f + 5.1f; // => 9.3f
+ 3 == 2; // => 0 (NO)
+ 3 != 2; // => 1 (YES)
+ 1 && 1; // => 1 (et logique)
+ 0 || 1; // => 1 (ou logique)
+ ~0x0F; // => 0xF0 (négation bit à bit)
+ 0x0F & 0xF0; // => 0x00 (et bit à bit)
+ 0x01 << 1; // => 0x02 (décalage à gauche (par 1))
+
+ ///////////////////////////////////////
+ // Les Structures de Contrôle
+ ///////////////////////////////////////
+
+ // Structure "Si-Sinon" (If-Else)
+ if (NO)
+ {
+ NSLog(@"Je ne suis jamais affiché");
+ } else if (0)
+ {
+ NSLog(@"Je ne suis jamais affiché aussi");
+ } else
+ {
+ NSLog(@"Je suis affiché");
+ }
+
+ // Structure "Selon" (Switch)
+ switch (2)
+ {
+ case 0:
+ {
+ NSLog(@"Je ne suis jamais affiché");
+ } break;
+ case 1:
+ {
+ NSLog(@"Je ne suis jamais affiché aussi");
+ } break;
+ default:
+ {
+ NSLog(@"Je suis affiché");
+ } break;
+ }
+
+ // Structure de boucle "Tant Que" (While)
+ int ii = 0;
+ while (ii < 4)
+ {
+ NSLog(@"%d,", ii++); // ii++ incrémente ii après avoir utilisé sa valeur
+ } // => affiche "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // Structure de boucle "Pour" (For)
+ int jj;
+ for (jj=0; jj < 4; jj++)
+ {
+ NSLog(@"%d,", jj);
+ } // => affiche "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // Structure de boucle "Pour Chaque" (Foreach)
+ NSArray *valeurs = @[@0, @1, @2, @3];
+ for (NSNumber *valeur in valeurs)
+ {
+ NSLog(@"%@,", valeur);
+ } // => affiche "0,"
+ // "1,"
+ // "2,"
+ // "3,"
+
+ // Structure "Essayer-Attraper-Finalement" (Try-Catch-Finally)
+ @try
+ {
+ @throw [NSException exceptionWithName:@"FileNotFoundException"
+ reason:@"Fichier non trouvé" userInfo:nil];
+ } @catch (NSException * e)
+ {
+ NSLog(@"Une exception est survenue : %@", e);
+ } @finally
+ {
+ NSLog(@"Finalement");
+ } // => affiche "Une exception est survenue : Fichier non trouvé"
+ // "Finalement"
+
+ ///////////////////////////////////////
+ // Les Objets
+ ///////////////////////////////////////
+
+ // Définis et créé une instance d'objet en allouant un espace mémoire puis en
+ // l'initialisant. Un objet n'est pas complétement fonctionnel tant que les deux
+ // étapes précédentes ne sont pas terminées
+ MaClass *monObjet = [[MaClass alloc] init];
+
+ // L'Objet en Objective-C est basé sur le principe d'envoie de message et non sur
+ // celui d'appel de méthode comme la plupart des autres langages
+ // C'est un détail important car cela veut dire que l'on peut envoyer un message
+ // à un objet qui ne possède pas la méthode demandée sans aucune incidence sur le
+ // fonctionnement du programme (aucune exception ne sera levée)
+ [myObject instanceMethodWithParameter:@"Steve Jobs"];
+
+ // Nettoie la mémoire qui a été utilisée dans le programme
+ [pool drain];
+
+ // Fin de l'@autoreleasepool
+ }
+
+ // Fin du programme
+ return 0;
+}
+
+///////////////////////////////////////
+// Les Classes et Les Fonctions
+///////////////////////////////////////
+
+// Déclaration d'une classe dans un en-tête de fichier (MaClasse.h) :
+// La déclaration d'une classe en Objective-C commence par la déclaration de son interface :
+// @interface NomDeLaClasse : NomDeLaClasseParent <ListeDesProtocoles>
+// {
+// type nom; // Déclaration d'une variable;
+// }
+// @property type nom; // Déclaration d'une propriété
+// -/+ (type)nomDeLaMethode; // Déclaration d'une methode
+// @end // Termine la déclaration
+// NSObject est la classe de base (super classe) en Objective-C
+@interface MaClasse : NSObject <MonProtocole>
+{
+ int nombre; // Accès protégé par défaut (équivalent à '@protected int nombre;')
+ @private id donnee; // Accès privé (il est plus pratique de le faire dans l'implémentation)
+ NSString *nom;
+}
+// Les propriétés permettent de générer les accésseurs/affecteurs publiques à la compilation
+// Par défaut, le nom de l'affecteur est la chaine 'set' suivi par le nom de la @property
+@property int propInt; // Nom de l'affecteur = 'setPropInt'
+@property (copy) id copyId; // (copy) => Copie l'objet pendant l'affectation
+// (readonly) => Ne peut pas affecté la variable en dehors de l'@interface
+// Il faut utiliser le mot clé '@synthesize' dans l'@implementation pour créer l'accésseur
+@property (readonly) NSString *roString;
+// Vous pouvez aussi personnaliser les noms des accésseurs ou des affecteurs
+@property (getter=longeurGet, setter=longeurSet:) int longeur;
+
+// Methodes
++/- (TypeDeRetour)signatureDeLaMethode:(TypeDuParametre *)nomDuParametre;
+
+// '+' signifie que c'est une méthode de classe (statique) :
++ (NSString *)methodeDeClasse;
++ (MaClasse *)maClasseDepuisLaHauteur:(NSNumber *)hauteurParDefaut;
+
+// '-' pour les méthodes d'instances :
+- (NSString *)methodeInstanceAvecUnParametre:(NSString *)string;
+- (NSNumber *)methodeInstanceAvecUnParametre:(NSString*)string puisUnDeuxieme:(NSNumber *)number;
+
+// Contructeur avec des arguments :
+- (id)initAvecDistance:(int)distanceParDefault;
+// Les méthodes en Objective-C sont très descriptives
+
+@end // Fin de l'interface
+
+
+// Voici un exemple d'utilisation de MaClasse
+MaClasse *maClasse = [[MaClasse alloc] init]; // créer une instance de MaClasse
+[maClasse setNombre:10];
+NSLog(@"%d", [maClasse nombre]); // affiche => 10
+[myClass longeurSet:32];
+NSLog(@"%i", [maClasse longeurGet]); // affiche => 32
+// Pour des raisons pratiques vous pouvez aussi utiliser la notation en point pour accéder aux
+// variables d'instances :
+maClasse.nombre = 45;
+NSLog(@"%i", maClasse.nombre); // maClasse => 45
+
+// Pour appeler une méthode de classe :
+NSString *s1 = [MaClasse methodeDeClasse];
+MaClasse *m2 = [MaClasse maClasseDepuisLaHauteur:38];
+
+// Pour appeler une méthode d'instance :
+MaClasse *maClasse = [[MaClasse alloc] init]; // Créer une instance de MaClasse
+NSString *stringDepuisUneInstanceDeMethode = [maClasse methodeInstanceAvecUnParametre:@"Salut"];
+
+// Les sélecteurs sont un moyen de décrire les méthodes dynamiquement
+// Ils sont utilisés pour appeler des méthodes de classe et avoir des pointeurs de fonctions
+// facilement manipulable
+// SEL est un type de donnée et @selector retourne un selecteur à partir d'un nom de methode
+SEL selecteur = @selector(methodeInstanceAvecUnParametre:puisUnDeuxieme:);
+if ([maClasse respondsToSelector:selecteur]) { // Vérifie si la classe possède la méthode
+ // Met les arguments de la méthode dans un seul objet pour l'envoyer via la fonction
+ // performSelector:withObject:
+ NSArray *arguments = [NSArray arrayWithObjects:@"Hello", @4, nil];
+ [myClass performSelector:selectorVar withObject:arguments]; // Appele la méthode via le sélecteur
+}
+else {
+ // NSStringFromSelector() retourne une chaine de caractères à partir d'un sélecteur
+ NSLog(@"MaClasse ne possède pas de méthode : %@", NSStringFromSelector(selecteur));
+}
+
+// Le fichier d'implémentation de la classe MaClasse (MaClasse.m) doit commencer comme ceci :
+@implementation MaClasse {
+ long distance; // Variable d'instance privée (équivalent à @private dans l'interface)
+ NSNumber hauteur;
+}
+
+// Pour accéder à une variable depuis l'implémentation on peut utiliser le _ (tiret bas) devant le nom
+// de la variable :
+_nombre = 5;
+// Accès d'une variable définie dans le fichier d'implémentation :
+distance = 18;
+// Pour utiliser la variable définie par l'intermédiaire de @property, il faut utiliser @synthesize
+// qui permet de créer les affecteurs et les accésseurs correspondants :
+@synthesize roString = _roString; // _roString est maintenant disponible dans l'implementation
+
+// A l'inverse dela méthode 'init' qui est appelée lors de la création d'un objet, la fonction
+// 'dealloc' est appelée quand l'objet est supprimé
+- (void)dealloc
+{
+ [hauteur release]; // Si vous n'utilisez pas ARC, pensez bien à supprimer l'objet
+ [super dealloc]; // et à appeler la méthode 'dealloc' de la classe parent
+}
+
+// Les constructeurs sont des fonctions qui permettent d'instancier un objet
+// 'init' est le constructeur par défaut en Objective-C
+- (id)init
+{
+ if ((self = [super init])) // 'super' est utilisé pour appeler la méthode de la classe parent
+ {
+ self.count = 1; // 'self' permet d'appeler la méthode de l'instance courante
+ }
+ return self;
+}
+
+// Vous pouvez aussi créer des constructeurs avec des arguments
+// Attention : chaque nom de constructeur doit absolument commencer par 'init'
+- (id)initAvecUneDistance:(int)distanceParDefault
+{
+ if ((self = [super init]))
+ {
+ distance = distanceParDefault;
+ return self;
+ }
+}
+
+// Implémentation d'une méthode de classe
++ (NSString *)methodDeClasse
+{
+ return [[self alloc] init];
+}
+
++ (MaClasse *)maClasseDepuisUneHauteur:(NSNumber *)hauteurParDefaut
+{
+ hauteur = hauteurParDefaut;
+ return [[self alloc] init];
+}
+
+// Implémentation d'une méthode d'instance
+- (NSString *)methodeInstanceAvecUnParametre:(NSString *)string
+{
+ return @"Ma chaine de caractère";
+}
+
+- (NSNumber *)methodeInstanceAvecUnParametre:(NSString*)string puisUnDeuxieme:(NSNumber *)number
+{
+ return @42;
+}
+
+// Pour créer une méthode privée, il faut la définir dans l'implementation et non pas dans
+// l'interface
+- (NSNumber *)methodePrivee
+{
+ return @72;
+}
+
+[self methodePrivee]; // Appel de la méthode privée
+
+// Implémentation d'une méthode qui est déclarée dans <MonProtocole>
+- (void)methodeDuProtocole
+{
+ // expressions
+}
+
+@end // Fin de l'implémentation
+
+/*
+ * Un protocole déclare des méthodes et propriétés que chaque implémentation doit avoir afin de se
+ * conformer à celui-ci
+ * Un protocole n'est pas une classe, c'est juste une interface
+ */
+@protocol MonProtocole
+ - (void)methodeDuProtocole;
+@end
+
+
+///////////////////////////////////////
+// Gestion de la mémoire
+///////////////////////////////////////
+/*
+À chaque fois qu'un objet est créé dans l'application, un bloc mémoire doit être alloué.
+Quand l'application en a fini avec cet objet, la mémoire doit être libérée afin d'éviter les fuites
+mémoires
+Il n'y a pas de ramasse-miettes en Objective-C contrairement à Java par exemple. La gestion de la
+mémoire repose sur le comptage de référence qui, pour chaque objet, assigne un compteur qui permet
+de connaitre le nombre de référence qui l'utilise.
+
+Le principe est le suivant :
+Lorsque l'objet est créé, le compteur est initialisé à 1. Quand une instance détient un objet, le
+compteur est incrémenté de un. Quand l'objet est libéré, le compteur est décrémenté de un. Au moment
+où le compteur arrive à zéro, l'objet est supprimé de la mémoire
+
+Une bonne pratique à suivre quand on travaille avec des objets est la suivante :
+(1) créer un objet, (2) utiliser l'objet, (3) supprimer l'objet de la mémoire
+*/
+
+MaClasse *classeVar = [MyClass alloc]; // 'alloc' incrémente le compteur de référence
+[classeVar release]; // Décrémente le compteur de rérence
+// 'retain' incrémente le compteur de référence
+// Si 'classeVar' est libéré, l'objet reste en mémoire car le compteur de référence est non nul
+MaClasse *nouvelleVar = [classVar retain];
+[classeVar autorelease]; // Supprime l'appartenance de l'objet à la fin du bloc
+
+// Les @property peuvent utiliser 'retain' et 'assign'
+@property (retain) MaClasse *instance; // Libère l'ancienne valeur et retient la nouvelle
+@property (assign) NSSet *set; // Pointeur vers la valeur sans retenir/libérer l'ancienne valeur
+
+// Automatic Reference Counting (ARC)
+// La gestion de la mémoire étant pénible, depuis iOS 4 et Xcode 4.2, Apple a introduit le comptage de
+// référence automatique (Automatic Reference Counting en anglais)
+// ARC est une fonctionnalité du compilateur qui permet d'ajouter les 'retain', 'release' et 'autorelease'
+// automatiquement. Cela veut dire que lorsque vous utilisez ARC vous ne devez plus utiliser ces mot-clés
+MaClasse *arcMaClasse = [[MaClasse alloc] init];
+// ... code utilisant arcMaClasse
+// Sans ARC, vous auriez dû appeler [arcMaClasse release] après avoir utilisé l'objet. Mais avec ARC
+// activé il n'est plus nécessaire de le faire car le compilateur ajoutera l'expréssion automatiquement
+// pour vous
+
+// Les mots clés 'assign' et 'retain', avec ARC sont respectivement remplacé par 'weak' et 'strong'
+@property (weak) MaClasse *weakVar; // 'weak' ne retient pas l'objet. Si le compteur de référence
+// descend à zero, weakVar sera automatiquement mis à nil
+@property (strong) MaClasse *strongVar; // 'strong' prend possession de l'objet comme le ferait avec
+// le mot-clé 'retain'
+
+// Pour l'instanciation des variables (en dehors de @property), vous pouvez utiliser les instructions
+// suivantes :
+__strong NSString *strongString; // Par défaut. La variable est retenue en mémoire jusqu'à la fin
+// de sa portée
+__weak NSSet *weakSet; // Maintient une référence vers l'objet sans incrémenter son compteur de référence :
+// Lorsque l'objet sera supprimé, weakSet sera mis à nil automatiquement
+__unsafe_unretained NSArray *unsafeArray; // Comme __weak, mais la variable n'est pas mis à nil quand
+// l'objet est supprimé
+
+```
+## Lectures Complémentaires
+
+[La Page Wikipedia de l'Objective-C](http://fr.wikipedia.org/wiki/Objective-C)
+
+[iOS pour les écoliers : Votre première app iOS](http://www.raywenderlich.com/fr/39272/ios-pour-les-ecoliers-votre-premiere-app-ios-partie-12)
+
+[Programming with Objective-C. Apple PDF book](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/ProgrammingWithObjectiveC.pdf)
diff --git a/fr-fr/python-fr.html.markdown b/fr-fr/python-fr.html.markdown
index 9dbdafe1..58a036ba 100644
--- a/fr-fr/python-fr.html.markdown
+++ b/fr-fr/python-fr.html.markdown
@@ -75,7 +75,7 @@ not False #=> True
# Les chaînes de caractères sont créées avec " ou '
"C'est une chaîne."
-'C'est aussi une chaîne.'
+'C\'est aussi une chaîne.'
# On peut aussi les "additioner" !
"Hello " + "world!" #=> "Hello world!"
diff --git a/go.html.markdown b/go.html.markdown
index ee41642a..bb6b04eb 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -5,6 +5,10 @@ language: Go
filename: learngo.go
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["Christopher Bess", "https://github.com/cbess"]
+ - ["Jesse Johnson", "https://github.com/holocronweaver"]
+ - ["Quint Guvernator", "https://github.com/qguv"]
+ - ["Jose Donizetti", "https://github.com/josedonizetti"]
---
Go was created out of the need to get work done. It's not the latest trend
@@ -29,9 +33,10 @@ package main
// Import declaration declares library packages referenced in this file.
import (
- "fmt" // A package in the Go standard library
+ "fmt" // A package in the Go standard library.
"net/http" // Yes, a web server!
- "strconv" // String conversions
+ "strconv" // String conversions.
+ m "math" // Math library with local alias m.
)
// A function definition. Main is special. It is the entry point for the
@@ -52,49 +57,49 @@ func beyondHello() {
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
+ sum, prod := learnMultiple(x, y) // Function returns two values.
+ fmt.Println("sum:", sum, "prod:", prod) // Simple output.
learnTypes() // < y minutes, learn more!
}
// Functions can have parameters and (multiple!) return values.
func learnMultiple(x, y int) (sum, prod int) {
- return x + y, x * y // return two values
+ return x + y, x * y // Return two values.
}
// Some built-in types and literals.
func learnTypes() {
// Short declaration usually gives you what you want.
- s := "Learn Go!" // string type
+ s := "Learn Go!" // string type.
s2 := `A "raw" string literal
-can include line breaks.` // same string type
+can include line breaks.` // Same string type.
- // non-ASCII literal. Go source is UTF-8.
- g := 'Σ' // rune type, an alias for uint32, holds a unicode code point
+ // Non-ASCII literal. Go source is UTF-8.
+ g := 'Σ' // rune type, an alias for uint32, holds a unicode code point.
- f := 3.14195 // float64, an IEEE-754 64-bit floating point number
- c := 3 + 4i // complex128, represented internally with two float64s
+ f := 3.14195 // float64, an IEEE-754 64-bit floating point number.
+ c := 3 + 4i // complex128, represented internally with two float64's.
// Var syntax with an initializers.
- var u uint = 7 // unsigned, but implementation dependent size as with int
+ var 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
+ 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
+ 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
+ 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.
+ 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
@@ -108,23 +113,23 @@ can include line breaks.` // same string type
// Output of course counts as using a variable.
fmt.Println(s, c, a4, s3, d2, m)
- learnFlowControl() // back in the flow
+ learnFlowControl() // Back in the flow.
}
// 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.
+ 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
+ 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 expensiveComputation() float64 {
+ return m.Exp(10)
}
func learnFlowControl() {
@@ -134,29 +139,31 @@ func learnFlowControl() {
}
// Formatting is standardized by the command line command "go fmt."
if false {
- // pout
+ // Pout.
} else {
- // gloat
+ // Gloat.
}
// Use switch in preference to chained if statements.
- x := 1
+ x := 42.0
switch x {
case 0:
case 1:
- // cases don't "fall through"
- case 2:
- // unreached
+ case 42:
+ // Cases don't "fall through".
+ case 43:
+ // Unreached.
}
// Like if, for doesn't use parens either.
- for x := 0; x < 3; x++ { // ++ is a statement
+ // Variables declared in for and if are local to their scope.
+ for x := 0; x < 3; x++ { // ++ is a statement.
fmt.Println("iteration", x)
}
- // x == 1 here.
+ // x == 42 here.
// For is the only loop statement in Go, but it has alternate forms.
- for { // infinite loop
- break // just kidding
- continue // unreached
+ 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.
@@ -165,19 +172,29 @@ func learnFlowControl() {
}
// Function literals are closures.
xBig := func() bool {
- return x > 100 // references x declared above switch statement.
+ return x > 10000 // 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
+ fmt.Println("xBig:", xBig()) // true (we last assigned e^10 to x).
+ x = 1.3e3 // This makes x == 1300
+ fmt.Println("xBig:", xBig()) // false now.
// When you need it, you'll love it.
goto love
love:
+ learnDefer() // A quick detour to an important keyword.
learnInterfaces() // Good stuff coming up!
}
+func learnDefer() (ok bool) {
+ // Deferred statements are executed just before the function returns.
+ defer fmt.Println("deferred statements execute in reverse (LIFO) order.")
+ defer fmt.Println("\nThis line is being printed first because")
+ // Defer is commonly used to close a file, so the function closing the file
+ // stays close to the function opening the file
+ return true
+}
+
// Define Stringer as an interface type with one method, String.
type Stringer interface {
String() string
@@ -199,16 +216,30 @@ 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
+ 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
+ fmt.Println(p) // Output same as above. Println calls String method.
+ fmt.Println(i) // Output same as above.
+
+ learnVariadicParams("great", "learning", "here!")
+}
+
+// Functions can have variadic parameters.
+func learnVariadicParams(myStrings ...interface{}) {
+ // Iterate each value of the variadic.
+ // The underbar here is ignoring the index argument of the array.
+ for _, param := range myStrings {
+ fmt.Println("param:", param)
+ }
+
+ // Pass variadic value as a variadic parameter.
+ fmt.Println("params:", fmt.Sprintln(myStrings...))
learnErrorHandling()
}
@@ -223,7 +254,7 @@ func learnErrorHandling() {
}
// 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"
+ // prints 'strconv.ParseInt: parsing "non-int": invalid syntax'
fmt.Println(err)
}
// We'll revisit interfaces a little later. Meanwhile,
@@ -250,30 +281,30 @@ func learnConcurrency() {
// 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 string channels.
- go func() { c <- 84 }() // start a new goroutine just to send a value
- go func() { cs <- "wordy" }() // again, for cs this time
+ cs := make(chan string) // Another channel, this one handles strings.
+ ccs := make(chan chan string) // A channel of string channels.
+ go func() { c <- 84 }() // Start a new goroutine just to send a value.
+ go func() { cs <- "wordy" }() // Again, for cs this time.
// Select has syntax like a switch statement but each case involves
// a channel operation. It selects a case at random out of the cases
// that are ready to communicate.
select {
- case i := <-c: // the value received can be assigned to a variable
+ case i := <-c: // The value received can be assigned to a variable,
fmt.Printf("it's a %T", i)
- case <-cs: // or the value received can be discarded
+ case <-cs: // or the value received can be discarded.
fmt.Println("it's a string")
- case <-cc: // empty channel, not ready for communication.
+ case <-ccs: // Empty channel, not ready for communication.
fmt.Println("didn't happen.")
}
// At this point a value was taken from either c or cs. One of the two
// goroutines started above has completed, the other will remain blocked.
- learnWebProgramming() // Go does it. You want to do it too.
+ 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.
+ // First parameter of ListenAndServe is TCP address to listen to.
// Second parameter is an interface, specifically http.Handler.
err := http.ListenAndServe(":8080", pair{})
fmt.Println(err) // don't ignore errors
@@ -281,7 +312,7 @@ func learnWebProgramming() {
// 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
+ // Serve data with a method of http.ResponseWriter.
w.Write([]byte("You learned Go in Y minutes!"))
}
```
@@ -300,3 +331,4 @@ demonstrates the best of readable and understandable Go, Go style, and Go
idioms. Or you can click on a function name in [the
documentation](http://golang.org/pkg/) and the source code comes up!
+Another great resource to learn Go is [Go by example](https://gobyexample.com/).
diff --git a/haskell.html.markdown b/haskell.html.markdown
index 341c013e..e0489710 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -303,7 +303,7 @@ Nothing -- of type `Maybe a` for any `a`
-- While IO can't be explained fully without explaining monads,
-- it is not hard to explain enough to get going.
--- When a Haskell program is executed, the function `main` is
+-- When a Haskell program is executed, `main` is
-- called. It must return a value of type `IO ()`. For example:
main :: IO ()
diff --git a/haxe.html.markdown b/haxe.html.markdown
index eb39834e..6a868f09 100644
--- a/haxe.html.markdown
+++ b/haxe.html.markdown
@@ -231,7 +231,7 @@ class LearnHaxe3{
trace((4 + 3) + " is the value for (4 + 3)");
trace((5 - 1) + " is the value for (5 - 1)");
trace((2 * 4) + " is the value for (2 * 4)");
- trace((8 / 4) + " is the value for (8 / 3) (division always produces Floats)");
+ trace((8 / 3) + " is the value for (8 / 3) (division always produces Floats)");
trace((12 % 4) + " is the value for (12 % 4)");
diff --git a/hu-hu/go.html.markdown b/hu-hu/go.html.markdown
index 621ebdbf..638c9489 100644
--- a/hu-hu/go.html.markdown
+++ b/hu-hu/go.html.markdown
@@ -6,6 +6,7 @@ contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
translators:
- ["Szabó Krisztián", "https://github.com/thenonameguy/"]
+ - ["Árpád Goretity", "https://github.com/H2CO3"]
---
A Go programozási nyelv az életszerű feladatok könnyebb elvégzése miatt született.
@@ -38,14 +39,14 @@ import (
"strconv" // Stringek átalakítására szolgáló csomag
)
-// Funkció deklarálás, a main nevű funkció a program kezdőpontja.
+// Függvénydeklarálás, a main nevű függvény a program kezdőpontja.
func main() {
// Println kiírja a beadott paramétereket a standard kimenetre.
- // Ha más csomagot funkcióját akarjuk használni, akkor azt jelezni kell a
+ // Ha más csomagot függvényeit akarjuk használni, akkor azt jelezni kell a
// csomag nevével
fmt.Println("Hello world!")
- // Meghívunk egy másik funkciót ebből a csomagból
+ // Meghívunk egy másik függvényt ebből a csomagból
beyondHello()
}
@@ -92,7 +93,7 @@ func learnTypes() {
// lebegőpontos szám
c := 3 + 4i // complex128, belsőleg két float64-gyel tárolva
- // Var szintaxis változó típus definiálással
+ // Var szintaxis változótípus-definiálással
var u uint = 7 // unsigned, az implementáció dönti el mekkora, akárcsak az
// int-nél
var pi float32 = 22. / 7
@@ -105,8 +106,8 @@ func learnTypes() {
a3 := [...]int{3, 1, 5} // egy tömb 3 int-tel, láthatóan inicalizálva egyedi
// értékekre
- // Szeleteknek dinamikus a méretük. A szeleteknek és a tömböknek is meg
- // vannak az előnyeik de a szeleteket sokkal gyakrabban használjuk.
+ // A "szeleteknek" (slices) dinamikus a méretük. A szeleteknek és a tömböknek is
+ // megvannak az előnyeik de a szeleteket sokkal gyakrabban használjuk.
s3 := []int{4, 5, 9} // vesd össze a3-mal, nincsenek pontok.
s4 := make([]int, 4) // allokál 4 int-et, mind 0-ra inicializálva
var d2 [][]float64 // ez csak deklaráció, semmi sincs még allokálva
@@ -129,8 +130,8 @@ func learnTypes() {
learnFlowControl()
}
-// A Go nyelv teljesen szemétgyűjtött (garbage-collected). Megtalálhatók benne
-// mutatók, de nincs mutató aritmetika. Ez azt jelenti, hogy üres mutatóval még
+// A Go nyelvben szemétgyűjtés (garbage collection) működik. Megtalálhatók benne
+// mutatók, de nincs pointeraritmetika. Ez azt jelenti, hogy üres (null) mutatóval még
// mindig hibázhatsz, de hozzáadni/műveleteket végezni már nem lehet.
func learnMemory() (p, q *int) {
// Elnevezett visszatérési változóknak int-re mutató a típusa
@@ -213,7 +214,7 @@ type pair struct {
}
// Definiáljunk egy metódust a pair struktúrának, ezzel teljesítve a Stringer interfészt.
-func (p pair) String() string { // p lesz a "vevő"
+func (p pair) String() string { // p lesz a "fogadó" (receiver)
// Sprintf az fmt csomag egy publikus függvénye, műkődése megegyezik a C-s
// megfelelőjével. A pontokkal érjük el a mindenkori p struktúra elemeit
return fmt.Sprintf("(%d, %d)", p.x, p.y)
@@ -230,7 +231,7 @@ func learnInterfaces() {
// Meghívjuk i String metódusát, az eredmény ugyanaz, mint az előbb.
fmt.Println(i.String())
- // Az fmt csomag funckciói automatikusan meghívják a String funkciót
+ // Az fmt csomag függvényei automatikusan meghívják a String függvényt
// hogy megtudják egy objektum szöveges reprezentációját.
fmt.Println(p) // ugyan az az eredmény mint az előbb, a Println meghívja
// a String metódust.
@@ -267,8 +268,8 @@ func inc(i int, c chan int) {
// Az inc-et fogjuk arra használni, hogy konkurensen megnöveljünk számokat
func learnConcurrency() {
- // Ugyan az a make funkció amivel korábban szeleteket hoztunk létre.
- // Make allokál mapokat, szeleteket és csatornákat.
+ // Ugyanaz a make függvény, amivel korábban szeleteket hoztunk létre.
+ // A make allokál map-eket, szeleteket és csatornákat.
c := make(chan int)
// Indítsunk három konkurens goroutine-t. A számok konkurensen lesznek
// megnövelve, ha a számítógép képes rá és jól be van állítva, akkor pedig
@@ -299,14 +300,14 @@ func learnConcurrency() {
case <-cc: // üres csatorna, soha nem fog rajta semmi se érkezni
fmt.Println("sose futok le :'( ")
}
- // Ezen a ponton vagy c vagy a cs goroutineja lefutott.
+ // Ezen a ponton vagy c vagy a cs goroutine-ja lefutott.
// Amelyik hamarabb végzett, annak a megfelelő case-e lefutott, a másik
// blokkolva vár.
- learnWebProgramming() // Go képes rá. Te is képes akarsz rá lenni.
+ learnWebProgramming() // a Go képes rá. Te is képes akarsz rá lenni.
}
-// Egy funkció a http csomagból elindít egy webszervert.
+// Egy függvény a http csomagból elindít egy webszervert.
func learnWebProgramming() {
// A ListenAndServe első paramétre egy TCP port, amin kiszolgálunk majd.
// Második paramétere egy interfész, pontosabban a http.Handler interfész.
@@ -315,7 +316,7 @@ func learnWebProgramming() {
}
// Csináljunk a pair-ból egy http.Handler-t úgy, hogy implementáljuk az
-// egyetlen metódusát a ServeHTTP-t.
+// egyetlen metódusát, a ServeHTTP-t.
func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Minden kapcsolatra elküldjük ezt a http.ResponseWriter-rel
w.Write([]byte("Megtanultad a Go-t Y perc alatt!"))
@@ -325,11 +326,12 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
## További olvasmányok
Minden Go-val kapcsolatos megtaláható a [hivatalos Go weboldalon](http://golang.org/).
-Ott követhetsz egy tutorialt, játszhatsz a nyelvvel az interneten és sok érdekességet olvashatsz.
+Ott követhetsz egy tutorialt, játszhatsz a nyelvvel az interneten, és sok érdekességet olvashatsz.
A nyelv specifikációját kifejezetten érdemes olvasni, viszonylag rövid és sokat tanul belőle az ember.
-Ha pedig jobban bele akarod vetni magad a Go-ba, akkor a standard könyvtárban a legjobb praktikákat kilesheted.
-TIPP: a dokumentációban kattints egy funkció nevére és rögtön megmutatja a hozzá tartozó kódot!
+Ha pedig jobban bele akarod vetni magad a Go-ba, akkor a legjobb praktikákat kilesheted a standard könyvtárból.
+TIPP: a dokumentációban kattints egy függvény nevére és rögtön megmutatja a hozzá tartozó kódot!
-Ha pedig a nyelvnek egy bizonyos részéről szeretnél hasonló leírást találni, akkor a [gobyexample.com](https://gobyexample.com/)-on megtalálod, amit keresel.
+Ha pedig a nyelvnek egy bizonyos részéről szeretnél hasonló leírást találni, akkor a
+[gobyexample.com](https://gobyexample.com/)-on megtalálod, amit keresel.
diff --git a/hy.html.markdown b/hy.html.markdown
new file mode 100644
index 00000000..04bd05c9
--- /dev/null
+++ b/hy.html.markdown
@@ -0,0 +1,174 @@
+---
+language: hy
+filename: learnhy.hy
+contributors:
+ - ["Abhishek L", "http://twitter.com/abhishekl"]
+---
+
+Hy is a lisp dialect built on top of python. This is achieved by
+converting hy code to python's abstract syntax tree (ast). This allows
+hy to call native python code or python to call native hy code as well
+
+This tutorial works for hy ≥ 0.9.12
+
+```clojure
+;; this gives an gentle introduction to hy for a quick trial head to
+;; http://try-hy.appspot.com
+;;
+; Semicolon comments, like other LISPS
+
+;; s-expression basics
+; lisp programs are made of symbolic expressions or sexps which
+; resemble
+(some-function args)
+; now the quintessential hello world
+(print "hello world")
+
+;; simple data types
+; All simple data types are exactly similar to their python counterparts
+; which
+42 ; => 42
+3.14 ; => 3.14
+True ; => True
+4+10j ; => (4+10j) a complex number
+
+; lets start with some really simple arithmetic
+(+ 4 1) ;=> 5
+; the operator is applied to all arguments, like other lisps
+(+ 4 1 2 3) ;=> 10
+(- 2 1) ;=> 1
+(* 4 2) ;=> 8
+(/ 4 1) ;=> 4
+(% 4 2) ;=> 0 the modulo operator
+; power is represented by ** operator like python
+(** 3 2) ;=> 9
+; nesting forms will do the expected thing
+(+ 2 (* 4 2)) ;=> 10
+; also logical operators and or not and equal to etc. do as expected
+(= 5 4) ;=> False
+(not (= 5 4)) ;=> True
+
+;; variables
+; variables are set using setv, variable names can use utf-8 except
+; for ()[]{}",'`;#|
+(setv a 42)
+(setv π 3.14159)
+(def *foo* 42)
+;; other container data types
+; strings, lists, tuples & dicts
+; these are exactly same as python's container types
+"hello world" ;=> "hello world"
+; string operations work similar to python
+(+ "hello " "world") ;=> "hello world"
+; lists are created using [], indexing starts at 0
+(setv mylist [1 2 3 4])
+; tuples are immutable data structures
+(setv mytuple (, 1 2))
+; dictionaries are key value pairs
+(setv dict1 {"key1" 42 "key2" 21})
+; :name can be used to define keywords in hy which can be used for keys
+(setv dict2 {:key1 41 :key2 20})
+; use `get' to get the element at an index/key
+(get mylist 1) ;=> 2
+(get dict1 "key1") ;=> 42
+; Alternatively if keywords were used they can directly be called
+(:key1 dict2) ;=> 41
+
+;; functions and other program constructs
+; functions are defined using defn, the last sexp is returned by default
+(defn greet [name]
+ "A simple greeting" ; an optional docstring
+ (print "hello " name))
+
+(greet "bilbo") ;=> "hello bilbo"
+
+; functions can take optional arguments as well as keyword arguments
+(defn foolist [arg1 &optional [arg2 2]]
+ [arg1 arg2])
+
+(foolists 3) ;=> [3 2]
+(foolists 10 3) ;=> [10 3]
+
+; anonymous functions are created using `fn' or `lambda' constructs
+; which are similiar to `defn'
+(map (fn [x] (* x x)) [1 2 3 4]) ;=> [1 4 9 16]
+
+;; Sequence operations
+; hy has some builtin utils for sequence operations etc.
+; retrieve the first element using `first' or `car'
+(setv mylist [1 2 3 4])
+(setv mydict {"a" 1 "b" 2})
+(first mylist) ;=> 1
+
+; slice lists using slice
+(slice mylist 1 3) ;=> [2 3]
+
+; get elements from a list or dict using `get'
+(get mylist 1) ;=> 2
+(get mydict "b") ;=> 2
+; list indexing starts from 0 same as python
+; assoc can set elements at keys/indexes
+(assoc mylist 2 10) ; makes mylist [1 2 10 4]
+(assoc mydict "c" 3) ; makes mydict {"a" 1 "b" 2 "c" 3}
+; there are a whole lot of other core functions which makes working with
+; sequences fun
+
+;; Python interop
+;; import works just like in python
+(import datetime)
+(import [functools [partial reduce]]) ; imports fun1 and fun2 from module1
+(import [matplotlib.pyplot :as plt]) ; doing an import foo as bar
+; all builtin python methods etc. are accessible from hy
+; a.foo(arg) is called as (.foo a arg)
+(.split (.strip "hello world ")) ;=> ["hello" "world"]
+
+;; Conditionals
+; (if condition (body-if-true) (body-if-false)
+(if (= passcode "moria")
+ (print "welcome")
+ (print "Speak friend, and Enter!"))
+
+; nest multiple if else if clauses with cond
+(cond
+ [(= someval 42)
+ (print "Life, universe and everything else!")]
+ [(> someval 42)
+ (print "val too large")]
+ [(< someval 42)
+ (print "val too small")])
+
+; group statements with do, these are executed sequentially
+; forms like defn have an implicit do
+(do
+ (setv someval 10)
+ (print "someval is set to " someval)) ;=> 10
+
+; create lexical bindings with `let', all variables defined thusly
+; have local scope
+(let [[nemesis {"superman" "lex luther"
+ "sherlock" "moriarty"
+ "seinfeld" "newman"}]]
+ (for [(, h v) (.items nemesis)]
+ (print (.format "{0}'s nemesis was {1}" h v))))
+
+;; classes
+; classes are defined in the following way
+(defclass Wizard [object]
+ [[--init-- (fn [self spell]
+ (setv self.spell spell) ; init the spell attr
+ None)]
+ [get-spell (fn [self]
+ self.spell)]])
+
+;; do checkout hylang.org
+```
+
+### Further Reading
+
+This tutorial is just a very basic introduction to hy/lisp/python.
+
+Hy docs are here: [http://hy.readthedocs.org](http://hy.readthedocs.org)
+
+Hy's Github repo: [http://github.com/hylang/hy](http://github.com/hylang/hy)
+
+On freenode irc #hy, twitter hashtag #hylang
diff --git a/id-id/css-id.html.markdown b/id-id/css-id.html.markdown
new file mode 100644
index 00000000..456dfafe
--- /dev/null
+++ b/id-id/css-id.html.markdown
@@ -0,0 +1,246 @@
+---
+language: css
+contributors:
+ - ["Mohammad Valipour", "https://github.com/mvalipour"]
+translators:
+ - ["Eka Y Saputra", "http://github.com/ekajogja"]
+lang: id-id
+filename: learncss-id.css
+---
+
+Pada mulanya, web tidak memiliki elemen visual, murni teks saja.
+Tapi seiring perkembangan peramban, laman web dengan elemen visual menjadi umum.
+CSS adalah bahasa standar yang ada untuk menjaga keterpisahan antara
+konten (HTML) serta tampilan-dan-kesan laman web.
+
+Singkatnya, fungsi CSS ialah menyajikan sintaks yang memampukan kita
+untuk memilih elemen tertentu dalam sebuah laman HTML
+dan menerapkan berbagai properti visual bagi elemen tersebut.
+
+Seperti bahasa lainnya, CSS memiliki banyak versi.
+Di artikel ini, kita fokus pada CSS2.0 - yang meskipun bukan versi termutakhir
+namun paling kompatibel dan didukung secara luas.
+
+**CATATAN:** Lantaran keluaran dari CSS berwujud efek-efek visual,
+maka untuk mempelajarinya, kita perlu mencoba berbagai hal dalam dunia olah CSS
+semisal [dabblet](http://dabblet.com/).
+Fokus utama artikel ini ialah pada sintaks dan sejumlah tips umum.
+
+
+```css
+/* komentar terletak diantara sepasang tanda garis miring dan bintang,
+persis seperti larik ini! */
+
+/* ####################
+ ## SELEKTOR
+ ####################*/
+
+/* Secara garis besar, statemen utama dalam CSS sangat sederhana */
+selektor { properti: nilai; /* properti lainnya */ }
+
+/* selektor berfungsi untuk memilih suatu elemen dalam sebuah laman.
+
+Kita juga bisa memilih semua elemen di sebuah halaman! */
+* { color:red; }
+
+/*
+Dengan menentukan sebuah elemen seperti ini pada sebuah laman:
+
+<div class='suatu-class class2' id='suatuId' attr='nilai' />
+*/
+
+/* kita bisa memilih elemen berdasarkan nama class-nya */
+.suatu-class { }
+
+/*atau dengan dua class sekaligus! */
+.suatu-class.class2 { }
+
+/* atau dengan nama tag-nya */
+div { }
+
+/* atau id-nya */
+#suatuId { }
+
+/* atau - jika ada - dengan attribute-nya! */
+[attr] { font-size:smaller; }
+
+/* atau jika attribute tersebut memiliki nilai spesifik */
+[attr='nilai'] { font-size:smaller; }
+
+/* dibuka dengan sebuah nilai*/
+[attr^='nil'] { font-size:smaller; }
+
+/* atau ditutup dengan nilai */
+[attr$='ai'] { font-size:smaller; }
+
+/* atau bahkan disisipi nilai */
+[attr~='la'] { font-size:smaller; }
+
+
+/* dan yang lebih penting lagi, kita bisa mengombinasikannya sekaligus
+dengan syarat tidak ada spasi diantara selektor-selektor. sebab adanya spasi
+akan membuat selektor itu memiliki makna yang berbeda.*/
+div.suatu-class[attr$='ai'] { }
+
+/* kita juga bisa memilih sebuah elemen berdasarkan posisi elemen induknya.*/
+
+/*sebuah elemen yang merupakan anak langsung dari elemen induk (diseleksi dng
+cara yang sama) */
+div.suatu-induk > .-suatu-class {}
+
+/* atau salah satu induk elemennya dalam hirarki elemen */
+/* berikut ini dimaksudkan pada elemen manapun dengan class "class-entah" dan
+merupakan anak elemen dari suatu div dengan class "induk-entah" PADA LEVEL
+HIRARKI MANAPUN */
+div.suatu-induk .suatu-class {}
+
+/* peringatan: selektor yang sama jika tanpa ada spasi akan bermakna lain.
+misalnya? */
+div.suatu-induk.suatu-class {}
+
+/* kita juga bisa memilih sebuah elemen berdasarkan saudara elemen yang muncul
+tepat sebelumnya */
+.aku-muncul-tepat-sebelum + .elemen-ini { }
+
+/*atau saudara elemen manapun yang pernah muncul selang beberapa elemen
+sebelumnya */
+.aku-pernah-muncul-sebelum ~ .elemen-ini {}
+
+/* Ada beberapa pseudo-class yang memampukan kita memilih suatu elemen
+berdasarkan perilaku lamannya (bukan struktur lamannya) */
+
+/* semisal ketika sebuah elemen ditimpa hover (pointer mouse) */
+:hover {}
+
+/* atau link yang sudah pernah diklik*/
+:visited {}
+
+/* atau link yang belum pernah diklik*/
+:link {}
+
+/* atau elemen input yang menjadi fokus */
+:focus {}
+
+
+/* ####################
+ ## PROPERTI
+ ####################*/
+
+selektor {
+
+ /* Unit */
+ width: 50%; /* dalam persen */
+ font-size: 2em; /* angka kali jumlah font-size saat ini */
+ width: 200px; /* dalam pixel */
+ font-size: 20pt; /* dalam point */
+ width: 5cm; /* dalam centimeter */
+ width: 50mm; /* dalam milimeter */
+ width: 5in; /* dalam inci */
+
+ /* Warna */
+ background-color: #F6E; /* dalam short hex */
+ background-color: #F262E2; /* dalam format long hex */
+ background-color: tomato; /* warna yang sudah punya konvensi nama */
+ background-color: rgb(255, 255, 255); /* dalam rgb */
+ background-color: rgb(10%, 20%, 50%); /* dalam persen rgb */
+ background-color: rgba(255, 0, 0, 0.3); /* dalam rgb semi-transparan*/
+
+ /* Gambar */
+ background-image: url(/folder-gambar/image.jpg);
+
+ /* Font */
+ font-family: Arial;
+ font-family: "Courier New"; /* jika nama font memiliki spasi,
+ ia diketik dalam tanda petik ganda */
+ font-family: "Courier New", Trebuchet, Arial; /* jika font pertama tidak
+ ditemukan, peramban menggunakan font berikutnya,
+ demikian secara berturut-turut */
+}
+
+```
+
+## Penggunaan
+
+Simpan semua CSS yang hendak kita pakai dengan ekstensi `.css`.
+
+```xml
+<!-- kita harus menautkan file css itu ke laman di bagian <head>: -->
+<link rel='stylesheet' type='text/css' href='folder/namafile.css' />
+
+<!-- kita juga bisa mengetik CSS secara inline di dalam markup.
+Namun, sebisa mungkin metode ini dihindari. -->
+<style>
+ selektor { properti:nilai; }
+</style>
+
+<!-- atau langsung mengetik properti CSS pada sebuah elemen.
+Metode ini harus dihindari sebisa mungkin. -->
+<div style='properti:nilai;'>
+</div>
+
+```
+
+## Prioritas
+
+Kita tahu bahwa sebuah elemen bisa dipilih dengan lebih dari satu selektor,
+serta bisa diberi lebih dari satu properti.
+Dalam kasus seperti ini, hanya salah satu properti saja yang akan diterapkan
+pada elemen dengan prioritas tertentu.
+
+Dengan susunan CSS:
+
+```css
+
+/*A*/
+p.class1[attr='nilai']
+
+/*B*/
+p.class1 {}
+
+/*C*/
+p.class2 {}
+
+/*D*/
+p {}
+
+/*E*/
+p { properti: nilai !important; }
+
+```
+
+dan susunan markup:
+
+```xml
+<p style='/*F*/ properti:nilai;' class='class1 class2' attr='nilai'>
+</p>
+```
+
+Maka prioritas penerapan style-nya ialah sbb.:
+Ingat, penerapan ini untuk masing-masing **properti**,
+bukan keseluruhan larik.
+
+* `E` prioritas pertama sebab ada kata `!important`.
+ Dianjurkan untuk menghindari kata ini jika tidak benar-benar perlu.
+* `F` prioritas kedua sebab ia diketik secara inline.
+* `A` prioritas ketiga sebab selektor ini lebih spesifik dibanding yang lain.
+ lebih spesifik = lebih banyak unsur selektor. contoh ini punya 3 unsur:
+ 1 tagname `p` + 1 nama class `class1` + 1 attribute `attr='nilai'`
+* `C` prioritas berikutnya sebab meski sama spesifik dengan `B` namun
+ ia muncul lebih akhir.
+* Lalu `B`
+* dan terakhir baru `D`.
+
+## Kompatibilitas
+
+Sebagian besar fitur dalam CSS2 (dan lambat laun juga CSS3) kompatibel dengan
+semua peramban dan perangkat. Namun selalu vital untuk memastikan kompatibilitas
+unsur dan nilai yang kita ketikkan dalam CSS dengan peramban yang ditargetkan.
+
+[QuirksMode CSS](http://www.quirksmode.org/css/) ialah salah satu sumber terbaik untuk memeriksa kompatibilitas CSS dan peramban.
+
+## Referensi Lanjut
+
+* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
+* [QuirksMode CSS](http://www.quirksmode.org/css/)
+* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
+
diff --git a/it-it/brainfuck-it.html.markdown b/it-it/brainfuck-it.html.markdown
new file mode 100644
index 00000000..4999d7e6
--- /dev/null
+++ b/it-it/brainfuck-it.html.markdown
@@ -0,0 +1,101 @@
+---
+
+language: brainfuck
+contributors:
+ - ["Prajit Ramachandran", "http://prajitr.github.io/"]
+ - ["Mathias Bynens", "http://mathiasbynens.be/"]
+translators:
+ - ["Ivan Sala", "http://slavni96.github.io/"]
+lang: it-it
+
+---
+
+Brainfuck è un linguaggio di programmazione estremamente minimale,
+ma è ingrado di rappresentare completamente una macchina di turnig,
+e sfrutta solo 8 caratteri.
+[Per saperne di più](http://it.wikipedia.org/wiki/Brainfuck)
+
+```
+
+Qualsiasi carattere che non sia "><+-.,[]" (escludendo gli apici)
+viene ignorato.
+Branfuck è caratterizzato da un array (vettore) di 30,000 celle
+inizializzare a zero, e un puntatore che punta alla cella corrente.
+
+Vi sono solo otto comando:
++ : Incrementa il valore della cella attuale di uno.
+- : Decrementa il valore della cella attuale di uno.
+> : Sposta il puntatore sulla cella seguente (prossima a destra).
+< : Sposta il puntatore sulla cella precendete (precedente a sinistra).
+. : Stampa il valore in ASCII della cella corrente. (es: 65 = 'A')
+, : Legge un singolo carattere come input per la cella corrente.
+[ : Se il valore della cella corrente è zero, conclude il ciclo
+ andando alla sua corrispondente ].
+ Altrimenti, passa alla prossima istruzione.
+] : Se il valore della cella corrente è zero, passa alla prossima istruzione.
+ Altrimenti torna indetro fino alla [ corrispondente.
+
+[ e ] creano un loop (while). Ovviamente dovranno essere bilanciati.
+Per ogni [ dovrà corrispondere una ]
+
+Alcuni semplici esempi di programmi scritti in Brainfuck:
+
+++++++ [ > ++++++++++ < - ] > +++++ .
+
+Questo programma stampa in output la lettera 'A'. Priam incrementa
+la cella #1 fino a 6, Quindi la cella #1 viene usata per crare un ciclo.
+Poi, entra in un loop ([) e si sposta alla cella #2.
+Incrementa la cella #2 10 volte, e torna alla cella #1, e la decrementa.
+Questo avviene 6 volte (servono che la cella #1 venga decrementata 6 volte
+per raggiungere lo 0. Quindi passa alla corrispondente ] e prosegue).
+
+A questo punto, siamo sulla cella #1, che ha valore 0,
+la cella #2 ha valore 60 (6*10). Ci spostiamo sulla cella #2, incrementiamo
+per 5 volte, e otteniamo il valore 65, quindi stampaimo il valore della cella
+#2 (.).
+65 è 'A' in ASCII, quindi alla fine viene stampata 'A'.
+
+
+, [ > + < - ] > .
+
+Questo programma legge un carattere come input dall'utente,
+quindi salva il carattere dentro la cella #1.
+In seguito, incominca a ciclare.
+Si sposta alla cella #², e increementa il valore della cella (#2).
+Quindi torna alla cella #1, e decrementa il valore della cella (#1).
+Questo continua fino a quando la cella #²1 diventa 0, e quindi la cella #2
+avrà il valore iniziale della cella #1.
+Infine, visto che ci troviamo sulla cella #1 alla fine del ciclo, si sposta
+sulla cella #2 e stampa il valore in ASCII.
+
+Gli spazi nel codice sovrastante, sono presenti solo a scopo di ottenere
+una maggiore leggibilità, si poteva anche scrivere senza:
+
+,[>+<-]>.
+
+Proviamo, adesso, a capire cosa fa invece questo programma:
+
+,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
+
+Prende due numeri in input e quindi li moltiplica.
+
+Prima prende in input i due numeri (,>,<), quindi inizia un cilclo
+basandosi sulla cella #1.
+Quindi si sposta sulla cella #2, e inizia un altro ciclo condizionato
+dal valore della cella #2, incrementando la cella #3.
+Arrivati a questo punto abbiamo un problema: alla fine del ciclo interno
+la cella #2 ha valore 0. In questo caso, quando il ciclo esterno rifarà
+partire il ciclo interno, non funzionerà più perchè la cella #2 ha valore 0.
+Per ovviare a questo problema, oltre alla cella 3, incrementiamo anche la cella
+#4, e alla fine di ogni ciclo interno copiala il valore della cella #4
+nella cella #2, in modo che il ciclo interno
+possa essere eseguito una altra volta.
+Alla fine la cella #3 contiene il risultato.
+```
+
+E questo è brainfuck...Non è difficele, vero?
+Per divertimento adesso puoi scrivere i tuoi programmi in brainfuck,
+oppure puoi scrivere un interprete brainfuck in un altro linguaggio.
+L'interprete è abbastanza semplice da implementare, ma se sei veramente
+masochista prova ad implementare un interprete brainfuck in...
+brainfuck.
diff --git a/it-it/java-it.html.markdown b/it-it/java-it.html.markdown
new file mode 100644
index 00000000..6eabd61f
--- /dev/null
+++ b/it-it/java-it.html.markdown
@@ -0,0 +1,502 @@
+---
+language: java
+filename: LearnJava-it.java
+contributors:
+ - ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Madison Dickson", "http://github.com/mix3d"]
+translators:
+ - ["Ivan Sala","http://github.com/slavni96"]
+lang: it-it
+---
+
+Java è un linguaggio di programmazione orientato ad oggetti,
+concorrente, basato su classi e adatto a svariati scopi.
+[Per saperne di più](http://docs.oracle.com/javase/tutorial/java/index.html)
+
+```java
+// I commenti su singola linea incominciano con //
+/*
+I commenti su piu' linee invece sono cosi'
+*/
+/**
+I commenti per la documentazione JavaDoc si fanno cosi'.
+Vengono usati per descrivere una classe o alcuni suoi attributi.
+*/
+
+// Per importare la classe ArrayList conenuta nel package java.util
+import java.util.ArrayList;
+// Per importare tutte le classi contenute nel package java.security
+import java.security.*;
+
+// Ogni file .java contiene una classe pubblica, con lo stesso nome del file
+public class LearnJava {
+
+ // Un programma deve avere un metodo main come punto di partenza
+ // Ma si possono creare anche file senza main, che però per essere usati
+ // devono essere richiamati da altri file.
+ public static void main (String[] args) {
+
+ // Per stampare a schermo si usa System.out.println
+ System.out.println("Ciao Mondo!");
+ System.out.println(
+ "Intero [integer]: " + 10 +
+ " Reale [double]: " + 3.14 +
+ " Booleano [boolean]: " + true);
+
+ // Se non si vuole andare a capo, si puo' usare System.out.print
+ System.out.print("Ciao ");
+ System.out.print("Mondo ");
+
+
+ ///////////////////////////////////////
+ // Tipi e Variabili
+ ///////////////////////////////////////
+ // Si dichiara una variabile usando <tipo> <nome>
+ // Byte - variabile intera da 8 bit con segno
+ // (-128 <= byte <= 127)
+ byte fooByte = 100;
+
+ // Short - variabile intera da 18 bit con segno
+ // (-32,768 <= short <= 32,767)
+ short fooShort = 10000;
+
+ // Integer - variabile intera da 32 bit con segno
+ // (-2,147,483,648 <= int <= 2,147,483,647)
+ int fooInt = 1;
+
+ // Long - variabile da 64 bit intera con segno
+ // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
+ long fooLong = 100000L;
+ // L viene usato per specificare che il valore dalla variabile
+ // e' di tipo "Long", qualsiasi variabile che non viene contrassegnata
+ // e' trattata di base come un intero.
+
+ // Nota: Java non dispone di variabili senza segno
+
+ // Float - variabile piu' precisa, con virgola [numeri reali]
+ // di grandezza 32 bit
+ float fooFloat = 234.5f;
+ // f e' usato per specificare che la variabile e'' di tipo "float"
+ // altrimenti di default viene trattata come un "dobule"
+
+ // Double - ancora piu' precisione la si puo' ottenere con una variabile
+ // Double, con granzezza di 64 bit.
+ double fooDouble = 123.4;
+
+ // Boolean - vero & falso
+ boolean fooBoolean = true;
+ boolean barBoolean = false;
+
+ // Char - un singolo carattere con grandezza 16 bit
+ char fooChar = 'A';
+
+ // final - Costanti, non possono essere riassegnate ad un altro oggetto
+ final int ORE_LAVORATIVE_DI_UNA_SETTIMANA = 9001;
+
+ // String - Stringhe, array di caratteri
+ String fooString = "Ecco una stringa!";
+
+ // \n e' un carattere speciale che permette di andare a capo.
+ String barString = "Andare a capo?\nNessun problema!";
+ // \t e' un carattere speciale che permette di aggiungere un 'Tab'
+ String bazString = "Vuoi inserire tab?\tNessun problema";
+ System.out.println(fooString);
+ System.out.println(barString);
+ System.out.println(bazString);
+
+ // Vettori [array]
+ //La lunghezza del vettore deve essere decisa quando viene istanziato
+ //Si puo' dichiarare come segue:
+ //<tipodato> [] <nomevariabile> = new <tipodato>[<grandezza vettore>];
+ //<tipodato> <nomevariabile>[] = new <tipodato>[<grandezza vettore>];
+ int [] intArray = new int[10];
+ String [] stringArray = new String[1];
+ boolean boolArray [] = new boolean[100];
+
+ // Un altro modo per dichiarare & inizializzare un vettore
+ int [] y = {9000, 1000, 1337};
+ String nomi [] = {"Andrea", "Bob", "Pippo", "Susan"};
+ boolean bools[] = new boolean[] {true, false, false};
+
+ // I vettori vengono indicizzati a parire dallo 0
+ System.out.println("intArray @ 0: " + intArray[0]);
+
+ // e' possibile un accesso diretto ad un elemento
+ intArray[1] = 1;
+ System.out.println("intArray @ 1: " + intArray[1]); // => 1
+
+ // Altro da vedere:
+ // Liste di array - come i vettori ma piu' funzionali
+ // e la loro grandezza puo' variare in corso di esecuzione
+ // Liste concatenate di memoria
+
+ ///////////////////////////////////////
+ // Operatori
+ ///////////////////////////////////////
+ System.out.println("\n->Operatori");
+
+ int i1 = 1, i2 = 2; // Dichiarazone multipla in contemporanea
+
+ // L'aritmetica e' lineare.
+ System.out.println("1+2 = " + (i1 + i2)); // => 3
+ System.out.println("2-1 = " + (i2 - i1)); // => 1
+ System.out.println("2*1 = " + (i2 * i1)); // => 2
+ System.out.println("1/2 = " + (i1 / i2)); // => 0
+ // (con 0.5 arrotonda per difetto)
+
+ // Modulo
+ System.out.println("11%3 = "+(11 % 3)); // => 2
+
+ // Operatori di confronto
+ System.out.println("3 == 2? " + (3 == 2)); // => falso
+ System.out.println("3 != 2? " + (3 != 2)); // => vero
+ System.out.println("3 > 2? " + (3 > 2)); // => vero
+ System.out.println("3 < 2? " + (3 < 2)); // => falso
+ System.out.println("2 <= 2? " + (2 <= 2)); // => vero
+ System.out.println("2 >= 2? " + (2 >= 2)); // => vero
+
+ // Operatori binari orientati ai bit
+ // effettuano le operazioni logiche confrontando, i bit degli operandi:
+ /*
+ ~ complemento
+ << shift sinistro con segno
+ >> shift destro con segno
+ >>> shift destro senza segno
+ & AND Binario Bitwise AND
+ ^ OR Esclusivo
+ | OR Incusivo
+ */
+
+ // Incrementare e Decrementare
+ int i = 0;
+ System.out.println("\n->Incrementare/Decrementare");
+ // Gli operatori ++ e -- incrementano e decrementano rispettivamente di 1.
+ // Se posizionati prima della variabile, incrementano, quindi riportano.
+ // Se si trovano dopo la variabile, riporano, e quindi incrementano.
+ System.out.println(i++); //i = 1, Stampa 0 (post-incremento)
+ System.out.println(++i); //i = 2, Stampa 2 (pre-incremento)
+ System.out.println(i--); //i = 1, Stampa 2 (post-decremento)
+ System.out.println(--i); //i = 0, Stampa 0 (pre-decremento)
+
+ ///////////////////////////////////////
+ // Strutture di controllo
+ ///////////////////////////////////////
+ System.out.println("\n->Strutture di controllo");
+
+ // La dichiarazione dell'If e'' C-like.
+ int j = 10;
+ if (j == 10){
+ System.out.println("Io vengo stampato");
+ } else if (j > 10) {
+ System.out.println("Io no");
+ } else {
+ System.out.println("E io neppure");
+ }
+
+ // Struttura While
+ int fooWhile = 0;
+ while(fooWhile < 100)
+ {
+ //System.out.println(fooWhile);
+ //Incrementa il contatore
+ //Si ripete per 100 volte, fooWhile 0,1,2...99
+ fooWhile++;
+ }
+ System.out.println("Valore di fooWhile: " + fooWhile);
+
+ // Struttura Do While
+ int fooDoWhile = 0;
+ do
+ {
+ //System.out.println(fooDoWhile);
+ //Incrementa il contaore
+ //Si repete per 99 volte, fooDoWhile 0->99
+ fooDoWhile++;
+ }while(fooDoWhile < 100);
+ System.out.println("Valore di fooWhile: " + fooDoWhile);
+
+ // Struttura For
+ int fooFor;
+ //Struttura For => for(<Situazione iniziale>; <Condizione>; <passo>)
+ for(fooFor=0; fooFor<10; fooFor++){
+ //System.out.println(fooFor);
+ //Itera 10 volte, fooFor 0->9
+ }
+ System.out.println("Valore di fooFor: " + fooFor);
+
+ // Struttura For Each
+ // Una iterazione automatica attraverso un array o una lista di oggetti
+ int[] fooList = {1,2,3,4,5,6,7,8,9};
+ //struttura for each => for(<oggetto> : <oggetto dell'attay>)
+ //si legge: per ogni oggetto dell'array fai...
+ //Nota: il tipo dell'oggetto deve essere uguale a quello dell'array
+
+ for( int bar : fooList ){
+ //System.out.println(bar);
+ //Itera 9 volte e stampa 1-9 andando a capo.
+ }
+
+ // Struttura Switch Case
+ // La struttura switch lavora con byte, short, char e int.
+ // Se funziona con i char funzionera ovviamente anche con le stringhe.
+ int mese = 3;
+ String stringaMese;
+ switch (mese){
+ case 1:
+ stringaMese = "Genneio";
+ break;
+ case 2:
+ stringaMese = "Febbraio";
+ break;
+ case 3:
+ stringaMese = "Marzo";
+ break;
+ default:
+ stringaMese = "Altri mesi";
+ break;
+ }
+ System.out.println("Risultato del costrutto switch: " + stringaMese);
+
+ // Condizioni brevi
+ // Si puo' usare l'operatore '?' per un rapido assegnamento
+ // o per operazioni logiche.
+ // Si legge:
+ // Se (condizione) e' vera, usa <primo valore>, altrimenti usa <secondo valore>
+ int foo = 5;
+ String bar = (foo < 10) ? "A" : "B";
+ System.out.println("Se la condizione e' vera stampa A: "+bar);
+ // Stampa A, perche' la condizione e' vera.
+
+
+ /////////////////////////////////////////
+ // Convertire i tipi di tati e Typcasting
+ /////////////////////////////////////////
+
+ // Convertire tipi di dati
+
+ // Stringhe ad interi
+ Integer.parseInt("123");//Riporta una versione intera di "123"
+
+ // Interi a Stringhe
+ Integer.toString(123);//Riporta la stringa "123"
+ // Per altre conversioni guarda le seguenti classi
+ // Double
+ // Long
+ // String
+
+ // Typecasting
+ // Vi sono molti dettagli che non si possono spiegare qui,
+ // java dispone di una ottima documentazione
+ // Sentiti libero di leggerla
+ // http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
+
+
+ ///////////////////////////////////////
+ // Classi e funzioni
+ ///////////////////////////////////////
+
+ System.out.println("\n->Classi & Funzioni");
+
+ // (Di seguito la definizione della classe Bicicletta)
+
+ // Instanziare una nuova classe
+ Bicicletta percorso = new Bicicletta();
+
+ // Chiamare metodi
+ percorso.accellera(3); // Si usano sempre metodi set... get...
+ percorso.setCadenza(100);
+
+ // toString riporta la rappresenzazione dell'oggetto
+ // come se fosse una stringa
+ System.out.println("percorso info: " + percorso.toString());
+
+ } // Fine metodo main
+} // Fine classe LearnJava
+
+
+// Si possono inculdere altre anche delle classi non pubbliche (private)
+// oltre a quella pubblica principale, in un file .java
+
+// Sintassi per dichiarare una classe:
+// <public/private/protected> class <Nome classe>{
+// //dati, variabili, costruttori, funzioni, tutto qua.
+// //le funzioni sono chiamate come i metodi.
+// }
+
+class Bicicletta {
+
+ // Variabili della bicicletta
+ public int cadenza;
+ // Public: Puo' essere richiamato da qualsiasi classe
+ private int velocita;
+ // Private: e'' accessibile solo dalla classe dove e'' stato inizializzato
+ protected int ingranaggi;
+ // Protected: e'' visto sia dalla classe che dalle sottoclassi
+ String nome;
+ // default: e'' accessibile sono all'interno dello stesso package
+
+ // I costruttori vengono usati per creare variabili
+ // Questo e'' un costruttore
+ public Bicicletta() {
+ ingranaggi = 1;
+ cadenza = 50;
+ velocita = 5;
+ nome = "Bontrager";
+ }
+
+ // Questo e'' un costruttore che richiede parametri
+ public Bicicletta(int cadenza, int velocita, int ingranaggi, String nome) {
+ this.ingranaggi = ingranaggi;
+ this.cadenza = cadenza;
+ this.velocita = velocita;
+ this.nome = nome;
+ }
+
+ // Sintassi delle funzioni:
+ // <public/private/protected> <tipo di ritorino> <nome della funzione>(<parametri>)
+
+ // Le classi in java spesso implementano delle funzioni o metodo
+ // 'get...' o 'set...'
+
+ // Dichiarazione di un metodo
+ // <scope> <tipo di ritorno> <nome del metodo>(<parametri>)
+ public int getCandenza() {
+ return cadenza;
+ }
+
+ // i medodi (void) non necessitano di riportare un valore
+ public void setCadenza(int nuovoValore) {
+ cadenza = nuovoValore;
+ }
+
+ public void setIngranaggi(int nuovoValore) {
+ ingranaggi = nuovoValore;
+ }
+
+ public void accellera(int incrementa) {
+ velocita += incrementa;
+ }
+
+ public void decellera(int decrementa) {
+ velocita -= decrementa;
+ }
+
+ public void setNome(String nuovoNome) {
+ nome = nuovoNome;
+ }
+
+ public String getNome() {
+ return nome;
+ }
+
+ //Medoto per visualizzare gli attributi dell'oggetto
+ @Override
+ public String toString() {
+ return "Ingranaggi: " + ingranaggi +
+ " Cadenza: " + cadenza +
+ " Velocita: " + velocita +
+ " Nome: " + nome;
+ }
+} // Fine classe bicicletta
+
+// PennyFarthing e'' una sottoclasse della bicicletta
+class PennyFarthing extends Bicicletta {
+ // (Sono quelle biciclette con un unica ruota enorme
+ // Non hanno ingranaggi.)
+
+ public PennyFarthing(int cadenzaIniziale, int velocitaIniziale){
+ // Richiamo il costruttore del padre con super
+ super(cadenzaIniziale, velocitaIniziale, 0, "PennyFarthing");
+ }
+
+ // Bisogna contrassegnre un medodo che si sta riscrivendo
+ // con una @annotazione
+ // Per saperne di piu' sulle annotazioni
+ // Vedi la guida: http://docs.oracle.com/javase/tutorial/java/annotations/
+ @Override
+ public void setIngranaggi(int ingranaggi) {
+ ingranaggi = 0;
+ }
+
+}
+/*
+//Interfacce
+//Sintassi per dichiarare una interfaccia
+//<livello di accesso> interface <nome dell'interfaccia> extends <super-interfaccia> {
+// //Costanti
+// //Dichiarazioni dei metodi
+//}
+
+//Esempi- Cibo:
+interface Commestibile {
+ public void mangia();
+ //Ogni classe che implementa questa interfaccia
+ //deve implementare questo metodo.
+ }
+interface Digeribile {
+ public void digerisci();
+}
+
+//Possiamo quindi creare una classe che implementa entrambe le interfaccie
+class Frutta implements Commestibile, Digestibile {
+ public void mangia() {
+ //...
+ }
+
+ public void digerisci() {
+ //...
+ }
+}
+
+//In Java si puo' estendere solo una classe, ma si possono implementare
+//piu' interfaccie, per esempio:
+class ClasseEsempio extends AltraClasse implements PrimaInterfaccia, SecondaInterfaccia {
+ public void MetodoPrimaInterfaccia() {
+
+ }
+
+ public void MetodoSecondaInterfaccia() {
+
+ }
+}
+*/
+```
+## Letture future
+
+I link di seguito sono solo per capire l'argomento, cerca pure su Google degli esempi specifici
+
+
+**Guida ufficiale di Oracle [solo in inglese]**:
+
+* [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html)
+
+* [Java Access level modifiers](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)
+
+* [Object-Oriented Programming Concepts](http://docs.oracle.com/javase/tutorial/java/concepts/index.html):
+ * [Inheritance](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html)
+ * [Polymorphism](http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html)
+ * [Abstraction](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html)
+
+* [Exceptions](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html)
+
+* [Interfaces](http://docs.oracle.com/javase/tutorial/java/IandI/createinterface.html)
+
+* [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html)
+
+* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html)
+
+
+**Tutorial Online [in inglese]**
+
+* [Learneroo.com - Learn Java](http://www.learneroo.com)
+
+* [Codingbat.com](http://codingbat.com/java)
+
+
+**Libri [in italiano]** :
+
+* [Java la guida completa](http://www.amazon.it/Java-guida-completa-Herbert-Schildt/dp/8838667667/ref=sr_1_1?ie=UTF8&qid=1393422296&sr=8-1&keywords=java)
+
+* [Thinking in java](http://www.amazon.it/Thinking-Java-1-Bruce-Eckel/dp/8871923030/ref=sr_1_8?ie=UTF8&qid=1393422296&sr=8-8&keywords=java)
+
+* [Manuale di Java 7](http://www.amazon.com/gp/product/0071606300)
diff --git a/java.html.markdown b/java.html.markdown
index b4624d5e..50875491 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -101,14 +101,17 @@ public class LearnJava {
// Arrays
//The array size must be decided upon instantiation
- //The format for declaring an array is follows:
+ //The following formats work for declaring an arrow
//<datatype> [] <var name> = new <datatype>[<array size>];
+ //<datetype> <var name>[] = new <datatype>[<array size>];
int [] intArray = new int[10];
String [] stringArray = new String[1];
- boolean [] booleanArray = new boolean[100];
+ boolean boolArray [] = new boolean[100];
// Another way to declare & initialize an array
int [] y = {9000, 1000, 1337};
+ String names [] = {"Bob", "John", "Fred", "Juan Pedro"};
+ boolean bools[] = new boolean[] {true, false, false};
// Indexing an array - Accessing an element
System.out.println("intArray @ 0: " + intArray[0]);
@@ -191,7 +194,7 @@ public class LearnJava {
{
//System.out.println(fooWhile);
//Increment the counter
- //Iterated 99 times, fooWhile 0->99
+ //Iterated 100 times, fooWhile 0,1,2...99
fooWhile++;
}
System.out.println("fooWhile Value: " + fooWhile);
@@ -405,13 +408,53 @@ class PennyFarthing extends Bicycle {
}
+//Interfaces
+//Interface declaration syntax
+//<access-level> interface <interface-name> extends <super-interfaces> {
+// //Constants
+// //Method declarations
+//}
+
+//Example - Food:
+public interface Edible {
+ public void eat(); //Any class that implements this interface, must implement this method
+}
+
+public interface Digestible {
+ public void digest();
+}
+
+
+//We can now create a class that implements both of these interfaces
+public class Fruit implements Edible, Digestible {
+ public void eat() {
+ //...
+ }
+
+ public void digest() {
+ //...
+ }
+}
+
+//In java, you can extend only one class, but you can implement many interfaces.
+//For example:
+public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo {
+ public void InterfaceOneMethod() {
+
+ }
+
+ public void InterfaceTwoMethod() {
+
+ }
+}
+
```
## Further Reading
The links provided here below are just to get an understanding of the topic, feel free to Google and find specific examples.
-Other Topics To Research:
+**Official Oracle Guides**:
* [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html)
@@ -430,6 +473,19 @@ Other Topics To Research:
* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html)
-Books:
+**Online Practice and Tutorials**
+
+* [Learneroo.com - Learn Java](http://www.learneroo.com)
+
+* [Codingbat.com](http://codingbat.com/java)
+
+
+**Books**:
+
+* [Head First Java](http://www.headfirstlabs.com/books/hfjava/)
+
+* [Objects First with Java](http://www.amazon.com/Objects-First-Java-Practical-Introduction/dp/0132492660)
+
+* [Java The Complete Reference](http://www.amazon.com/gp/product/0071606300)
+
-* [Head First Java] (http://www.headfirstlabs.com/books/hfjava/)
diff --git a/javascript.html.markdown b/javascript.html.markdown
index 7fb7ba55..76017c17 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -2,10 +2,11 @@
language: javascript
contributors:
- ["Adam Brenecki", "http://adam.brenecki.id.au"]
+ - ["Ariel Krakowski", "http://www.learneroo.com"]
filename: javascript.js
---
-Javascript was created by Netscape's Brendan Eich in 1995. It was originally
+JavaScript was created by Netscape's Brendan Eich in 1995. It was originally
intended as a simpler scripting language for websites, complimenting the use of
Java for more complex web applications, but its tight integration with Web pages
and built-in support in browsers has caused it to become far more common than
@@ -37,7 +38,7 @@ doStuff()
///////////////////////////////////
// 1. Numbers, Strings and Operators
-// Javascript has one number type (which is a 64-bit IEEE 754 double).
+// JavaScript has one number type (which is a 64-bit IEEE 754 double).
// As with Lua, don't freak out about the lack of ints: doubles have a 52-bit
// mantissa, which is enough to store integers up to about 9✕10¹⁵ precisely.
3; // = 3
@@ -103,7 +104,13 @@ 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); // = 'T'
+
+// ...or use substring to get larger pieces
+"Hello world".substring(0, 5); // = "Hello"
+
+// length is a property, so don't use ()
+"Hello".length; // = 5
// There's also null and undefined
null; // used to indicate a deliberate non-value
@@ -116,7 +123,7 @@ undefined; // used to indicate a value is not currently present (although
///////////////////////////////////
// 2. Variables, Arrays and Objects
-// Variables are declared with the var keyword. Javascript is dynamically typed,
+// 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;
@@ -148,6 +155,9 @@ myArray[1]; // = 45
myArray.push("World");
myArray.length; // = 4
+// Add/Modify at specific index
+myArray[3] = "Hello";
+
// JavaScript's objects are equivalent to 'dictionaries' or 'maps' in other
// languages: an unordered collection of key-value pairs.
var myObj = {key1: "Hello", key2: "World"};
@@ -171,18 +181,20 @@ myObj.myFourthKey; // = undefined
///////////////////////////////////
// 3. Logic and Control Structures
+// The syntax for this section is almost identical to Java's.
+
// The if structure works as you'd expect.
var count = 1;
if (count == 3){
// evaluated if count is 3
-} else if (count == 4) {
+} else if (count == 4){
// evaluated if count is 4
} else {
// evaluated if it's not either 3 or 4
}
// As does while.
-while (true) {
+while (true){
// An infinite loop!
}
@@ -209,6 +221,27 @@ if (colour == "red" || colour == "blue"){
// && and || "short circuit", which is useful for setting default values.
var name = otherName || "default";
+
+// switch statement checks for equality with ===
+// use 'break' after each case
+// or the cases after the correct one will be executed too.
+grade = 'B';
+switch (grade) {
+ case 'A':
+ console.log("Great job");
+ break;
+ case 'B':
+ console.log("OK job");
+ break;
+ case 'C':
+ console.log("You can do better");
+ break;
+ default:
+ console.log("Oy vey");
+ break;
+}
+
+
///////////////////////////////////
// 4. Functions, Scope and Closures
@@ -327,7 +360,7 @@ var anotherFunc = function(s){
}
anotherFunc.call(myObj, " And Hello Moon!"); // = "Hello World! And Hello Moon!"
-// The 'apply' function is nearly identical, but takes an array for an argument list.
+// The 'apply' function is nearly identical, but takes an array for an argument list.
anotherFunc.apply(myObj, [" And Hello Sun!"]); // = "Hello World! And Hello Sun!"
@@ -477,9 +510,13 @@ more about how to use JavaScript in web pages, start by learning about the
[Document Object
Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core)
-[Javascript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth
+[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) is a variant of this reference with built-in challenges.
+
+[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth
guide of all the counter-intuitive parts of the language.
+[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) is a classic guide / reference book.
+
In addition to direct contributors to this article, some content is adapted
from Louie Dinh's Python tutorial on this site, and the [JS
Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
diff --git a/json.html.markdown b/json.html.markdown
new file mode 100644
index 00000000..f86f0ae9
--- /dev/null
+++ b/json.html.markdown
@@ -0,0 +1,48 @@
+---
+language: json
+filename: learnjson.json
+contributors:
+ - ["Anna Harren", "https://github.com/iirelu"]
+---
+
+As JSON is an extremely simple data-interchange format, this is most likely going
+to be the simplest Learn X in Y Minutes ever.
+
+JSON in its purest form has no actual comments, but most parsers will accept
+C-style (//, /\* \*/) comments. For the purposes of this, however, everything is
+going to be 100% valid JSON. Luckily, it kind of speaks for itself.
+
+```json
+{
+ "numbers": 0,
+ "strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
+ "has bools?": true,
+ "nothingness": null,
+
+ "big number": 1.2e+100,
+
+ "objects": {
+ "comment": "Most of your structure will come from objects.",
+
+ "array": [0, 1, 2, 3, "Arrays can have anything in them.", 5],
+
+ "another object": {
+ "comment": "These things can be nested, very useful."
+ }
+ },
+
+ "silliness": [
+ {
+ "sources of potassium": ["bananas"]
+ },
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, "neo"],
+ [0, 0, 0, 1]
+ ]
+ ],
+
+ "that was short": "And, you're done. You know know everything JSON has to offer."
+}
+```
diff --git a/julia.html.markdown b/julia.html.markdown
index 4b946d46..15b4be90 100644
--- a/julia.html.markdown
+++ b/julia.html.markdown
@@ -12,7 +12,11 @@ This is based on the current development version of Julia, as of October 18th, 2
```ruby
-# Single line comments start with a hash.
+# Single line comments start with a number symbol.
+#= Multiline comments can be written
+ by putting '#=' before the text and '=#'
+ after the text. They can also be nested.
+=#
####################################################
## 1. Primitive Datatypes and Operators
@@ -21,58 +25,58 @@ This is based on the current development version of Julia, as of October 18th, 2
# Everything in Julia is a expression.
# There are several basic types of numbers.
-3 #=> 3 (Int64)
-3.2 #=> 3.2 (Float64)
-2 + 1im #=> 2 + 1im (Complex{Int64})
-2//3 #=> 2//3 (Rational{Int64})
+3 # => 3 (Int64)
+3.2 # => 3.2 (Float64)
+2 + 1im # => 2 + 1im (Complex{Int64})
+2//3 # => 2//3 (Rational{Int64})
# All of the normal infix operators are available.
-1 + 1 #=> 2
-8 - 1 #=> 7
-10 * 2 #=> 20
-35 / 5 #=> 7.0
-5 / 2 #=> 2.5 # dividing an Int by an Int always results in a Float
-div(5, 2) #=> 2 # for a truncated result, use div
-5 \ 35 #=> 7.0
-2 ^ 2 #=> 4 # power, not bitwise xor
-12 % 10 #=> 2
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+35 / 5 # => 7.0
+5 / 2 # => 2.5 # dividing an Int by an Int always results in a Float
+div(5, 2) # => 2 # for a truncated result, use div
+5 \ 35 # => 7.0
+2 ^ 2 # => 4 # power, not bitwise xor
+12 % 10 # => 2
# Enforce precedence with parentheses
-(1 + 3) * 2 #=> 8
+(1 + 3) * 2 # => 8
# Bitwise Operators
-~2 #=> -3 # bitwise not
-3 & 5 #=> 1 # bitwise and
-2 | 4 #=> 6 # bitwise or
-2 $ 4 #=> 6 # bitwise xor
-2 >>> 1 #=> 1 # logical shift right
-2 >> 1 #=> 1 # arithmetic shift right
-2 << 1 #=> 4 # logical/arithmetic shift left
+~2 # => -3 # bitwise not
+3 & 5 # => 1 # bitwise and
+2 | 4 # => 6 # bitwise or
+2 $ 4 # => 6 # bitwise xor
+2 >>> 1 # => 1 # logical shift right
+2 >> 1 # => 1 # arithmetic shift right
+2 << 1 # => 4 # logical/arithmetic shift left
# You can use the bits function to see the binary representation of a number.
bits(12345)
-#=> "0000000000000000000000000000000000000000000000000011000000111001"
+# => "0000000000000000000000000000000000000000000000000011000000111001"
bits(12345.0)
-#=> "0100000011001000000111001000000000000000000000000000000000000000"
+# => "0100000011001000000111001000000000000000000000000000000000000000"
# Boolean values are primitives
true
false
# Boolean operators
-!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
+!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
# Comparisons can be chained
-1 < 2 < 3 #=> true
-2 < 3 < 2 #=> false
+1 < 2 < 3 # => true
+2 < 3 < 2 # => false
# Strings are created with "
"This is a string."
@@ -81,43 +85,43 @@ false
'a'
# A string can be indexed like an array of characters
-"This is a string"[1] #=> 'T' # Julia indexes from 1
+"This is a string"[1] # => 'T' # Julia indexes from 1
# However, this is will not work well for UTF8 strings,
# so iterating over strings is recommended (map, for loops, etc).
# $ can be used for string interpolation:
-"2 + 2 = $(2 + 2)" #=> "2 + 2 = 4"
+"2 + 2 = $(2 + 2)" # => "2 + 2 = 4"
# You can put any Julia expression inside the parenthesis.
# Another way to format strings is the printf macro.
@printf "%d is less than %f" 4.5 5.3 # 5 is less than 5.300000
+# Printing is easy
+println("I'm Julia. Nice to meet you!")
+
####################################################
## 2. Variables and Collections
####################################################
-# Printing is easy
-println("I'm Julia. Nice to meet you!")
-
# You don't declare variables before assigning to them.
-some_var = 5 #=> 5
-some_var #=> 5
+some_var = 5 # => 5
+some_var # => 5
# Accessing a previously unassigned variable is an error
try
- some_other_var #=> ERROR: some_other_var not defined
+ some_other_var # => ERROR: some_other_var not defined
catch e
println(e)
end
# Variable names start with a letter.
# After that, you can use letters, digits, underscores, and exclamation points.
-SomeOtherVar123! = 6 #=> 6
+SomeOtherVar123! = 6 # => 6
# You can also use unicode characters
-☃ = 8 #=> 8
+☃ = 8 # => 8
# These are especially handy for mathematical notation
-2 * π #=> 6.283185307179586
+2 * π # => 6.283185307179586
# A note on naming conventions in Julia:
#
@@ -133,49 +137,49 @@ SomeOtherVar123! = 6 #=> 6
# functions are sometimes called mutating functions or in-place functions.
# Arrays store a sequence of values indexed by integers 1 through n:
-a = Int64[] #=> 0-element Int64 Array
+a = Int64[] # => 0-element Int64 Array
# 1-dimensional array literals can be written with comma-separated values.
-b = [4, 5, 6] #=> 3-element Int64 Array: [4, 5, 6]
-b[1] #=> 4
-b[end] #=> 6
+b = [4, 5, 6] # => 3-element Int64 Array: [4, 5, 6]
+b[1] # => 4
+b[end] # => 6
# 2-dimentional arrays use space-separated values and semicolon-separated rows.
-matrix = [1 2; 3 4] #=> 2x2 Int64 Array: [1 2; 3 4]
+matrix = [1 2; 3 4] # => 2x2 Int64 Array: [1 2; 3 4]
# Add stuff to the end of a list with push! and append!
-push!(a,1) #=> [1]
-push!(a,2) #=> [1,2]
-push!(a,4) #=> [1,2,4]
-push!(a,3) #=> [1,2,4,3]
-append!(a,b) #=> [1,2,4,3,4,5,6]
+push!(a,1) # => [1]
+push!(a,2) # => [1,2]
+push!(a,4) # => [1,2,4]
+push!(a,3) # => [1,2,4,3]
+append!(a,b) # => [1,2,4,3,4,5,6]
# Remove from the end with pop
-pop!(b) #=> 6 and b is now [4,5]
+pop!(b) # => 6 and b is now [4,5]
# Let's put it back
push!(b,6) # b is now [4,5,6] again.
-a[1] #=> 1 # remember that Julia indexes from 1, not 0!
+a[1] # => 1 # remember that Julia indexes from 1, not 0!
# end is a shorthand for the last index. It can be used in any
# indexing expression
-a[end] #=> 6
+a[end] # => 6
# we also have shift and unshift
-shift!(a) #=> 1 and a is now [2,4,3,4,5,6]
-unshift!(a,7) #=> [7,2,4,3,4,5,6]
+shift!(a) # => 1 and a is now [2,4,3,4,5,6]
+unshift!(a,7) # => [7,2,4,3,4,5,6]
# Function names that end in exclamations points indicate that they modify
# their argument.
-arr = [5,4,6] #=> 3-element Int64 Array: [5,4,6]
-sort(arr) #=> [4,5,6]; arr is still [5,4,6]
-sort!(arr) #=> [4,5,6]; arr is now [4,5,6]
+arr = [5,4,6] # => 3-element Int64 Array: [5,4,6]
+sort(arr) # => [4,5,6]; arr is still [5,4,6]
+sort!(arr) # => [4,5,6]; arr is now [4,5,6]
# Looking out of bounds is a BoundsError
try
- a[0] #=> ERROR: BoundsError() in getindex at array.jl:270
- a[end+1] #=> ERROR: BoundsError() in getindex at array.jl:270
+ a[0] # => ERROR: BoundsError() in getindex at array.jl:270
+ a[end+1] # => ERROR: BoundsError() in getindex at array.jl:270
catch e
println(e)
end
@@ -185,110 +189,109 @@ end
# inside the julia folder to find these files.
# You can initialize arrays from ranges
-a = [1:5] #=> 5-element Int64 Array: [1,2,3,4,5]
+a = [1:5] # => 5-element Int64 Array: [1,2,3,4,5]
# You can look at ranges with slice syntax.
-a[1:3] #=> [1, 2, 3]
-a[2:] #=> [2, 3, 4, 5]
-a[2:end] #=> [2, 3, 4, 5]
+a[1:3] # => [1, 2, 3]
+a[2:end] # => [2, 3, 4, 5]
# Remove elements from an array by index with splice!
arr = [3,4,5]
-splice!(arr,2) #=> 4 ; arr is now [3,5]
+splice!(arr,2) # => 4 ; arr is now [3,5]
# Concatenate lists with append!
b = [1,2,3]
append!(a,b) # Now a is [1, 2, 3, 4, 5, 1, 2, 3]
# Check for existence in a list with in
-in(1, a) #=> true
+in(1, a) # => true
# Examine the length with length
-length(a) #=> 8
+length(a) # => 8
# Tuples are immutable.
-tup = (1, 2, 3) #=> (1,2,3) # an (Int64,Int64,Int64) tuple.
-tup[1] #=> 1
+tup = (1, 2, 3) # => (1,2,3) # an (Int64,Int64,Int64) tuple.
+tup[1] # => 1
try:
- tup[1] = 3 #=> ERROR: no method setindex!((Int64,Int64,Int64),Int64,Int64)
+ tup[1] = 3 # => ERROR: no method setindex!((Int64,Int64,Int64),Int64,Int64)
catch e
println(e)
end
# Many list functions also work on tuples
-length(tup) #=> 3
-tup[1:2] #=> (1,2)
-in(2, tup) #=> true
+length(tup) # => 3
+tup[1:2] # => (1,2)
+in(2, tup) # => true
# You can unpack tuples into variables
-a, b, c = (1, 2, 3) #=> (1,2,3) # a is now 1, b is now 2 and c is now 3
+a, b, c = (1, 2, 3) # => (1,2,3) # a is now 1, b is now 2 and c is now 3
# Tuples are created even if you leave out the parentheses
-d, e, f = 4, 5, 6 #=> (4,5,6)
+d, e, f = 4, 5, 6 # => (4,5,6)
# A 1-element tuple is distinct from the value it contains
-(1,) == 1 #=> false
-(1) == 1 #=> true
+(1,) == 1 # => false
+(1) == 1 # => true
# Look how easy it is to swap two values
-e, d = d, e #=> (5,4) # d is now 5 and e is now 4
+e, d = d, e # => (5,4) # d is now 5 and e is now 4
# Dictionaries store mappings
-empty_dict = Dict() #=> Dict{Any,Any}()
+empty_dict = Dict() # => Dict{Any,Any}()
# You can create a dictionary using a literal
filled_dict = ["one"=> 1, "two"=> 2, "three"=> 3]
# => Dict{ASCIIString,Int64}
# Look up values with []
-filled_dict["one"] #=> 1
+filled_dict["one"] # => 1
# Get all keys
keys(filled_dict)
-#=> KeyIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# => KeyIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
# Note - dictionary keys are not sorted or in the order you inserted them.
# Get all values
values(filled_dict)
-#=> ValueIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# => ValueIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
# Note - Same as above regarding key ordering.
# Check for existence of keys in a dictionary with in, haskey
-in(("one", 1), filled_dict) #=> true
-in(("two", 3), filled_dict) #=> false
-haskey(filled_dict, "one") #=> true
-haskey(filled_dict, 1) #=> false
+in(("one", 1), filled_dict) # => true
+in(("two", 3), filled_dict) # => false
+haskey(filled_dict, "one") # => true
+haskey(filled_dict, 1) # => false
# Trying to look up a non-existant key will raise an error
try
- filled_dict["four"] #=> ERROR: key not found: four in getindex at dict.jl:489
+ filled_dict["four"] # => ERROR: key not found: four in getindex at dict.jl:489
catch e
println(e)
end
# Use the get method to avoid that error by providing a default value
# get(dictionary,key,default_value)
-get(filled_dict,"one",4) #=> 1
-get(filled_dict,"four",4) #=> 4
+get(filled_dict,"one",4) # => 1
+get(filled_dict,"four",4) # => 4
# Use Sets to represent collections of unordered, unique values
-empty_set = Set() #=> Set{Any}()
+empty_set = Set() # => Set{Any}()
# Initialize a set with values
-filled_set = Set(1,2,2,3,4) #=> Set{Int64}(1,2,3,4)
+filled_set = Set(1,2,2,3,4) # => Set{Int64}(1,2,3,4)
# Add more values to a set
-push!(filled_set,5) #=> Set{Int64}(5,4,2,3,1)
+push!(filled_set,5) # => Set{Int64}(5,4,2,3,1)
# Check if the values are in the set
-in(2, filled_set) #=> true
-in(10, filled_set) #=> false
+in(2, filled_set) # => true
+in(10, filled_set) # => false
# There are functions for set intersection, union, and difference.
-other_set = Set(3, 4, 5, 6) #=> Set{Int64}(6,4,5,3)
-intersect(filled_set, other_set) #=> Set{Int64}(3,4,5)
-union(filled_set, other_set) #=> Set{Int64}(1,2,3,4,5,6)
-setdiff(Set(1,2,3,4),Set(2,3,5)) #=> Set{Int64}(1,4)
+other_set = Set(3, 4, 5, 6) # => Set{Int64}(6,4,5,3)
+intersect(filled_set, other_set) # => Set{Int64}(3,4,5)
+union(filled_set, other_set) # => Set{Int64}(1,2,3,4,5,6)
+setdiff(Set(1,2,3,4),Set(2,3,5)) # => Set{Int64}(1,4)
####################################################
@@ -306,7 +309,7 @@ elseif some_var < 10 # This elseif clause is optional.
else # The else clause is optional too.
println("some_var is indeed 10.")
end
-#=> prints "some var is smaller than 10"
+# => prints "some var is smaller than 10"
# For loops iterate over iterables.
@@ -363,7 +366,7 @@ try
catch e
println("caught it $e")
end
-#=> caught it ErrorException("help")
+# => caught it ErrorException("help")
####################################################
@@ -381,7 +384,7 @@ function add(x, y)
x + y
end
-add(5, 6) #=> 11 after printing out "x is 5 and y is 6"
+add(5, 6) # => 11 after printing out "x is 5 and y is 6"
# You can define functions that take a variable number of
# positional arguments
@@ -389,20 +392,20 @@ function varargs(args...)
return args
# use the keyword return to return anywhere in the function
end
-#=> varargs (generic function with 1 method)
+# => varargs (generic function with 1 method)
-varargs(1,2,3) #=> (1,2,3)
+varargs(1,2,3) # => (1,2,3)
# The ... is called a splat.
# We just used it in a function definition.
# It can also be used in a fuction call,
# where it will splat an Array or Tuple's contents into the argument list.
-Set([1,2,3]) #=> Set{Array{Int64,1}}([1,2,3]) # produces a Set of Arrays
-Set([1,2,3]...) #=> Set{Int64}(1,2,3) # this is equivalent to Set(1,2,3)
+Set([1,2,3]) # => Set{Array{Int64,1}}([1,2,3]) # produces a Set of Arrays
+Set([1,2,3]...) # => Set{Int64}(1,2,3) # this is equivalent to Set(1,2,3)
-x = (1,2,3) #=> (1,2,3)
-Set(x) #=> Set{(Int64,Int64,Int64)}((1,2,3)) # a Set of Tuples
-Set(x...) #=> Set{Int64}(2,3,1)
+x = (1,2,3) # => (1,2,3)
+Set(x) # => Set{(Int64,Int64,Int64)}((1,2,3)) # a Set of Tuples
+Set(x...) # => Set{Int64}(2,3,1)
# You can define functions with optional positional arguments
@@ -410,12 +413,12 @@ function defaults(a,b,x=5,y=6)
return "$a $b and $x $y"
end
-defaults('h','g') #=> "h g and 5 6"
-defaults('h','g','j') #=> "h g and j 6"
-defaults('h','g','j','k') #=> "h g and j k"
+defaults('h','g') # => "h g and 5 6"
+defaults('h','g','j') # => "h g and j 6"
+defaults('h','g','j','k') # => "h g and j k"
try
- defaults('h') #=> ERROR: no method defaults(Char,)
- defaults() #=> ERROR: no methods defaults()
+ defaults('h') # => ERROR: no method defaults(Char,)
+ defaults() # => ERROR: no methods defaults()
catch e
println(e)
end
@@ -425,9 +428,9 @@ function keyword_args(;k1=4,name2="hello") # note the ;
return ["k1"=>k1,"name2"=>name2]
end
-keyword_args(name2="ness") #=> ["name2"=>"ness","k1"=>4]
-keyword_args(k1="mine") #=> ["k1"=>"mine","name2"=>"hello"]
-keyword_args() #=> ["name2"=>"hello","k2"=>4]
+keyword_args(name2="ness") # => ["name2"=>"ness","k1"=>4]
+keyword_args(k1="mine") # => ["k1"=>"mine","name2"=>"hello"]
+keyword_args() # => ["name2"=>"hello","k1"=>4]
# You can combine all kinds of arguments in the same function
function all_the_args(normal_arg, optional_positional_arg=2; keyword_arg="foo")
@@ -451,7 +454,7 @@ function create_adder(x)
end
# This is "stabby lambda syntax" for creating anonymous functions
-(x -> x > 2)(3) #=> true
+(x -> x > 2)(3) # => true
# This function is identical to create_adder implementation above.
function create_adder(x)
@@ -467,16 +470,16 @@ function create_adder(x)
end
add_10 = create_adder(10)
-add_10(3) #=> 13
+add_10(3) # => 13
# There are built-in higher order functions
-map(add_10, [1,2,3]) #=> [11, 12, 13]
-filter(x -> x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+map(add_10, [1,2,3]) # => [11, 12, 13]
+filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# We can use list comprehensions for nicer maps
-[add_10(i) for i=[1, 2, 3]] #=> [11, 12, 13]
-[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[add_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
####################################################
## 5. Types
@@ -485,11 +488,11 @@ filter(x -> x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
# Julia has a type system.
# Every value has a type; variables do not have types themselves.
# You can use the `typeof` function to get the type of a value.
-typeof(5) #=> Int64
+typeof(5) # => Int64
# Types are first-class values
-typeof(Int64) #=> DataType
-typeof(DataType) #=> DataType
+typeof(Int64) # => DataType
+typeof(DataType) # => DataType
# DataType is the type that represents types, including itself.
# Types are used for documentation, optimizations, and dispatch.
@@ -510,10 +513,10 @@ end
# The default constructor's arguments are the properties
# of the type, in the order they are listed in the definition
-tigger = Tiger(3.5,"orange") #=> Tiger(3.5,"orange")
+tigger = Tiger(3.5,"orange") # => Tiger(3.5,"orange")
# The type doubles as the constructor function for values of that type
-sherekhan = typeof(tigger)(5.6,"fire") #=> Tiger(5.6,"fire")
+sherekhan = typeof(tigger)(5.6,"fire") # => Tiger(5.6,"fire")
# These struct-style types are called concrete types
# They can be instantiated, but cannot have subtypes.
@@ -524,23 +527,23 @@ abstract Cat # just a name and point in the type hierarchy
# Abstract types cannot be instantiated, but can have subtypes.
# For example, Number is an abstract type
-subtypes(Number) #=> 6-element Array{Any,1}:
+subtypes(Number) # => 6-element Array{Any,1}:
# Complex{Float16}
# Complex{Float32}
# Complex{Float64}
# Complex{T<:Real}
# ImaginaryUnit
# Real
-subtypes(Cat) #=> 0-element Array{Any,1}
+subtypes(Cat) # => 0-element Array{Any,1}
# Every type has a super type; use the `super` function to get it.
-typeof(5) #=> Int64
-super(Int64) #=> Signed
-super(Signed) #=> Real
-super(Real) #=> Number
-super(Number) #=> Any
-super(super(Signed)) #=> Number
-super(Any) #=> Any
+typeof(5) # => Int64
+super(Int64) # => Signed
+super(Signed) # => Real
+super(Real) # => Number
+super(Number) # => Any
+super(super(Signed)) # => Number
+super(Any) # => Any
# All of these type, except for Int64, are abstract.
# <: is the subtyping operator
@@ -560,7 +563,7 @@ type Panther <: Cat # Panther is also a subtype of Cat
Panther() = new("green")
# Panthers will only have this constructor, and no default constructor.
end
-# Using inner constructors, like Panter does, gives you control
+# Using inner constructors, like Panther does, gives you control
# over how values of the type can be created.
# When possible, you should use outer constructors rather than inner ones.
@@ -588,23 +591,23 @@ function meow(animal::Tiger)
end
# Testing the meow function
-meow(tigger) #=> "rawwr"
-meow(Lion("brown","ROAAR")) #=> "ROAAR"
-meow(Panther()) #=> "grrr"
+meow(tigger) # => "rawwr"
+meow(Lion("brown","ROAAR")) # => "ROAAR"
+meow(Panther()) # => "grrr"
# Review the local type hierarchy
-issubtype(Tiger,Cat) #=> false
-issubtype(Lion,Cat) #=> true
-issubtype(Panther,Cat) #=> true
+issubtype(Tiger,Cat) # => false
+issubtype(Lion,Cat) # => true
+issubtype(Panther,Cat) # => true
# Defining a function that takes Cats
function pet_cat(cat::Cat)
println("The cat says $(meow(cat))")
end
-pet_cat(Lion("42")) #=> prints "The cat says 42"
+pet_cat(Lion("42")) # => prints "The cat says 42"
try
- pet_cat(tigger) #=> ERROR: no method pet_cat(Tiger,)
+ pet_cat(tigger) # => ERROR: no method pet_cat(Tiger,)
catch e
println(e)
end
@@ -617,31 +620,31 @@ end
function fight(t::Tiger,c::Cat)
println("The $(t.coatcolor) tiger wins!")
end
-#=> fight (generic function with 1 method)
+# => fight (generic function with 1 method)
-fight(tigger,Panther()) #=> prints The orange tiger wins!
-fight(tigger,Lion("ROAR")) #=> prints The orange tiger wins!
+fight(tigger,Panther()) # => prints The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => prints The orange tiger wins!
# Let's change the behavior when the Cat is specifically a Lion
fight(t::Tiger,l::Lion) = println("The $(l.mane_color)-maned lion wins!")
-#=> fight (generic function with 2 methods)
+# => fight (generic function with 2 methods)
-fight(tigger,Panther()) #=> prints The orange tiger wins!
-fight(tigger,Lion("ROAR")) #=> prints The green-maned lion wins!
+fight(tigger,Panther()) # => prints The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => prints The green-maned lion wins!
# We don't need a Tiger in order to fight
fight(l::Lion,c::Cat) = println("The victorious cat says $(meow(c))")
-#=> fight (generic function with 3 methods)
+# => fight (generic function with 3 methods)
-fight(Lion("balooga!"),Panther()) #=> prints The victorious cat says grrr
+fight(Lion("balooga!"),Panther()) # => prints The victorious cat says grrr
try
- fight(Panther(),Lion("RAWR")) #=> ERROR: no method fight(Panther,Lion)
+ fight(Panther(),Lion("RAWR")) # => ERROR: no method fight(Panther,Lion)
catch
end
# Also let the cat go first
fight(c::Cat,l::Lion) = println("The cat beats the Lion")
-#=> Warning: New definition
+# => Warning: New definition
# fight(Cat,Lion) at none:1
# is ambiguous with
# fight(Lion,Cat) at none:2.
@@ -651,12 +654,89 @@ fight(c::Cat,l::Lion) = println("The cat beats the Lion")
#fight (generic function with 4 methods)
# This warning is because it's unclear which fight will be called in:
-fight(Lion("RAR"),Lion("brown","rarrr")) #=> prints The victorious cat says rarrr
+fight(Lion("RAR"),Lion("brown","rarrr")) # => prints The victorious cat says rarrr
# The result may be different in other versions of Julia
fight(l::Lion,l2::Lion) = println("The lions come to a tie")
-fight(Lion("RAR"),Lion("brown","rarrr")) #=> prints The lions come to a tie
-
+fight(Lion("RAR"),Lion("brown","rarrr")) # => prints The lions come to a tie
+
+
+# Under the hood
+# You can take a look at the llvm and the assembly code generated.
+
+square_area(l) = l * l # square_area (generic function with 1 method)
+
+square_area(5) #25
+
+# What happens when we feed square_area an integer?
+code_native(square_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1 # Prologue
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # movsxd RAX, EDI # Fetch l from memory?
+ # imul RAX, RAX # Square l and store the result in RAX
+ # pop RBP # Restore old base pointer
+ # ret # Result will still be in RAX
+
+code_native(square_area, (Float32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulss XMM0, XMM0, XMM0 # Scalar single precision multiply (AVX)
+ # pop RBP
+ # ret
+
+code_native(square_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulsd XMM0, XMM0, XMM0 # Scalar double precision multiply (AVX)
+ # pop RBP
+ # ret
+ #
+# Note that julia will use floating point instructions if any of the
+# arguements are floats.
+# Let's calculate the area of a circle
+circle_area(r) = pi * r * r # circle_area (generic function with 1 method)
+circle_area(5) # 78.53981633974483
+
+code_native(circle_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vcvtsi2sd XMM0, XMM0, EDI # Load integer (r) from memory
+ # movabs RAX, 4593140240 # Load pi
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r
+ # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r
+ # pop RBP
+ # ret
+ #
+
+code_native(circle_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # movabs RAX, 4593140496
+ # Source line: 1
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX]
+ # vmulsd XMM0, XMM1, XMM0
+ # pop RBP
+ # ret
+ #
```
## Further Reading
diff --git a/ko-kr/coffeescript-kr.html.markdown b/ko-kr/coffeescript-kr.html.markdown
index 7d00a0fe..f8ac8069 100644
--- a/ko-kr/coffeescript-kr.html.markdown
+++ b/ko-kr/coffeescript-kr.html.markdown
@@ -3,7 +3,7 @@ language: coffeescript
category: language
contributors:
- ["Tenor Biel", "http://github.com/L8D"]
-filename: coffeescript.coffee
+filename: coffeescript-kr.coffee
translators:
- ["wikibook", "http://wikibook.co.kr"]
lang: ko-kr
diff --git a/ko-kr/go-kr.html.markdown b/ko-kr/go-kr.html.markdown
new file mode 100644
index 00000000..e6ebe097
--- /dev/null
+++ b/ko-kr/go-kr.html.markdown
@@ -0,0 +1,314 @@
+---
+name: Go
+category: language
+language: Go
+filename: learngo-kr.go
+contributors:
+ - ["Sonia Keys", "https://github.com/soniakeys"]
+translators:
+ - ["Jongmin Kim", "http://github.com/atomaths"]
+lang: ko-kr
+---
+
+Go는 어떤 일을 잘 끝낼 수 있도록 하기위해 만들어졌다. Go가 잘 알려진 최신의
+트렌드는 아니지만, 실세계의 문제들을 해결하기 위해서는 가장
+새롭고 빠른 방법이다.
+
+Go는 정적 타이핑(static typing)의 명령형 언어들(imperative languages)이
+갖고 있는 특징과 유사한 개념들을 가지고 있다. Go는 컴파일과 실행속도가
+빠르며, 오늘날의 멀티코어 CPU를 위해 이해하기 쉬운 동시성(concurrency)
+기능이 추가되었다. 그리고 큰 스케일의 프로그래밍에도 도움이 되는
+기능들을 가지고 있다.
+
+또한 Go에는 훌륭한 표준 라이브러리와 열정적인 커뮤니티가 있다.
+
+```go
+// 한 줄 주석
+/* 여러 줄
+ 주석 */
+
+// 모든 Go 소스 파일은 package로 시작한다.
+// 패키지 이름 중 main은 라이브러리가 아닌 실행파일을 선언하는 특별한 이름이다.
+package main
+
+// import는 이 Go 소스 파일 내에서 참조하는 라이브러리 패키지들을 선언한다.
+import (
+ "fmt" // Go 표준 라이브러리에 있는 패키지
+ "net/http" // 표준 라이브러리에는 웹 서버 패키지도 있다! (클라이언트도 있음)
+ "strconv" // 문자열 변환 패키지
+)
+
+// 함수 선언. main은 실행 프로그램에서 시작점이 되는 특별한 함수다.
+// 중괄호를 사용한다.
+func main() {
+ // Println은 표준 출력으로 개행을 출력한다.
+ // fmt 패키지를 통해 이용할 수 있다.
+ fmt.Println("Hello world!")
+
+ // 다른 함수를 호출한다.
+ beyondHello()
+}
+
+// 함수에 파라미터가 없더라도 빈 괄호는 있어야 한다.
+func beyondHello() {
+ var x int // 변수 선언. 변수는 사용하기 전에 선언해야 한다.
+ x = 3 // 변수에 값 할당.
+ // 짧은 선언(short declaration)으로 := 를 사용하는데,
+ // 이렇게 값을 할당하면 값의 타입에 따라 변수의 타입이 결정된다.
+ y := 4
+ sum, prod := learnMultiple(x, y) // 함수는 두 개 이상의 리턴 값을 줄 수 있다.
+ fmt.Println("sum:", sum, "prod:", prod) // 간단한 출력
+ learnTypes() // 잠시 후에 좀더 자세히!
+}
+
+// 함수는 파라미터들을 가질 수 있고, 복수개의 값을 리턴할 수 있다.
+func learnMultiple(x, y int) (sum, prod int) {
+ return x + y, x * y // 두 개의 값을 리턴.
+}
+
+// 내장 타입과 리터럴
+func learnTypes() {
+ // 짧은 선언은 유용하다.
+ s := "Learn Go!" // string 타입
+
+ s2 := `역따옴표 안의 string 리터럴은
+개행을 포함할 수 있다.` // 같은 string 타입
+
+ // non-ASCII 리터럴. Go 소스는 UTF-8로 작성해야 한다.
+ g := 'Σ' // 유니코드 코드 포인트를 담고 있고, uint32 타입의 가칭(alias)인 rune 타입
+
+ f := 3.14195 // float64, an IEEE-754 64-bit 부동소수 타입
+ c := 3 + 4i // complex128, 내부적으로는 두 개의 float64 타입으로 표현됨
+
+ // 초기값과 함께 사용하는 var 키워드.
+ var u uint = 7 // unsigned, 하지만 int에 따른 구현의존적인 크기
+ var pi float32 = 22. / 7
+
+ // 짧은 선언으로 변환(conversion)하는 문법.
+ // Go에서는 type casting 이라고 하지않고 type conversion 이라고 함.
+ n := byte('\n') // byte는 uint8의 가칭(alias)
+
+ // 배열은 컴파일 시에 크기가 정해진다.
+ var a4 [4]int // 모두 0으로 초기화되는 int 타입 4개짜리 배열
+ a3 := [...]int{3, 1, 5} // 3, 1, 5로 초기화되는 int 타입 3개짜리 배열
+
+ // 슬라이스(slice)라고 하는 타입은 배열에 대한 가변 크기를 가진다.
+ // 배열, 슬라이스 각자 장점이 있지만, 슬라이스가 더 많이 사용된다.
+ s3 := []int{4, 5, 9} // 위의 a3와 비교해보면 생략부호(...)가 없다.
+ s4 := make([]int, 4) // 모두 0으로 초기화되는 int 4개에 대한 슬라이스를 할당.
+ var d2 [][]float64 // 여기에서는 선언만 있고 할당은 없다.
+ bs := []byte("a slice") // string 타입을 byte 슬라이스 타입으로 형변환(type conversion)
+
+ p, q := learnMemory() // int에 대한 포인터 타입인 p와 q를 선언
+ fmt.Println(*p, *q) // C에서처럼 *는 포인터를 따라가 값을 참조한다. 여기서는 두 개의 int를 출력.
+
+ // 맵(map)은 다른 언어의 해시(hash)나 딕셔너리(dictionary)처럼 가변의 연관배열 타입.
+ m := map[string]int{"three": 3, "four": 4}
+ m["one"] = 1
+
+ // 선언만 하고 사용하지 않는 변수가 있다면 Go에서는 컴파일 시 에러가 난다.
+ // 언더바를 이용해서 변수를 사용한 것처럼 하고 그 값은 무시해버릴 수 있다.
+ _, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
+ // 물론 출력을 하면 변수로 취급한다.
+ fmt.Println(s, c, a4, s3, d2, m)
+
+ learnFlowControl() // 잠시 후에 다시 나옴
+}
+
+// Go는 가비지 컬렉션 기능을 JVM 같은 곳이 아닌 실행파일 런타임에 포함하고 있다.
+// 그리고 포인터는 있지만, 포인터 연산(*p++ 같은)은 없다.
+// 그래서 nil 포인터 접근같은 것 때문에 실수를 할 수는 있지만
+// 포인터 연산으로 인한 실수는 없게 된다.
+func learnMemory() (p, q *int) {
+ // 지명된 리턴 값(named return value)인 p와 q는 int에 대한 포인터 타입이다.
+ p = new(int) // 내장함수인 new는 메모리를 할당해준다.
+ // 메모리 할당된 int는 0으로 초기화 되고, p는 이제 nil이 아니다.
+ 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 소스의 코드 포맷팅은 "go fmt" 커맨드라인 명령으로 소스코드의 포맷을 맞춘다.
+ if false {
+ // pout
+ } else {
+ // gloat
+ }
+ // if-else 체인 형태보다 switch 사용이 권장된다.
+ x := 1
+ switch x {
+ case 0:
+ case 1:
+ // case 안에서는 break가 없어도 자동으로 다음 case로 내려가지 않는다.
+ // 자동으로 내려가게 하려면 fallthrough 키워드를 사용한다.
+ case 2:
+ // x는 1이므로 여기는 실행되지 않음.
+ }
+ // if 에서처럼 for 에서도 양쪽에 소괄호를 쓰지 않는다.
+ for x := 0; x < 3; x++ { // ++ 은 실행을 제어하는 하나의 구문(statement)이다.
+ fmt.Println("iteration", x)
+ }
+ // 여기서 x는 1이다. 위 for에서 x는 for 안의 블록 범위에 있기 때문.
+
+ // For is the only loop statement in Go, but it has alternate forms.
+ // for 는 Go에서 유일한 루프 구문이지만 다양한 형태로 조건을 주거나 while
+ // 처럼 쓸 수도 있다.
+ for { // 무한루프
+ break // 여기서 곧바로 break를 한 건 단지
+ continue // break, continue를 루프 안에서 쓸 수 있다는 것을 보여주기 위함.
+ }
+ // for 에서처럼 if 에서 := 를 사용하는것은 y에 먼저 값을 대입하고,
+ // 그리고 y > x를 검사한다는 의미.
+ if y := expensiveComputation(); y > x {
+ x = y
+ }
+ // 함수 리터럴은 클로저다.
+ xBig := func() bool {
+ return x > 100 // 위 switch 문 바로 위에 있는 x를 참조한다.
+ }
+ fmt.Println("xBig:", xBig()) // true (x에 1e6를 대입했었다.)
+ x /= 1e5 // x는 10이 된다.
+ fmt.Println("xBig:", xBig()) // 이제 xBig()의 결과는 false가 된다.
+
+ // `goto`가 필요하다면, 좋아하게 될지도...
+ goto love
+love:
+
+ learnInterfaces() // 곧이어서 좋은 기능에 대한 설명이 나올 거다.
+}
+
+// String 이라는 메서드 하나를 가진 Stringer 라는 인터페이스 타입을 정의하자.
+type Stringer interface {
+ String() string
+}
+
+// x와 y라는 이름의 int 타입 필드를 가진 pair라는 struct를 정의하자.
+type pair struct {
+ x, y int
+}
+
+// pair 타입에 메서드 String을 정의하자.
+// 이제 pair는 Stringer 인터페이스를 구현(implement)한 것이 되었다.
+func (p pair) String() string { // 여기서 p는 리시버(receiver)라고 부른다.
+ // Sprintf는 fmt 패키지 안에 있는 외부로 공개된(exported) 함수다.
+ // 점(.)으로 p의 필드들을 참조할 수 있다.
+ return fmt.Sprintf("(%d, %d)", p.x, p.y)
+}
+
+func learnInterfaces() {
+ // 중괄호 문법은 "구조체 리터럴(struct literal)"인데, 초기화된 구조체로
+ // 취급하게 해준다. := 문법으로 p를 이 구조체로 선언하고 초기화한다.
+ p := pair{3, 4}
+ fmt.Println(p.String()) // 타입 pair인 p의 String 메서드를 호출.
+ var i Stringer // Stringer 인터페이스 타입 i를 선언.
+ i = p // pair는 Stringer를 구현했기 때문에 이 대입은 유효하다.
+ // 타입 Stringer인 i의 String 메서드 호출. 결과는 위와 같다.
+ fmt.Println(i.String())
+
+ // fmt 패키지의 함수들을 통해 어떤 객체를 출력해보려고 할 때,
+ // fmt 패키지 내에서는 그 객체가 가진 String 메서드를 호출하도록 되어 있다.
+ fmt.Println(p) // 결과는 위와 같다. Println은 String 메서드를 호출한다.
+ fmt.Println(i) // 결과는 위와 같다.
+
+ learnErrorHandling()
+}
+
+func learnErrorHandling() {
+ // ", ok" (comma okay)표현은 무언가가 맞는 것인지 아닌지 확인하는데 사용된다.
+ m := map[int]string{3: "three", 4: "four"}
+ if x, ok := m[1]; !ok { // 이 map 안에 키가 1인 것은 없으므로 ok는 false가 된다.
+ fmt.Println("no one there")
+ } else {
+ fmt.Print(x) // 만일 1이 map에 있었다면 x는 키 1의 값이 들어가게 된다.
+ }
+
+ // Go에서는 함수가 복수 개의 리턴 값을 줄 수 있다는 점을 활용해 함수의 두 번째 리턴
+ // 값으로 error를 리턴해주고 그 error가 nil 인지 아닌지 확인하는 관례가 있다.
+ // 이때 이 error 값은 단지 위에서처럼 함수의 결과가 성공했는지 실패했는지를 확인하는
+ // 것뿐만 아니라 실패 시 어떤 문제가 있었는지 확인할 수 있는 수단도 된다.
+ if _, err := strconv.Atoi("non-int"); err != nil { // _ 는 값을 안 쓰고 버린다는 의미.
+ // "strconv.ParseInt: parsing "non-int": invalid syntax" 이런 에러가 출력된다.
+ fmt.Println(err)
+ }
+ // 인터페이스에 대해 잠시 후에 다시 잠깐 볼 것이다.
+ learnConcurrency()
+}
+
+// c는 goroutine 간의 통신을 위한 채널(channel)이다.
+func inc(i int, c chan int) {
+ c <- i + 1 // 채널이 <- 이 연산자 왼쪽에 온다면 그 채널로 데이터를 보낸다는 의미다.
+}
+
+// 우리는 어떤 숫자들을 동시에 증가시키기 위해 inc 함수를 사용할 것이다.
+func learnConcurrency() {
+ // make는 slice, map, channel 타입들에 대해 메모리를 할당하고 초기화를 한다.
+ // Go에는 메모리 할당 방법으로 new와 make가 있다.
+ c := make(chan int)
+ // 3개의 동시에 실행되는 goroutine를 시작한다. 만약 실행하고 있는 머신이
+ // 멀티코어 CPU를 가지고 있고 올바르게 설정되어(GOMAXPROCS) 있다면
+ // 숫자가 정말로 병렬적으로 증가하게 될 것이다.
+ go inc(0, c) // go는 새로운 goroutine을 시작하는 구문이다.
+ go inc(10, c)
+ go inc(-805, c)
+ // 채널로부터 3개의 결과를 읽어 출력한다.
+ // 결과가 어떤 순서로 오는지는 알 수 없다.
+ fmt.Println(<-c, <-c, <-c) // 채널이 <- 연산자 오른쪽에 있는 건, 채널로부터 데이터를 받는 연산이다.
+
+ cs := make(chan string) // string을 다루는 또 다른 채널
+ cc := make(chan chan string) // string 채널의 채널
+ go func() { c <- 84 }() // c 채널로 값을 보내는 goroutine 시작.
+ go func() { cs <- "wordy" }() // cs 채널로 값을 보내느 goroutine 시작.
+ // select 구문은 switch 문과 비슷하지만, case에서 채널 연산에 관한 일을 한다.
+ // select의 case들은 채널통신을 할 준비가 된 case 하나가 무작위로 선택되어
+ // 그 부분이 실행된다.
+ select {
+ case i := <-c: // 채널로부터 받아진 값은 변수에 대입할 수 있다.
+ fmt.Printf("it's a %T", i)
+ case <-cs: // 또는 받은 값을 그냥 버릴 수도 있다.
+ fmt.Println("it's a string")
+ case <-cc: // 통신할 준비가 되어 있지 않은 비어있는 채널.
+ fmt.Println("didn't happen.")
+ }
+ // 여기서는 c나 cs 채널로부터 값 하나를 받을 수 있다. 위에서 실행한 두 개의
+ // goroutine 중 하나가 완료되면 다른 하나는 블락된 상태로 있게 된다.
+
+ learnWebProgramming() // Go에서는 웹 서버쪽 개발도 쉽게 할 수 있다.
+}
+
+// http 패키지의 함수 하나로 웹 서버를 실행시킨다.
+func learnWebProgramming() {
+ // ListenAndServe의 첫 번째 파라미터는 listen 하기 위한 TCP 주소고,
+ // 두 번째 파라미터는 http.Handler 인터페이스다.
+ err := http.ListenAndServe(":8080", pair{})
+ fmt.Println(err) // don't ignore errors
+}
+
+// http.Handler의 하나 뿐인 메서드, ServeHTTP를 pair에서 구현한다.
+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/)를 참고하자.
+여기에는 따라해볼 튜토리얼, 웹 기반의 인터랙티브 실행환경과 많은 읽을거리들이 있다.
+
+Go 언어 자체에 대한 스펙도 읽어보기를 적극 추천한다. 읽기 쉽게 되어있고
+그리 길지는 않다.
+
+Go 소스코드에 대해 좀더 알아보고 싶다면 [Go 표준 라이브러리](http://golang.org/src/pkg/)를
+분석해보기 바란다. 이해하기 쉽게 문서화되어 있고, Go 스타일 그리고 Go에서의
+관례 배우기에 가장 좋은 방법일 것이다. 또는 [문서](http://golang.org/pkg/) 안에서
+함수 이름 하나를 클릭해보면 소스코드를 브라우저에서 살펴볼 수도 있다.
diff --git a/ko-kr/javascript-kr.html.markdown b/ko-kr/javascript-kr.html.markdown
index e5517aa8..f651fbe7 100644
--- a/ko-kr/javascript-kr.html.markdown
+++ b/ko-kr/javascript-kr.html.markdown
@@ -5,6 +5,7 @@ contributors:
- ["Adam Brenecki", "http://adam.brenecki.id.au"]
translators:
- ["wikibook", "http://wikibook.co.kr"]
+filename: javascript-kr.js
lang: ko-kr
---
diff --git a/ko-kr/lua-kr.html.markdown b/ko-kr/lua-kr.html.markdown
index 862c47a7..850587a0 100644
--- a/ko-kr/lua-kr.html.markdown
+++ b/ko-kr/lua-kr.html.markdown
@@ -6,6 +6,7 @@ contributors:
translators:
- ["wikibook", "http://wikibook.co.kr"]
lang: ko-kr
+filename: learnlua-kr.lua
---
```lua
diff --git a/ko-kr/php-kr.html.markdown b/ko-kr/php-kr.html.markdown
index 2382a8fb..80f324f3 100644
--- a/ko-kr/php-kr.html.markdown
+++ b/ko-kr/php-kr.html.markdown
@@ -4,7 +4,7 @@ category: language
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
-filename: learnphp.php
+filename: learnphp-kr.php
translators:
- ["wikibook", "http://wikibook.co.kr"]
lang: ko-kr
diff --git a/ko-kr/racket-kr.html.markdown b/ko-kr/racket-kr.html.markdown
new file mode 100644
index 00000000..8d830279
--- /dev/null
+++ b/ko-kr/racket-kr.html.markdown
@@ -0,0 +1,640 @@
+---
+
+language: racket
+filename: learnracket-kr.rkt
+contributors:
+ - ["th3rac25", "https://github.com/voila"]
+ - ["Eli Barzilay", "https://github.com/elibarzilay"]
+ - ["Gustavo Schmidt", "https://github.com/gustavoschmidt"]
+ - ["Duong H. Nguyen", "https://github.com/cmpitg"]
+translators:
+ - ["KIM Taegyoon", "https://github.com/kimtg"]
+lang: ko-kr
+---
+
+Racket 은 Lisp/Scheme 계열의 일반 목적의, 다중 패러다임 프로그래밍 언어이다.
+
+```racket
+#lang racket ; 우리가 사용하는 언어를 정의한다.
+
+;;; 주석
+
+;; 한 줄 주석은 세미콜론으로 시작한다.
+
+#| 블록 주석
+ 은 여러 줄에 걸칠 수 있으며...
+ #|
+ 중첩될 수 있다!
+ |#
+|#
+
+;; S-expression 주석은 아래 식을 버리므로,
+;; 디버깅할 때 식을 주석화할 때 유용하다.
+#; (이 식은 버려짐)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 1. 근본 자료형과 연산자
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 숫자
+9999999999999999999999 ; 정수
+#b111 ; 이진수 => 7
+#o111 ; 팔진수 => 73
+#x111 ; 16진수 => 273
+3.14 ; 실수
+6.02e+23
+1/2 ; 분수
+1+2i ; 복소수
+
+;; 함수 적용은 이렇게 쓴다: (f x y z ...)
+;; 여기에서 f는 함수이고 x, y, z는 피연산자이다.
+;; 글자 그대로의 데이터 리스트를 만들고 싶다면 평가를 막기 위해 '를 쓰시오.
+'(+ 1 2) ; => (+ 1 2)
+;; 이제, 산술 연산 몇 개
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(expt 2 3) ; => 8
+(quotient 5 2) ; => 2
+(remainder 5 2) ; => 1
+(/ 35 5) ; => 7
+(/ 1 3) ; => 1/3
+(exact->inexact 1/3) ; => 0.3333333333333333
+(+ 1+2i 2-3i) ; => 3-1i
+
+;;; 불린
+#t ; 참
+#f ; 거짓 -- #f가 아닌 것은 참
+(not #t) ; => #f
+(and 0 #f (error "doesn't get here")) ; => #f
+(or #f 0 (error "doesn't get here")) ; => 0
+
+;;; 문자
+#\A ; => #\A
+#\λ ; => #\λ
+#\u03BB ; => #\λ
+
+;;; 문자열은 고정 길이의 문자 배열이다.
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; 백슬래시는 탈출 문자이다.
+"Foo\tbar\41\x21\u0021\a\r\n" ; C 탈출 문자, 유니코드 포함
+"λx:(μα.α→α).xx" ; 유니코드 문자 포함 가능
+
+;; 문자열은 붙여질 수 있다!
+(string-append "Hello " "world!") ; => "Hello world!"
+
+;; 문자열은 문자의 리스트처럼 취급될 수 있다.
+(string-ref "Apple" 0) ; => #\A
+
+;; format은 문자열을 형식화하기 위해 사용된다:
+(format "~a can be ~a" "strings" "formatted")
+
+;; 인쇄는 쉽다.
+(printf "I'm Racket. Nice to meet you!\n")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. 변수
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; define으로 변수를 만든다.
+;; 변수명으로 다음 문자를 사용할 수 없다: ()[]{}",'`;#|\
+(define some-var 5)
+some-var ; => 5
+
+;; 유니코드 문자도 사용 가능하다.
+(define ⊆ subset?)
+(⊆ (set 3 2) (set 1 2 3)) ; => #t
+
+;; 앞에서 정의되지 않은 변수에 접근하면 예외가 발생한다.
+; x ; => x: undefined ...
+
+;; 지역 변수: `me'는 (let ...) 안에서만 "Bob"이다.
+(let ([me "Bob"])
+ "Alice"
+ me) ; => "Bob"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 구조체(Struct)와 모음(Collection)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 구조체
+(struct dog (name breed age))
+(define my-pet
+ (dog "lassie" "collie" 5))
+my-pet ; => #<dog>
+(dog? my-pet) ; => #t
+(dog-name my-pet) ; => "lassie"
+
+;;; 쌍 (불변)
+;; `cons'는 쌍을 만들고, `car'와 `cdr'는 첫번째와
+;; 두번째 원소를 추출한다.
+(cons 1 2) ; => '(1 . 2)
+(car (cons 1 2)) ; => 1
+(cdr (cons 1 2)) ; => 2
+
+;;; 리스트
+
+;; 리스트는 연결-리스트 데이터 구조이며, `cons' 쌍으로 만들어지며
+;; `null' (또는 '()) 로 리스트의 끝을 표시한다.
+(cons 1 (cons 2 (cons 3 null))) ; => '(1 2 3)
+;; `list'는 편리한 가변인자 리스트 생성자이다.
+(list 1 2 3) ; => '(1 2 3)
+;; 글자 그대로의 리스트 값에는 인용부호를 쓴다.
+'(1 2 3) ; => '(1 2 3)
+
+;; 리스트의 앞에 항목을 추가하기 위하여 `cons'를 사용한다.
+(cons 4 '(1 2 3)) ; => '(4 1 2 3)
+
+;; 리스트들을 붙이기 위해 `append'를 사용한다.
+(append '(1 2) '(3 4)) ; => '(1 2 3 4)
+
+;; 리스트는 매우 기본적인 자료형이기 때문에, 리스트에 대해 적용되는 많은 기능들이 있다.
+;; 예를 들어:
+(map add1 '(1 2 3)) ; => '(2 3 4)
+(map + '(1 2 3) '(10 20 30)) ; => '(11 22 33)
+(filter even? '(1 2 3 4)) ; => '(2 4)
+(count even? '(1 2 3 4)) ; => 2
+(take '(1 2 3 4) 2) ; => '(1 2)
+(drop '(1 2 3 4) 2) ; => '(3 4)
+
+;;; 벡터
+
+;; 벡터는 고정 길이의 배열이다.
+#(1 2 3) ; => '#(1 2 3)
+
+;; `vector-append'를 사용하여 벡터들을 붙인다.
+(vector-append #(1 2 3) #(4 5 6)) ; => #(1 2 3 4 5 6)
+
+;;; 집합
+
+;; 리스트로부터 집합 만들기
+(list->set '(1 2 3 1 2 3 3 2 1 3 2 1)) ; => (set 1 2 3)
+
+;; 원소를 추가하려면 `set-add'를 사용한다.
+;; (함수적: 확장된 집합을 반환하며, 원래의 입력을 변경하지 않는다.)
+(set-add (set 1 2 3) 4) ; => (set 1 2 3 4)
+
+;; 원소를 삭제하려면 `set-remove'
+(set-remove (set 1 2 3) 1) ; => (set 2 3)
+
+;; 존재 여부를 조사하려면 `set-member?'
+(set-member? (set 1 2 3) 1) ; => #t
+(set-member? (set 1 2 3) 4) ; => #f
+
+;;; 해시
+
+;; 불변의 해시 테이블을 만든다. (가변 예제는 아래에)
+(define m (hash 'a 1 'b 2 'c 3))
+
+;; 값 꺼내기
+(hash-ref m 'a) ; => 1
+
+;; 없는 값을 꺼내는 것은 예외를 발생시킨다.
+; (hash-ref m 'd) => no value found
+
+;; 키가 없을 때 반환할 기본값을 지정할 수 있다.
+(hash-ref m 'd 0) ; => 0
+
+;; `hash-set'을 사용하여 불변의 해시 테이블을 확장
+;; (원래 것을 변경하지 않고 확장된 해시를 반환한다.)
+(define m2 (hash-set m 'd 4))
+m2 ; => '#hash((b . 2) (a . 1) (d . 4) (c . 3))
+
+;; 이 해시들은 불변이라는 점을 기억하시오!
+m ; => '#hash((b . 2) (a . 1) (c . 3)) <-- no `d'
+
+;; `hash-remove'로 키를 삭제 (이것도 함수적)
+(hash-remove m 'a) ; => '#hash((b . 2) (c . 3))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. 함수
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; `lambda'로 함수를 만든다.
+;; 함수는 항상 마지막 식을 반환한다.
+(lambda () "Hello World") ; => #<procedure>
+;; 유니코드 `λ'도 사용 가능
+(λ () "Hello World") ; => same function
+
+;; 모든 함수를 호출할 때는 괄호를 쓴다, lambda 식도 포함하여.
+((lambda () "Hello World")) ; => "Hello World"
+((λ () "Hello World")) ; => "Hello World"
+
+;; 변수에 함수를 할당
+(define hello-world (lambda () "Hello World"))
+(hello-world) ; => "Hello World"
+
+;; 문법적 설탕을 사용하여 함수 정의를 더 짧게할 수 있다:
+(define (hello-world2) "Hello World")
+
+;; 위에서 ()는 함수의 인자 리스트이다.
+(define hello
+ (lambda (name)
+ (string-append "Hello " name)))
+(hello "Steve") ; => "Hello Steve"
+;; ... 또는, 설탕 친 정의로:
+(define (hello2 name)
+ (string-append "Hello " name))
+
+;; 가변인자 함수에는 `case-lambda'를 사용한다.
+(define hello3
+ (case-lambda
+ [() "Hello World"]
+ [(name) (string-append "Hello " name)]))
+(hello3 "Jake") ; => "Hello Jake"
+(hello3) ; => "Hello World"
+;; ... 또는 선택적 인자에 기본값 지정
+(define (hello4 [name "World"])
+ (string-append "Hello " name))
+
+;; 함수는 추가 인자를 리스트에 포장할 수 있다.
+(define (count-args . args)
+ (format "You passed ~a args: ~a" (length args) args))
+(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)"
+;; ... 설탕 안 친 `lambda' 형식으로는:
+(define count-args2
+ (lambda args
+ (format "You passed ~a args: ~a" (length args) args)))
+
+;; 일반 인자와 포장된 인자를 섞을 수 있다.
+(define (hello-count name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args)))
+(hello-count "Finn" 1 2 3)
+; => "Hello Finn, you passed 3 extra args"
+;; ... 설탕 안 친 것:
+(define hello-count2
+ (lambda (name . args)
+ (format "Hello ~a, you passed ~a extra args" name (length args))))
+
+;; 키워드 인자
+(define (hello-k #:name [name "World"] #:greeting [g "Hello"] . args)
+ (format "~a ~a, ~a extra args" g name (length args)))
+(hello-k) ; => "Hello World, 0 extra args"
+(hello-k 1 2 3) ; => "Hello World, 3 extra args"
+(hello-k #:greeting "Hi") ; => "Hi World, 0 extra args"
+(hello-k #:name "Finn" #:greeting "Hey") ; => "Hey Finn, 0 extra args"
+(hello-k 1 2 3 #:greeting "Hi" #:name "Finn" 4 5 6)
+ ; => "Hi Finn, 6 extra args"
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. 동등성
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 숫자에는 `='를 사용하시오.
+(= 3 3.0) ; => #t
+(= 2 1) ; => #f
+
+;; 개체의 동등성에는 `eq?'를 사용하시오.
+(eq? 3 3) ; => #t
+(eq? 3 3.0) ; => #f
+(eq? (list 3) (list 3)) ; => #f
+
+;; 모음에는 `equal?'을 사용하시오.
+(equal? (list 'a 'b) (list 'a 'b)) ; => #t
+(equal? (list 'a 'b) (list 'b 'a)) ; => #f
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. 흐름 제어하기
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; 조건
+
+(if #t ; 조사 식
+ "this is true" ; 그러면 식
+ "this is false") ; 아니면 식
+; => "this is true"
+
+;; 조건에서는 #f가 아니면 참으로 취급된다.
+(member 'Groucho '(Harpo Groucho Zeppo)) ; => '(Groucho Zeppo)
+(if (member 'Groucho '(Harpo Groucho Zeppo))
+ 'yep
+ 'nope)
+; => 'yep
+
+;; `cond'는 연속하여 조사하여 값을 선택한다.
+(cond [(> 2 2) (error "wrong!")]
+ [(< 2 2) (error "wrong again!")]
+ [else 'ok]) ; => 'ok
+
+;;; 양식 맞춤
+
+(define (fizzbuzz? n)
+ (match (list (remainder n 3) (remainder n 5))
+ [(list 0 0) 'fizzbuzz]
+ [(list 0 _) 'fizz]
+ [(list _ 0) 'buzz]
+ [_ #f]))
+
+(fizzbuzz? 15) ; => 'fizzbuzz
+(fizzbuzz? 37) ; => #f
+
+;;; 반복
+
+;; 반복은 (꼬리-) 재귀로 한다.
+(define (loop i)
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i))))
+(loop 5) ; => i=5, i=6, ...
+
+;; 이름 있는 let으로도...
+(let loop ((i 0))
+ (when (< i 10)
+ (printf "i=~a\n" i)
+ (loop (add1 i)))) ; => i=0, i=1, ...
+
+;; Racket은 매우 유연한 `for' 형식을 가지고 있다:
+(for ([i 10])
+ (printf "i=~a\n" i)) ; => i=0, i=1, ...
+(for ([i (in-range 5 10)])
+ (printf "i=~a\n" i)) ; => i=5, i=6, ...
+
+;;; 다른 Sequence들을 순회하는 반복
+;; `for'는 여러 가지의 sequence를 순회할 수 있다:
+;; 리스트, 벡터, 문자열, 집합, 해시 테이블 등...
+
+(for ([i (in-list '(l i s t))])
+ (displayln i))
+
+(for ([i (in-vector #(v e c t o r))])
+ (displayln i))
+
+(for ([i (in-string "string")])
+ (displayln i))
+
+(for ([i (in-set (set 'x 'y 'z))])
+ (displayln i))
+
+(for ([(k v) (in-hash (hash 'a 1 'b 2 'c 3 ))])
+ (printf "key:~a value:~a\n" k v))
+
+;;; 더 복잡한 반복
+
+;; 여러 sequence에 대한 병렬 순회 (가장 짧은 것 기준으로 중단)
+(for ([i 10] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x 1:y 2:z
+
+;; 중첩 반복
+(for* ([i 2] [j '(x y z)]) (printf "~a:~a\n" i j))
+; => 0:x, 0:y, 0:z, 1:x, 1:y, 1:z
+
+;; 조건
+(for ([i 1000]
+ #:when (> i 5)
+ #:unless (odd? i)
+ #:break (> i 10))
+ (printf "i=~a\n" i))
+; => i=6, i=8, i=10
+
+;;; 함축
+;; `for' 반복과 비슷하며, 결과만 수집한다.
+
+(for/list ([i '(1 2 3)])
+ (add1 i)) ; => '(2 3 4)
+
+(for/list ([i '(1 2 3)] #:when (even? i))
+ i) ; => '(2)
+
+(for/list ([i 10] [j '(x y z)])
+ (list i j)) ; => '((0 x) (1 y) (2 z))
+
+(for/list ([i 1000] #:when (> i 5) #:unless (odd? i) #:break (> i 10))
+ i) ; => '(6 8 10)
+
+(for/hash ([i '(1 2 3)])
+ (values i (number->string i)))
+; => '#hash((1 . "1") (2 . "2") (3 . "3"))
+
+;; 반복의 값을 수집하는 여러 가지 방법이 있다:
+(for/sum ([i 10]) (* i i)) ; => 285
+(for/product ([i (in-range 1 11)]) (* i i)) ; => 13168189440000
+(for/and ([i 10] [j (in-range 10 20)]) (< i j)) ; => #t
+(for/or ([i 10] [j (in-range 0 20 2)]) (= i j)) ; => #t
+;; 임의의 조합을 사용하려면 `for/fold'를 사용:
+(for/fold ([sum 0]) ([i '(1 2 3 4)]) (+ sum i)) ; => 10
+;; (이것은 명령형 반복문을 대체하기도 한다.)
+
+;;; 예외
+
+;; 예외를 잡으려면 `with-handlers' 형식을 사용
+(with-handlers ([exn:fail? (lambda (exn) 999)])
+ (+ 1 "2")) ; => 999
+(with-handlers ([exn:break? (lambda (exn) "no time")])
+ (sleep 3)
+ "phew") ; => "phew", but if you break it => "no time"
+
+;; 예외나 다른 값을 던지려면 `raise'를 사용
+(with-handlers ([number? ; catch numeric values raised
+ identity]) ; return them as plain values
+ (+ 1 (raise 2))) ; => 2
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. 변경
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 기존 변수에 새 값을 할당하려면 `set!'을 사용한다.
+(define n 5)
+(set! n (add1 n))
+n ; => 6
+
+;; 명시적인 가변 값을 사용하려면 box 사용 (다른 언어의 포인터나 참조와 비슷함)
+(define n* (box 5))
+(set-box! n* (add1 (unbox n*)))
+(unbox n*) ; => 6
+
+;; 많은 Racket 자료형은 불변이다 (쌍, 리스트 등). 그러나 어떤 것들은
+;; 가변과 불변형이 둘 다 있다. (string, vector, hash table 등)
+
+;; `vector'나 `make-vector'로 가변 벡터를 생성한다.
+(define vec (vector 2 2 3 4))
+(define wall (make-vector 100 'bottle-of-beer))
+;; 칸을 변경하려면 vector-set!을 사용한다.
+(vector-set! vec 0 1)
+(vector-set! wall 99 'down)
+vec ; => #(1 2 3 4)
+
+;; 비어 있는 가변 해시 테이블을 만들고 조작한다.
+(define m3 (make-hash))
+(hash-set! m3 'a 1)
+(hash-set! m3 'b 2)
+(hash-set! m3 'c 3)
+(hash-ref m3 'a) ; => 1
+(hash-ref m3 'd 0) ; => 0
+(hash-remove! m3 'a)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. 모듈
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 모듈은 코드를 여러 파일과 재사용 가능한 라이브러리로 조직하게 한다.
+;; 여기서 우리는 서브-모듈을 사용한다. 이 글이 만드는 전체 모듈("lang" 줄 부터 시작)에 포함된 모듈이다.
+
+(module cake racket/base ; racket/base 기반의 `cake' 모듈 정의
+
+ (provide print-cake) ; 모듈이 노출(export)시키는 함수
+
+ (define (print-cake n)
+ (show " ~a " n #\.)
+ (show " .-~a-. " n #\|)
+ (show " | ~a | " n #\space)
+ (show "---~a---" n #\-))
+
+ (define (show fmt n ch) ; 내부 함수
+ (printf fmt (make-string n ch))
+ (newline)))
+
+;; `require'를 사용하여 모듈에서 모든 `provide'된 이름을 사용한다.
+(require 'cake) ; '는 지역 지역 서브-모듈을 위한 것이다.
+(print-cake 3)
+; (show "~a" 1 #\A) ; => 에러, `show'가 export되지 않았음
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 8. 클래스와 개체
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 클래스 fish%를 생성한다. (-%는 클래스 정의에 쓰이는 관용구)
+(define fish%
+ (class object%
+ (init size) ; 초기화 인자
+ (super-new) ; 상위 클래스 초기화
+ ;; 필드
+ (define current-size size)
+ ;; 공용 메서드
+ (define/public (get-size)
+ current-size)
+ (define/public (grow amt)
+ (set! current-size (+ amt current-size)))
+ (define/public (eat other-fish)
+ (grow (send other-fish get-size)))))
+
+;; fish%의 인스턴스를 생성한다.
+(define charlie
+ (new fish% [size 10]))
+
+;; 개체의 메서드를 호출하기 위해 `send'를 사용한다.
+(send charlie get-size) ; => 10
+(send charlie grow 6)
+(send charlie get-size) ; => 16
+
+;; `fish%'는 보통의 "일급" 값이며, mixin을 줄 수 있다.
+(define (add-color c%)
+ (class c%
+ (init color)
+ (super-new)
+ (define my-color color)
+ (define/public (get-color) my-color)))
+(define colored-fish% (add-color fish%))
+(define charlie2 (new colored-fish% [size 10] [color 'red]))
+(send charlie2 get-color)
+;; 또는, 이름 없이:
+(send (new (add-color fish%) [size 10] [color 'red]) get-color)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 9. 매크로
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 매크로는 언어의 문법을 확장할 수 있게 한다.
+
+;; while 반복문을 추가하자.
+(define-syntax-rule (while condition body ...)
+ (let loop ()
+ (when condition
+ body ...
+ (loop))))
+
+(let ([i 0])
+ (while (< i 10)
+ (displayln i)
+ (set! i (add1 i))))
+
+;; 매크로는 위생적이다. 즉, 기존 변수를 침범할 수 없다.
+(define-syntax-rule (swap! x y) ; -!는 변경의 관용구
+ (let ([tmp x])
+ (set! x y)
+ (set! y tmp)))
+
+(define tmp 2)
+(define other 3)
+(swap! tmp other)
+(printf "tmp = ~a; other = ~a\n" tmp other)
+;; `tmp` 변수는 이름 충돌을 피하기 위해 `tmp_1`로 이름이 변경된다.
+;; (let ([tmp_1 tmp])
+;; (set! tmp other)
+;; (set! other tmp_1))
+
+;; 하지만 그것들은 단지 코드 변형일 뿐이다. 예를 들어:
+(define-syntax-rule (bad-while condition body ...)
+ (when condition
+ body ...
+ (bad-while condition body ...)))
+;; 이 매크로는 엉터리다: 무한 코드를 생성하며,
+;; 이것을 사용하려고 하면 컴파일러가 무한 반복에 빠진다.
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 10. 계약(Contract)
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; 계약은 모듈에서 노출된 값에 대해 제약을 부여한다.
+
+(module bank-account racket
+ (provide (contract-out
+ [deposit (-> positive? any)] ; 값은 양수여야 함
+ [balance (-> positive?)]))
+
+ (define amount 0)
+ (define (deposit a) (set! amount (+ amount a)))
+ (define (balance) amount)
+ )
+
+(require 'bank-account)
+(deposit 5)
+
+(balance) ; => 5
+
+;; 양수가 아닌 값을 예치하려고 하는 고객은 비난받는다.
+;; (deposit -5) ; => deposit: contract violation
+;; expected: positive?
+;; given: -5
+;; more details....
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 11. 입력과 출력
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Racket은 이 "port"라는 개념이 있다. 이것은 다른 언어의
+;; 파일 서술자 (file descriptor)와 매우 비슷하다.
+
+;; "/tmp/tmp.txt"를 열고 "Hello World"를 기록한다.
+;; 그 파일이 이미 있다면 에러를 발생시킨다.
+(define out-port (open-output-file "/tmp/tmp.txt"))
+(displayln "Hello World" out-port)
+(close-output-port out-port)
+
+;; "/tmp/tmp.txt"에 붙이기
+(define out-port (open-output-file "/tmp/tmp.txt"
+ #:exists 'append))
+(displayln "Hola mundo" out-port)
+(close-output-port out-port)
+
+;; 파일에서 다시 읽기
+(define in-port (open-input-file "/tmp/tmp.txt"))
+(displayln (read-line in-port))
+; => "Hello World"
+(displayln (read-line in-port))
+; => "Hola mundo"
+(close-input-port in-port)
+
+;; 다르게, call-with-output-file을 사용하면, 명시적으로 파일을 닫지 않아도 된다.
+(call-with-output-file "/tmp/tmp.txt"
+ #:exists 'update ; 내용을 다시 쓴다.
+ (λ (out-port)
+ (displayln "World Hello!" out-port)))
+
+;; call-with-input-file은 입력에 대해 같은 방식으로 작동한다.
+(call-with-input-file "/tmp/tmp.txt"
+ (λ (in-port)
+ (displayln (read-line in-port))))
+```
+
+## 더 읽을거리
+
+더 배우고 싶으면, [Getting Started with Racket](http://docs.racket-lang.org/getting-started/)도 보시오.
diff --git a/livescript.html.markdown b/livescript.html.markdown
index 5fd61f49..429b91cb 100644
--- a/livescript.html.markdown
+++ b/livescript.html.markdown
@@ -23,7 +23,7 @@ Feedback is always welcome, so feel free to reach me over at
```coffeescript
-# Just like its CoffeeScript cousin, LiveScript uses hash symbols for
+# Just like its CoffeeScript cousin, LiveScript uses number symbols for
# single-line comments.
/*
diff --git a/lua.html.markdown b/lua.html.markdown
index 27ce105b..be9f3141 100644
--- a/lua.html.markdown
+++ b/lua.html.markdown
@@ -12,15 +12,13 @@ filename: learnlua.lua
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
-
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 1. Variables and flow control.
-----------------------------------------------------
+--------------------------------------------------------------------------------
num = 42 -- All numbers are doubles.
--- Don't freak out, 64-bit doubles have 52 bits for
--- storing exact int values; machine precision is
--- not a problem for ints that need < 52 bits.
+-- Don't freak out, 64-bit doubles have 52 bits for storing exact int
+-- values; machine precision is not a problem for ints that need < 52 bits.
s = 'walternate' -- Immutable strings like Python.
t = "double-quotes are also fine"
@@ -60,8 +58,8 @@ aBoolValue = false
-- Only nil and false are falsy; 0 and '' are true!
if not aBoolValue then print('twas false') end
--- 'or' and 'and' are short-circuited.
--- This is similar to the a?b:c operator in C/js:
+-- 'or' and 'and' are short-circuited. This is similar to the a?b:c operator
+-- in C/js:
ans = aBoolValue and 'yes' or 'no' --> 'no'
karlSum = 0
@@ -81,10 +79,9 @@ repeat
num = num - 1
until num == 0
-
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 2. Functions.
-----------------------------------------------------
+--------------------------------------------------------------------------------
function fib(n)
if n < 2 then return n end
@@ -93,8 +90,8 @@ end
-- Closures and anonymous functions are ok:
function adder(x)
- -- The returned function is created when adder is
- -- called, and remembers the value of x:
+ -- The returned function is created when adder is called, and remembers the
+ -- value of x:
return function (y) return x + y end
end
a1 = adder(9)
@@ -102,10 +99,9 @@ a2 = adder(36)
print(a1(16)) --> 25
print(a2(64)) --> 100
--- Returns, func calls, and assignments all work
--- with lists that may be mismatched in length.
--- Unmatched receivers are nil;
--- unmatched senders are discarded.
+-- Returns, func calls, and assignments all work with lists that may be
+-- mismatched in length. Unmatched receivers are nil; unmatched senders are
+-- discarded.
x, y, z = 1, 2, 3, 4
-- Now x = 1, y = 2, z = 3, and 4 is thrown away.
@@ -118,16 +114,15 @@ end
x, y = bar('zaphod') --> prints "zaphod nil nil"
-- Now x = 4, y = 8, values 15..42 are discarded.
--- Functions are first-class, may be local/global.
--- These are the same:
+-- Functions are first-class, may be local/global. These are the same:
function f(x) return x * x end
f = function (x) return x * x end
-- And so are these:
local function g(x) return math.sin(x) end
local g = function(x) return math.sin(x) end
--- Equivalent to local function g(x)..., except referring
--- to g in the function body won't work as expected.
+-- Equivalent to local function g(x)..., except referring to g in the function
+-- body won't work as expected.
local g; g = function (x) return math.sin(x) end
-- the 'local g' decl makes g-self-references ok.
@@ -136,19 +131,16 @@ local g; g = function (x) return math.sin(x) end
-- Calls with one string param don't need parens:
print 'hello' -- Works fine.
--- Calls with one table param don't need parens
--- either (more on tables below):
+-- Calls with one table param don't need parens either (more on tables below):
print {} -- Works fine too.
-
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 3. Tables.
-----------------------------------------------------
+--------------------------------------------------------------------------------
--- Tables = Lua's only compound data structure;
--- they are associative arrays.
--- Similar to php arrays or js objects, they are
--- hash-lookup dicts that can also be used as lists.
+-- Tables = Lua's only compound data structure; they are associative arrays.
+-- Similar to php arrays or js objects, they are hash-lookup dicts that can
+-- also be used as lists.
-- Using tables as dictionaries / maps:
@@ -164,14 +156,13 @@ t.key2 = nil -- Removes key2 from the table.
u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'}
print(u[6.28]) -- prints "tau"
--- Key matching is basically by value for numbers
--- and strings, but by identity for tables.
+-- Key matching is basically by value for numbers and strings, but by identity
+-- for tables.
a = u['@!#'] -- Now a = 'qbert'.
b = u[{}] -- We might expect 1729, but it's nil:
--- b = nil since the lookup fails. It fails
--- because the key we used is not the same object
--- as the one used to store the original value. So
--- strings & numbers are more portable keys.
+-- b = nil since the lookup fails. It fails because the key we used is not the
+-- same object as the one used to store the original value. So strings &
+-- numbers are more portable keys.
-- A one-table-param function call needs no parens:
function h(x) print(x.key1) end
@@ -191,16 +182,15 @@ v = {'value1', 'value2', 1.21, 'gigawatts'}
for i = 1, #v do -- #v is the size of v for lists.
print(v[i]) -- Indices start at 1 !! SO CRAZY!
end
--- A 'list' is not a real type. v is just a table
--- with consecutive integer keys, treated as a list.
+-- A 'list' is not a real type. v is just a table with consecutive integer
+-- keys, treated as a list.
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 3.1 Metatables and metamethods.
-----------------------------------------------------
+--------------------------------------------------------------------------------
--- A table can have a metatable that gives the table
--- operator-overloadish behavior. Later we'll see
--- how metatables support js-prototypey behavior.
+-- A table can have a metatable that gives the table operator-overloadish
+-- behavior. Later we'll see how metatables support js-prototypey behavior.
f1 = {a = 1, b = 2} -- Represents the fraction a/b.
f2 = {a = 2, b = 3}
@@ -221,10 +211,9 @@ setmetatable(f2, metafraction)
s = f1 + f2 -- call __add(f1, f2) on f1's metatable
--- f1, f2 have no key for their metatable, unlike
--- prototypes in js, so you must retrieve it as in
--- getmetatable(f1). The metatable is a normal table
--- with keys that Lua knows about, like __add.
+-- f1, f2 have no key for their metatable, unlike prototypes in js, so you must
+-- retrieve it as in getmetatable(f1). The metatable is a normal table with
+-- keys that Lua knows about, like __add.
-- But the next line fails since s has no metatable:
-- t = s + s
@@ -236,11 +225,12 @@ myFavs = {food = 'pizza'}
setmetatable(myFavs, {__index = defaultFavs})
eatenBy = myFavs.animal -- works! thanks, metatable
--- Direct table lookups that fail will retry using
--- the metatable's __index value, and this recurses.
+--------------------------------------------------------------------------------
+-- Direct table lookups that fail will retry using the metatable's __index
+-- value, and this recurses.
--- An __index value can also be a function(tbl, key)
--- for more customized lookups.
+-- An __index value can also be a function(tbl, key) for more customized
+-- lookups.
-- Values of __index,add, .. are called metamethods.
-- Full list. Here a is a table with the metamethod.
@@ -261,12 +251,12 @@ eatenBy = myFavs.animal -- works! thanks, metatable
-- __newindex(a, b, c) for a.b = c
-- __call(a, ...) for a(...)
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 3.2 Class-like tables and inheritance.
-----------------------------------------------------
+--------------------------------------------------------------------------------
--- Classes aren't built in; there are different ways
--- to make them using tables and metatables.
+-- Classes aren't built in; there are different ways to make them using
+-- tables and metatables.
-- Explanation for this example is below it.
@@ -286,22 +276,20 @@ mrDog = Dog:new() -- 7.
mrDog:makeSound() -- 'I say woof' -- 8.
-- 1. Dog acts like a class; it's really a table.
--- 2. function tablename:fn(...) is the same as
--- function tablename.fn(self, ...)
--- The : just adds a first arg called self.
--- Read 7 & 8 below for how self gets its value.
+-- 2. "function tablename:fn(...)" is the same as
+-- "function tablename.fn(self, ...)", The : just adds a first arg called
+-- self. Read 7 & 8 below for how self gets its value.
-- 3. newObj will be an instance of class Dog.
--- 4. self = the class being instantiated. Often
--- self = Dog, but inheritance can change it.
--- newObj gets self's functions when we set both
--- newObj's metatable and self's __index to self.
+-- 4. "self" is the class being instantiated. Often self = Dog, but inheritance
+-- can change it. newObj gets self's functions when we set both newObj's
+-- metatable and self's __index to self.
-- 5. Reminder: setmetatable returns its first arg.
--- 6. The : works as in 2, but this time we expect
--- self to be an instance instead of a class.
+-- 6. The : works as in 2, but this time we expect self to be an instance
+-- instead of a class.
-- 7. Same as Dog.new(Dog), so self = Dog in new().
-- 8. Same as mrDog.makeSound(mrDog); self = mrDog.
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- Inheritance example:
@@ -315,17 +303,16 @@ end
seymour = LoudDog:new() -- 3.
seymour:makeSound() -- 'woof woof woof' -- 4.
+--------------------------------------------------------------------------------
-- 1. LoudDog gets Dog's methods and variables.
-- 2. self has a 'sound' key from new(), see 3.
--- 3. Same as LoudDog.new(LoudDog), and converted to
--- Dog.new(LoudDog) as LoudDog has no 'new' key,
--- but does have __index = Dog on its metatable.
--- Result: seymour's metatable is LoudDog, and
--- LoudDog.__index = LoudDog. So seymour.key will
--- = seymour.key, LoudDog.key, Dog.key, whichever
+-- 3. Same as "LoudDog.new(LoudDog)", and converted to "Dog.new(LoudDog)" as
+-- LoudDog has no 'new' key, but does have "__index = Dog" on its metatable.
+-- Result: seymour's metatable is LoudDog, and "LoudDog.__index = Dog". So
+-- seymour.key will equal seymour.key, LoudDog.key, Dog.key, whichever
-- table is the first with the given key.
--- 4. The 'makeSound' key is found in LoudDog; this
--- is the same as LoudDog.makeSound(seymour).
+-- 4. The 'makeSound' key is found in LoudDog; this is the same as
+-- "LoudDog.makeSound(seymour)".
-- If needed, a subclass's new() is like the base's:
function LoudDog:new()
@@ -335,13 +322,13 @@ function LoudDog:new()
return setmetatable(newObj, self)
end
-----------------------------------------------------
+--------------------------------------------------------------------------------
-- 4. Modules.
-----------------------------------------------------
+--------------------------------------------------------------------------------
---[[ I'm commenting out this section so the rest of
--- this script remains runnable.
+--[[ I'm commenting out this section so the rest of this script remains
+-- runnable.
```
```lua
@@ -367,8 +354,8 @@ local mod = require('mod') -- Run the file mod.lua.
local mod = (function ()
<contents of mod.lua>
end)()
--- It's like mod.lua is a function body, so that
--- locals inside mod.lua are invisible outside it.
+-- It's like mod.lua is a function body, so that locals inside mod.lua are
+-- invisible outside it.
-- This works because mod here = M in mod.lua:
mod.sayHello() -- Says hello to Hrunkner.
@@ -376,8 +363,8 @@ mod.sayHello() -- Says hello to Hrunkner.
-- This is wrong; sayMyName only exists in mod.lua:
mod.sayMyName() -- error
--- require's return values are cached so a file is
--- run at most once, even when require'd many times.
+-- require's return values are cached so a file is run at most once, even when
+-- require'd many times.
-- Suppose mod2.lua contains "print('Hi!')".
local a = require('mod2') -- Prints Hi!
diff --git a/markdown.html.markdown b/markdown.html.markdown
new file mode 100644
index 00000000..606840d3
--- /dev/null
+++ b/markdown.html.markdown
@@ -0,0 +1,246 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+filename: markdown.md
+---
+
+Markdown was created by John Gruber in 2004. It's meant to be an easy to read and write syntax which converts easily to HTML (and now many other formats as well).
+
+Give me as much feedback as you want! / Feel free to fork and pull request!
+
+
+```
+<!-- Markdown is a superset of HTML, so any HTML file is valid Markdown, that
+means we can use HTML elements in Markdown, such as the comment element, and
+they won't be affected by a markdown parser. However, if you create an HTML
+element in your markdown file, you cannot use markdown syntax within that
+element's contents. -->
+
+<!-- Markdown also varies in implementation from one parser to a next. This
+guide will attempt to clarify when features are universal or when they are
+specific to a certain parser. -->
+
+<!-- Headers -->
+<!-- You can create HTML elements <h1> through <h6> easily by prepending the
+text you want to be in that element by a number of hashes (#) -->
+# This is an <h1>
+## This is an <h2>
+### This is an <h3>
+#### This is an <h4>
+##### This is an <h5>
+###### This is an <h6>
+
+<!-- Markdown also provides us with two alternative ways of indicating h1 and h2 -->
+This is an h1
+=============
+
+This is an h2
+-------------
+
+<!-- Simple text styles -->
+<!-- Text can be easily styled as italic, bold, or strikethrough using markdown -->
+
+*This text is in italics.*
+_And so is this text._
+
+**This text is in bold.**
+__And so is this text.__
+
+***This text is in both.***
+**_As is this!_**
+*__And this!__*
+
+<!-- In Github Flavored Markdown, which is used to render markdown files on
+Github, we also have: -->
+
+~~This text is rendered with strikethrough.~~
+
+<!-- Paragraphs are a one or multiple adjacent lines of text separated by one or
+multiple blank lines. -->
+
+This is a paragraph. I'm tryping in a paragraph isn't this fun?
+
+Now I'm in paragraph 2.
+I'm still in paragraph 2 too!
+
+
+I'm in paragraph three!
+
+<!-- Should you ever want to insert an HTML <br /> tag, you can end a paragraph
+with two or more spaces and then begin a new paragraph. -->
+
+I end with two spaces (highlight me to see them).
+
+There's a <br /> above me!
+
+<!-- Block quotes are easy and done with the > character. -->
+
+> This is a block quote. You can either
+> manually wrap your lines and put a `>` before every line or you can let your lines get really long and wrap on their own.
+> It doesn't make a difference so long as they start with a `>`.
+
+> You can also use more than one level
+>> of indentation?
+> How neat is that?
+
+<!-- Lists -->
+<!-- Unordered lists can be made using asterisks, pluses, or hyphens -->
+
+* Item
+* Item
+* Another item
+
+or
+
++ Item
++ Item
++ One more item
+
+or
+
+- Item
+- Item
+- One last item
+
+<!-- Ordered lists are done with a number followed by a period -->
+
+1. Item one
+2. Item two
+3. Item three
+
+<!-- You don't even have to label the items correctly and markdown will still
+render the numbers in order, but this may not be a good idea -->
+
+1. Item one
+1. Item two
+1. Item three
+<!-- (This renders the same as the above example) -->
+
+<!-- You can also use sublists -->
+
+1. Item one
+2. Item two
+3. Item three
+ * Sub-item
+ * Sub-item
+4. Item four
+
+<!-- Code blocks -->
+<!-- You can indicate a code block (which uses the <code> element) by indenting
+a line with four spaces or a tab -->
+
+ This is code
+ So is this
+
+<!-- You can also re-tab (or add an additional four spaces) for indentation
+inside your code -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Inline code can be created using the backtick character ` -->
+
+John didn't even know what the `go_to()` function did!
+
+<!-- In Github Flavored Markdown, you can use a special syntax for code -->
+
+\`\`\`ruby <!-- except remove those backslashes when you do this, just ```ruby ! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- here too, no backslashes, just ``` -->
+
+<-- The above text doesn't require indenting, plus Github will use syntax
+highlighting of the language you specify after the ``` -->
+
+<!-- Horizontal rule (<hr />) -->
+<!-- Horizontal rules are easily added with three or more asterisks or hyphens,
+with or without spaces. -->
+
+***
+---
+- - -
+****************
+
+<!-- Links -->
+<!-- One of the best things about markdown is how easy it is to make links. Put
+the text to display in hard brackets [] followed by the url in parentheses () -->
+
+[Click me!](http://test.com/)
+
+<!-- You can also add a link title using quotes inside the parentheses -->
+
+[Click me!](http://test.com/ "Link to Test.com")
+
+<!-- Relative paths work too. -->
+
+[Go to music](/music/).
+
+<!-- Markdown also supports reference style links -->
+
+[Click this link][link1] for more info about it!
+[Also check out this link][foobar] if you want to.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- The title can also be in single quotes or in parentheses, or omitted
+entirely. The references can be anywhere in your document and the reference IDs
+can be anything so long as they are unique. -->
+
+<!-- There is also "implicit naming" which lets you use the link text as the id -->
+
+[This][] is a link.
+
+[this]: http://thisisalink.com/
+
+<!-- But it's not that commonly used. -->
+
+<!-- Images -->
+<!-- Images are done the same way as links but with an exclamation point in front! -->
+
+![This is hover-text (alt text) for my image](http://imgur.com/myimage.jpg "An optional title")
+
+<!-- And reference style works as expected -->
+
+![This is the hover-text.][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "if you need a title, it's here"
+
+<!-- Miscellany -->
+<!-- Auto-links -->
+
+<http://testwebsite.com/> is equivalent to
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Auto-links for emails -->
+
+<foo@bar.com>
+
+<!-- Escaping characters -->
+
+I want to type *this text surrounded by asterisks* but I don't want it to be
+in italics, so I do this: \*this text surrounded by asterisks\*.
+
+<!-- Tables -->
+<!-- Tables are only available in Github Flavored Markdown and are slightly
+cumbersome, but if you really want it: -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| Left-aligned | Centered | Right-aligned |
+| blah | blah | blah |
+
+<!-- or, for the same results -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ugh this is so ugly | make it | stop
+
+<!-- The end! -->
+
+```
+
+For more info, check out John Gruber's official post of syntax [here](http://daringfireball.net/projects/markdown/syntax) and Adam Pritchard's great cheatsheet [here](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
diff --git a/matlab.html.markdown b/matlab.html.markdown
index 15ff2303..9baefe68 100644
--- a/matlab.html.markdown
+++ b/matlab.html.markdown
@@ -181,7 +181,7 @@ size(A) % ans = 3 3
A(1, :) =[] % Delete the first row of the matrix
-A' % Hermitian transpose the matrix
+ctranspose(A) % Hermitian transpose the matrix
% (the transpose, followed by taking complex conjugate of each element)
transpose(A) % Transpose the matrix, without taking complex conjugate
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
index f2787649..772e72ca 100644
--- a/objective-c.html.markdown
+++ b/objective-c.html.markdown
@@ -16,15 +16,21 @@ It is a general-purpose, object-oriented programming language that adds Smalltal
// Single-line comments start with //
/*
-Multi-line comments look like this.
+Multi-line comments look like this
*/
// Imports the Foundation headers with #import
+// Use <> to import global files (in general frameworks)
+// Use "" to import local files (from project)
#import <Foundation/Foundation.h>
#import "MyClass.h"
+// If you enable modules for iOS >= 7.0 or OS X >= 10.9 projects in
+// Xcode 5 you can import frameworks like that:
+@import Foundation;
+
// Your program's entry point is a function called
-// main with an integer return type.
+// main with an integer return type
int main (int argc, const char * argv[])
{
// Create an autorelease pool to manage the memory into the program
@@ -54,7 +60,7 @@ int main (int argc, const char * argv[])
// String
NSString *worldString = @"World";
NSLog(@"Hello %@!", worldString); // prints => "Hello World!"
- // NSMutableString is a mutable version of the NSString object.
+ // NSMutableString is a mutable version of the NSString object
NSMutableString *mutableString = [NSMutableString stringWithString:@"Hello"];
[mutableString appendString:@" World!"];
NSLog(@"%@", mutableString); // prints => "Hello World!"
@@ -108,7 +114,7 @@ int main (int argc, const char * argv[])
[oneDecNum decimalNumberBySubtracting:twoDecNum];
[oneDecNum decimalNumberByMultiplyingBy:twoDecNum];
[oneDecNum decimalNumberByDividingBy:twoDecNum];
- NSLog(@"%@", oneDecNum); // prints => 10.99 as NSDecimalNumber is immutable.
+ NSLog(@"%@", oneDecNum); // prints => 10.99 as NSDecimalNumber is immutable
// BOOL literals
NSNumber *yesNumber = @YES;
@@ -119,12 +125,12 @@ int main (int argc, const char * argv[])
NSLog(@"%i", yesBool); // prints => 1
// Array object
- // May contain different data types, but must be an Objective-C object.
+ // May contain different data types, but must be an Objective-C object
NSArray *anArray = @[@1, @2, @3, @4];
NSNumber *thirdNumber = anArray[2];
NSLog(@"Third number = %@", thirdNumber); // Print "Third number = 3"
// NSMutableArray is mutable version of NSArray allowing to change items in array
- // and extend or shrink array object. Convenient, but not as efficient as NSArray.
+ // and extend or shrink array object. Convenient, but not as efficient as NSArray
NSMutableArray *mutableArray = [NSMutableArray arrayWithCapacity:2];
[mutableArray addObject:@"Hello"];
[mutableArray addObject:@"World"];
@@ -135,7 +141,7 @@ int main (int argc, const char * argv[])
NSDictionary *aDictionary = @{ @"key1" : @"value1", @"key2" : @"value2" };
NSObject *valueObject = aDictionary[@"A Key"];
NSLog(@"Object = %@", valueObject); // Print "Object = (null)"
- // NSMutableDictionary also available as a mutable dictionary object.
+ // NSMutableDictionary also available as a mutable dictionary object
NSMutableDictionary *mutableDictionary = [NSMutableDictionary dictionaryWithCapacity:2];
[mutableDictionary setObject:@"value1" forKey:@"key1"];
[mutableDictionary setObject:@"value2" forKey:@"key2"];
@@ -144,7 +150,7 @@ int main (int argc, const char * argv[])
// Set object
NSSet *set = [NSSet setWithObjects:@"Hello", @"Hello", @"World", nil];
NSLog(@"%@", set); // prints => {(Hello, World)} (may be in different order)
- // NSMutableSet also available as a mutable set object.
+ // NSMutableSet also available as a mutable set object
NSMutableSet *mutableSet = [NSMutableSet setWithCapacity:2];
[mutableSet addObject:@"Hello"];
[mutableSet addObject:@"Hello"];
@@ -203,7 +209,7 @@ int main (int argc, const char * argv[])
int ii = 0;
while (ii < 4)
{
- NSLog(@"%d,", ii++); // ii++ increments ii in-place, after using its value.
+ NSLog(@"%d,", ii++); // ii++ increments ii in-place, after using its value
} // => prints "0,"
// "1,"
// "2,"
@@ -229,7 +235,7 @@ int main (int argc, const char * argv[])
// "2,"
// "3,"
- // Object for loop statement. Can be used with any Objective-C object type.
+ // Object for loop statement. Can be used with any Objective-C object type
for (id item in values) {
NSLog(@"%@,", item);
} // => prints "0,"
@@ -243,32 +249,35 @@ int main (int argc, const char * argv[])
// Your statements here
@throw [NSException exceptionWithName:@"FileNotFoundException"
reason:@"File Not Found on System" userInfo:nil];
- } @catch (NSException * e)
+ } @catch (NSException * e) // use: @catch (id exceptionName) to catch all objects.
{
NSLog(@"Exception: %@", e);
} @finally
{
- NSLog(@"Finally");
+ NSLog(@"Finally. Time to clean up.");
} // => prints "Exception: File Not Found on System"
- // "Finally"
+ // "Finally. Time to clean up."
+
+ // NSError objects are useful for function arguments to populate on user mistakes.
+ NSError *error = [NSError errorWithDomain:@"Invalid email." code:4 userInfo:nil];
///////////////////////////////////////
// Objects
///////////////////////////////////////
- // Create an object instance by allocating memory and initializing it.
- // An object is not fully functional until both steps have been completed.
+ // 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.
+ // 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 of @autoreleasepool.
+ // End of @autoreleasepool
}
// End the program
@@ -285,22 +294,22 @@ int main (int argc, const char * argv[])
// {
// type name; <= variable declarations;
// }
-// @property type name; <= property declarations.
-// -/+ (type) Method declarations; <= Method declarations.
+// @property type name; <= property declarations
+// -/+ (type) Method declarations; <= Method declarations
// @end
@interface MyClass : NSObject <MyProtocol> // NSObject is Objective-C's base object class.
{
- // Instance variable declarations (can exist in either interface or implementation file).
+ // Instance variable declarations (can exist in either interface or implementation file)
int count; // Protected access by default.
- @private id data; // Private access. (More convenient to declare in implementation file).
+ @private id data; // Private access (More convenient to declare in implementation file)
NSString *name;
}
-// Convenient notation for public access variables to auto generate a setter method.
-// By default, setter method name is 'set' followed by @property variable name.
+// Convenient notation for public access variables to auto generate a setter method
+// By default, setter method name is 'set' followed by @property variable name
@property int propInt; // Setter method name = 'setPropInt'
-@property (copy) id copyId; // (copy) => Copy the object during assignment.
-// (readonly) => Cannot set value outside @interface.
-@property (readonly) NSString *roString; // Use @synthesize in @implementation to create accessor.
+@property (copy) id copyId; // (copy) => Copy the object during assignment
+// (readonly) => Cannot set value outside @interface
+@property (readonly) NSString *roString; // Use @synthesize in @implementation to create accessor
// You can customize the getter and setter names instead of using default 'set' name:
@property (getter=lengthGet, setter=lengthSet:) int length;
@@ -317,14 +326,14 @@ int main (int argc, const char * argv[])
// Constructor methods with arguments:
- (id)initWithDistance:(int)defaultDistance;
-// Objective-C method names are very descriptive. Always name methods according to their arguments.
+// Objective-C method names are very descriptive. Always name methods according to their arguments
-@end // States the end of the interface.
+@end // States the end of the interface
// To access public variables from the implementation file, @property generates a setter method
// automatically. Method name is 'set' followed by @property variable name:
-MyClass *myClass = [[MyClass alloc] init]; // create MyClass object instance.
+MyClass *myClass = [[MyClass alloc] init]; // create MyClass object instance
[myClass setCount:10];
NSLog(@"%d", [myClass count]); // prints => 10
// Or using the custom getter and setter method defined in @interface:
@@ -339,39 +348,39 @@ NSString *classMethodString = [MyClass classMethod];
MyClass *classFromName = [MyClass myClassFromName:@"Hello"];
// Call instance methods:
-MyClass *myClass = [[MyClass alloc] init]; // Create MyClass object instance.
+MyClass *myClass = [[MyClass alloc] init]; // Create MyClass object instance
NSString *stringFromInstanceMethod = [myClass instanceMethodWithParameter:@"Hello"];
-// Selectors.
+// Selectors
// Way to dynamically represent methods. Used to call methods of a class, pass methods
// through functions to tell other classes they should call it, and to save methods
-// as a variable.
-// SEL is the data type. @selector() returns a selector from method name provided.
+// as a variable
+// SEL is the data type. @selector() returns a selector from method name provided
// methodAParameterAsString:andAParameterAsNumber: is method name for method in MyClass
SEL selectorVar = @selector(methodAParameterAsString:andAParameterAsNumber:);
-if ([myClass respondsToSelector:selectorVar]) { // Checks if class contains method.
- // Must put all method arguments into one object to send to performSelector function.
+if ([myClass respondsToSelector:selectorVar]) { // Checks if class contains method
+ // Must put all method arguments into one object to send to performSelector function
NSArray *arguments = [NSArray arrayWithObjects:@"Hello", @4, nil];
- [myClass performSelector:selectorVar withObject:arguments]; // Calls the method.
+ [myClass performSelector:selectorVar withObject:arguments]; // Calls the method
} else {
- // NSStringFromSelector() returns a NSString of the method name of a given selector.
+ // NSStringFromSelector() returns a NSString of the method name of a given selector
NSLog(@"MyClass does not have method: %@", NSStringFromSelector(selectedVar));
}
// Implement the methods in an implementation (MyClass.m) file:
@implementation MyClass {
- long distance; // Private access instance variable.
+ long distance; // Private access instance variable
NSNumber height;
}
// To access a public variable from the interface file, use '_' followed by variable name:
-_count = 5; // References "int count" from MyClass interface.
+_count = 5; // References "int count" from MyClass interface
// Access variables defined in implementation file:
-distance = 18; // References "long distance" from MyClass implementation.
+distance = 18; // References "long distance" from MyClass implementation
// To use @property variable in implementation, use @synthesize to create accessor variable:
-@synthesize roString = _roString; // _roString available now in @implementation.
+@synthesize roString = _roString; // _roString available now in @implementation
-// Called before calling any class methods or instantiating any objects.
+// Called before calling any class methods or instantiating any objects
+ (void)initialize
{
if (self == [MyClass class]) {
@@ -379,20 +388,20 @@ distance = 18; // References "long distance" from MyClass implementation.
}
}
-// Counterpart to initialize method. Called when an object's reference count is zero.
+// Counterpart to initialize method. Called when an object's reference count is zero
- (void)dealloc
{
[height release]; // If not using ARC, make sure to release class variable objects
- [super dealloc]; // and call parent class dealloc.
+ [super dealloc]; // and call parent class dealloc
}
-// Constructors are a way of creating instances of a class.
-// This is a default constructor which is called when the object is initialized.
+// Constructors are a way of creating instances of a class
+// This is a default constructor which is called when the object is initialized.
- (id)init
{
- if ((self = [super init])) // 'super' used to access methods from parent class.
+ if ((self = [super init])) // 'super' used to access methods from parent class
{
- self.count = 1; // 'self' used for object to call itself.
+ self.count = 1; // 'self' used for object to call itself
}
return self;
}
@@ -424,11 +433,12 @@ distance = 18; // References "long distance" from MyClass implementation.
return @42;
}
-// To create a private method, create the method in the @implementation but not in the @interface.
+// Objective-C does not have private method declarations, but you can simulate them.
+// To simulate a private method, create the method in the @implementation but not in the @interface.
- (NSNumber *)secretPrivateMethod {
return @72;
}
-[self secretPrivateMethod]; // Calls private method.
+[self secretPrivateMethod]; // Calls private method
// Methods declared into MyProtocol
- (void)myProtocolMethod
@@ -436,19 +446,253 @@ distance = 18; // References "long distance" from MyClass implementation.
// statements
}
-@end // States the end of the implementation.
+@end // States the end of the implementation
+
+///////////////////////////////////////
+// Categories
+///////////////////////////////////////
+// A category is a group of methods designed to extend a class. They allow you to add new methods
+// to an existing class for organizational purposes. This is not to be mistaken with subclasses.
+// Subclasses are meant to CHANGE functionality of an object while categories instead ADD
+// functionality to an object.
+// Categories allow you to:
+// -- Add methods to an existing class for organizational purposes.
+// -- Allow you to extend Objective-C object classes (ex: NSString) to add your own methods.
+// -- Add ability to create protected and private methods to classes.
+// NOTE: Do not override methods of the base class in a category even though you have the ability
+// to. Overriding methods may cause compiler errors later between different categories and it
+// ruins the purpose of categories to only ADD functionality. Subclass instead to override methods.
+
+// Here is a simple Car base class.
+@interface Car : NSObject
+
+@property NSString *make;
+@property NSString *color;
+
+- (void)turnOn;
+- (void)accelerate;
+
+@end
+
+// And the simple Car base class implementation:
+#import "Car.h"
+
+@implementation Car
+
+@synthesize make = _make;
+@synthesize color = _color;
+
+- (void)turnOn {
+ NSLog(@"Car is on.");
+}
+- (void)accelerate {
+ NSLog(@"Accelerating.");
+}
+
+@end
+
+// Now, if we wanted to create a Truck object, we would instead create a subclass of Car as it would
+// be changing the functionality of the Car to behave like a truck. But lets say we want to just add
+// functionality to this existing Car. A good example would be to clean the car. So we would create
+// a category to add these cleaning methods:
+// @interface filename: Car+Clean.h (BaseClassName+CategoryName.h)
+#import "Car.h" // Make sure to import base class to extend.
+
+@interface Car (Clean) // The category name is inside () following the name of the base class.
+
+- (void)washWindows; // Names of the new methods we are adding to our Car object.
+- (void)wax;
+
+@end
+
+// @implementation filename: Car+Clean.m (BaseClassName+CategoryName.m)
+#import "Car+Clean.h" // Import the Clean category's @interface file.
+
+@implementation Car (Clean)
+
+- (void)washWindows {
+ NSLog(@"Windows washed.");
+}
+- (void)wax {
+ NSLog(@"Waxed.");
+}
+
+@end
+
+// Any Car object instance has the ability to use a category. All they need to do is import it:
+#import "Car+Clean.h" // Import as many different categories as you want to use.
+#import "Car.h" // Also need to import base class to use it's original functionality.
+
+int main (int argc, const char * argv[]) {
+ @autoreleasepool {
+ Car *mustang = [[Car alloc] init];
+ mustang.color = @"Red";
+ mustang.make = @"Ford";
+
+ [mustang turnOn]; // Use methods from base Car class.
+ [mustang washWindows]; // Use methods from Car's Clean category.
+ }
+ return 0;
+}
+
+// Objective-C does not have protected method declarations but you can simulate them.
+// Create a category containing all of the protected methods, then import it ONLY into the
+// @implementation file of a class belonging to the Car class:
+@interface Car (Protected) // Naming category 'Protected' to remember methods are protected.
+
+- (void)lockCar; // Methods listed here may only be created by Car objects.
+
+@end
+//To use protected methods, import the category, then implement the methods:
+#import "Car+Protected.h" // Remember, import in the @implementation file only.
+
+@implementation Car
+
+- (void)lockCar {
+ NSLog(@"Car locked."); // Instances of Car can't use lockCar because it's not in the @interface.
+}
+
+@end
+
+///////////////////////////////////////
+// Extensions
+///////////////////////////////////////
+// Extensions allow you to override public access property attributes and methods of an @interface.
+// @interface filename: Shape.h
+@interface Shape : NSObject // Base Shape class extension overrides below.
+
+@property (readonly) NSNumber *numOfSides;
+
+- (int)getNumOfSides;
+
+@end
+// You can override numOfSides variable or getNumOfSides method to edit them with an extension:
+// @implementation filename: Shape.m
+#import "Shape.h"
+// Extensions live in the same file as the class @implementation.
+@interface Shape () // () after base class name declares an extension.
+
+@property (copy) NSNumber *numOfSides; // Make numOfSides copy instead of readonly.
+-(NSNumber)getNumOfSides; // Make getNumOfSides return a NSNumber instead of an int.
+-(void)privateMethod; // You can also create new private methods inside of extensions.
+
+@end
+// The main @implementation:
+@implementation Shape
+
+@synthesize numOfSides = _numOfSides;
+
+-(NSNumber)getNumOfSides { // All statements inside of extension must be in the @implementation.
+ return _numOfSides;
+}
+-(void)privateMethod {
+ NSLog(@"Private method created by extension. Shape instances cannot call me.");
+}
+
+@end
+
+///////////////////////////////////////
+// Protocols
+///////////////////////////////////////
+// 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 filename: "CarUtilities.h"
+@protocol CarUtilities <NSObject> // <NSObject> => Name of another protocol this protocol includes.
+ @property BOOL engineOn; // Adopting class must @synthesize all defined @properties and
+ - (void)turnOnEngine; // all defined methods.
+@end
+// Below is an example class implementing the protocol.
+#import "CarUtilities.h" // Import the @protocol file.
+
+@interface Car : NSObject <CarUtilities> // Name of protocol goes inside <>
+ // You don't need the @property or method names here for CarUtilities. Only @implementation does.
+- (void)turnOnEngineWithUtilities:(id <CarUtilities>)car; // You can use protocols as data too.
+@end
+// The @implementation needs to implement the @properties and methods for the protocol.
+@implementation Car : NSObject <CarUtilities>
+
+@synthesize engineOn = _engineOn; // Create a @synthesize statement for the engineOn @property.
+
+- (void)turnOnEngine { // Implement turnOnEngine however you would like. Protocols do not define
+ _engineOn = YES; // how you implement a method, it just requires that you do implement it.
+}
+// You may use a protocol as data as you know what methods and variables it has implemented.
+- (void)turnOnEngineWithCarUtilities:(id <CarUtilities>)objectOfSomeKind {
+ [objectOfSomeKind engineOn]; // You have access to object variables
+ [objectOfSomeKind turnOnEngine]; // and the methods inside.
+ [objectOfSomeKind engineOn]; // May or may not be YES. Class implements it however it wants.
+}
+
+@end
+// Instances of Car now have access to the protocol.
+Car *carInstance = [[Car alloc] init];
+[[carInstance setEngineOn:NO];
+[carInstance turnOnEngine];
+if ([carInstance engineOn]) {
+ NSLog(@"Car engine is on."); // prints => "Car engine is on."
+}
+// Make sure to check if an object of type 'id' implements a protocol before calling protocol methods:
+if ([myClass conformsToProtocol:@protocol(CarUtilities)]) {
+ NSLog(@"This does not run as the MyClass class does not implement the CarUtilities protocol.");
+} else if ([carInstance conformsToProtocol:@protocol(CarUtilities)]) {
+ NSLog(@"This does run as the Car class implements the CarUtilities protocol.");
+}
+// Categories may implement protocols as well: @interface Car (CarCategory) <CarUtilities>
+// You may implement many protocols: @interface Car : NSObject <CarUtilities, CarCleaning>
+// NOTE: If two or more protocols rely on each other, make sure to forward-declare them:
+#import "Brother.h"
+
+@protocol Brother; // Forward-declare statement. Without it, compiler would through error.
+
+@protocol Sister <NSObject>
+
+- (void)beNiceToBrother:(id <Brother>)brother;
+
+@end
+
+// See the problem is that Sister relies on Brother, and Brother relies on Sister.
+#import "Sister.h"
+
+@protocol Sister; // These lines stop the recursion, resolving the issue.
+
+@protocol Brother <NSObject>
+
+- (void)beNiceToSister:(id <Sister>)sister;
-/*
- * 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
///////////////////////////////////////
+// Blocks
+///////////////////////////////////////
+// Blocks are statements of code, just like a function, that are able to be used as data.
+// Below is a simple block with an integer argument that returns the argument plus 4.
+int (^addUp)(int n); // Declare a variable to store the block.
+void (^noParameterBlockVar)(void); // Example variable declaration of block with no arguments.
+// Blocks have access to variables in the same scope. But the variables are readonly and the
+// value passed to the block is the value of the variable when the block is created.
+int outsideVar = 17; // If we edit outsideVar after declaring addUp, outsideVar is STILL 17.
+__block long mutableVar = 3; // __block makes variables writable to blocks, unlike outsideVar.
+addUp = ^(int n) { // Remove (int n) to have a block that doesn't take in any parameters.
+ NSLog(@"You may have as many lines in a block as you would like.");
+ NSSet *blockSet; // Also, you can declare local variables.
+ mutableVar = 32; // Assigning new value to __block variable.
+ return n + outsideVar; // Return statements are optional.
+}
+int addUp = add(10 + 16); // Calls block code with arguments.
+// Blocks are often used as arguments to functions to be called later, or for callbacks.
+@implementation BlockExample : NSObject
+
+ - (void)runBlock:(void (^)(NSString))block {
+ NSLog(@"Block argument returns nothing and takes in a NSString object.");
+ block(@"Argument given to block to execute."); // Calling block.
+ }
+
+ @end
+
+
+///////////////////////////////////////
// Memory Management
///////////////////////////////////////
/*
@@ -466,34 +710,34 @@ With all object interactions, follow the pattern of:
(1) create the object, (2) use the object, (3) then free the object from memory.
*/
-MyClass *classVar = [MyClass alloc]; // 'alloc' sets classVar's reference count to one. Returns pointer to object.
-[classVar release]; // Decrements classVar's reference count.
-// 'retain' claims ownership of existing object instance and increments reference count. Returns pointer to object.
-MyClass *newVar = [classVar retain]; // If classVar is released, object is still in memory because newVar is owner.
-[classVar autorelease]; // Removes ownership of object at end of @autoreleasepool block. Returns pointer to object.
+MyClass *classVar = [MyClass alloc]; // 'alloc' sets classVar's reference count to one. Returns pointer to object
+[classVar release]; // Decrements classVar's reference count
+// 'retain' claims ownership of existing object instance and increments reference count. Returns pointer to object
+MyClass *newVar = [classVar retain]; // If classVar is released, object is still in memory because newVar is owner
+[classVar autorelease]; // Removes ownership of object at end of @autoreleasepool block. Returns pointer to object
-// @property can use 'retain' and 'assign' as well for small convenient definitions.
-@property (retain) MyClass *instance; // Release old value and retain a new one (strong reference).
-@property (assign) NSSet *set; // Pointer to new value without retaining/releasing old (weak reference).
+// @property can use 'retain' and 'assign' as well for small convenient definitions
+@property (retain) MyClass *instance; // Release old value and retain a new one (strong reference)
+@property (assign) NSSet *set; // Pointer to new value without retaining/releasing old (weak reference)
// Automatic Reference Counting (ARC)
// Because memory management can be a pain, Xcode 4.2 and iOS 4 introduced Automatic Reference Counting (ARC).
// ARC is a compiler feature that inserts retain, release, and autorelease automatically for you, so when using ARC,
-// you must not use retain, relase, or autorelease.
+// you must not use retain, relase, or autorelease
MyClass *arcMyClass = [[MyClass alloc] init];
// ... code using arcMyClass
// Without ARC, you will need to call: [arcMyClass release] after you're done using arcMyClass. But with ARC,
-// there is no need. It will insert this release statement for you.
+// there is no need. It will insert this release statement for you
-// As for the 'assign' and 'retain' @property attributes, with ARC you use 'weak' and 'strong'.
+// As for the 'assign' and 'retain' @property attributes, with ARC you use 'weak' and 'strong'
@property (weak) MyClass *weakVar; // 'weak' does not take ownership of object. If original instance's reference count
-// is set to zero, weakVar will automatically receive value of nil to avoid application crashing.
-@property (strong) MyClass *strongVar; // 'strong' takes ownership of object. Ensures object will stay in memory to use.
+// is set to zero, weakVar will automatically receive value of nil to avoid application crashing
+@property (strong) MyClass *strongVar; // 'strong' takes ownership of object. Ensures object will stay in memory to use
// For regular variables (not @property declared variables), use the following:
-__strong NSString *strongString; // Default. Variable is retained in memory until it leaves it's scope.
-__weak NSSet *weakSet; // Weak reference to existing object. When existing object is released, weakSet is set to nil.
-__unsafe_unretained NSArray *unsafeArray; // Like __weak, but unsafeArray not set to nil when existing object is released.
+__strong NSString *strongString; // Default. Variable is retained in memory until it leaves it's scope
+__weak NSSet *weakSet; // Weak reference to existing object. When existing object is released, weakSet is set to nil
+__unsafe_unretained NSArray *unsafeArray; // Like __weak, but unsafeArray not set to nil when existing object is released
```
## Further Reading
diff --git a/paren.html.markdown b/paren.html.markdown
new file mode 100644
index 00000000..cde14853
--- /dev/null
+++ b/paren.html.markdown
@@ -0,0 +1,193 @@
+---
+
+language: Paren
+filename: learnparen.paren
+contributors:
+ - ["KIM Taegyoon", "https://github.com/kimtg"]
+---
+
+[Paren](https://bitbucket.org/ktg/paren) is a dialect of Lisp. It is designed to be an embedded language.
+
+Some examples are from <http://learnxinyminutes.com/docs/racket/>.
+
+```scheme
+;;; Comments
+# comments
+
+;; Single line comments start with a semicolon or a sharp sign
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 1. Primitive Datatypes and Operators
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Numbers
+123 ; int
+3.14 ; double
+6.02e+23 ; double
+(int 3.14) ; => 3 : int
+(double 123) ; => 123 : double
+
+;; Function application is written (f x y z ...)
+;; where f is a function and x, y, z, ... are operands
+;; If you want to create a literal list of data, use (quote) to stop it from
+;; being evaluated
+(quote (+ 1 2)) ; => (+ 1 2)
+;; Now, some arithmetic operations
+(+ 1 1) ; => 2
+(- 8 1) ; => 7
+(* 10 2) ; => 20
+(^ 2 3) ; => 8
+(/ 5 2) ; => 2
+(% 5 2) ; => 1
+(/ 5.0 2) ; => 2.5
+
+;;; Booleans
+true ; for true
+false ; for false
+(! true) ; => false
+(&& true false (prn "doesn't get here")) ; => false
+(|| false true (prn "doesn't get here")) ; => true
+
+;;; Characters are ints.
+(char-at "A" 0) ; => 65
+(chr 65) ; => "A"
+
+;;; Strings are fixed-length array of characters.
+"Hello, world!"
+"Benjamin \"Bugsy\" Siegel" ; backslash is an escaping character
+"Foo\tbar\r\n" ; includes C escapes: \t \r \n
+
+;; Strings can be added too!
+(strcat "Hello " "world!") ; => "Hello world!"
+
+;; A string can be treated like a list of characters
+(char-at "Apple" 0) ; => 65
+
+;; Printing is pretty easy
+(pr "I'm" "Paren. ") (prn "Nice to meet you!")
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 2. Variables
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; You can create or set a variable using (set)
+;; a variable name can use any character except: ();#"
+(set some-var 5) ; => 5
+some-var ; => 5
+
+;; Accessing a previously unassigned variable is an exception
+; x ; => Unknown variable: x : nil
+
+;; Local binding: Use lambda calculus! `a' and `b' are bound to `1' and `2' only within the (fn ...)
+((fn (a b) (+ a b)) 1 2) ; => 3
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Collections
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Lists
+
+;; Lists are vector-like data structures. (Random access is O(1).)
+(cons 1 (cons 2 (cons 3 (list)))) ; => (1 2 3)
+;; `list' is a convenience variadic constructor for lists
+(list 1 2 3) ; => (1 2 3)
+;; and a quote can also be used for a literal list value
+(quote (+ 1 2)) ; => (+ 1 2)
+
+;; Can still use `cons' to add an item to the beginning of a list
+(cons 0 (list 1 2 3)) ; => (0 1 2 3)
+
+;; Lists are a very basic type, so there is a *lot* of functionality for
+;; them, a few examples:
+(map inc (list 1 2 3)) ; => (2 3 4)
+(filter (fn (x) (== 0 (% x 2))) (list 1 2 3 4)) ; => (2 4)
+(length (list 1 2 3 4)) ; => 4
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 3. Functions
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `fn' to create functions.
+;; A function always returns the value of its last expression
+(fn () "Hello World") ; => (fn () Hello World) : fn
+
+;; Use parentheses to call all functions, including a lambda expression
+((fn () "Hello World")) ; => "Hello World"
+
+;; Assign a function to a var
+(set hello-world (fn () "Hello World"))
+(hello-world) ; => "Hello World"
+
+;; You can shorten this using the function definition syntatcic sugae:
+(defn hello-world2 () "Hello World")
+
+;; The () in the above is the list of arguments for the function
+(set hello
+ (fn (name)
+ (strcat "Hello " name)))
+(hello "Steve") ; => "Hello Steve"
+
+;; ... or equivalently, using a sugared definition:
+(defn hello2 (name)
+ (strcat "Hello " name))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 4. Equality
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; for numbers use `=='
+(== 3 3.0) ; => true
+(== 2 1) ; => false
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 5. Control Flow
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Conditionals
+
+(if true ; test expression
+ "this is true" ; then expression
+ "this is false") ; else expression
+; => "this is true"
+
+;;; Loops
+
+;; for loop is for number
+;; (for SYMBOL START END STEP EXPR ..)
+(for i 0 10 2 (pr i "")) ; => prints 0 2 4 6 8 10
+(for i 0.0 10 2.5 (pr i "")) ; => prints 0 2.5 5 7.5 10
+
+;; while loop
+((fn (i)
+ (while (< i 10)
+ (pr i)
+ (++ i))) 0) ; => prints 0123456789
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 6. Mutation
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Use `set' to assign a new value to a variable or a place
+(set n 5) ; => 5
+(set n (inc n)) ; => 6
+n ; => 6
+(set a (list 1 2)) ; => (1 2)
+(set (nth 0 a) 3) ; => 3
+a ; => (3 2)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 7. Macros
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;; Macros let you extend the syntax of the language.
+;; Paren macros are easy.
+;; In fact, (defn) is a macro.
+(defmacro setfn (name ...) (set name (fn ...)))
+(defmacro defn (name ...) (def name (fn ...)))
+
+;; Let's add an infix notation
+(defmacro infix (a op ...) (op a ...))
+(infix 1 + 2 (infix 3 * 4)) ; => 15
+
+;; Macros are not hygienic, you can clobber existing variables!
+;; They are code transformations.
+```
diff --git a/perl.html.markdown b/perl.html.markdown
index ad9155e4..da2e0cdf 100644
--- a/perl.html.markdown
+++ b/perl.html.markdown
@@ -12,7 +12,7 @@ Perl 5 is a highly capable, feature-rich programming language with over 25 years
Perl 5 runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large scale development projects.
```perl
-# Single line comments start with a hash.
+# Single line comments start with a number symbol.
#### Perl variable types
diff --git a/php.html.markdown b/php.html.markdown
index c3317d59..e1bb86a0 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -212,7 +212,7 @@ assert($c >= $d);
// The following will only be true if the values match and are the same type.
assert($c === $d);
assert($a !== $d);
-assert(1 == '1');
+assert(1 === '1');
assert(1 !== '1');
// Variables can be converted between types, depending on their usage.
diff --git a/pt-br/go-pt.html.markdown b/pt-br/go-pt.html.markdown
index cca58b16..32c8fbdd 100644
--- a/pt-br/go-pt.html.markdown
+++ b/pt-br/go-pt.html.markdown
@@ -6,6 +6,7 @@ filename: learngo-pt.go
lang: pt-br
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["Jose Donizetti", "https://github.com/josedonizetti"]
translators:
- ["Nuno Antunes", "https://github.com/ntns"]
---
@@ -306,3 +307,6 @@ a melhor demonstração de código fácil de ler e de perceber, do estilo Go, e
sua escrita idiomática. Ou então clique no nome de uma função na [documentação]
(http://golang.org/pkg/) e veja o código fonte aparecer!
+Outra ótima fonte para aprender Go é o [Go by example](https://gobyexample.com/).
+Apesar de ser em inglês, é possível recodificar os exemplos para aprender sobre
+a linguagem.
diff --git a/pt-br/java-pt.html.markdown b/pt-br/java-pt.html.markdown
index e8d5a538..a884f273 100644
--- a/pt-br/java-pt.html.markdown
+++ b/pt-br/java-pt.html.markdown
@@ -8,7 +8,7 @@ translators:
- ["Victor Kléber Santos L. Melo", "http://victormelo.com.br/blog"]
- ["Renê Douglas N. de Morais", "mailto:rene.douglas.bsi@gmail.com"]
lang: pt-br
-filename: LearnJava.java
+filename: LearnJava-pt.java
---
diff --git a/pt-br/ruby-pt.html.markdown b/pt-br/ruby-pt.html.markdown
index a2f40c3b..4a8a1b5c 100644
--- a/pt-br/ruby-pt.html.markdown
+++ b/pt-br/ruby-pt.html.markdown
@@ -1,7 +1,7 @@
---
language: ruby
-lang: br-pt
-filename: learnruby.rb
+lang: pt-br
+filename: learnruby-pt.rb
contributors:
- ["Bruno Henrique - Garu", "http://garulab.com"]
translators:
diff --git a/pt-br/visualbasic-pt.html.markdown b/pt-br/visualbasic-pt.html.markdown
new file mode 100644
index 00000000..76cca567
--- /dev/null
+++ b/pt-br/visualbasic-pt.html.markdown
@@ -0,0 +1,285 @@
+---
+language: Visual Basic
+contributors:
+ - ["Brian Martin", "http://brianmartin.biz"]
+translators:
+ - ["AdrianoJP", "https://github.com/AdrianoJP"]
+lang: pt-br
+filename: learnvisualbasic-pt.vb
+---
+
+```vb
+Module Module1
+
+module Module1
+
+ Sub Main ()
+ ' Uma visão geral de console de aplicativos do Visual Basic antes de
+ ' mergulharmos mais profundamente na linguagem
+ ' Aspas simples começam comentários.
+ ' Para Navegar este tutorial dentro do compilador do Visual Basic,
+ ' eu criei um sistema de navegação.
+ ' Este sistema de navegação vai ser explicado conforme avançarmos no
+ ' tutorial, e você vai entender o que isso significa.
+ Console.Title = (" Saiba X em Y Minutes" )
+ Console.WriteLine ( "NAVEGAÇÃO" ) 'Mostrar
+ Console.ForegroundColor = ConsoleColor.Green
+ Console.WriteLine ("1. Saída Olá Mundo" )
+ Console.WriteLine ("2. Entrada Olá Mundo" )
+ Console.WriteLine ("3. Cálculando números inteiros " )
+ Console.WriteLine ("4. Calculando números decimais " )
+ Console.WriteLine ("5 . Calculadora de Trabalho " )
+ Console.WriteLine ("6. Usando Do While Loops " )
+ Console.WriteLine ("7. Usando Para While Loops " )
+ Console.WriteLine ("8 . Declarações condicionais " )
+ Console.WriteLine ("9. Selecione uma bebida" )
+ Console.WriteLine ("50 . About" )
+ Console.WriteLine ("Por favor, escolha um número da lista acima " )
+ Seleção Dim As String = Console.ReadLine
+ Select A seleção dos casos
+ Caso "1" 'Output HelloWorld
+ Console.clear () ' Limpa a aplicação e abre o sub privado
+ HelloWorldOutput () ' Nome Private Sub, Abre Private Sub
+ Caso "2" 'Olá entrada
+ Console.clear ( )
+ HelloWorldInput ( )
+ Caso de "3" 'Calculando Números Inteiros
+ Console.clear ( )
+ CalculatingWholeNumbers ( )
+ Caso "4" ' Números decimais Calculting
+ Console.clear ( )
+ CalculatingDecimalNumbers ( )
+ Caso "5" ' Calcculator Trabalho
+ Console.clear ( )
+ WorkingCalculator ( )
+ Caso "6" 'Usando Do While Loops
+ Console.clear ( )
+ UsingDoWhileLoops ( )
+ Caso de "7" 'Usando pois enquanto Loops
+ Console.clear ( )
+ UsingForLoops ( )
+ Caso "8" ' Instruções condicionais
+ Console.clear ( )
+ ConditionalStatement ( )
+ Caso "9" "Declaração If / Else
+ Console.clear ( )
+ IfElseStatement () ' Selecione uma bebida
+ Caso "50" 'Quem caixa de msg
+ Console.clear ( )
+ Console.Title = (" Saiba X em Y Minutos :: Quem " )
+ MsgBox (" Este tutorial é de Brian Martin ( @ BrianMartinn " )
+ Console.clear ( )
+ Main ()
+ Console.ReadLine ()
+
+ End Select
+ End Sub
+
+ ' Um - Eu estou usando números para ajudar com a navegação acima quando eu voltar
+ ' depois de construí-lo .
+
+ " Nós usamos subs privadas para separar diferentes seções do programa.
+ Private Sub HelloWorldOutput ()
+ ' Título de aplicativo do console
+ Console.Title = " Olá Mundo Ouput | Saiba X em Y Minutes"
+ 'Use Console.Write ("") ou Console.WriteLine ("") para imprimir saídas.
+ " Seguido por Console.Read () alternativamente Console.ReadLine ()
+ ' Console.ReadLine () imprime a saída para o console.
+ Console.WriteLine ( "Olá Mundo" )
+ Console.ReadLine ()
+ End Sub
+
+ ' Dois
+ Private Sub HelloWorldInput ()
+ Console.Title = " Olá Mundo YourName | Saiba X em Y Minutes"
+ ' Variáveis
+ 'Os dados inseridos por um usuário precisa ser armazenada .
+ ' As variáveis ​​também começar com um Dim e terminar com um Como VariableType .
+
+ ' Neste tutorial, nós queremos saber o que o seu nome, e faça o programa
+ ' Responder ao que é dito.
+ Nome de usuário Dim As String
+ " Nós usamos string como string é uma variável de texto baseado .
+ Console.WriteLine (" Olá, Qual é o seu nome? ") ' Peça ao usuário seu nome.
+ username = Console.ReadLine () ' armazena o nome usuários.
+ Console.WriteLine (" Olá " + nome do usuário) " A saída é Olá ' Seu nome '
+ Console.ReadLine () ' Outsputs acima.
+ ' O código acima irá lhe fazer uma pergunta seguiu imprimindo sua resposta.
+ " Outras variáveis ​​incluem Integer e usamos inteiro para números inteiros.
+ End Sub
+
+ "Três
+ Sub CalculatingWholeNumbers particulares ()
+ Console.Title = " Cálculo de Números Inteiros | Saiba X em Y Minutes"
+ Console.Write ("Primeiro número:") 'Digite um número inteiro, 1, 2, 50, 104 ect
+ Dim a As Integer = Console.ReadLine ()
+ Console.Write ("Segundo número:") 'Enter segundo número inteiro.
+ Dim b As Integer = Console.ReadLine ()
+ Dim c As Integer = a + b
+ Console.WriteLine ( c)
+ Console.ReadLine ()
+ " O texto acima é uma calculadora simples
+ End Sub
+
+ 'Quatro
+ Sub CalculatingDecimalNumbers particulares ()
+ Console.Title = " Calculando com duplo | Saiba X em Y Minutes"
+ ' Claro que gostaria de ser capaz de somar decimais .
+ " Por isso, poderia mudar o acima de Integer para Double.
+
+ " Digite um número inteiro , 1,2 , 2,4 , 50,1 , 104,9 ect
+ Console.Write ("Primeiro número:")
+ Dim a As Double = Console.ReadLine
+ Console.Write ("Segundo número:") 'Enter segundo número inteiro.
+ Dim b As Double = Console.ReadLine
+ Dim c As Double = a + b
+ Console.WriteLine ( c)
+ Console.ReadLine ()
+ " Portanto, o programa acima pode adicionar até 1,1-2,2
+ End Sub
+
+ ' Cinco
+ Private Sub WorkingCalculator ()
+ Console.Title = " A Calculadora de Trabalho | Saiba X em Y Minutes"
+ " No entanto, se você gostaria que a calculadora para subtrair, dividir , múltiplos e
+ ' somar.
+ ' Copie e cole o código acima novamente .
+ Console.Write ("Primeiro número:")
+ Dim a As Double = Console.ReadLine
+ Console.Write ("Segundo número:") 'Enter segundo número inteiro.
+ Dim b As Integer = Console.ReadLine
+ Dim c As Integer = a + b
+ Dim d As Integer = a * b
+ Dim e As Integer = a - b
+ Dim f As Integer = a / b
+
+ " Ao adicionar as linhas abaixo , somos capazes de calcular a subtração ,
+ ' multply bem como dividir os valores de a e b
+ Console.Gravar ( a.ToString ( ) + " + " + b.ToString ( ) )
+ 'Queremos pad as respostas para a esquerda por três espaços.
+ Console.WriteLine (" =" + c.ToString.PadLeft (3) )
+ Console.Gravar ( a.ToString ( ) + " * " + b.ToString ( ) )
+ Console.WriteLine (" =" + d.ToString.PadLeft (3) )
+ Console.Gravar ( a.ToString ( ) + " - " + b.ToString ( ) )
+ Console.WriteLine (" =" + e.ToString.PadLeft (3) )
+ Console.Write ( a.ToString () + "/" + b.ToString ())
+ Console.WriteLine (" =" + e.ToString.PadLeft (3) )
+ Console.ReadLine ()
+
+ End Sub
+
+ ' Seis
+ Sub UsingDoWhileLoops particulares ()
+ ' Assim como o sub privado anterior
+ ' Desta vez, perguntar se o usuário deseja continuar ( Sim ou Não ? )
+ ' Estamos usando Do While Loop , como não temos certeza se o usuário quer usar o
+ 'programa mais de uma vez .
+ Console.Title = " UsingDoWhileLoops | Saiba X em Y Minutes"
+ Dim resposta As String ' Nós usamos a variável " String" como a resposta é um texto
+ Do ' Começamos o programa com
+ Console.Write ("Primeiro número:")
+ Dim a As Double = Console.ReadLine
+ Console.Write ("Segundo número:")
+ Dim b As Integer = Console.ReadLine
+ Dim c As Integer = a + b
+ Dim d As Integer = a * b
+ Dim e As Integer = a - b
+ Dim f As Integer = a / b
+
+ Console.Gravar ( a.ToString ( ) + " + " + b.ToString ( ) )
+ Console.WriteLine (" =" + c.ToString.PadLeft (3) )
+ Console.Gravar ( a.ToString ( ) + " * " + b.ToString ( ) )
+ Console.WriteLine (" =" + d.ToString.PadLeft (3) )
+ Console.Gravar ( a.ToString ( ) + " - " + b.ToString ( ) )
+ Console.WriteLine (" =" + e.ToString.PadLeft (3) )
+ Console.Write ( a.ToString () + "/" + b.ToString ())
+ Console.WriteLine (" =" + e.ToString.PadLeft (3) )
+ Console.ReadLine ()
+ ' Faça a pergunta , se o usuário deseja continuar? Infelizmente,
+ "é sensível a maiúsculas.
+ Console.Write ( "Deseja continuar? (Sim / não )")
+ " O programa pega a variável e imprime e começa de novo.
+ answer = Console.ReadLine
+ " O comando para a variável para trabalhar seria , neste caso, " sim "
+ Loop While resposta = "yes"
+
+ End Sub
+
+ ' Sete
+ Sub UsingForLoops particulares ()
+ ' Às vezes, o programa só precisa ser executado uma vez.
+ " Neste programa vamos estar em contagem regressiva a partir de 10.
+
+ Console.Title = " Usando Para Loops | Saiba X em Y Minutes"
+ 'Declare variável e qual o número que deve contar para baixo na etapa 1,
+ ' Passo -2, -3 Passo ect.
+ Para i As Integer = 10 para 0 passo -1
+ Console.WriteLine ( i.ToString ) ' Imprime o valor do contador
+ Next i ' Calcular novo valor
+ Console.WriteLine ( "Start ") ' Vamos começar o bebê programa !
+ Console.ReadLine () ' POW ! - Talvez eu fiquei um pouco animado, então :)
+ End Sub
+
+ ' Oito
+ Private Sub ConditionalStatement ()
+ Console.Title = " Instruções condicionais | Saiba X em Y Minutes"
+ UserName Dim As String = Console.ReadLine
+ Console.WriteLine (" Olá, Qual é o seu nome? ") ' Peça ao usuário seu nome.
+ username = Console.ReadLine () ' armazena o nome usuários.
+ Se userName = " Adam " Então
+ Console.WriteLine (" Olá Adam " )
+ Console.WriteLine (" Obrigado por criar este site útil " )
+ Console.ReadLine ()
+ outro
+ Console.WriteLine (" Olá " + nome do usuário)
+ Console.WriteLine (" Você check-out www.learnxinyminutes.com " )
+ Console.ReadLine () ' Fins e imprime a declaração acima .
+ End If
+ End Sub
+
+ 'Nove
+ Private Sub IfElseStatement ()
+ Console.Title = "Se Declaração / Else | Saiba X em Y Minutes"
+ 'Às vezes é importante ter em conta mais de duas alternativas.
+ 'Às vezes, há um bom número de outros.
+ 'Quando este for o caso , mais do que uma if seria necessária .
+ 'Uma instrução if é ótimo para máquinas de venda automática . Quando o usuário digita um código.
+ ' A1 , A2, A3 , ect para selecionar um item.
+ 'Todas as opções podem ser combinadas em uma única if.
+
+ Seleção Dim Valor String = Console.ReadLine ' para a seleção
+ Console.WriteLine (" A1. Para Soda " )
+ Console.WriteLine (" A2. Para Fanta " )
+ Console.WriteLine (" A3 . Para Guaraná" )
+ Console.WriteLine (" A4. Para Coca Diet" )
+ Console.ReadLine ()
+ Se a seleção = "A1" Então
+ Console.WriteLine (" soda " )
+ Console.ReadLine ()
+ Seleção ElseIf = " A2 " Então
+ Console.WriteLine (" fanta " )
+ Console.ReadLine ()
+ Seleção ElseIf = " A3 " Então
+ Console.WriteLine ( "guaraná" )
+ Console.ReadLine ()
+ Seleção ElseIf = " A4 " Então
+ Console.WriteLine ( "coca diet" )
+ Console.ReadLine ()
+ outro
+ Console.WriteLine (" Por favor seleccione um produto" )
+ Console.ReadLine ()
+ End If
+
+ End Sub
+
+End Module
+
+```
+
+##Referências
+
+Aprendi Visual Basic no aplicativo de console. Isso me permitiu entender os princípios da programação de computador para continuar a aprender outras linguagens de programação facilmente.
+
+Eu criei um tutorial mais aprofundado do <a href="http://www.vbbootcamp.co.uk/" Title="Visual Basic Tutorial">Visual Basic</a> para aqueles que gostariam de saber mais.
+
+Toda a sintaxe deste tutorial é válida. Copie e cole o código no compilador do Visual Basic e execute (com o F5) o programa.
diff --git a/python.html.markdown b/python.html.markdown
index 941ba9f4..210c9619 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -16,7 +16,9 @@ Note: This article applies to Python 2.7 specifically, but should be applicable
to Python 2.x. Look for another tour of Python 3 soon!
```python
-# Single line comments start with a hash.
+
+# Single line comments start with a number symbol.
+
""" Multiline strings can be written
using three "'s, and are often used
as comments
@@ -27,60 +29,60 @@ to Python 2.x. Look for another tour of Python 3 soon!
####################################################
# You have numbers
-3 #=> 3
+3 # => 3
# Math is what you would 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
# Division is a bit tricky. It is integer division and floors the results
# automatically.
-5 / 2 #=> 2
+5 / 2 # => 2
# To fix division we need to learn about floats.
2.0 # This is a float
-11.0 / 4.0 #=> 2.75 ahhh...much better
+11.0 / 4.0 # => 2.75 ahhh...much better
# Enforce precedence with parentheses
-(1 + 3) * 2 #=> 8
+(1 + 3) * 2 # => 8
# Boolean values are primitives
True
False
# negate with not
-not True #=> False
-not False #=> True
+not True # => False
+not 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
# Comparisons can be chained!
-1 < 2 < 3 #=> True
-2 < 3 < 2 #=> False
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
# Strings are created with " or '
"This is a string."
'This is also a string.'
# Strings can be added too!
-"Hello " + "world!" #=> "Hello world!"
+"Hello " + "world!" # => "Hello world!"
# A string can be treated like a list of characters
-"This is a string"[0] #=> 'T'
+"This is a string"[0] # => 'T'
# % can be used to format strings, like this:
"%s can be %s" % ("strings", "interpolated")
@@ -92,12 +94,12 @@ not False #=> True
"{name} wants to eat {food}".format(name="Bob", food="lasagna")
# None is an object
-None #=> None
+None # => None
# Don't use the equality "==" symbol to compare objects to None
# Use "is" instead
-"etc" is None #=> False
-None is None #=> True
+"etc" is None # => False
+None is None # => True
# The 'is' operator tests for object identity. This isn't
# very useful when dealing with primitive values, but is
@@ -105,8 +107,8 @@ None is None #=> True
# None, 0, and empty strings/lists all evaluate to False.
# All other values are True
-bool(0) #=> False
-bool("") #=> False
+bool(0) # => False
+bool("") # => False
####################################################
@@ -121,14 +123,14 @@ print "I'm also Python!"
# No need to declare variables before assigning to them.
some_var = 5 # Convention is to use lower_case_with_underscores
-some_var #=> 5
+some_var # => 5
# Accessing a previously unassigned variable is an exception.
# See Control Flow to learn more about exception handling.
some_other_var # Raises a name error
# if can be used as an expression
-"yahoo!" if 3 > 2 else 2 #=> "yahoo!"
+"yahoo!" if 3 > 2 else 2 # => "yahoo!"
# Lists store sequences
li = []
@@ -136,59 +138,63 @@ li = []
other_li = [4, 5, 6]
# Add stuff to the end of a list with append
-li.append(1) #li is now [1]
-li.append(2) #li is now [1, 2]
-li.append(4) #li is now [1, 2, 4]
-li.append(3) #li is now [1, 2, 4, 3]
+li.append(1) # li is now [1]
+li.append(2) # li is now [1, 2]
+li.append(4) # li is now [1, 2, 4]
+li.append(3) # li is now [1, 2, 4, 3]
# Remove from the end with pop
-li.pop() #=> 3 and li is now [1, 2, 4]
+li.pop() # => 3 and li is now [1, 2, 4]
# Let's put it back
li.append(3) # li is now [1, 2, 4, 3] again.
# Access a list like you would any array
-li[0] #=> 1
+li[0] # => 1
# Look at the last element
-li[-1] #=> 3
+li[-1] # => 3
# Looking out of bounds is an IndexError
-li[4] # Raises an IndexError
+li[4] # Raises an IndexError
# You can look at ranges with slice syntax.
# (It's a closed/open range for you mathy types.)
-li[1:3] #=> [2, 4]
+li[1:3] # => [2, 4]
# Omit the beginning
-li[2:] #=> [4, 3]
+li[2:] # => [4, 3]
# Omit the end
-li[:3] #=> [1, 2, 4]
+li[:3] # => [1, 2, 4]
+# Select every second entry
+li[::2] # =>[1, 4]
# Revert the list
-li[::-1] #=> [3, 4, 2, 1]
+li[::-1] # => [3, 4, 2, 1]
+# Use any combination of these to make advanced slices
+# li[start:end:step]
# Remove arbitrary elements from a list with "del"
-del li[2] # li is now [1, 2, 3]
+del li[2] # li is now [1, 2, 3]
# You can add lists
-li + other_li #=> [1, 2, 3, 4, 5, 6] - Note: li and other_li is left alone
+li + other_li # => [1, 2, 3, 4, 5, 6] - Note: values for li and for other_li are not modified.
# Concatenate lists with "extend()"
-li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
+li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
# Check for existence in a list with "in"
-1 in li #=> True
+1 in li # => True
# Examine the length with "len()"
-len(li) #=> 6
+len(li) # => 6
# Tuples are like lists but are immutable.
tup = (1, 2, 3)
-tup[0] #=> 1
+tup[0] # => 1
tup[0] = 3 # Raises a TypeError
# You can do all those list thingies on tuples too
-len(tup) #=> 3
-tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
-tup[:2] #=> (1, 2)
-2 in tup #=> True
+len(tup) # => 3
+tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
+tup[:2] # => (1, 2)
+2 in tup # => True
# You can unpack tuples (or lists) into variables
a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
@@ -204,60 +210,60 @@ empty_dict = {}
filled_dict = {"one": 1, "two": 2, "three": 3}
# Look up values with []
-filled_dict["one"] #=> 1
+filled_dict["one"] # => 1
# Get all keys as a list with "keys()"
-filled_dict.keys() #=> ["three", "two", "one"]
+filled_dict.keys() # => ["three", "two", "one"]
# Note - Dictionary key ordering is not guaranteed.
# Your results might not match this exactly.
# Get all values as a list with "values()"
-filled_dict.values() #=> [3, 2, 1]
+filled_dict.values() # => [3, 2, 1]
# Note - Same as above regarding key ordering.
# Check for existence of keys in a dictionary with "in"
-"one" in filled_dict #=> True
-1 in filled_dict #=> False
+"one" in filled_dict # => True
+1 in filled_dict # => False
# Looking up a non-existing key is a KeyError
-filled_dict["four"] # KeyError
+filled_dict["four"] # KeyError
# Use "get()" method to avoid the KeyError
-filled_dict.get("one") #=> 1
-filled_dict.get("four") #=> None
+filled_dict.get("one") # => 1
+filled_dict.get("four") # => None
# The get method supports a default argument when the value is missing
-filled_dict.get("one", 4) #=> 1
-filled_dict.get("four", 4) #=> 4
+filled_dict.get("one", 4) # => 1
+filled_dict.get("four", 4) # => 4
# "setdefault()" inserts into a dictionary only if the given key isn't present
-filled_dict.setdefault("five", 5) #filled_dict["five"] is set to 5
-filled_dict.setdefault("five", 6) #filled_dict["five"] is still 5
+filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5
+filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5
# Sets store ... well sets
empty_set = set()
# Initialize a "set()" with a bunch of values
-some_set = set([1,2,2,3,4]) # some_set is now set([1, 2, 3, 4])
+some_set = set([1, 2, 2, 3, 4]) # some_set is now set([1, 2, 3, 4])
# Since Python 2.7, {} can be used to declare a set
-filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
+filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
# Add more items to a set
-filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5}
+filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5}
# Do set intersection with &
other_set = {3, 4, 5, 6}
-filled_set & other_set #=> {3, 4, 5}
+filled_set & other_set # => {3, 4, 5}
# Do set union with |
-filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+filled_set | other_set # => {1, 2, 3, 4, 5, 6}
# Do set difference with -
-{1,2,3,4} - {2,3,5} #=> {1, 4}
+{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}
# Check for existence in a set with in
-2 in filled_set #=> True
-10 in filled_set #=> False
+2 in filled_set # => True
+10 in filled_set # => False
####################################################
@@ -333,17 +339,18 @@ def add(x, y):
return x + y # Return values with a return statement
# Calling functions with parameters
-add(5, 6) #=> prints out "x is 5 and y is 6" and returns 11
+add(5, 6) # => prints out "x is 5 and y is 6" and returns 11
# Another way to call functions is with keyword arguments
add(y=6, x=5) # Keyword arguments can arrive in any order.
+
# You can define functions that take a variable number of
# positional arguments
def varargs(*args):
return args
-varargs(1, 2, 3) #=> (1,2,3)
+varargs(1, 2, 3) # => (1, 2, 3)
# You can define functions that take a variable number of
@@ -352,7 +359,8 @@ def keyword_args(**kwargs):
return kwargs
# Let's call it to see what happens
-keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"}
+
# You can do both at once, if you like
def all_the_args(*args, **kwargs):
@@ -368,9 +376,10 @@ all_the_args(1, 2, a=3, b=4) prints:
# Use * to expand tuples and use ** to expand kwargs.
args = (1, 2, 3, 4)
kwargs = {"a": 3, "b": 4}
-all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
-all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
-all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+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)
+
# Python has first class functions
def create_adder(x):
@@ -379,23 +388,24 @@ def create_adder(x):
return adder
add_10 = create_adder(10)
-add_10(3) #=> 13
+add_10(3) # => 13
# There are also anonymous functions
-(lambda x: x > 2)(3) #=> True
+(lambda x: x > 2)(3) # => True
# There are built-in higher order functions
-map(add_10, [1,2,3]) #=> [11, 12, 13]
-filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+map(add_10, [1, 2, 3]) # => [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
# We can use list comprehensions for nice maps and filters
-[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. Classes
####################################################
+
# We subclass from object to get a class.
class Human(object):
@@ -409,7 +419,7 @@ class Human(object):
# An instance method. All methods take "self" as the first argument
def say(self, msg):
- return "%s: %s" % (self.name, msg)
+ return "%s: %s" % (self.name, msg)
# A class method is shared among all instances
# They are called with the calling class as the first argument
@@ -428,18 +438,18 @@ i = Human(name="Ian")
print(i.say("hi")) # prints out "Ian: hi"
j = Human("Joel")
-print(j.say("hello")) #prints out "Joel: hello"
+print(j.say("hello")) # prints out "Joel: hello"
# Call our class method
-i.get_species() #=> "H. sapiens"
+i.get_species() # => "H. sapiens"
# Change the shared attribute
Human.species = "H. neanderthalensis"
-i.get_species() #=> "H. neanderthalensis"
-j.get_species() #=> "H. neanderthalensis"
+i.get_species() # => "H. neanderthalensis"
+j.get_species() # => "H. neanderthalensis"
# Call the static method
-Human.grunt() #=> "*grunt*"
+Human.grunt() # => "*grunt*"
####################################################
@@ -448,12 +458,12 @@ Human.grunt() #=> "*grunt*"
# You can import modules
import math
-print(math.sqrt(16) )#=> 4
+print(math.sqrt(16)) # => 4
# You can get specific functions from a module
from math import ceil, floor
-print(ceil(3.7)) #=> 4.0
-print(floor(3.7)) #=> 3.0
+print(ceil(3.7)) # => 4.0
+print(floor(3.7)) # => 3.0
# You can import all functions from a module.
# Warning: this is not recommended
@@ -461,7 +471,7 @@ from math import *
# You can shorten module names
import math as m
-math.sqrt(16) == m.sqrt(16) #=> True
+math.sqrt(16) == m.sqrt(16) # => True
# Python modules are just ordinary python files. You
# can write your own, and import them. The name of the
@@ -473,6 +483,55 @@ import math
dir(math)
+####################################################
+## 7. Advanced
+####################################################
+
+# Generators help you make lazy code
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# A generator creates values on the fly.
+# Instead of generating and returning all values at once it creates one in each
+# iteration. This means values bigger than 15 wont be processed in
+# double_numbers.
+# Note range is a generator too. Creating a list 1-900000000 would take lot of
+# time to be made
+_range = range(1, 900000000)
+# will double all numbers until a result >=30 found
+for i in double_numbers(_range):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decorators
+# in this example beg wraps say
+# Beg will call say. If say_please is True then it will change the returned
+# message
+from functools import wraps
+
+
+def beg(_say):
+ @wraps(_say)
+ def wrapper(*args, **kwargs):
+ msg, say_please = _say(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, "Please! I am poor :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Can you buy me a beer?"
+ return msg, say_please
+
+
+print(say()) # Can you buy me a beer?
+print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(
```
## Ready For More?
diff --git a/python3.html.markdown b/python3.html.markdown
new file mode 100644
index 00000000..77811535
--- /dev/null
+++ b/python3.html.markdown
@@ -0,0 +1,578 @@
+---
+language: python3
+contributors:
+ - ["Louie Dinh", "http://pythonpracticeprojects.com"]
+filename: learnpython3.py
+---
+
+Python was created by Guido Van Rossum in the early 90's. It is now one of the most popular
+languages in existence. I fell in love with Python for its syntactic clarity. It's basically
+executable pseudocode.
+
+Feedback would be highly appreciated! You can reach me at [@louiedinh](http://twitter.com/louiedinh) or louiedinh [at] [google's email service]
+
+Note: This article applies to Python 3 specifically. Check out the other tutorial if you want to learn the old Python 2.7
+
+```python
+
+# Single line comments start with a number symbol.
+
+""" Multiline strings can be written
+ using three "'s, and are often used
+ as comments
+"""
+
+####################################################
+## 1. Primitive Datatypes and Operators
+####################################################
+
+# You have numbers
+3 # => 3
+
+# Math is what you would expect
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+
+# Except division which returns floats by default
+35 / 5 # => 7.0
+
+# When you use a float, results are floats
+3 * 2.0 # => 6.0
+
+# Enforce precedence with parentheses
+(1 + 3) * 2 # => 8
+
+
+# Boolean values are primitives
+True
+False
+
+# negate with not
+not True # => False
+not False # => True
+
+
+# Equality is ==
+1 == 1 # => True
+2 == 1 # => False
+
+# Inequality is !=
+1 != 1 # => False
+2 != 1 # => True
+
+# More comparisons
+1 < 10 # => True
+1 > 10 # => False
+2 <= 2 # => True
+2 >= 2 # => True
+
+# Comparisons can be chained!
+1 < 2 < 3 # => True
+2 < 3 < 2 # => False
+
+
+# Strings are created with " or '
+"This is a string."
+'This is also a string.'
+
+# Strings can be added too! But try not to do this.
+"Hello " + "world!" # => "Hello world!"
+
+# A string can be treated like a list of characters
+"This is a string"[0] # => 'T'
+
+# .format can be used to format strings, like this:
+"{} can be {}".format("strings", "interpolated")
+
+# You can repeat the formatting arguments to save some typing.
+"{0} be nimble, {0} be quick, {0} jump over the {1}".format("Jack", "candle stick") #=> "Jack be nimble, Jack be quick, Jack jump over the candle stick"
+# You can use keywords if you don't want to count.
+"{name} wants to eat {food}".format(name="Bob", food="lasagna") #=> "Bob wants to eat lasagna"
+
+
+# None is an object
+None # => None
+
+# Don't use the equality "==" symbol to compare objects to None
+# Use "is" instead. This checks for equality of object identity.
+"etc" is None # => False
+None is None # => True
+
+# None, 0, and empty strings/lists/dicts all evaluate to False.
+# All other values are True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Variables and Collections
+####################################################
+
+# Python has a print function
+print("I'm Python. Nice to meet you!")
+
+# No need to declare variables before assigning to them. Convention is to use lower_case_with_underscores
+some_var = 5
+some_var # => 5
+
+# Accessing a previously unassigned variable is an exception.
+# See Control Flow to learn more about exception handling.
+some_unknown_var # Raises a NameError
+
+# Lists store sequences
+li = []
+# You can start with a prefilled list
+other_li = [4, 5, 6]
+
+# Add stuff to the end of a list with append
+li.append(1) # li is now [1]
+li.append(2) # li is now [1, 2]
+li.append(4) # li is now [1, 2, 4]
+li.append(3) # li is now [1, 2, 4, 3]
+# Remove from the end with pop
+li.pop() # => 3 and li is now [1, 2, 4]
+# Let's put it back
+li.append(3) # li is now [1, 2, 4, 3] again.
+
+# Access a list like you would any array
+li[0] # => 1
+# Look at the last element
+li[-1] # => 3
+
+# Looking out of bounds is an IndexError
+li[4] # Raises an IndexError
+
+# You can look at ranges with slice syntax.
+# (It's a closed/open range for you mathy types.)
+li[1:3] # => [2, 4]
+# Omit the beginning
+li[2:] # => [4, 3]
+# Omit the end
+li[:3] # => [1, 2, 4]
+# Select every second entry
+li[::2] # =>[1, 4]
+# Revert the list
+li[::-1] # => [3, 4, 2, 1]
+# Use any combination of these to make advanced slices
+# li[start:end:step]
+
+# Remove arbitrary elements from a list with "del"
+del li[2] # li is now [1, 2, 3]
+
+# You can add lists
+li + other_li # => [1, 2, 3, 4, 5, 6] - Note: values for li and for other_li are not modified.
+
+# Concatenate lists with "extend()"
+li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
+
+# Check for existence in a list with "in"
+1 in li # => True
+
+# Examine the length with "len()"
+len(li) # => 6
+
+
+# Tuples are like lists but are immutable.
+tup = (1, 2, 3)
+tup[0] # => 1
+tup[0] = 3 # Raises a TypeError
+
+# You can do all those list thingies on tuples too
+len(tup) # => 3
+tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
+tup[:2] # => (1, 2)
+2 in tup # => True
+
+# You can unpack tuples (or lists) into variables
+a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3
+# Tuples are created by default if you leave out the parentheses
+d, e, f = 4, 5, 6
+# Now look how easy it is to swap two values
+e, d = d, e # d is now 5 and e is now 4
+
+
+# Dictionaries store mappings
+empty_dict = {}
+# Here is a prefilled dictionary
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# Look up values with []
+filled_dict["one"] # => 1
+
+# Get all keys as a list with "keys()". We need to wrap the call in list() because we are getting back an iterable. We'll talk about those later.
+list(filled_dict.keys()) # => ["three", "two", "one"]
+# Note - Dictionary key ordering is not guaranteed.
+# Your results might not match this exactly.
+
+# Get all values as a list with "values()". Once again we need to wrap it in list() to get it out of the iterable.
+list(filled_dict.values()) # => [3, 2, 1]
+# Note - Same as above regarding key ordering.
+
+# Check for existence of keys in a dictionary with "in"
+"one" in filled_dict # => True
+1 in filled_dict # => False
+
+# Looking up a non-existing key is a KeyError
+filled_dict["four"] # KeyError
+
+# Use "get()" method to avoid the KeyError
+filled_dict.get("one") # => 1
+filled_dict.get("four") # => None
+# The get method supports a default argument when the value is missing
+filled_dict.get("one", 4) # => 1
+filled_dict.get("four", 4) # => 4
+
+# "setdefault()" inserts into a dictionary only if the given key isn't present
+filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5
+filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5
+
+# Remove keys from a dictionary with del
+del filled_dict["one"] # Removes the key "one" from filled dict
+
+
+# Sets store ... well sets
+empty_set = set()
+# Initialize a set with a bunch of values. Yeah, it looks a bit like a dict. Sorry.
+some_set = {1, 1, 2, 2, 3, 4} # some_set is now {1, 2, 3, 4}
+
+# Add more items to a set
+filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5}
+
+# Do set intersection with &
+other_set = {3, 4, 5, 6}
+filled_set & other_set # => {3, 4, 5}
+
+# Do set union with |
+filled_set | other_set # => {1, 2, 3, 4, 5, 6}
+
+# Do set difference with -
+{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}
+
+# Check for existence in a set with in
+2 in filled_set # => True
+10 in filled_set # => False
+
+
+####################################################
+## 3. Control Flow and Iterables
+####################################################
+
+# Let's just make a variable
+some_var = 5
+
+# Here is an if statement. Indentation is significant in python!
+# prints "some_var is smaller than 10"
+if some_var > 10:
+ print("some_var is totally bigger than 10.")
+elif some_var < 10: # This elif clause is optional.
+ print("some_var is smaller than 10.")
+else: # This is optional too.
+ print("some_var is indeed 10.")
+
+
+"""
+For loops iterate over lists
+prints:
+ dog is a mammal
+ cat is a mammal
+ mouse is a mammal
+"""
+for animal in ["dog", "cat", "mouse"]:
+ # You can use % to interpolate formatted strings
+ print("{} is a mammal".format(animal))
+
+"""
+"range(number)" returns a list of numbers
+from zero to the given number
+prints:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+While loops go until a condition is no longer met.
+prints:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # Shorthand for x = x + 1
+
+# Handle exceptions with a try/except block
+try:
+ # Use "raise" to raise an error
+ raise IndexError("This is an index error")
+except IndexError as e:
+ pass # Pass is just a no-op. Usually you would do recovery here.
+
+
+# Python's offers a fundamental abstraction called the Iterable.
+# An iterable is an object that can be treated as a sequence.
+# The object returned the range function, is an iterable.
+
+filled_dict = {"one": 1, "two": 2, "three": 3}
+our_iterable = filled_dict.keys()
+print(our_iterable) #=> range(1,10). This is an object that implements our Iterable interface
+
+i We can loop over it.
+for i in our_iterable:
+ print(i) # Prints one, two, three
+
+# However we cannot address elements by index.
+our_iterable[1] # Raises a TypeError
+
+# An iterable is an object that knows how to create an iterator.
+our_iterator = iter(our_iterable)
+
+# Our iterator is an object that can remember the state as we traverse through it.
+# We get the next object by calling the __next__ function.
+our_iterator.__next__() #=> "one"
+
+# It maintains state as we call __next__.
+our_iterator.__next__() #=> "two"
+our_iterator.__next__() #=> "three"
+
+# After the iterator has returned all of its data, it gives you a StopIterator Exception
+our_iterator.__next__() # Raises StopIteration
+
+# You can grab all the elements of an iterator by calling list() on it.
+list(filled_dict.keys()) #=> Returns ["one", "two", "three"]
+
+
+
+####################################################
+## 4. Functions
+####################################################
+
+# Use "def" to create new functions
+def add(x, y):
+ print("x is {} and y is {}".format(x, y))
+ return x + y # Return values with a return statement
+
+# Calling functions with parameters
+add(5, 6) # => prints out "x is 5 and y is 6" and returns 11
+
+# Another way to call functions is with keyword arguments
+add(y=6, x=5) # Keyword arguments can arrive in any order.
+
+
+# You can define functions that take a variable number of
+# positional arguments
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) # => (1, 2, 3)
+
+
+# You can define functions that take a variable number of
+# keyword arguments, as well
+def keyword_args(**kwargs):
+ return kwargs
+
+# Let's call it to see what happens
+keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"}
+
+
+# You can do both at once, if you like
+def all_the_args(*args, **kwargs):
+ print(args)
+ print(kwargs)
+"""
+all_the_args(1, 2, a=3, b=4) prints:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# When calling functions, you can do the opposite of args/kwargs!
+# Use * to expand tuples and use ** to expand kwargs.
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # equivalent to foo(1, 2, 3, 4)
+all_the_args(**kwargs) # equivalent to foo(a=3, b=4)
+all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4)
+
+
+# Python has first class functions
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) # => 13
+
+# There are also anonymous functions
+(lambda x: x > 2)(3) # => True
+
+# TODO - Fix for iterables
+# There are built-in higher order functions
+map(add_10, [1, 2, 3]) # => [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# We can use list comprehensions for nice maps and filters
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
+
+####################################################
+## 5. Classes
+####################################################
+
+
+# We subclass from object to get a class.
+class Human(object):
+
+ # A class attribute. It is shared by all instances of this class
+ species = "H. sapiens"
+
+ # Basic initializer
+ def __init__(self, name):
+ # Assign the argument to the instance's name attribute
+ self.name = name
+
+ # An instance method. All methods take "self" as the first argument
+ def say(self, msg):
+ return "{name}: {message}" % (name=self.name, message=msg)
+
+ # A class method is shared among all instances
+ # They are called with the calling class as the first argument
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # A static method is called without a class or instance reference
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# Instantiate a class
+i = Human(name="Ian")
+print(i.say("hi")) # prints out "Ian: hi"
+
+j = Human("Joel")
+print(j.say("hello")) # prints out "Joel: hello"
+
+# Call our class method
+i.get_species() # => "H. sapiens"
+
+# Change the shared attribute
+Human.species = "H. neanderthalensis"
+i.get_species() # => "H. neanderthalensis"
+j.get_species() # => "H. neanderthalensis"
+
+# Call the static method
+Human.grunt() # => "*grunt*"
+
+
+####################################################
+## 6. Modules
+####################################################
+
+# You can import modules
+import math
+print(math.sqrt(16)) # => 4
+
+# You can get specific functions from a module
+from math import ceil, floor
+print(ceil(3.7)) # => 4.0
+print(floor(3.7)) # => 3.0
+
+# You can import all functions from a module.
+# Warning: this is not recommended
+from math import *
+
+# You can shorten module names
+import math as m
+math.sqrt(16) == m.sqrt(16) # => True
+
+# Python modules are just ordinary python files. You
+# can write your own, and import them. The name of the
+# module is the same as the name of the file.
+
+# You can find out which functions and attributes
+# defines a module.
+import math
+dir(math)
+
+
+####################################################
+## 7. Advanced
+####################################################
+
+# Generators help you make lazy code
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# A generator creates values on the fly.
+# Instead of generating and returning all values at once it creates one in each
+# iteration. This means values bigger than 15 wont be processed in
+# double_numbers.
+# Note range is a generator too. Creating a list 1-900000000 would take lot of
+# time to be made
+_range = range(1, 900000000)
+# will double all numbers until a result >=30 found
+for i in double_numbers(_range):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Decorators
+# in this example beg wraps say
+# Beg will call say. If say_please is True then it will change the returned
+# message
+from functools import wraps
+
+
+def beg(_say):
+ @wraps(_say)
+ def wrapper(*args, **kwargs):
+ msg, say_please = _say(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, "Please! I am poor :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Can you buy me a beer?"
+ return msg, say_please
+
+
+print(say()) # Can you buy me a beer?
+print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(
+```
+
+## Ready For More?
+
+### Free Online
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+
+* [The Official Docs](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Dead Tree
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/r.html.markdown b/r.html.markdown
index 9c17e8ca..b59fc29c 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -6,34 +6,42 @@ contributors:
filename: learnr.r
---
-R is a statistical computing language. It has lots of libraries for uploading and cleaning data sets, running statistical procedures, and making graphs. You can also run `R`commands within a LaTeX document.
+R is a statistical computing language. It has lots of libraries for uploading and cleaning data sets, running statistical procedures, and making graphs. You can also run `R` commands within a LaTeX document.
```python
-# Comments start with hashtags.
+# Comments start with number symbols.
-# You can't make a multi-line comment per se,
+# You can't make multi-line comments,
# but you can stack multiple comments like so.
-# in Windows, hit COMMAND-ENTER to execute a line
+# in Windows or Mac, hit COMMAND-ENTER to execute a line
-###################################################################
+
+#############################################################################
# Stuff you can do without understanding anything about programming
-###################################################################
+#############################################################################
+
+# In this section, we show off some of the cool stuff you can do in
+# R without understanding anything about programming. Do not worry
+# about understanding everything the code does. Just enjoy!
-data() # Browse pre-loaded data sets
-data(rivers) # Lengths of Major North American Rivers
-ls() # Notice that "rivers" appears in the workspace
-head(rivers) # peek at the dataset
+data() # browse pre-loaded data sets
+data(rivers) # get this one: "Lengths of Major North American Rivers"
+ls() # notice that "rivers" now appears in the workspace
+head(rivers) # peek at the data set
# 735 320 325 392 524 450
+
length(rivers) # how many rivers were measured?
# 141
-summary(rivers)
+summary(rivers) # what are some summary statistics?
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 135.0 310.0 425.0 591.2 680.0 3710.0
-stem(rivers) #stem-and-leaf plot (like a histogram)
-#
+
+# make a stem-and-leaf plot (a histogram-like data visualization)
+stem(rivers)
+
# The decimal point is 2 digit(s) to the right of the |
#
# 0 | 4
@@ -56,8 +64,8 @@ stem(rivers) #stem-and-leaf plot (like a histogram)
# 34 |
# 36 | 1
-
-stem(log(rivers)) #Notice that the data are neither normal nor log-normal! Take that, Bell Curve fundamentalists.
+stem(log(rivers)) # Notice that the data are neither normal nor log-normal!
+# Take that, Bell curve fundamentalists.
# The decimal point is 1 digit(s) to the left of the |
#
@@ -80,17 +88,19 @@ stem(log(rivers)) #Notice that the data are neither normal nor log-normal! Take
# 80 |
# 82 | 2
+# make a histogram:
+hist(rivers, col="#333333", border="white", breaks=25) # play around with these parameters
+hist(log(rivers), col="#333333", border="white", breaks=25) # you'll do more plotting later
-hist(rivers, col="#333333", border="white", breaks=25) #play around with these parameters
-hist(log(rivers), col="#333333", border="white", breaks=25) #you'll do more plotting later
-
-#Here's another neat data set that comes pre-loaded. R has tons of these. data()
+# Here's another neat data set that comes pre-loaded. R has tons of these.
data(discoveries)
-plot(discoveries, col="#333333", lwd=3, xlab="Year", main="Number of important discoveries per year")
-plot(discoveries, col="#333333", lwd=3, type = "h", xlab="Year", main="Number of important discoveries per year")
+plot(discoveries, col="#333333", lwd=3, xlab="Year",
+ main="Number of important discoveries per year")
+plot(discoveries, col="#333333", lwd=3, type = "h", xlab="Year",
+ main="Number of important discoveries per year")
-
-#rather than leaving the default ordering (by year) we could also sort to see what's typical
+# Rather than leaving the default ordering (by year),
+# we could also sort to see what's typical:
sort(discoveries)
# [1] 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2
# [26] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3
@@ -117,231 +127,250 @@ stem(discoveries, scale=2)
max(discoveries)
# 12
-
summary(discoveries)
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 0.0 2.0 3.0 3.1 4.0 12.0
-
-
-
-#Basic statistical operations don't require any programming knowledge either
-
-#roll a die a few times
+# Roll a die a few times
round(runif(7, min=.5, max=6.5))
# 1 4 6 1 4 6 4
+# Your numbers will differ from mine unless we set the same random.seed(31337)
-#your numbers will differ from mine unless we set the same random.seed(31337)
-
-
-#draw from a standard Gaussian 9 times
+# Draw from a standard Gaussian 9 times
rnorm(9)
# [1] 0.07528471 1.03499859 1.34809556 -0.82356087 0.61638975 -1.88757271
# [7] -0.59975593 0.57629164 1.08455362
-
-
-
-
-
-
-#########################
-# Basic programming stuff
-#########################
-
-# NUMBERS
-
-# "numeric" means double-precision floating-point numbers
-5 # 5
-class(5) # "numeric"
-5e4 # 50000 #handy when dealing with large,small,or variable orders of magnitude
-6.02e23 # Avogadro's number
-1.6e-35 # Planck length
-
-# long-storage integers are written with L
-5L # 5
-class(5L) # "integer"
-
-# Try ?class for more information on the class() function
-# In fact, you can look up the documentation on `xyz` with ?xyz
-# or see the source for `xyz` by evaluating xyz
-
-# Arithmetic
-10 + 66 # 76
-53.2 - 4 # 49.2
-2 * 2.0 # 4
-3L / 4 # 0.75
-3 %% 2 # 1
-
-# Weird number types
-class(NaN) # "numeric"
+##################################################
+# Data types and basic arithmetic
+##################################################
+
+# Now for the programming-oriented part of the tutorial.
+# In this section you will meet the important data types of R:
+# integers, numerics, characters, logicals, and factors.
+# There are others, but these are the bare minimum you need to
+# get started.
+
+# INTEGERS
+# Long-storage integers are written with L
+5L # 5
+class(5L) # "integer"
+# (Try ?class for more information on the class() function.)
+# In R, every single value, like 5L, is considered a vector of length 1
+length(5L) # 1
+# You can have an integer vector with length > 1 too:
+c(4L, 5L, 8L, 3L) # 4 5 8 3
+length(c(4L, 5L, 8L, 3L)) # 4
+class(c(4L, 5L, 8L, 3L)) # "integer"
+
+# NUMERICS
+# A "numeric" is a double-precision floating-point number
+5 # 5
+class(5) # "numeric"
+# Again, everything in R is a vector;
+# you can make a numeric vector with more than one element
+c(3,3,3,2,2,1) # 3 3 3 2 2 1
+# You can use scientific notation too
+5e4 # 50000
+6.02e23 # Avogadro's number
+1.6e-35 # Planck length
+# You can also have infinitely large or small numbers
class(Inf) # "numeric"
-class(-Inf) # "numeric" #used in for example integrate( dnorm(x), 3, Inf ) -- which obviates Z-score tables
-
-# but beware, NaN isn't the only weird type...
-class(NA) # see below
-class(NULL) # NULL
-
-
-# SIMPLE LISTS
-c(6, 8, 7, 5, 3, 0, 9) # 6 8 7 5 3 0 9
-c('alef', 'bet', 'gimmel', 'dalet', 'he') # "alef" "bet" "gimmel" "dalet" "he"
-c('Z', 'o', 'r', 'o') == "Zoro" # FALSE FALSE FALSE FALSE
-
-#some more nice built-ins
-5:15 # 5 6 7 8 9 10 11 12 13 14 15
-
-seq(from=0, to=31337, by=1337)
-# [1] 0 1337 2674 4011 5348 6685 8022 9359 10696 12033 13370 14707
-# [13] 16044 17381 18718 20055 21392 22729 24066 25403 26740 28077 29414 30751
-
-letters
-# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
-# [20] "t" "u" "v" "w" "x" "y" "z"
-
-month.abb # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
-
-
-# Access the n'th element of a list with list.name[n] or sometimes list.name[[n]]
-letters[18] # "r"
-LETTERS[13] # "M"
-month.name[9] # "September"
-c(6, 8, 7, 5, 3, 0, 9)[3] # 7
-
-
+class(-Inf) # "numeric"
+# You might use "Inf", for example, in integrate( dnorm(x), 3, Inf);
+# this obviates Z-score tables.
+
+# BASIC ARITHMETIC
+# You can do arithmetic with numbers
+# Doing arithmetic on a mix of integers and numerics gives you another numeric
+10L + 66L # 76 # integer plus integer gives integer
+53.2 - 4 # 49.2 # numeric minus numeric gives numeric
+2.0 * 2L # 4 # numeric times integer gives numeric
+3L / 4 # 0.75 # integer over numeric gives numeric
+3 %% 2 # 1 # the remainder of two numerics is another numeric
+# Illegal arithmetic yeilds you a "not-a-number":
+0 / 0 # NaN
+class(NaN) # "numeric"
+# You can do arithmetic on two vectors with length greater than 1,
+# so long as the larger vector's length is an integer multiple of the smaller
+c(1,2,3) + c(1,2,3) # 2 4 6
# CHARACTERS
-
# There's no difference between strings and characters in R
-
-"Horatio" # "Horatio"
+"Horatio" # "Horatio"
class("Horatio") # "character"
-substr("Fortuna multis dat nimis, nulli satis.", 9, 15) # "multis "
-gsub('u', 'ø', "Fortuna multis dat nimis, nulli satis.") # "Fortøna møltis dat nimis, nølli satis."
-
-
+class('H') # "character"
+# Those were both character vectors of length 1
+# Here is a longer one:
+c('alef', 'bet', 'gimmel', 'dalet', 'he')
+# =>
+# "alef" "bet" "gimmel" "dalet" "he"
+length(c("Call","me","Ishmael")) # 3
+# You can do regex operations on character vectors:
+substr("Fortuna multis dat nimis, nulli satis.", 9, 15) # "multis "
+gsub('u', 'ø', "Fortuna multis dat nimis, nulli satis.") # "Fortøna møltis dat nimis, nølli satis."
+# R has several built-in character vectors:
+letters
+# =>
+# [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
+# [20] "t" "u" "v" "w" "x" "y" "z"
+month.abb # "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"
# LOGICALS
-
-# booleans
+# In R, a "logical" is a boolean
class(TRUE) # "logical"
class(FALSE) # "logical"
-# Behavior is normal
+# Their behavior is normal
TRUE == TRUE # TRUE
TRUE == FALSE # FALSE
FALSE != FALSE # FALSE
FALSE != TRUE # TRUE
# Missing data (NA) is logical, too
class(NA) # "logical"
-
-
+# Here we get a logical vector with many elements:
+c('Z', 'o', 'r', 'r', 'o') == "Zorro" # FALSE FALSE FALSE FALSE FALSE
+c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
# FACTORS
-
# The factor class is for categorical data
-# which can be ordered (like childrens' grade levels)
-# or unordered (like gender)
-levels(factor(c("female", "male", "male", "female", "NA", "female"))) # "female" "male" "NA"
-
+# Factors can be ordered (like childrens' grade levels) or unordered (like gender)
factor(c("female", "female", "male", "NA", "female"))
# female female male NA female
# Levels: female male NA
+# The "levels" are the values the categorical data can take
+levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male" "NA"
+# If a factor vector has length 1, its levels will have length 1, too
+length(factor("male")) # 1
+length(levels(factor("male"))) # 1
+# Factors are commonly seen in data frames, a data structure we will cover later
+data(infert) # "Infertility after Spontaneous and Induced Abortion"
+levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
+
+# NULL
+# "NULL" is a weird one; use it to "blank out" a vector
+class(NULL) # NULL
+parakeet
+# =>
+# [1] "beak" "feathers" "wings" "eyes"
+parakeet <- NULL
+parakeet
+# =>
+# NULL
+
+# TYPE COERCION
+# Type-coercion is when you force a value to take on a different type
+as.character(c(6, 8)) # "6" "8"
+as.logical(c(1,0,1,1)) # TRUE FALSE TRUE TRUE
+# If you put elements of different types into a vector, weird coercions happen:
+c(TRUE, 4) # 1 4
+c("dog", TRUE, 4) # "dog" "TRUE" "4"
+as.numeric("Bilbo")
+# =>
+# [1] NA
+# Warning message:
+# NAs introduced by coercion
-data(infert) #Infertility after Spontaneous and Induced Abortion
-levels(infert$education) # "0-5yrs" "6-11yrs" "12+ yrs"
+# Also note: those were just the basic data types
+# There are many more data types, such as for dates, time series, etc.
-# VARIABLES
+##################################################
+# Variables, loops, if/else
+##################################################
-# Lots of way to assign stuff
+# A variable is like a box you store a value in for later use.
+# We call this "assigning" the value to the variable.
+# Having variables lets us write loops, functions, and if/else statements
+
+# VARIABLES
+# Lots of way to assign stuff:
x = 5 # this is possible
y <- "1" # this is preferred
TRUE -> z # this works but is weird
-# We can use coerce variables to different classes
-as.numeric(y) # 1
-as.character(x) # "5"
-
# LOOPS
-
# We've got for loops
for (i in 1:4) {
print(i)
}
-
# We've got while loops
a <- 10
while (a > 4) {
cat(a, "...", sep = "")
a <- a - 1
}
-
# Keep in mind that for and while loops run slowly in R
# Operations on entire vectors (i.e. a whole row, a whole column)
# or apply()-type functions (we'll discuss later) are preferred
# IF/ELSE
-
# Again, pretty standard
if (4 > 3) {
- print("Huzzah! It worked!")
+ print("4 is greater than 3")
} else {
- print("Noooo! This is blatantly illogical!")
+ print("4 is not greater than 3")
}
# =>
-# [1] "Huzzah! It worked!"
+# [1] "4 is greater than 3"
# FUNCTIONS
-
# Defined like so:
jiggle <- function(x) {
x = x + rnorm(1, sd=.1) #add in a bit of (controlled) noise
return(x)
}
-
# Called like any other R function:
jiggle(5) # 5±ε. After set.seed(2716057), jiggle(5)==5.005043
-#########################
-# Fun with data: vectors, matrices, data frames, and arrays
-#########################
+
+
+###########################################################################
+# Data structures: Vectors, matrices, data frames, and arrays
+###########################################################################
# ONE-DIMENSIONAL
-# You can vectorize anything, so long as all components have the same type
+# Let's start from the very beginning, and with something you already know: vectors.
vec <- c(8, 9, 10, 11)
vec # 8 9 10 11
-# The class of a vector is the class of its components
-class(vec) # "numeric"
-# If you vectorize items of different classes, weird coercions happen
-c(TRUE, 4) # 1 4
-c("dog", TRUE, 4) # "dog" "TRUE" "4"
-
-# We ask for specific components like so (R starts counting from 1)
-vec[1] # 8
+# We ask for specific elements by subsetting with square brackets
+# (Note that R starts counting from 1)
+vec[1] # 8
+letters[18] # "r"
+LETTERS[13] # "M"
+month.name[9] # "September"
+c(6, 8, 7, 5, 3, 0, 9)[3] # 7
# We can also search for the indices of specific components,
which(vec %% 2 == 0) # 1 3
-# or grab just the first or last entry in the vector
+# grab just the first or last few entries in the vector,
head(vec, 1) # 8
-tail(vec, 1) # 11
+tail(vec, 2) # 10 11
+# or figure out if a certain value is in the vector
+any(vec == 10) # TRUE
# If an index "goes over" you'll get NA:
vec[6] # NA
# You can find the length of your vector with length()
length(vec) # 4
-
# You can perform operations on entire vectors or subsets of vectors
vec * 4 # 16 20 24 28
vec[2:3] * 5 # 25 30
-# and there are many built-in functions to summarize vectors
+any(vec[2:3] == 8) # FALSE
+# and R has many built-in functions to summarize vectors
mean(vec) # 9.5
var(vec) # 1.666667
-sd(vec) # 1.290994
+sd(vec) # 1.290994
max(vec) # 11
min(vec) # 8
sum(vec) # 38
+# Some more nice built-ins:
+5:15 # 5 6 7 8 9 10 11 12 13 14 15
+seq(from=0, to=31337, by=1337)
+# =>
+# [1] 0 1337 2674 4011 5348 6685 8022 9359 10696 12033 13370 14707
+# [13] 16044 17381 18718 20055 21392 22729 24066 25403 26740 28077 29414 30751
# TWO-DIMENSIONAL (ALL ONE CLASS)
@@ -361,6 +390,7 @@ mat[1,] # 1 4
3 * mat[,1] # 3 6 9
# Ask for a specific cell
mat[3,2] # 6
+
# Transpose the whole matrix
t(mat)
# =>
@@ -368,6 +398,14 @@ t(mat)
# [1,] 1 2 3
# [2,] 4 5 6
+# Matrix multiplication
+mat %*% t(mat)
+# =>
+# [,1] [,2] [,3]
+# [1,] 17 22 27
+# [2,] 22 29 36
+# [3,] 27 36 45
+
# cbind() sticks vectors together column-wise to make a matrix
mat2 <- cbind(1:4, c("dog", "cat", "bird", "dog"))
mat2
@@ -390,33 +428,138 @@ mat3
# [,1] [,2] [,3] [,4]
# [1,] 1 2 4 5
# [2,] 6 7 0 4
-# Aah, everything of the same class. No coercions. Much better.
+# Ah, everything of the same class. No coercions. Much better.
# TWO-DIMENSIONAL (DIFFERENT CLASSES)
-# For columns of different classes, use the data frame
-dat <- data.frame(c(5,2,1,4), c("dog", "cat", "bird", "dog"))
-names(dat) <- c("number", "species") # name the columns
-class(dat) # "data.frame"
-dat
+# For columns of different types, use a data frame
+# This data structure is so useful for statistical programming,
+# a version of it was added to Python in the package "pandas".
+
+students <- data.frame(c("Cedric","Fred","George","Cho","Draco","Ginny"),
+ c(3,2,2,1,0,-1),
+ c("H", "G", "G", "R", "S", "G"))
+names(students) <- c("name", "year", "house") # name the columns
+class(students) # "data.frame"
+students
# =>
-# number species
-# 1 5 dog
-# 2 2 cat
-# 3 1 bird
-# 4 4 dog
-class(dat$number) # "numeric"
-class(dat[,2]) # "factor"
+# name year house
+# 1 Cedric 3 H
+# 2 Fred 2 G
+# 3 George 2 G
+# 4 Cho 1 R
+# 5 Draco 0 S
+# 6 Ginny -1 G
+class(students$year) # "numeric"
+class(students[,3]) # "factor"
+# find the dimensions
+nrow(students) # 6
+ncol(students) # 3
+dim(students) # 6 3
# The data.frame() function converts character vectors to factor vectors
+# by default; turn this off by setting stringsAsFactors = FALSE when
+# you create the data.frame
+?data.frame
# There are many twisty ways to subset data frames, all subtly unalike
-dat$number # 5 2 1 4
-dat[,1] # 5 2 1 4
-dat[,"number"] # 5 2 1 4
+students$year # 3 2 2 1 0 -1
+students[,2] # 3 2 2 1 0 -1
+students[,"year"] # 3 2 2 1 0 -1
+
+# An augmented version of the data.frame structure is the data.table
+# If you're working with huge or panel data, or need to merge a few data
+# sets, data.table can be a good choice. Here's a whirlwind tour:
+install.packages("data.table") # download the package from CRAN
+require(data.table) # load it
+students <- as.data.table(students)
+students # note the slightly different print-out
+# =>
+# name year house
+# 1: Cedric 3 H
+# 2: Fred 2 G
+# 3: George 2 G
+# 4: Cho 1 R
+# 5: Draco 0 S
+# 6: Ginny -1 G
+students[name=="Ginny"] # get rows with name == "Ginny"
+# =>
+# name year house
+# 1: Ginny -1 G
+students[year==2] # get rows with year == 2
+# =>
+# name year house
+# 1: Fred 2 G
+# 2: George 2 G
+# data.table makes merging two data sets easy
+# let's make another data.table to merge with students
+founders <- data.table(house=c("G","H","R","S"),
+ founder=c("Godric","Helga","Rowena","Salazar"))
+founders
+# =>
+# house founder
+# 1: G Godric
+# 2: H Helga
+# 3: R Rowena
+# 4: S Salazar
+setkey(students, house)
+setkey(founders, house)
+students <- founders[students] # merge the two data sets by matching "house"
+setnames(students, c("house","houseFounderName","studentName","year"))
+students[,order(c("name","year","house","houseFounderName")), with=F]
+# =>
+# studentName year house houseFounderName
+# 1: Fred 2 G Godric
+# 2: George 2 G Godric
+# 3: Ginny -1 G Godric
+# 4: Cedric 3 H Helga
+# 5: Cho 1 R Rowena
+# 6: Draco 0 S Salazar
+
+# data.table makes summary tables easy
+students[,sum(year),by=house]
+# =>
+# house V1
+# 1: G 3
+# 2: H 3
+# 3: R 1
+# 4: S 0
+
+# To drop a column from a data.frame or data.table,
+# assign it the NULL value
+students$houseFounderName <- NULL
+students
+# =>
+# studentName year house
+# 1: Fred 2 G
+# 2: George 2 G
+# 3: Ginny -1 G
+# 4: Cedric 3 H
+# 5: Cho 1 R
+# 6: Draco 0 S
+
+# Drop a row by subsetting
+# Using data.table:
+students[studentName != "Draco"]
+# =>
+# house studentName year
+# 1: G Fred 2
+# 2: G George 2
+# 3: G Ginny -1
+# 4: H Cedric 3
+# 5: R Cho 1
+# Using data.frame:
+students <- as.data.frame(students)
+students[students$house != "G",]
+# =>
+# house houseFounderName studentName year
+# 4 H Helga Cedric 3
+# 5 R Rowena Cho 1
+# 6 S Salazar Draco 0
-# MULTI-DIMENSIONAL (ALL OF ONE CLASS)
+# MULTI-DIMENSIONAL (ALL ELEMENTS OF ONE TYPE)
# Arrays creates n-dimensional tables
+# All elements must be of the same type
# You can make a two-dimensional table (sort of like a matrix)
array(c(c(1,2,4,5),c(8,9,3,6)), dim=c(2,4))
# =>
@@ -446,15 +589,23 @@ array(c(c(c(2,300,4),c(8,9,0)),c(c(5,60,0),c(66,7,847))), dim=c(3,2,2))
list1 <- list(time = 1:40)
list1$price = c(rnorm(40,.5*list1$time,4)) # random
list1
-
# You can get items in the list like so
-list1$time
-# You can subset list items like vectors
+list1$time # one way
+list1[["time"]] # another way
+list1[[1]] # yet another way
+# =>
+# [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
+# [34] 34 35 36 37 38 39 40
+# You can subset list items like any other vector
list1$price[4]
-#########################
+# Lists are not the most efficient data structure to work with in R;
+# unless you have a very good reason, you should stick to data.frames
+# Lists are often returned by functions that perform linear regressions
+
+##################################################
# The apply() family of functions
-#########################
+##################################################
# Remember mat?
mat
@@ -467,7 +618,7 @@ mat
# over rows (MAR = 1) or columns (MAR = 2)
# That is, R does FUN to each row (or column) of X, much faster than a
# for or while loop would do
-apply(mat, MAR = 2, myFunc)
+apply(mat, MAR = 2, jiggle)
# =>
# [,1] [,2]
# [1,] 3 15
@@ -478,16 +629,18 @@ apply(mat, MAR = 2, myFunc)
# Don't feel too intimidated; everyone agrees they are rather confusing
# The plyr package aims to replace (and improve upon!) the *apply() family.
-
install.packages("plyr")
require(plyr)
?plyr
+
+
#########################
# Loading data
#########################
# "pets.csv" is a file on the internet
+# (but it could just as easily be be a file on your own computer)
pets <- read.csv("http://learnxinyminutes.com/docs/pets.csv")
pets
head(pets, 2) # first two rows
@@ -499,10 +652,13 @@ write.csv(pets, "pets2.csv") # to make a new .csv file
# Try ?read.csv and ?write.csv for more information
+
+
#########################
# Plots
#########################
+# BUILT-IN PLOTTING FUNCTIONS
# Scatterplots!
plot(list1$time, list1$price, main = "fake data")
# Regressions!
@@ -512,18 +668,25 @@ linearModel # outputs result of regression
abline(linearModel, col = "red")
# Get a variety of nice diagnostics
plot(linearModel)
-
# Histograms!
hist(rpois(n = 10000, lambda = 5), col = "thistle")
-
# Barplots!
barplot(c(1,4,5,1,2), names.arg = c("red","blue","purple","green","yellow"))
+# GGPLOT2
+# But these are not even the prettiest of R's plots
# Try the ggplot2 package for more and better graphics
-
install.packages("ggplot2")
require(ggplot2)
?ggplot2
+pp <- ggplot(students, aes(x=house))
+pp + geom_histogram()
+ll <- as.data.table(list1)
+pp <- ggplot(ll, aes(x=time,price))
+pp + geom_point()
+# ggplot2 has excellent documentation (available http://docs.ggplot2.org/current/)
+
+
```
diff --git a/racket.html.markdown b/racket.html.markdown
index eddc00bf..6abc8759 100644
--- a/racket.html.markdown
+++ b/racket.html.markdown
@@ -196,7 +196,7 @@ my-pet ; => #<dog>
(hash-ref m 'd 0) ; => 0
;; Use `hash-set' to extend an immutable hash table
-;; (Returns the extended hash instdead of mutating it)
+;; (Returns the extended hash instead of mutating it)
(define m2 (hash-set m 'd 4))
m2 ; => '#hash((b . 2) (a . 1) (d . 4) (c . 3))
@@ -224,7 +224,7 @@ m ; => '#hash((b . 2) (a . 1) (c . 3)) <-- no `d'
(define hello-world (lambda () "Hello World"))
(hello-world) ; => "Hello World"
-;; You can shorten this using the function definition syntatcic sugae:
+;; You can shorten this using the function definition syntactic sugar:
(define (hello-world2) "Hello World")
;; The () in the above is the list of arguments for the function
@@ -496,7 +496,7 @@ vec ; => #(1 2 3 4)
;; 8. Classes and Objects
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Create a class fish% (-% is idomatic for class bindings)
+;; Create a class fish% (-% is idiomatic for class bindings)
(define fish%
(class object%
(init size) ; initialization argument
@@ -552,7 +552,7 @@ vec ; => #(1 2 3 4)
(set! i (add1 i))))
;; Macros are hygienic, you cannot clobber existing variables!
-(define-syntax-rule (swap! x y) ; -! is idomatic for mutation
+(define-syntax-rule (swap! x y) ; -! is idiomatic for mutation
(let ([tmp x])
(set! x y)
(set! y tmp)))
diff --git a/red.html.markdown b/red.html.markdown
new file mode 100644
index 00000000..73a13606
--- /dev/null
+++ b/red.html.markdown
@@ -0,0 +1,219 @@
+---
+name: Red
+category: language
+language: Red
+filename: learnred.red
+contributors:
+ - ["Arnold van Hofwegen", "https://github.com/iArnold"]
+---
+
+
+Red was created out of the need to get work done, and the tool the author wanted to use, the language of REBOL, had a couple of drawbacks.
+It was not Open Sourced at that time and it is an interpreted language, what means that it is on average slow compared to a compiled language.
+
+Red, together with its C-level dialect Red/System, provides a language that covers the entire programming space you ever need to program something in.
+Red is a language heavily based on the language of REBOL. Where Red itself reproduces the flexibility of the REBOL language, the underlying language Red will be built upon,
+Red/System, covers the more basic needs of programming like C can, being closer to the metal.
+
+Red will be the world's first Full Stack Programming Language. This means that it will be an effective tool to do (almost) any programming task on every level
+from the metal to the meta without the aid of other stack tools.
+Furthermore Red will be able to cross-compile Red source code without using any GCC like toolchain
+from any platform to any other platform. And it will do this all from a binary executable that is supposed to stay under 1 MB.
+
+Ready to learn your first Red?
+
+```
+All text before the header will be treated as comment, as long as you avoid using the
+word "red" starting with a capital "R" in this pre-header text. This is a temporary
+shortcoming of the used lexer but most of the time you start your script or program
+with the header itself.
+The header of a red script is the capitalized word "red" followed by a
+whitespace character followed by a block of square brackets [].
+The block of brackets can be filled with useful information about this script or
+program: the author's name, the filename, the version, the license, a summary of
+what the program does or any other files it needs.
+The red/System header is just like the red header, only saying "red/System" and
+not "red".
+
+Red []
+
+;this is a commented line
+
+print "Hello Red World" ; this is another comment
+
+comment {
+ This is a multiline comment.
+ You just saw the Red version of the "Hello World" program.
+}
+
+; Your program's entry point is the first executable code that is found
+; no need to restrict this to a 'main' function.
+
+; Valid variable names start with a letter and can contain numbers,
+; variables containing only capital A thru F and numbers and ending with 'h' are
+; forbidden, because that is how hexadecimal numbers are expressed in Red and
+; Red/System.
+
+; assign a value to a variable using a colon ":"
+my-name: "Red"
+reason-for-using-the-colon: {Assigning values using the colon makes
+ the equality sign "=" exclusively usable for comparisons purposes,
+ exactly what "=" was intended for in the first place!
+ Remember this y = x + 1 and x = 1 => y = 2 stuff from school?
+}
+is-this-name-valid?: true
+
+; print output using print, or prin for printing without a newline or linefeed at the
+; end of the printed text.
+
+prin " My name is " print my-name
+My name is Red
+
+print ["My name is " my-name lf]
+My name is Red
+
+; In case you haven't already noticed: statements do NOT end with a semicolon ;-)
+
+;
+; Datatypes
+;
+; If you know Rebol, you probably have noticed it has lots of datatypes. Red
+; does not have yet all those types, but as Red want to be close to Rebol it
+; will have a lot of datatypes.
+; You can recognize types by the exclamation sign at the end. But beware
+; names ending with an exclamation sign are allowed.
+; Some of the available types are integer! string! block!
+
+; Declaring variables before using them?
+; Red knows by itself what variable is best to use for the data you want to use it
+; for.
+; A variable declaration is not always necessary.
+; It is considered good coding practise to declare your variables,
+; but it is not forced upon you by Red.
+; You can declare a variable and specify its type. a variable's type determines its
+; size in bytes.
+
+; Variables of integer! type are usually 4 bytes or 32 bits
+my-integer: 0
+; Red's integers are signed. No support for unsigned atm but that will come.
+
+; To find out the type of variable use type?
+type? my-integer
+integer!
+
+; A variable can be initialized using another variable that gets initialized
+; at the same time.
+i2: 1 + i1: 1
+
+; Arithmetic is straightforward
+i1 + i2 ; result 3
+i2 - i1 ; result 1
+i2 * i1 ; result 2
+i1 / i2 ; result 0 (0.5, but truncated towards 0)
+
+; Comparison operators are probably familiar, and unlike in other languages you
+; only need a single '=' sign for comparison.
+; There is a boolean like type in Red. It has values true and false, but also the
+; values on/off or yes/no can be used
+
+3 = 2 ; result false
+3 != 2 ; result true
+3 > 2 ; result true
+3 < 2 ; result false
+2 <= 2 ; result true
+2 >= 2 ; result true
+
+;
+; Control Structures
+;
+; if
+; Evaluate a block of code if a given condition is true. IF does not return any value,
+; so cannot be used in an expression.
+if a < 0 [print "a is negative"]
+
+; either
+; Evaluate a block of code if a given condition is true, else evaluate an alternative
+; block of code. If the last expressions in both blocks have the same type, EITHER can
+; be used inside an expression.
+either a < 0 [
+ either a = 0 [
+ msg: "zero"
+ ][
+ msg: "negative"
+ ]
+][
+ msg: "positive"
+]
+
+print ["a is " msg lf]
+
+; There is an alternative way to write this
+; (Which is allowed because all code paths return a value of the same type):
+
+msg: either a < 0 [
+ either a = 0 [
+ "zero"
+ ][
+ "negative"
+ ]
+ ][
+ "positive"
+]
+print ["a is " msg lf]
+
+; until
+; Loop over a block of code until the condition at end of block, is met.
+; UNTIL does not return any value, so it cannot be used in an expression.
+c: 5
+until [
+ prin "o"
+ c: c - 1
+ c = 0 ; the condition to end the until loop
+]
+; will output:
+ooooo
+; Note that the loop will always be evaluated at least once, even if the condition is
+; not met from the beginning.
+
+; while
+; While a given condition is met, evaluate a block of code.
+; WHILE does not return any value, so it cannot be used in an expression.
+c: 5
+while [c > 0][
+ prin "o"
+ c: c - 1
+]
+; will output:
+ooooo
+
+;
+; Functions
+;
+; function example
+twice: function [a [integer!] /one return: [integer!]][
+ c: 2
+ a: a * c
+ either one [a + 1][a]
+]
+b: 3
+print twice b ; will output 6.
+
+; Import external files with #include and filenames start with a % sign
+#include %includefile.red
+; Now the functions in the included file can be used too.
+
+```
+
+## Further Reading
+
+The main source for information about Red is the [Red language homepage](http://www.red-lang.org).
+
+The source can be found on [github](https://github.com/red/red).
+
+The Red/System language specification can be found [here](http://static.red-lang.org/red-system-specs-light.html).
+
+To learn more about Rebol and Red join the [chat on StackOverflow](http://chat.stackoverflow.com/rooms/291/rebol-and-red). You will need 20 points to chat but if you ask or answer questions about Red or Rebol we will help you get those points. And if that is not working for you drop a mail to us on the [Red mailing list](mailto: red-langNO_SPAM@googlegroups.com) (remove NO_SPAM).
+
+Maybe you want to try Red right away? That is possible on the [try Rebol and Red site](http://tryrebol.esperconsultancy.nl).
+
+You can also learn Red by learning some [Rebol](http://www.rebol.com/docs.html).
diff --git a/ro-ro/bash-ro.html.markdown b/ro-ro/bash-ro.html.markdown
new file mode 100644
index 00000000..debeb67a
--- /dev/null
+++ b/ro-ro/bash-ro.html.markdown
@@ -0,0 +1,177 @@
+---
+category: tool
+tool: bash
+contributors:
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Darren Lin", "https://github.com/CogBear"]
+ - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
+ - ["Denis Arh", "https://github.com/darh"]
+translators:
+ - ["Adrian Bordinc", "https://github.com/ellimist"]
+lang: ro-ro
+filename: LearnBash-ro.sh
+---
+
+Bash este numele shell-ului unix, care a fost de asemenea distribuit drept shell pentru sistemul de operare GNU si ca shell implicit pentru Linux si Mac OS X.
+Aproape toate exemplele de mai jos pot fi parte dintr-un script sau pot fi executate direct in linia de comanda.
+
+[Citeste mai multe:](http://www.gnu.org/software/bash/manual/bashref.html)
+
+```bash
+#!/bin/bash
+# Prima linie din script se numeste "shebang"
+# care spune systemului cum sa execute scriptul
+# http://en.wikipedia.org/wiki/Shebang_(Unix)
+# Dupa cum te-ai prins deja, comentariile incep cu #.
+# Shebang este de asemenea un comentariu.
+
+# Exemplu simplu de hello world:
+echo Hello world!
+
+# Fiecare comanda incepe pe o linie noua, sau dupa punct si virgula ;
+echo 'Prima linie'; echo 'A doua linie'
+
+# Declararea unei variabile se face astfel:
+VARIABLE="Niste text"
+
+# DAR nu asa:
+VARIABLE = "Niste text"
+# Bash va crede ca VARIABLE este o comanda care trebuie executata si va
+# returna o eroare pentru ca nu va putea fi gasita.
+
+# Folosind variabila:
+echo $VARIABLE
+echo "$VARIABLE"
+echo '$VARIABLE'
+# Atunci cand folosesti variabila, o atribui, o exporti sau altfel,
+# numele ei se scrie fara $.
+# Daca vrei sa folosesti valoarea variabilei, atunci trebuie sa folosesti $.
+# Atentie la faptul ca ' (apostrof) nu va inlocui variabla cu valoarea ei.
+
+# Inlocuirea de caractere in variabile
+echo ${VARIABLE/Some/A}
+# Asta va inlocui prima aparitie a "Some" cu "A" in variabila de mai sus.
+
+# Substring dintr-o variabila
+echo ${VARIABLE:0:7}
+# Asta va returna numai primele 7 caractere din variabila.
+
+# Valoarea implicita a unei variabile:
+echo ${FOO:-"ValoareaImplicitaDacaFOOLipsesteSauEGoala"}
+# Asta functioneaza pentru null (FOO=),
+# sir de caractere gol (FOO=""), zero (FOO=0) returneaza 0
+
+# Variabile pre-existente
+echo "Ulima valoare returnata de ultimul program rulat: $?"
+echo "ID-ul procesului (PID) care ruleaza scriptul: $$"
+echo "Numarul de argumente: $#"
+echo "Argumentele scriptului: $@"
+echo "Argumentele scriptului separate in variabile: $1 $2..."
+
+# Citind o valoare din consola
+echo "Care e numele tau?"
+read NAME # Observa faptul ca nu a trebuit sa declaram o variabila noua
+echo Salut, $NAME!
+
+# Avem obisnuita instructiune "if"
+# Foloseste "man test" pentru mai multe informatii
+# despre instructinea conditionala
+if [ $NAME -ne $USER ]
+then
+ echo "Numele tau este username-ul tau"
+else
+ echo "Numele tau nu este username-ul tau"
+fi
+
+# Este de asemenea si executarea conditionala de comenzi
+echo "Intotdeauna executat" || echo "Executat daca prima instructiune esueaza"
+echo "Intotdeauna executat" && echo "Executat daca prima instructiune NU esueaza"
+
+# Expresiile apar in urmatorul format
+echo $(( 10 + 5 ))
+
+# Spre deosebire de alte limbaje de programare bash este un shell - asa ca
+# functioneaza in contextul directorului curent. Poti vedea fisiere si directoare
+# din directorul curent folosind comanda "ls":
+ls
+
+# Aceste comenzi au optiuni care la controleaza executia
+ls -l # Listeaza fiecare fisier si director pe o linie separata
+
+# Rezultatele comenzii anterioare pot fi
+# trimise urmatoarei comenzi drept argument
+# Comanda grep filtreaza argumentele trimise cu sabloane.
+# Astfel putem vedea fiserele .txt din directorul curent.
+ls -l | grep "\.txt"
+
+# De asemenea poti redirectiona o comanda, input si error output
+python2 hello.py < "input.in"
+python2 hello.py > "output.out"
+python2 hello.py 2> "error.err"
+# Output-ul va suprascrie fisierul daca acesta exista.
+# Daca vrei sa fie concatenate poti folosi ">>"
+
+# Comenzile pot fi inlocuite in interiorul altor comenzi folosind $( ):
+# Urmatoarea comanda afiseaza numarul de fisiere
+# si directoare din directorul curent
+echo "Sunt $(ls | wc -l) fisiere aici."
+
+# Acelasi lucru se poate obtine folosind apostrf-ul inversat ``,
+# dar nu pot fi folosite unele in interiorul celorlalte asa ca modalitatea
+# preferata este de a folosi $( )
+echo "Sunt `ls | wc -l` fisiere aici."
+
+# Bash foloseste o instructiune 'case' care functioneaza
+# in mod similar cu instructiunea switch din Java si C++
+case "$VARIABLE" in
+ 0) echo "Este un zero.";;
+ 1) echo "Este un unu.";;
+ *) echo "Nu este null";;
+esac
+
+# Instructiunea for parcurge toate elementele trimise:
+# Continutul variabilei $VARIABLE este printat de 3 ori
+for VARIABLE in {1..3}
+do
+ echo "$VARIABLE"
+done
+
+# while loop:
+while [true]
+do
+ echo "in interiorul iteratiei aici..."
+ break
+done
+
+# De asemenea poti defini functii
+# Definitie:
+function foo ()
+{
+ echo "Argumentele functioneaza ca si argumentele scriptului: $@"
+ echo "Si: $1 $2..."
+ echo "Asta este o functie"
+ return 0
+}
+
+# sau mai simplu
+bar ()
+{
+ echo "Alta metoda de a declara o functie"
+ return 0
+}
+
+# Invocarea unei functii
+foo "Numele meu este: " $NAME
+
+# Sunt o multime de comenzi utile pe care ar trebui sa le inveti:
+tail -n 10 file.txt
+# printeaza ultimele 10 linii din fisierul file.txt
+head -n 10 file.txt
+# printeaza primele 10 linii din fisierul file.txt
+sort file.txt
+# sorteaza liniile din file.txt
+uniq -d file.txt
+# raporteaza sau omite liniile care se repeta, cu -d le raporteaza
+cut -d ',' -f 1 file.txt
+# printeaza doar prima coloana inainte de caracterul ","
+```
diff --git a/ro-ro/ruby-ro.html.markdown b/ro-ro/ruby-ro.html.markdown
new file mode 100644
index 00000000..12672b68
--- /dev/null
+++ b/ro-ro/ruby-ro.html.markdown
@@ -0,0 +1,491 @@
+---
+language: ruby
+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"]
+ - ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
+translators:
+ - ["Adrian Bordinc", "https://github.com/ellimist"]
+filename: learnruby-ro.rb
+lang: ro-ro
+---
+
+```ruby
+# Acesta este un comentariu
+
+=begin
+Acesta este un comentariu pe mai multe linii
+Nimeni nu le foloseste
+Si nici tu nu ar trebui sa o faci
+=end
+
+# In primul rand: totul este un obiect
+
+# Numerele sunt obiecte
+
+3.class #=> Fixnum
+
+3.to_s #=> "3"
+
+
+# Aritmetica de baza
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+35 / 5 #=> 7
+
+# Aritmetica este doar "zahar sintactic"
+# pentru a putea chema metode pe un obiect
+1.+(3) #=> 4
+10.* 5 #=> 50
+
+# Valorile speciale sunt obiecte
+nil # Nimic
+true # true
+false # false
+
+nil.class #=> NilClass
+true.class #=> TrueClass
+false.class #=> FalseClass
+
+# Egalitate
+1 == 1 #=> true
+2 == 1 #=> false
+
+# Inegalitate
+1 != 1 #=> false
+2 != 1 #=> true
+!true #=> false
+!false #=> true
+
+# Excluzand "false", "nil" este singura valoare "falsa"
+
+!nil #=> true
+!false #=> true
+!0 #=> false
+
+# Mai multe comparatii
+1 < 10 #=> true
+1 > 10 #=> false
+2 <= 2 #=> true
+2 >= 2 #=> true
+
+# Sirurule de caractere sunt obiecte
+
+'Sunt un sir de caractere'.class #=> String
+"Si eu sunt un sir de caractere".class #=> String
+
+fi_inlocuit = "fi inlocuit"
+"Pot #{fi_inlocuit} atunci cand folosesc dublu apostrof"
+#=> "Pot fi inlocuit atunci cand folosesc dublu apostrof"
+
+
+# Printeaza
+puts "Afisez rezultate!"
+
+# Variabile
+x = 25 #=> 25
+x #=> 25
+
+# Retineti faptul ca atribuire unei valori, o si returneaza pe aceasta
+# Asta inseamna ca poti sa faci atribuire multipla:
+
+x = y = 10 #=> 10
+x #=> 10
+y #=> 10
+
+# Prin conventie se foloseste "snake_case" in denumirea variabilelor
+snake_case = true
+
+# Folositi nume descriptive pentru variablie
+adresa_radacina_proiect = '/nume/bun/'
+adresa = '/nume/nu atat de bun/'
+
+# Simbolurile (sunt obiecte)
+# Simbolurile sunt constante imutabile, reutilizabile, reprezentate intern
+# de o valoare numerica. Sunt deseori folosite in locul sirurilor de caractere
+# pentru a da un nume reprezentativ unei valori
+
+:exemplu_simbol.class #=> Symbol
+
+status = :exemplu_simbol
+
+status == :exemplu_simbol #=> adevarat
+
+status == 'exemplu_simbol' #=> fals
+
+status == :aprobat #=> fals
+
+# Vectori
+
+# Acesta este un vector
+vector = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
+
+# Vectorii pot contine diferite tipuri de date
+
+[1, "salut", false] #=> [1, "salut", false]
+
+# Vectorii pot fi indexati
+# de la inceput
+vector[0] #=> 1
+vector[12] #=> nil
+
+# Ca si aritmetica, accessul [valoare]
+# este doar "zahar sintactic"
+# pentru a chema metoda [] a unui obiect
+vector.[] 0 #=> 1
+vector.[] 12 #=> nil
+
+# De la sfarsit
+vector[-1] #=> 5
+
+# Cu un index de inceput si o lungime
+vector[2, 3] #=> [3, 4, 5]
+
+# Sau cu un interval
+vector[1..3] #=> [2, 3, 4]
+
+# Adauga elemente intr-un vector in felul urmator:
+vector << 6 #=> [1, 2, 3, 4, 5, 6]
+
+# Hash-urile sunt dictionarele din Ruby cu perechi cheie/valoare.
+# Hash-urile sunt notate cu acolade
+hash = {'culoare' => 'verde', 'numar' => 5}
+
+hash.keys #=> ['culoare', 'numar']
+
+# Poti lua valoare unui element dintr-un hash foarte rapid folosind cheia
+hash['culoare'] #=> 'verde'
+hash['numar'] #=> 5
+
+# Incercand sa accesezi un element dintr-un hash
+# printr-o cheie care nu exista va returna "nil".
+hash['nimic_aici'] #=> nil
+
+# Incepand cu Ruby 1.9, este o sintaxa speciala
+# pentru atunci cand se folosesc simboluri drept chei:
+
+hash_nou = { defcon: 3, actiune: true}
+
+hash_now.keys #=> [:defcon, :actiune]
+
+# Pont: Atat vectorii (Array) si hash-urile (Hash) sunt enumerabile (Enumerable)
+# Ele impart o multime de metode utile precum each, map, count si altele
+
+
+# Structuri de control
+
+if true
+ "instructiune if"
+elsif false
+ "else if, optional"
+else
+ "else, de asemenea optional"
+end
+
+for numar in 1..5
+ puts "iteratia #{numar}"
+end
+#=> iteratia 1
+#=> iteratia 2
+#=> iteratia 3
+#=> iteratia 4
+#=> iteratia 5
+
+# TOTUSI, Nici una nu foloseste instructiunea for
+# In locul acesteia ar trebui sa folosesti metoda "each" si sa ii trimiti un block
+# Un bloc este o bucata de cod pe care o poti trimite unei metode precum "each".
+# Este analog pentru "lambda", functii anonime,
+# sau closures in alte limbaje de programare.
+#
+# Metoda "each" a unui interval, ruleaza block-ul o data
+# pentru fiecare element din interval.
+# Block-ul primeste ca si parametru un index
+# Invocand metoda "each" cu un block, arata in urmatorul fel:
+
+(1..5).each do |index|
+ puts "iteratia #{index}"
+end
+#=> iteratia 1
+#=> iteratia 2
+#=> iteratia 3
+#=> iteratia 4
+#=> iteratia 5
+
+# Poti de asemenea sa pui block-ul intre acolade
+(1..5).each {|index| puts "iteratia #{index}"}
+
+# Continutul unei structuri de date poate fi parcurs folosind "each".
+array.each do |element|
+ puts "#{element} parte din vector"
+end
+hash.each do |cheie, valoare|
+ puts "#{cheie} este #{valoare}"
+end
+
+index = 1
+while index <= 5 do
+ puts "iteratia #{index}"
+ index += 1
+end
+#=> iteratia 1
+#=> iteratia 2
+#=> iteratia 3
+#=> iteratia 4
+#=> iteratia 5
+
+nota = 'B'
+
+case nota
+when 'A'
+ puts "Bravo pustiule!"
+when 'B'
+ puts "Mai mult noroc data viitoare"
+when 'C'
+ puts "Poti mai mult"
+when 'D'
+ puts "Incet, incet..."
+when 'F'
+ puts "Ai esuat!"
+else
+ puts "Sistem de notare alternativ?!"
+end
+
+# Functii
+
+def dublu(x)
+ x * 2
+end
+
+# Functille (si toate block-urile)
+# returneaza implicit valoarea ultimei instructiuni
+dublu(2) #=> 4
+
+# Parantezele sunt optionale cand rezultatul nu este ambiguu
+dublu 3 #=> 6
+
+dublu dublu 3 #=> 12
+
+def suma(x,y)
+ x + y
+end
+
+# Argumentele metodei sunt separate printr-o virgula
+suma 3, 4 #=> 7
+
+suma suma(3,4), 5 #=> 12
+
+# yield
+# Toate metodele au un parametru block, implicit si optional
+# care poate fi invocat folosit cuvantul cheie 'yield'
+
+def incercuieste
+ puts "{"
+ yield
+ puts "}"
+end
+
+incercuieste { puts 'Salut Mihai!' }
+
+# {
+# Salut Mihai!
+# }
+
+
+# Poti trimite un block unei functii.
+# "&" marcheaza o referinta trimisa unui block
+def vizitatori(&block)
+ block.call "un_parametru"
+end
+
+# Poti trimite o lista de argumente, care va fi convertita intr-un vector (array).
+# Pentru asta se foloseste ("*")
+def vizitatori(*vector)
+ vector.each { |vizitator| puts "#{vizitator}" }
+end
+
+# Defineste o clasa folosind cuvantul cheie "class"
+class Om
+
+ # O variabila apartinand clasei. Este folosita in toate instantele clasei
+ @@specie = "H. sapiens"
+
+ # Constructor
+ def initialize(nume, varsta=0)
+ # Atribuie argumentul, variabilei "nume", care apartine doar unei instante
+ @nume = nume
+ # Daca varsta nu este data, o sa ii atribuim valoarea implicita
+ # din lista de argumente (0, in cazul nostru)
+ @varsta = varsta
+ end
+
+ # Metoda pentru a seta valoarea unei variabile
+ def nume=(nume)
+ @nume = nume
+ end
+
+ # Metoda pentru a lua valoarea unei variabile
+ def nume
+ @nume
+ end
+
+ # Functionalitatea de mai sus poate fi obtinuta
+ # folosing metoda "attr_accessor" dupa cum urmeaza:
+ attr_accessor :nume
+
+ # Metodele pentru a lua si a seta valoarea unei variabile
+ # pot fi de asemenea obtinute individial:
+ attr_reader :nume
+ attr_writer :nume
+
+ # O metoda apartinand unei clase foloseste "self" pentru a se diferentia
+ # de metodele unei instante ale clasei respective
+ # Poate fi invocata doar pe clasa, si nu pe o instanta a acesteia
+ def self.spune(msg)
+ puts "#{msg}"
+ end
+
+ def specie
+ @@specie
+ end
+
+end
+
+
+# Creaza o instanta a unei clase
+ion = Om.new("Ionut Popescu")
+
+eugen = Om.new("Eugen Ionescu")
+
+# Sa invocam niste metode
+ion.specie #=> "H. sapiens"
+ion.nume #=> "Ionut Popescu"
+ion.nume = "Ionut Popescu JR." #=> "Ionut Popescu JR."
+ion.nume #=> "Ionut Popescu JR."
+eugen.specie #=> "H. sapiens"
+eugen.nume #=> "Eugen Ionescu"
+
+# Invoca o metoda a unei clase
+Om.spune("Salut") #=> "Salut"
+
+
+# Scopul unei variabile este definit de modul in care le numim
+# Variabilele care incep cu $ au scop global
+$var = "Sunt o variabila globala"
+defined? $var #=> "global-variable"
+
+# Variabilele care incep cu @ apartin unei instante
+@var = "Sunt o variabila a unei instante"
+defined? @var #=> "instance-variable"
+
+# Variabilele care incep cu @@ apartin unei clase
+@@var = "Sunt variabila unei clase"
+defined? @@var #=> "class variable"
+
+# Variabilele care incep cu litera mare sunt constante
+Var = "Sunt o constanta"
+defined? Var #=> "constant"
+
+# Clasele sunt de asemenea obiecte in ruby. Astfel incat clasele
+# pot avea variabile care apartin unei instante
+# O variabila care apartine unei clase poate fi accesata de toate
+# instantele acesteia si de clasele care o extind
+
+# clasa parinte
+class Om
+ @@foo = 0
+
+ def self.foo
+ @@foo
+ end
+
+ def self.foo=(valoare)
+ @@foo = valoare
+ end
+end
+
+# clasa copil
+class Muncitor < Om
+end
+
+Om.foo # 0
+Muncitor.foo # 0
+
+Om.foo = 2 # 2
+Muncitor.foo # 2
+
+# Variabilele care apartin unei instante ale unei clase,
+# nu sunt impartite de (copii acesteia) clasele care o extind
+class Om
+ @bar = 0
+
+ def self.bar
+ @bar
+ end
+
+ def self.bar=(valoare)
+ @bar = valoare
+ end
+end
+
+class Doctor < Om
+end
+
+Om.bar # 0
+Doctor.bar # nil
+
+module ExempluModul
+ def foo
+ 'foo'
+ end
+end
+
+# Incluzand modulul instantei unui obiect
+# Extinzand modulul unei instante ale unei clase
+
+class Persoana
+ include ExempluModul
+end
+
+class Carte
+ extend ExempluModul
+end
+
+Persoana.foo # => NoMethodError: undefined method `foo' for Persoana:Class
+Persoana.new.foo # => 'foo'
+Carte.foo # => 'foo'
+Carte.new.foo # => NoMethodError: undefined method `foo'
+
+# Callbacks atunci cand includerea si extinderea unui modul sunt executate
+
+module ModulExempluCallBack
+ def self.included(base)
+ base.extend(ClassMethods)
+ base.send(:include, InstanceMethods)
+ end
+
+ module ClassMethods
+ def bar
+ 'bar'
+ end
+ end
+
+ module InstanceMethods
+ def qux
+ 'qux'
+ end
+ end
+end
+
+class CevaRelevant
+ include ModulExempluCallBack
+end
+
+CevaRelevant.bar # => 'bar'
+CevaRelevant.qux # => NoMethodError: undefined method `qux'
+CevaRelevant.new.bar # => NoMethodError: undefined method `bar'
+CevaRelevant.new.qux # => 'qux'
+```
diff --git a/ru-ru/c-ru.html.markdown b/ru-ru/c-ru.html.markdown
index 874e0821..5988b159 100644
--- a/ru-ru/c-ru.html.markdown
+++ b/ru-ru/c-ru.html.markdown
@@ -1,6 +1,6 @@
---
language: c
-filename: learnc.c
+filename: learnc-ru.c
contributors:
- ["Adam Bard", "http://adambard.com/"]
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
@@ -480,4 +480,4 @@ void str_reverse_through_pointer(char *str_in) {
Также не забывайте, что [Google](http://google.com) и [Яндекс](http://yandex.ru) – ваши хорошие друзья.
-[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member \ No newline at end of file
+[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member
diff --git a/ru-ru/go-ru.html.markdown b/ru-ru/go-ru.html.markdown
index 27b5d894..ffda01b7 100644
--- a/ru-ru/go-ru.html.markdown
+++ b/ru-ru/go-ru.html.markdown
@@ -3,8 +3,12 @@ language: Go
filename: learngo-ru.go
contributors:
- ["Sonia Keys", "https://github.com/soniakeys"]
+ - ["Christopher Bess", "https://github.com/cbess"]
+ - ["Jesse Johnson", "https://github.com/holocronweaver"]
+ - ["Quint Guvernator", "https://github.com/qguv"]
translators:
- ["Artem Medeusheyev", "https://github.com/armed"]
+ - ["Valery Cherepanov", "https://github.com/qumeric"]
lang: ru-ru
---
@@ -17,7 +21,7 @@ Go - это язык общего назначения, целью которо
для создания масштабируемых и многопоточных программ.
Может похвастаться отличной стандартной библиотекой и большим комьюнити, полным
-энтузиазтов.
+энтузиастов.
```go
// Однострочный комментарий
@@ -31,8 +35,9 @@ package main
// Import предназначен для указания зависимостей этого файла.
import (
"fmt" // Пакет в стандартной библиотеке Go
- "net/http" // Да, это web server!
+ "net/http" // Да, это веб-сервер!
"strconv" // Конвертирование типов в строки и обратно
+ m "math" // Импортировать math под локальным именем m.
)
// Объявление функции. Main это специальная функция, служащая точкой входа для
@@ -40,7 +45,7 @@ import (
// скобки.
func main() {
// Println выводит строку в stdout.
- // В данном случае фигурирует вызов функции из пакета fmt.
+ // Данная функция находится в пакете fmt.
fmt.Println("Hello world!")
// Вызов другой функции из текущего пакета.
@@ -55,57 +60,57 @@ func beyondHello() {
// Краткое определение := позволяет объявить перменную с автоматической
// подстановкой типа из значения.
y := 4
- sum, prod := learnMultiple(x, y) // функция возвращает два значения
- fmt.Println("sum:", sum, "prod:", prod) // простой вывод
+ sum, prod := learnMultiple(x, y) // Функция возвращает два значения.
+ fmt.Println("sum:", sum, "prod:", prod) // Простой вывод.
learnTypes() // < y minutes, learn more!
}
// Функция имеющая входные параметры и возврат нескольких значений.
func learnMultiple(x, y int) (sum, prod int) {
- return x + y, x * y // возврат двух результатов
+ return x + y, x * y // Возврат двух значений.
}
// Некотрые встроенные типы и литералы.
func learnTypes() {
// Краткое определение переменной говорит само за себя.
- s := "Learn Go!" // тип string
+ s := "Learn Go!" // Тип string.
s2 := `"Чистый" строковой литерал
-может содержать переносы строк` // тоже тип данных string
+может содержать переносы строк` // Тоже тип данных string
- // символ не из ASCII. Исходный код Go в кодировке UTF-8.
- g := 'Σ' // тип rune, это алиас для типа uint32, содержит юникод символ
+ // Символ не из ASCII. Исходный код Go в кодировке UTF-8.
+ g := 'Σ' // тип rune, это алиас для типа uint32, содержит символ юникода.
- f := 3.14195 // float64, 64-х битное число с плавающей точкой (IEEE-754)
- c := 3 + 4i // complex128, внутри себя содержит два float64
+ f := 3.14195 // float64, 64-х битное число с плавающей точкой (IEEE-754).
+ c := 3 + 4i // complex128, внутри себя содержит два float64.
- // Синтаксис var с инициализациями
- var u uint = 7 // беззнаковое, но размер зависит от реализации, как и у int
+ // Синтаксис var с инициализациями.
+ var u uint = 7 // Беззнаковое, но размер зависит от реализации, как и у int.
var pi float32 = 22. / 7
// Синтаксис приведения типа с кратким определением
- n := byte('\n') // byte алиас для uint8
+ n := byte('\n') // byte – это алиас для uint8.
- // Массивы (Array) имеют фиксированный размер на момент компиляции.
- var a4 [4]int // массив из 4-х int, проинициализирован нулями
- a3 := [...]int{3, 1, 5} // массив из 3-х int, ручная инициализация
+ // Массивы имеют фиксированный размер на момент компиляции.
+ var a4 [4]int // массив из 4-х int, инициализирован нулями.
+ a3 := [...]int{3, 1, 5} // массив из 3-х int, ручная инициализация.
- // Slice имеют динамическую длину. И массивы и slice-ы имеют каждый свои
- // преимущества, но slice-ы используются гораздо чаще.
- s3 := []int{4, 5, 9} // по сравнению с a3 тут нет троеточия
- s4 := make([]int, 4) // выделение памяти для slice из 4-х int (нули)
- var d2 [][]float64 // только объявление, память не выделяется
- bs := []byte("a slice") // конвертирование строки в slice байтов
+ // Слайсы (slices) имеют динамическую длину. И массивы, и слайсы имеют свои
+ // преимущества, но слайсы используются гораздо чаще.
+ s3 := []int{4, 5, 9} // Сравните с a3. Тут нет троеточия.
+ s4 := make([]int, 4) // Выделение памяти для слайса из 4-х int (нули).
+ var d2 [][]float64 // Только объявление, память не выделяется.
+ bs := []byte("a slice") // Синтаксис приведения типов.
- p, q := learnMemory() // объявление p и q как указателей на int.
+ p, q := learnMemory() // Объявление p и q как указателей на int.
fmt.Println(*p, *q) // * извлекает указатель. Печатает два int-а.
- // Map как словарь или хеш теблица из других языков является ассоциативным
- // массивом с динамически изменяемым размером.
+ // Map, также как и словарь или хеш из некоторых других языков, является
+ // ассоциативным массивом с динамически изменяемым размером.
m := map[string]int{"three": 3, "four": 4}
m["one"] = 1
- delete(m, "three") // встроенная функция, удаляет элемент из map-а.
+ delete(m, "three") // Встроенная функция, удаляет элемент из map-а.
// Неиспользуемые переменные в Go являются ошибкой.
// Нижнее подчеркивание позволяет игнорировать такие переменные.
@@ -113,79 +118,91 @@ func learnTypes() {
// Вывод считается использованием переменной.
fmt.Println(s, c, a4, s3, d2, m)
- learnFlowControl() // идем далее
+ learnFlowControl() // Идем дальше.
}
// У Go есть полноценный сборщик мусора. В нем есть указатели но нет арифметики
-// указатеей. Вы можете допустить ошибку с указателем на nil, но не с его
-// инкрементацией.
+// указателей. Вы можете допустить ошибку с указателем на nil, но не с
+// инкрементацией указателя.
func learnMemory() (p, q *int) {
// Именованные возвращаемые значения p и q являются указателями на int.
- p = new(int) // встроенная функция new выделяет память.
+ p = new(int) // Встроенная функция new выделяет память.
// Выделенный int проинициализирован нулем, p больше не содержит nil.
- s := make([]int, 20) // Выделение единого блока памяти под 20 int-ов,
- s[3] = 7 // назначение одному из них,
- r := -2 // опредление еще одной локальной переменной,
- return &s[3], &r // амперсанд обозначает получение адреса переменной.
+ s := make([]int, 20) // Выделение единого блока памяти под 20 int-ов.
+ s[3] = 7 // Присвоить значение одному из них.
+ r := -2 // Определить еще одну локальную переменную.
+ return &s[3], &r // Амперсанд(&) обозначает получение адреса переменной.
}
-func expensiveComputation() int {
- return 1e6
+func expensiveComputation() float64 {
+ return m.Exp(10)
}
func learnFlowControl() {
- // If-ы всегда требуют наличине фигурных скобок, но круглые скобки
- // необязательны.
+ // If-ы всегда требуют наличине фигурных скобок, но не круглых.
if true {
fmt.Println("told ya")
}
// Форматирование кода стандартизировано утилитой "go fmt".
if false {
- // все тлен
+ // Будущего нет.
} else {
- // жизнь прекрасна
+ // Жизнь прекрасна.
}
- // Использоване switch на замену нескольким if-else
- x := 1
+ // Используйте switch вместо нескольких if-else.
+ x := 42.0
switch x {
case 0:
case 1:
- // case-ы в Go не проваливаются, т.е. break по умолчанию
- case 2:
- // не выполнится
+ case 42:
+ // Case-ы в Go не "проваливаются" (неявный break).
+ case 43:
+ // Не выполнится.
}
// For, как и if не требует круглых скобок
- for x := 0; x < 3; x++ { // ++ это операция
+ // Переменные, объявленные в for и if являются локальными.
+ for x := 0; x < 3; x++ { // ++ – это операция.
fmt.Println("итерация", x)
}
- // тут x == 1.
+ // Здесь x == 42.
- // For это единственный цикл в Go, но у него несколько форм.
- for { // бесконечный цикл
- break // не такой уж и бесконечный
- continue // не выполнится
+ // For – это единственный цикл в Go, но у него есть альтернативные формы.
+ for { // Бесконечный цикл.
+ break // Не такой уж и бесконечный.
+ continue // Не выполнится.
}
// Как и в for, := в if-е означает объявление и присвоение значения y,
- // затем проверка y > x.
+ // проверка y > x происходит после.
if y := expensiveComputation(); y > x {
x = y
}
// Функции являются замыканиями.
xBig := func() bool {
- return x > 100 // ссылается на x, объявленый выше switch.
+ return x > 10000 // Ссылается на x, объявленый выше switch.
}
- fmt.Println("xBig:", xBig()) // true (т.к. мы присвоили x = 1e6)
- x /= 1e5 // тут х == 10
- fmt.Println("xBig:", xBig()) // теперь false
+ fmt.Println("xBig:", xBig()) // true (т.к. мы присвоили x = e^10).
+ x = 1.3e3 // Тут х == 1300
+ fmt.Println("xBig:", xBig()) // Теперь false.
// Метки, куда же без них, их все любят.
goto love
love:
+ learnDefer() // Быстрый обзор важного ключевого слова.
learnInterfaces() // О! Интерфейсы, идем далее.
}
-// Объявление Stringer как интерфейса с одним мметодом, String.
+func learnDefer() (ok bool) {
+ // Отложенные(deferred) выражения выполняются сразу перед тем, как функция
+ // возвратит значение.
+ defer fmt.Println("deferred statements execute in reverse (LIFO) order.")
+ defer fmt.Println("\nThis line is being printed first because")
+ // defer широко используется для закрытия файлов, чтобы закрывающая файл
+ // функция находилась близко к открывающей.
+ return true
+}
+
+// Объявление Stringer как интерфейса с одним методом, String.
type Stringer interface {
String() string
}
@@ -196,35 +213,48 @@ type pair struct {
}
// Объявление метода для типа pair. Теперь pair реализует интерфейс Stringer.
-func (p pair) String() string { // p в данном случае называют receiver-ом
- // Sprintf - еще одна функция из пакета fmt.
+func (p pair) String() string { // p в данном случае называют receiver-ом.
+ // Sprintf – еще одна функция из пакета fmt.
// Обращение к полям p через точку.
return fmt.Sprintf("(%d, %d)", p.x, p.y)
}
func learnInterfaces() {
// Синтаксис с фигурными скобками это "литерал структуры". Он возвращает
- // проинициализированную структуру, а оператор := присваивает ее в p.
+ // проинициализированную структуру, а оператор := присваивает её p.
p := pair{3, 4}
- fmt.Println(p.String()) // вызов метода String у p, типа pair.
- var i Stringer // объявление i как типа с интерфейсом Stringer.
- i = p // валидно, т.к. pair реализует Stringer.
- // Вызов метода String у i, типа Stringer. Вывод такой же что и выше.
+ fmt.Println(p.String()) // Вызов метода String у переменной p типа pair.
+ var i Stringer // Объявление i как типа с интерфейсом Stringer.
+ i = p // Валидно, т.к. pair реализует Stringer.
+ // Вызов метода String у i типа Stringer. Вывод такой же, что и выше.
fmt.Println(i.String())
// Функции в пакете fmt сами всегда вызывают метод String у объектов для
// получения строкового представления о них.
- fmt.Println(p) // Вывод такой же что и выше. Println вызывает метод String.
- fmt.Println(i) // тоже самое
+ fmt.Println(p) // Вывод такой же, что и выше. Println вызывает метод String.
+ fmt.Println(i) // Вывод такой же, что и выше.
+
+ learnVariadicParams("Учиться", "учиться", "и еще раз учиться!")
+}
+
+// Функции могут иметь варьируемое количество параметров.
+func learnVariadicParams(myStrings ...interface{}) {
+ // Вывести все параметры с помощью итерации.
+ for _, param := range myStrings {
+ fmt.Println("param:", param)
+ }
+
+ // Передать все варьируемые параметры.
+ fmt.Println("params:", fmt.Sprintln(myStrings...))
learnErrorHandling()
}
func learnErrorHandling() {
- // Идиома ", ok" служит для обозначения сработало что-то или нет.
+ // Идиома ", ok" служит для обозначения корректного срабатывания чего-либо.
m := map[int]string{3: "three", 4: "four"}
if x, ok := m[1]; !ok { // ok будет false, потому что 1 нет в map-е.
- fmt.Println("тут никого")
+ fmt.Println("тут никого нет")
} else {
fmt.Print(x) // x содержал бы значение, если бы 1 был в map-е.
}
@@ -237,7 +267,7 @@ func learnErrorHandling() {
learnConcurrency()
}
-// c это тип данных channel (канал), объект для конкуррентного взаимодействия.
+// c – это тип данных channel (канал), объект для конкуррентного взаимодействия.
func inc(i int, c chan int) {
c <- i + 1 // когда channel слева, <- являтся оператором "отправки".
}
@@ -300,7 +330,7 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
объемную документацию.
Для живого ознакомления рекомендуется почитать исходные коды [стандартной
-библиотеки Go](http://golang.org/src/pkg/). Отлично задокументированая, она
+библиотеки Go](http://golang.org/src/pkg/). Отлично задокументированная, она
является лучшим источником для чтения и понимания Go, его стиля и идиом. Либо
можно, кликнув на имени функции в [документации](http://golang.org/pkg/),
перейти к ее исходным кодам.
diff --git a/ru-ru/haskell-ru.html.markdown b/ru-ru/haskell-ru.html.markdown
new file mode 100644
index 00000000..03e66d05
--- /dev/null
+++ b/ru-ru/haskell-ru.html.markdown
@@ -0,0 +1,546 @@
+---
+language: haskell
+contributors:
+ - ["Adit Bhargava", "http://adit.io"]
+translators:
+ - ["Aleksey Pirogov", "http://astynax.github.io"]
+lang: ru-ru
+---
+
+Haskell разрабатывался, как чистый функциональный язык программирования, применимый на практике. Язык известен благодаря своей системе типов, и "знаменит" благодаря монадам. [Меня][autor] же Haskell заставляет возвращаться к себе снова и снова именно своей элегантностью и [я][autor] получаю истинное удовольствие, программируя на Haskell.
+
+```haskell
+-- Однострочные комментарии начинаются с двух дефисов
+{- Многострочный комментарий
+заключается в пару фигурных скобок с дефисами с внутренней стороны.
+-}
+
+-------------------------------------------------------
+-- 1. Примитивные типы и простейшие операции над ними
+-------------------------------------------------------
+
+-- Числа объявляются просто
+3 -- 3
+
+-- Арифметика тоже выглядит вполне ожидаемо
+1 + 1 -- 2
+8 - 1 -- 7
+10 * 2 -- 20
+35 / 5 -- 7.0
+
+-- Операция деления всегда возвращает действительное число
+35 / 4 -- 8.75
+
+-- Делим нацело так
+35 `div` 4 -- 8
+
+-- Булевы значения - тоже примитивные значения
+True
+False
+
+-- Булева алгебра
+not True -- False
+not False -- True
+1 == 1 -- True
+1 /= 1 -- False
+1 < 10 -- True
+
+-- В примере выше `not`, это функция, принимающая один аргумент.
+-- При вызове функции в Haskell список аргументов
+-- не нужно заключать в скобки - аргументы просто
+-- перечисляются через пробелы сразу после имени функции.
+-- Т.о. типичный вызов выглядит так:
+-- func arg1 arg2 arg3...
+-- Ниже же будет показано, как определять свои функции.
+
+-- Строки и символы
+"Это строка."
+'ы' -- а это символ
+'Нельзя заключать длинные строки в одинарные кавычки.' -- ошибка!
+
+-- Строки можно конкатенировать
+"Привет" ++ ", Мир!" -- "Привет, Мир!"
+
+-- При этом строки - это просто списки символов!
+"Я - строка!" !! 0 -- 'Я'
+
+
+----------------------------------------------------
+-- Списки и Кортежи
+----------------------------------------------------
+
+-- Все элементы списка в Haskell
+-- должны иметь один и тот же тип.
+
+-- Эти два списка - эквивалентны:
+[1, 2, 3, 4, 5]
+[1..5]
+
+-- Haskell позволяет определять даже бесконечные списки!
+[1..] -- список всех натуральных чисел!
+
+-- Бесконечные списки возможно в Haskell потому, что он "ленив".
+-- В Haskell все вычисления производятся тогда и только тогда,
+-- когда их результат потребуется.
+-- Эта стратегия так и называется - "lazy evaluation".
+-- Скажем, если вам нужен тысячный элемент из
+-- списка натуральных чисел (бесконечного) и вы напишете так:
+
+[1..] !! 999 -- 1000
+
+-- То Haskell вычислит элементы этого списка от 1 до 1000...
+-- ... и остановится, ведь последующие элементы пока не нужны.
+-- Это значит, что остальные элементы нашего
+-- "бесконечного" списка не будут вычисляться! По крайней мере,
+-- пока не понадобятся и они.
+
+-- Списки можно объединять
+[1..5] ++ [6..10]
+
+-- И добавлять значения в начало
+0:[1..5] -- [0, 1, 2, 3, 4, 5]
+
+-- А можно обратиться по индексу
+[0..] !! 5 -- 5
+
+-- Вот ещё несколько функций, часто используемых со списками
+head [1..5] -- 1
+tail [1..5] -- [2, 3, 4, 5]
+init [1..5] -- [1, 2, 3, 4]
+last [1..5] -- 5
+
+-- list comprehensions - "формулы" для описания списков
+[x*2 | x <- [1..5]] -- [2, 4, 6, 8, 10]
+
+-- можно указать условие попадания элементов в список
+[x*2 | x <- [1..5], x*2 > 4] -- [6, 8, 10]
+
+-- Списки могут даже состоять из других списков
+[[1,2,3],[4,5,6]] !! 1 !! 2 -- 6 (вторая строка, третий столбец)
+
+-- Кортежи позволяют своим элементам иметь различные типы,
+-- но при этом кортежи имеют фиксированную длину.
+-- Кортеж:
+("haskell", 1)
+
+-- Часто кортежи из двух элементов называются "парами".
+-- Элементы пары можно получать так:
+fst ("haskell", 1) -- "haskell"
+snd ("haskell", 1) -- 1
+
+----------------------------------------------------
+-- 3. Функции
+----------------------------------------------------
+-- Простая функция, принимающая два аргумента
+add a b = a + b
+
+-- Внимание!
+-- Если вы используете ghci (интерактивный интерпретатор Haskell),
+-- вам нужно использовать ключевое слово `let`, примерно так:
+-- let add a b = a + b
+
+-- Вызовем нашу функцию
+add 1 2 -- 3
+
+-- Функцию можно поместить между первым и вторым аргументами,
+-- если заключить её имя в обратные кавычки
+1 `add` 2 -- 3
+
+{- Вы можете также определять функции, имя которых
+вообще не содержит букв! Таки функции и называются "операторами",
+и, да, вы можете определять свои операторы!
+Скажем, оператор целочисленного деления можно определить так -}
+(//) a b = a `div` b
+35 // 4 -- 8
+{- Здесь оператор заключен в скобки - как говорят,
+поставлен в префиксную позицию.
+В префиксной позиции оператор можно не только определять,
+но и вызывать -}
+(+) 1 2 -- 3
+
+-- Охранные выражения (guards) порой удобны,
+-- если наша функция ветвится
+fib x
+ | x < 2 = x
+ | otherwise = fib (x - 1) + fib (x - 2)
+
+{- Сопоставление с образцом (pattern matching)
+чем-то напоминает охранные выражения.
+Здесь мы видим три определения функции fib.
+При вызове функции по имени Haskell использует
+первое определение, к образцу которого
+"подойдет" набор аргументов -}
+fib 1 = 1
+fib 2 = 2
+fib x = fib (x - 1) + fib (x - 2)
+
+-- Pattern matching для кортежей выглядит так
+foo (x, y) = (x + 1, y + 2)
+
+{- Pattern matching для списков устроен чуть сложнее.
+Пусть `x` - первый элемент списка, а `xs` - остальные элементы.
+Тогда операции `head` и `tail` могут быть определены так -}
+myHead (x:xs) = x
+myTail (x:xs) = xs
+
+-- Функцию отображения мы можем написать так
+myMap func [] = []
+myMap func (x:xs) = func x:(myMap func xs)
+
+-- При сопоставлении происходит привязка
+-- элементов значения с именами в образце
+fstPlusThird (a : _ : b : _) = a + b
+fstPlusThird [1,2,3,4,5] -- 4
+-- Значения, для которых вместо имени указано `_`,
+-- игнорируются. Это удобно, когда важен сам факт
+-- совпадения образца
+oneElem [_] = True
+oneElem _ = False
+
+startsWith x (y:_) = x == y
+startsWith _ _ = False
+
+startsWith 'H' "Hello!" -- True
+startsWith 'H' "hello!" -- False
+
+{- Обратите внимание на тот факт,
+что первый аргумент нашей функции `myMap` - тоже функция!
+Функции, подобно `myMap`, принимающие другие функции
+в качестве параметров, или, скажем, возвращающие функции
+в качестве результата, называются
+Функциями Высших Порядков (ФВП, High Order Functions, HOF)
+-}
+
+-- Вместе с ФВП часто используются анонимные функции
+myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7]
+-- Такие функции описываются в виде
+-- \arg1 arg1 .. -> expression
+
+-- Популярные в других языках ФВП присутствуют и в Haskell
+map (\x -> x * 10) [1..5] -- [10, 20, 30, 40, 50]
+filter (\x -> x > 2) [1..5] -- [3, 4, 5]
+
+{- Функция свертки
+(она же `reduce` или `inject` в других языках)
+в Haskell представлены функциями `foldr` и `foldl`.
+Суть свертки можно представить так:
+
+foldl f x0 [x1,x2,x3] -> (f (f (f x0 x1) x2) x3)
+foldr f x0 [x1,x2,x3] -> (f x1 (f x2 (f x3 x0)))
+
+Здесь x0 - начальное значения так называемого "аккумулятора"
+-}
+-- Эти два вызова дают одинаковый результат
+foldr (\x acc -> acc + x) 0 [1..5] -- 15
+foldl (\acc x -> acc + x) 0 [1..5] -- 15
+-- Тут можно даже заменить анонимную функцию на оператор
+foldr (+) 0 [1..5] -- 15
+foldl (+) 0 [1..5] -- 15
+
+-- Зато здесь разница видна
+foldr (\x acc -> (x + 10) : acc) [] [1..3] -- [11, 12, 13]
+foldl (\acc x -> (x + 10) : acc) [] [1..3] -- [13, 12, 11]
+
+{- Часто в качестве начального значения
+удобно брать крайнее значение списка (крайнее слева или справа).
+Для этого есть пара функций - `foldr1` и `foldl1` -}
+foldr1 (+) [1..5] -- 15
+foldl1 (+) [1..5] -- 15
+
+----------------------------------------------------
+-- 4. Больше о функциях
+----------------------------------------------------
+
+{- Каррирование (currying)
+Если в Haskell при вызове функции передать не все аргументы,
+Функция становится "каррированой" - результатом вызова станет
+новая функция, которая при вызове и примет оставшиеся аргументы -}
+
+add a b = a + b
+foo = add 10 -- теперь foo будет принимать число
+ -- и добавлять к нему 10
+foo 5 -- 15
+
+-- Для операторов можно "опустить" любой из двух аргументов
+-- Используя этот факт можно определить
+-- функцию `foo` из кода выше несколько иначе
+foo = (+10)
+foo 5 -- 15
+
+-- Поупражняемся
+map (10-) [1..3] -- [9, 8, 7]
+filter (<5) [1..10] -- [1, 2, 3, 4]
+
+{- Композиция функций
+Функция (.) соединяет пару функций в цепочку.
+К примеру, можно соединить функцию, добавляющую 10,
+с функцией, умножающей на 5 -}
+foo = (*5) . (+10)
+
+-- (5 + 10) * 5 = 75
+foo 5 -- 75
+
+{- Управление приоритетом вычисления
+В Haskell есть функция `$`, которая применяет
+свой первый аргумент ко второму с наименьшим приоритетом
+(обычное применение функций имеет наивысший приоритет)
+Эта функция часто позволяет избежать использования
+"лишних" скобок -}
+head (tail (tail "abcd")) -- 'c'
+head $ tail $ tail "abcd" -- 'c'
+-- того же эффекта иногда можно достичь использованием композиции
+(head . tail . tail) "abcd" -- 'c'
+head . tail . tail $ "abcd" -- 'c'
+{- Тут стоит сразу запомнить, что композиция функций
+возвращает именно новую функцию, как в последнем примере.
+Т.е. можно делать так -}
+third = head . tail . tail
+-- но не так
+third = head $ tail $ tail -- (head (tail (tail))) - ошибка!
+
+----------------------------------------------------
+-- 5. Сигнатуры типов
+----------------------------------------------------
+
+{- Haskell обладает очень сильной системой типов.
+И типизация в Haskell - строгая. Каждое выражение имеет тип,
+который может быть описан сигнатурой.
+Сигнатура записывается в форме
+expression :: type signature
+-}
+
+-- Типы примитивов
+5 :: Integer
+"hello" :: String
+True :: Bool
+
+{- Функции тоже имеют тип
+`not` принимает булево значение и возвращает булев результат
+not :: Bool -> Bool
+
+Вот функция двух аргументов
+add :: Integer -> Integer -> Integer
+
+Тут то мы и видим предпосылки к каррированию: тип
+на самом деле выглядит так (скобки просто обычно опускаются)
+add :: (Integer -> Integer) -> Integer
+т.е. функция принимает аргумент,
+и возвращает функцию от второго аргумента! -}
+
+-- Считается хорошим тоном указывать сигнатуру определений,
+-- которые доступны другим разработчикам (публичны). Пример:
+double :: Integer -> Integer
+double x = x * 2
+
+----------------------------------------------------
+-- 6. Управление потоком исполнения
+----------------------------------------------------
+
+-- Выражение `if`
+haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome"
+
+-- Выражение `if` можно записать и в несколько строк.
+-- Соблюдайте отступы!
+haskell = if 1 == 1
+ then "awesome"
+ else "awful"
+
+-- Так как `if` - выражение, ветка `else` обязательна!
+-- И более того, результаты выражений в ветках `then` и `else`
+-- должны иметь одинаковый тип!
+
+-- `case`-выражение выглядит так
+case args of -- парсим аргументы командной строки
+ "help" -> printHelp
+ "start" -> startProgram
+ _ -> putStrLn "bad args"
+
+-- При вычислении результата `case`-выражения производится
+-- сопоставление с образцом:
+fib x = case x of
+ 1 -> 1
+ 2 -> 1
+ _ -> fib (x - 1) + fib (x - 2)
+
+-- В Haskell нет циклов - вместо них используются рекурсия,
+-- отображение, фильтрация и свертка (map/filter/fold)
+map (*2) [1..5] -- [2, 4, 6, 8, 10]
+
+for array func = map func array
+for [0..3] $ \i -> show i -- ["0", "1", "2", "3"]
+for [0..3] show -- ["0", "1", "2", "3"]
+
+----------------------------------------------------
+-- 7. Пользовательские типы данных
+----------------------------------------------------
+
+-- Создадим свой Haskell-тип данных
+
+data Color = Red | Blue | Green
+
+-- Попробуем использовать
+
+say :: Color -> String
+say Red = "You are Red!"
+say Blue = "You are Blue!"
+say Green = "You are Green!"
+
+-- Типы могут иметь параметры (параметры типов)
+
+data Maybe a = Nothing | Just a
+
+-- Все эти выражения имеют тип `Maybe`
+Just "hello" -- :: `Maybe String`
+Just 1 -- :: `Maybe Int`
+Nothing -- :: `Maybe a` для любого `a`
+
+-- Типы могут быть достаточно сложными
+data Figure = Rectangle (Int, Int) Int Int
+ | Square (Int, Int) Int
+ | Point (Int, Int)
+
+area :: Figure -> Int
+area (Point _) = 0
+area (Square _ s) = s * s
+area (Rectangle _ w h) = w * h
+
+----------------------------------------------------
+-- 8. Ввод-вывод в Haskell
+----------------------------------------------------
+
+-- Полноценно объяснить тему ввода-вывода невозможно
+-- без объяснения монад, но для использования в простых случаях
+-- вводного описания будет достаточно.
+
+-- Когда программа на Haskell выполняется,
+-- вызывается функция с именем `main`.
+-- Эта функция должна вернуть значение типа `IO ()`
+-- Например
+
+main :: IO ()
+main = putStrLn $ "Hello, sky! " ++ (say Blue)
+-- `putStrLn` имеет тип `String -> IO ()`
+
+-- Проще всего реализовать программу с вводом-выводом (IO),
+-- если вы реализуете функцию с типом `String -> String`.
+-- Далее ФВП
+-- interact :: (String -> String) -> IO ()
+-- сделает всё за нас!
+
+countLines :: String -> String
+countLines = show . length . lines
+-- здесь `lines` разделяет строку на список строк
+-- по символу перевода строки
+
+main' :: IO ()
+main' = interact countLines
+
+{- Вы можете думать о типе `IO ()`,
+как о некотором представлении последовательности
+действий, которые должен совершить компьютер.
+Такое представление напоминает программу
+на императивном языке программирования. Для описания
+такой последовательности используется `do`-нотация -}
+
+sayHello :: IO ()
+sayHello = do
+ putStrLn "What is your name?"
+ name <- getLine -- запрашиваем строку и связываем с "name"
+ putStrLn $ "Hello, " ++ name
+
+-- Упражнение:
+-- напишите свою реализацию функции `interact`,
+-- которая запрашивает и обрабатывает только одну строку
+
+{- Код функции `sayHello` не будет исполняться
+при её определении. Единственное место, где IO-действия
+могут быть произведены - функция `main`!
+Чтобы эта программа выполнила действия в функции `sayHello`,
+закомментируйте предыдущее определение функции `main`
+и добавьте новое определение:
+
+main = sayHello -}
+
+{- Давайте подробнее рассмотрим, как работает функция `getLine`
+Её тип:
+ getLine :: IO String
+Вы можете думать, что значение типа `IO a` представляет
+собой компьютерную программу, в результате выполнения которой
+генерируется значение типа `a`, в дополнение
+к остальным эффектам, производимым при выполнении - таким как
+печать текста на экран. Это значение типа `a` мы можем
+сохранить с помощью оператора `<-`. Мы даже можем реализовать
+свое действие, возвращающее значение: -}
+
+action :: IO String
+action = do
+ putStrLn "This is a line. Duh"
+ input1 <- getLine
+ input2 <- getLine
+ -- Тип блока `do` будет соответствовать типу последнего
+ -- выполненного в блоке выражения.
+ -- Заметим, что `return` - не ключевое слово, а функция
+ -- типа `a -> IO a`
+ return (input1 ++ "\n" ++ input2) -- return :: String -> IO String
+
+-- Теперь это действие можно использовать вместо `getLine`:
+
+main'' = do
+ putStrLn "I will echo two lines!"
+ result <- action
+ putStrLn result
+ putStrLn "This was all, folks!"
+
+{- Тип `IO` - пример "монады". Языку Haskell нужны монады,
+чтобы оставаться преимущественно чистым функциональным языком.
+Любые функции, взаимодействующие с внешним миром
+(производящие ввод-вывод) имеют `IO` в своих сигнатурах.
+Это позволяет судить о функции как о "чистой" - такая не будет
+производить ввод-вывод. В ином случая функция - не "чистая".
+
+Такой подход позволяет очень просто разрабатывать многопоточные
+программы - чистые функции, запущенные параллельно
+не будут конфликтовать между собой в борьбе за ресурсы. -}
+
+----------------------------------------------------
+-- 9. Haskell REPL
+----------------------------------------------------
+
+{- Интерактивная консоль Haskell запускается командой `ghci`.
+Теперь можно вводить строки кода на Haskell.
+Связывание значений с именами производится
+с помощью выражения `let`: -}
+
+let foo = 5
+
+-- Тип значения или выражения можно узнать
+-- с помощью команды `:t`:
+
+>:t foo
+foo :: Integer
+
+-- Также можно выполнять действия с типом `IO ()`
+
+> sayHello
+What is your name?
+Friend!
+Hello, Friend!
+
+```
+
+Многое о Haskell, например классы типов и монады невозможно уместить в столь короткую статью. Огромное количество очень интересных идей лежит в основе языка, и именно благодаря этому фундаменту на языке так приятно писать код. Позволю себе привести ещё один маленький пример кода на Haskell - реализацию быстрой сортировки:
+
+```haskell
+qsort [] = []
+qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater
+ where lesser = filter (< p) xs
+ greater = filter (>= p) xs
+```
+
+Haskell прост в установке, забирайте [здесь](http://www.haskell.org/platform/) и пробуйте! Это же так интересно!.
+
+Более глубокое погрузиться в язык позволят прекрасные книги
+[Learn you a Haskell](http://learnyouahaskell.com/) и
+[Real World Haskell](http://book.realworldhaskell.org/).
+
+[autor]: http://adit.io имеется в виду автор оригинального текста Adit Bhargava *(примечание переводчика)*
diff --git a/ru-ru/julia-ru.html.markdown b/ru-ru/julia-ru.html.markdown
new file mode 100644
index 00000000..cd55e116
--- /dev/null
+++ b/ru-ru/julia-ru.html.markdown
@@ -0,0 +1,750 @@
+---
+language: julia
+contributors:
+ - ["Leah Hanson", "http://leahhanson.us"]
+translators:
+ - ["Sergey Skovorodkin", "https://github.com/skovorodkin"]
+filename: learnjulia-ru.jl
+lang: ru-ru
+---
+
+Julia — гомоиконный функциональный язык программирования для технических расчётов.
+Несмотря на полную поддержку гомоиконных макросов, функций первого класса и конструкций управления низкого уровня, этот язык так же прост в изучении и применении, как и Python.
+
+Документ описывает текущую dev-версию Julia от 18-о октября 2013 года.
+
+```ruby
+
+# Однострочные комментарии начинаются со знака решётки.
+
+####################################################
+## 1. Примитивные типы данных и операторы
+####################################################
+
+# Всё в Julia — выражение.
+
+# Простые численные типы
+3 # => 3 (Int64)
+3.2 # => 3.2 (Float64)
+2 + 1im # => 2 + 1im (Complex{Int64})
+2//3 # => 2//3 (Rational{Int64})
+
+# Доступны все привычные инфиксные операторы
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+35 / 5 # => 7.0
+5 / 2 # => 2.5 # деление Int на Int всегда возвращает Float
+div(5, 2) # => 2 # для округления к нулю используется div
+5 \ 35 # => 7.0
+2 ^ 2 # => 4 # возведение в степень
+12 % 10 # => 2
+
+# С помощью скобок можно изменить приоритет операций
+(1 + 3) * 2 # => 8
+
+# Побитовые операторы
+~2 # => -3 # НЕ (NOT)
+3 & 5 # => 1 # И (AND)
+2 | 4 # => 6 # ИЛИ (OR)
+2 $ 4 # => 6 # сложение по модулю 2 (XOR)
+2 >>> 1 # => 1 # логический сдвиг вправо
+2 >> 1 # => 1 # арифметический сдвиг вправо
+2 << 1 # => 4 # логический/арифметический сдвиг влево
+
+# Функция bits возвращает бинарное представление числа
+bits(12345)
+# => "0000000000000000000000000000000000000000000000000011000000111001"
+bits(12345.0)
+# => "0100000011001000000111001000000000000000000000000000000000000000"
+
+# Логические значения являются примитивами
+true
+false
+
+# Булевы операторы
+!true # => false
+!false # => true
+1 == 1 # => true
+2 == 1 # => false
+1 != 1 # => false
+2 != 1 # => true
+1 < 10 # => true
+1 > 10 # => false
+2 <= 2 # => true
+2 >= 2 # => true
+# Сравнения можно объединять цепочкой
+1 < 2 < 3 # => true
+2 < 3 < 2 # => false
+
+# Строки объявляются с помощью двойных кавычек — "
+"This is a string."
+
+# Символьные литералы создаются с помощью одинарных кавычек — '
+'a'
+
+# Строки индексируются как массивы символов
+"This is a string"[1] # => 'T' # Индексы начинаются с единицы
+# Индексирование не всегда правильно работает для UTF8-строк,
+# поэтому рекомендуется использовать итерирование (map, for-циклы и т.п.).
+
+# Для строковой интерполяции используется знак доллара ($):
+"2 + 2 = $(2 + 2)" # => "2 + 2 = 4"
+# В скобках можно использовать любое выражение языка.
+
+# Другой способ форматирования строк — макрос printf
+@printf "%d is less than %f" 4.5 5.3 # 5 is less than 5.300000
+
+####################################################
+## 2. Переменные и коллекции
+####################################################
+
+# Вывод
+println("I'm Julia. Nice to meet you!")
+
+# Переменные инициализируются без предварительного объявления
+some_var = 5 # => 5
+some_var # => 5
+
+# Попытка доступа к переменной до инициализации вызывает ошибку
+try
+ some_other_var # => ERROR: some_other_var not defined
+catch e
+ println(e)
+end
+
+# Имена переменных начинаются с букв.
+# После первого символа можно использовать буквы, цифры,
+# символы подчёркивания и восклицательные знаки.
+SomeOtherVar123! = 6 # => 6
+
+# Допустимо использование unicode-символов
+☃ = 8 # => 8
+# Это особенно удобно для математических обозначений
+2 * π # => 6.283185307179586
+
+# Рекомендации по именованию:
+# * имена переменных в нижнем регистре, слова разделяются символом
+# подчёркивания ('\_');
+#
+# * для имён типов используется CamelCase;
+#
+# * имена функций и макросов в нижнем регистре
+# без разделения слов символом подчёркивания;
+#
+# * имя функции, изменяющей переданные ей аргументы (in-place function),
+# оканчивается восклицательным знаком.
+
+# Массив хранит последовательность значений, индексируемых с единицы до n:
+a = Int64[] # => пустой массив Int64-элементов
+
+# Одномерный массив объявляется разделёнными запятой значениями.
+b = [4, 5, 6] # => массив из трёх Int64-элементов: [4, 5, 6]
+b[1] # => 4
+b[end] # => 6
+
+# Строки двумерного массива разделяются точкой с запятой.
+# Элементы строк разделяются пробелами.
+matrix = [1 2; 3 4] # => 2x2 Int64 Array: [1 2; 3 4]
+
+# push! и append! добавляют в список новые элементы
+push!(a,1) # => [1]
+push!(a,2) # => [1,2]
+push!(a,4) # => [1,2,4]
+push!(a,3) # => [1,2,4,3]
+append!(a,b) # => [1,2,4,3,4,5,6]
+
+# pop! удаляет из списка последний элемент
+pop!(b) # => возвращает 6; массив b снова равен [4,5]
+
+# Вернём 6 обратно
+push!(b,6) # b снова [4,5,6].
+
+a[1] # => 1 # индексы начинаются с единицы!
+
+# Последний элемент можно получить с помощью end
+a[end] # => 6
+
+# Операции сдвига
+shift!(a) # => 1 and a is now [2,4,3,4,5,6]
+unshift!(a,7) # => [7,2,4,3,4,5,6]
+
+# Восклицательный знак на конце названия функции означает,
+# что функция изменяет переданные ей аргументы.
+arr = [5,4,6] # => массив из 3 Int64-элементов: [5,4,6]
+sort(arr) # => [4,5,6]; но arr равен [5,4,6]
+sort!(arr) # => [4,5,6]; а теперь arr — [4,5,6]
+
+# Попытка доступа за пределами массива выбрасывает BoundsError
+try
+ a[0] # => ERROR: BoundsError() in getindex at array.jl:270
+ a[end+1] # => ERROR: BoundsError() in getindex at array.jl:270
+catch e
+ println(e)
+end
+
+# Вывод ошибок содержит строку и файл, где произошла ошибка,
+# даже если это случилось в стандартной библиотеке.
+# Если вы собрали Julia из исходных кодов,
+# то найти эти файлы можно в директории base.
+
+# Создавать массивы можно из последовательности
+a = [1:5] # => массив из 5 Int64-элементов: [1,2,3,4,5]
+
+# Срезы
+a[1:3] # => [1, 2, 3]
+a[2:] # => [2, 3, 4, 5]
+a[2:end] # => [2, 3, 4, 5]
+
+# splice! удаляет элемент из массива
+# Remove elements from an array by index with splice!
+arr = [3,4,5]
+splice!(arr,2) # => 4 ; arr теперь равен [3,5]
+
+# append! объединяет списки
+b = [1,2,3]
+append!(a,b) # теперь a равен [1, 2, 3, 4, 5, 1, 2, 3]
+
+# Проверка на вхождение
+in(1, a) # => true
+
+# Длина списка
+length(a) # => 8
+
+# Кортеж — неизменяемая структура.
+tup = (1, 2, 3) # => (1,2,3) # кортеж (Int64,Int64,Int64).
+tup[1] # => 1
+try:
+ tup[1] = 3 # => ERROR: no method setindex!((Int64,Int64,Int64),Int64,Int64)
+catch e
+ println(e)
+end
+
+# Многие функции над списками работают и для кортежей
+length(tup) # => 3
+tup[1:2] # => (1,2)
+in(2, tup) # => true
+
+# Кортежи можно распаковывать в переменные
+a, b, c = (1, 2, 3) # => (1,2,3) # a = 1, b = 2 и c = 3
+
+# Скобки из предыдущего примера можно опустить
+d, e, f = 4, 5, 6 # => (4,5,6)
+
+# Кортеж из одного элемента не равен значению этого элемента
+(1,) == 1 # => false
+(1) == 1 # => true
+
+# Обмен значений
+e, d = d, e # => (5,4) # d = 5, e = 4
+
+
+# Словари содержат ассоциативные массивы
+empty_dict = Dict() # => Dict{Any,Any}()
+
+# Для создания словаря можно использовать литерал
+filled_dict = ["one"=> 1, "two"=> 2, "three"=> 3]
+# => Dict{ASCIIString,Int64}
+
+# Значения ищутся по ключу с помощью оператора []
+filled_dict["one"] # => 1
+
+# Получить все ключи
+keys(filled_dict)
+# => KeyIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# Заметьте, словарь не запоминает порядок, в котором добавляются ключи.
+
+# Получить все значения.
+values(filled_dict)
+# => ValueIterator{Dict{ASCIIString,Int64}}(["three"=>3,"one"=>1,"two"=>2])
+# То же касается и порядка значений.
+
+# Проверка вхождения ключа в словарь
+in(("one", 1), filled_dict) # => true
+in(("two", 3), filled_dict) # => false
+haskey(filled_dict, "one") # => true
+haskey(filled_dict, 1) # => false
+
+# Попытка обратиться к несуществующему ключу выбросит ошибку
+try
+ filled_dict["four"] # => ERROR: key not found: four in getindex at dict.jl:489
+catch e
+ println(e)
+end
+
+# Используйте метод get со значением по умолчанию, чтобы избежать этой ошибки
+# get(dictionary,key,default_value)
+get(filled_dict,"one",4) # => 1
+get(filled_dict,"four",4) # => 4
+
+# Для коллекций неотсортированных уникальных элементов используйте Set
+empty_set = Set() # => Set{Any}()
+# Инициализация множества
+filled_set = Set(1,2,2,3,4) # => Set{Int64}(1,2,3,4)
+
+# Добавление элементов
+push!(filled_set,5) # => Set{Int64}(5,4,2,3,1)
+
+# Проверка вхождения элементов во множество
+in(2, filled_set) # => true
+in(10, filled_set) # => false
+
+# Функции для получения пересечения, объединения и разницы.
+other_set = Set(3, 4, 5, 6) # => Set{Int64}(6,4,5,3)
+intersect(filled_set, other_set) # => Set{Int64}(3,4,5)
+union(filled_set, other_set) # => Set{Int64}(1,2,3,4,5,6)
+setdiff(Set(1,2,3,4),Set(2,3,5)) # => Set{Int64}(1,4)
+
+
+####################################################
+## 3. Поток управления
+####################################################
+
+# Создадим переменную
+some_var = 5
+
+# Выражение if. Отступы не имеют значения.
+if some_var > 10
+ println("some_var is totally bigger than 10.")
+elseif some_var < 10 # Необязательная ветка elseif.
+ println("some_var is smaller than 10.")
+else # else-ветка также опциональна.
+ println("some_var is indeed 10.")
+end
+# => prints "some var is smaller than 10"
+
+
+# Цикл for проходит по итерируемым объектам
+# Примеры итерируемых типов: Range, Array, Set, Dict и String.
+for animal=["dog", "cat", "mouse"]
+ println("$animal is a mammal")
+ # Для вставки значения переменной или выражения в строку используется $
+end
+# Выведет:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+# Другой вариант записи.
+for animal in ["dog", "cat", "mouse"]
+ println("$animal is a mammal")
+end
+# Выведет:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+for a in ["dog"=>"mammal","cat"=>"mammal","mouse"=>"mammal"]
+ println("$(a[1]) is a $(a[2])")
+end
+# Выведет:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+for (k,v) in ["dog"=>"mammal","cat"=>"mammal","mouse"=>"mammal"]
+ println("$k is a $v")
+end
+# Выведет:
+# dog is a mammal
+# cat is a mammal
+# mouse is a mammal
+
+# Цикл while выполняется до тех пор, пока верно условие
+x = 0
+while x < 4
+ println(x)
+ x += 1 # Короткая запись x = x + 1
+end
+# Выведет:
+# 0
+# 1
+# 2
+# 3
+
+# Обработка исключений
+try
+ error("help")
+catch e
+ println("caught it $e")
+end
+# => caught it ErrorException("help")
+
+
+####################################################
+## 4. Функции
+####################################################
+
+# Для определения новой функции используется ключевое слово 'function'
+#function имя(аргументы)
+# тело...
+#end
+function add(x, y)
+ println("x is $x and y is $y")
+
+ # Функция возвращает значение последнего выражения
+ x + y
+end
+
+add(5, 6) # => Вернёт 11, напечатав "x is 5 and y is 6"
+
+# Функция может принимать переменное количество позиционных аргументов.
+function varargs(args...)
+ return args
+ # для возвращения из функции в любом месте используется 'return'
+end
+# => varargs (generic function with 1 method)
+
+varargs(1,2,3) # => (1,2,3)
+
+# Многоточие (...) — это splat.
+# Мы только что воспользовались им в определении функции.
+# Также его можно использовать при вызове функции,
+# где он преобразует содержимое массива или кортежа в список аргументов.
+Set([1,2,3]) # => Set{Array{Int64,1}}([1,2,3]) # формирует множество массивов
+Set([1,2,3]...) # => Set{Int64}(1,2,3) # эквивалентно Set(1,2,3)
+
+x = (1,2,3) # => (1,2,3)
+Set(x) # => Set{(Int64,Int64,Int64)}((1,2,3)) # множество кортежей
+Set(x...) # => Set{Int64}(2,3,1)
+
+
+# Опциональные позиционные аргументы
+function defaults(a,b,x=5,y=6)
+ return "$a $b and $x $y"
+end
+
+defaults('h','g') # => "h g and 5 6"
+defaults('h','g','j') # => "h g and j 6"
+defaults('h','g','j','k') # => "h g and j k"
+try
+ defaults('h') # => ERROR: no method defaults(Char,)
+ defaults() # => ERROR: no methods defaults()
+catch e
+ println(e)
+end
+
+# Именованные аргументы
+function keyword_args(;k1=4,name2="hello") # обратите внимание на ;
+ return ["k1"=>k1,"name2"=>name2]
+end
+
+keyword_args(name2="ness") # => ["name2"=>"ness","k1"=>4]
+keyword_args(k1="mine") # => ["k1"=>"mine","name2"=>"hello"]
+keyword_args() # => ["name2"=>"hello","k2"=>4]
+
+# В одной функции можно совмещать все виды аргументов
+function all_the_args(normal_arg, optional_positional_arg=2; keyword_arg="foo")
+ println("normal arg: $normal_arg")
+ println("optional arg: $optional_positional_arg")
+ println("keyword arg: $keyword_arg")
+end
+
+all_the_args(1, 3, keyword_arg=4)
+# Выведет:
+# normal arg: 1
+# optional arg: 3
+# keyword arg: 4
+
+# Функции в Julia первого класса
+function create_adder(x)
+ adder = function (y)
+ return x + y
+ end
+ return adder
+end
+
+# Анонимная функция
+(x -> x > 2)(3) # => true
+
+# Эта функция идентичная предыдущей версии create_adder
+function create_adder(x)
+ y -> x + y
+end
+
+# Если есть желание, можно воспользоваться полным вариантом
+function create_adder(x)
+ function adder(y)
+ x + y
+ end
+ adder
+end
+
+add_10 = create_adder(10)
+add_10(3) # => 13
+
+
+# Встроенные функции высшего порядка
+map(add_10, [1,2,3]) # => [11, 12, 13]
+filter(x -> x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# Списковые сборки
+[add_10(i) for i=[1, 2, 3]] # => [11, 12, 13]
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+
+####################################################
+## 5. Типы
+####################################################
+
+# Julia has a type system.
+# Каждое значение имеет тип, но переменные не определяют тип значения.
+# Функция `typeof` возвращает тип значения.
+typeof(5) # => Int64
+
+# Types are first-class values
+# Типы являются значениями первого класса
+typeof(Int64) # => DataType
+typeof(DataType) # => DataType
+# Тип DataType представляет типы, включая себя самого.
+
+# Типы используются в качестве документации, для оптимизации и организации.
+# Статически типы не проверяются.
+
+# Пользователь может определять свои типы
+# Типы похожи на структуры в других языках
+# Новые типы определяются с помощью ключевого слова `type`
+
+# type Name
+# field::OptionalType
+# ...
+# end
+type Tiger
+ taillength::Float64
+ coatcolor # отсутствие типа равносильно `::Any`
+end
+
+# Аргументы конструктора по умолчанию — свойства типа
+# в порядке их определения.
+tigger = Tiger(3.5,"orange") # => Tiger(3.5,"orange")
+
+# Тип объекта по сути является конструктором значений такого типа
+sherekhan = typeof(tigger)(5.6,"fire") # => Tiger(5.6,"fire")
+
+# Эти типы, похожие на структуры, называются конкретными.
+# Можно создавать объекты таких типов, но не их подтипы.
+# Другой вид типов — абстрактные типы.
+
+# abstract Name
+abstract Cat # просто имя и точка в иерархии типов
+
+# Объекты абстрактных типов создавать нельзя,
+# но зато от них можно наследовать подтипы.
+# Например, Number — это абстрактный тип.
+subtypes(Number) # => 6 элементов в массиве Array{Any,1}:
+ # Complex{Float16}
+ # Complex{Float32}
+ # Complex{Float64}
+ # Complex{T<:Real}
+ # ImaginaryUnit
+ # Real
+subtypes(Cat) # => пустой массив Array{Any,1}
+
+# У всех типов есть супертип. Для его определения есть функция `super`.
+typeof(5) # => Int64
+super(Int64) # => Signed
+super(Signed) # => Real
+super(Real) # => Number
+super(Number) # => Any
+super(super(Signed)) # => Number
+super(Any) # => Any
+# Все эти типы, за исключением Int64, абстрактные.
+
+# Для создания подтипа используется оператор <:
+type Lion <: Cat # Lion — это подтип Cat
+ mane_color
+ roar::String
+end
+
+# У типа может быть несколько конструкторов.
+# Для создания нового определите функцию с именем, как у типа,
+# и вызовите имеющийся конструктор.
+Lion(roar::String) = Lion("green",roar)
+# Мы создали внешний (т.к. он находится вне определения типа) конструктор.
+
+type Panther <: Cat # Panther — это тоже подтип Cat
+ eye_color
+
+ # Определим свой конструктор вместо конструктора по умолчанию
+ Panther() = new("green")
+end
+# Использование внутренних конструкторов позволяет
+# определять, как будут создаваться объекты типов.
+# Но по возможности стоит пользоваться внешними конструкторами.
+
+####################################################
+## 6. Мультиметоды
+####################################################
+
+# Все именованные функции являются generic-функциями,
+# т.е. все они состоят из разных методов.
+# Каждый конструктор типа Lion — это метод generic-функции Lion.
+
+# Приведём пример без использования конструкторов, создадим функцию meow
+
+# Определения Lion, Panther и Tiger
+function meow(animal::Lion)
+ animal.roar # доступ к свойству типа через точку
+end
+
+function meow(animal::Panther)
+ "grrr"
+end
+
+function meow(animal::Tiger)
+ "rawwwr"
+end
+
+# Проверка
+meow(tigger) # => "rawwr"
+meow(Lion("brown","ROAAR")) # => "ROAAR"
+meow(Panther()) # => "grrr"
+
+# Вспомним иерархию типов
+issubtype(Tiger,Cat) # => false
+issubtype(Lion,Cat) # => true
+issubtype(Panther,Cat) # => true
+
+# Определим функцию, принимающую на вход объекты типа Cat
+function pet_cat(cat::Cat)
+ println("The cat says $(meow(cat))")
+end
+
+pet_cat(Lion("42")) # => выведет "The cat says 42"
+try
+ pet_cat(tigger) # => ERROR: no method pet_cat(Tiger,)
+catch e
+ println(e)
+end
+
+# В объектно-ориентированных языках распространена одиночная диспетчеризация —
+# подходящий метод выбирается на основе типа первого аргумента.
+# В Julia все аргументы участвуют в выборе нужного метода.
+
+# Чтобы понять разницу, определим функцию с несколькими аргументами.
+function fight(t::Tiger,c::Cat)
+ println("The $(t.coatcolor) tiger wins!")
+end
+# => fight (generic function with 1 method)
+
+fight(tigger,Panther()) # => выведет The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => выведет The orange tiger wins!
+
+# Переопределим поведение функции, если Cat-объект является Lion-объектом
+fight(t::Tiger,l::Lion) = println("The $(l.mane_color)-maned lion wins!")
+# => fight (generic function with 2 methods)
+
+fight(tigger,Panther()) # => выведет The orange tiger wins!
+fight(tigger,Lion("ROAR")) # => выведет The green-maned lion wins!
+
+# Драться можно не только с тиграми!
+fight(l::Lion,c::Cat) = println("The victorious cat says $(meow(c))")
+# => fight (generic function with 3 methods)
+
+fight(Lion("balooga!"),Panther()) # => выведет The victorious cat says grrr
+try
+ fight(Panther(),Lion("RAWR")) # => ERROR: no method fight(Panther,Lion)
+catch
+end
+
+# Вообще, пускай кошачьи могут первыми проявлять агрессию
+fight(c::Cat,l::Lion) = println("The cat beats the Lion")
+# => Warning: New definition
+# fight(Cat,Lion) at none:1
+# is ambiguous with
+# fight(Lion,Cat) at none:2.
+# Make sure
+# fight(Lion,Lion)
+# is defined first.
+#fight (generic function with 4 methods)
+
+# Предупреждение говорит, что неясно, какой из методов вызывать:
+fight(Lion("RAR"),Lion("brown","rarrr")) # => выведет The victorious cat says rarrr
+# Результат может оказаться разным в разных версиях Julia
+
+fight(l::Lion,l2::Lion) = println("The lions come to a tie")
+fight(Lion("RAR"),Lion("brown","rarrr")) # => выведет The lions come to a tie
+
+
+# Под капотом
+# Язык позволяет посмотреть на сгенерированные ассемблерный и LLVM-код.
+
+square_area(l) = l * l # square_area (generic function with 1 method)
+
+square_area(5) #25
+
+# Что происходит, когда мы передаём функции square_area целое число?
+code_native(square_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1 # Вводная часть
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # movsxd RAX, EDI #
+ # imul RAX, RAX #
+ # pop RBP #
+ # ret #
+
+code_native(square_area, (Float32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulss XMM0, XMM0, XMM0 # Произведение чисел одинарной точности (AVX)
+ # pop RBP
+ # ret
+
+code_native(square_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vmulsd XMM0, XMM0, XMM0 # Произведение чисел двойной точности (AVX)
+ # pop RBP
+ # ret
+ #
+# Если хотя бы один из аргументов является числом с плавающей запятой,
+# то Julia будет использовать соответствующие инструкции.
+# Вычислим площать круга
+circle_area(r) = pi * r * r # circle_area (generic function with 1 method)
+circle_area(5) # 78.53981633974483
+
+code_native(circle_area, (Int32,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # Source line: 1
+ # vcvtsi2sd XMM0, XMM0, EDI # Загрузить целое число (r)
+ # movabs RAX, 4593140240 # Загрузить pi
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX] # pi * r
+ # vmulsd XMM0, XMM0, XMM1 # (pi * r) * r
+ # pop RBP
+ # ret
+ #
+
+code_native(circle_area, (Float64,))
+ # .section __TEXT,__text,regular,pure_instructions
+ # Filename: none
+ # Source line: 1
+ # push RBP
+ # mov RBP, RSP
+ # movabs RAX, 4593140496
+ # Source line: 1
+ # vmulsd XMM1, XMM0, QWORD PTR [RAX]
+ # vmulsd XMM0, XMM1, XMM0
+ # pop RBP
+ # ret
+ #
+```
+
+## Что дальше?
+
+Для более подробной информации читайте [документацию по языку](http://docs.julialang.org/en/latest/manual/)
+
+Если вам нужна помощь, задавайте вопросы в [списке рассылки](https://groups.google.com/forum/#!forum/julia-users).
diff --git a/ruby.html.markdown b/ruby.html.markdown
index a4c74a4f..962853a2 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -8,6 +8,8 @@ contributors:
- ["Tristan Hume", "http://thume.ca/"]
- ["Nick LaMuro", "https://github.com/NickLaMuro"]
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
+ - ["Ariel Krakowski", "http://www.learneroo.com"]
+
---
```ruby
@@ -33,6 +35,7 @@ You shouldn't either
8 - 1 #=> 7
10 * 2 #=> 20
35 / 5 #=> 7
+2 ** 5 #=> 32
# Arithmetic is just syntactic sugar
# for calling a method on an object
@@ -79,6 +82,10 @@ placeholder = "use string interpolation"
"I can #{placeholder} when using double quoted strings"
#=> "I can use string interpolation when using double quoted strings"
+# Combine strings, but not with numbers
+"hello " + "world" #=> "hello world"
+"hello " + 3 #=> TypeError: can't convert Fixnum into String
+"hello " + 3.to_s #=> "hello 3"
# print to the output
puts "I'm printing!"
@@ -247,6 +254,22 @@ else
puts "Alternative grading system, eh?"
end
+#=> "Better luck next time"
+
+# cases can also use ranges
+grade = 82
+case grade
+ when 90..100
+ puts "Hooray!"
+ when 80...90
+ puts "OK job"
+ else
+ puts "You failed!"
+end
+
+#=> "OK job"
+
+
# Functions
def double(x)
@@ -474,3 +497,12 @@ Something.qux # => NoMethodError: undefined method `qux'
Something.new.bar # => NoMethodError: undefined method `bar'
Something.new.qux # => 'qux'
```
+
+## Additional resources
+
+- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
+- [Official Documentation](http://www.ruby-doc.org/core-2.1.1/)
+- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
+- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
+
+
diff --git a/scala.html.markdown b/scala.html.markdown
index 5dfaefe0..2666746e 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -104,10 +104,13 @@ val sq = (x:Int) => x * x
sq(10) // Gives you this: res33: Int = 100.
+// The colon explicitly defines the type of a value, in this case a function
+// taking an Int and returning an Int.
+val add10: Int => Int = _ + 10
+
// Scala allows methods and functions to return, or take as parameters, other
// functions or methods.
-val add10: Int => Int = _ + 10 // A function taking an Int and returning an Int
List(1, 2, 3) map add10 // List(11, 12, 13) - add10 is applied to each element
// Anonymous functions can be used instead of named functions:
diff --git a/xml.html.markdown b/xml.html.markdown
new file mode 100644
index 00000000..94fc93f4
--- /dev/null
+++ b/xml.html.markdown
@@ -0,0 +1,126 @@
+---
+language: xml
+filename: learnxml.xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+---
+
+XML is a markup language designed to store and transport data.
+
+Unlike HTML, XML does not specifies how to display or to format data, just carry it.
+
+* XML Syntax
+
+```xml
+<!-- Comments in XML are like this -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<bookstore>
+ <book category="COOKING">
+ <title lang="en">Everyday Italian</title>
+ <author>Giada De Laurentiis</author>
+ <year>2005</year>
+ <price>30.00</price>
+ </book>
+ <book category="CHILDREN">
+ <title lang="en">Harry Potter</title>
+ <author>J K. Rowling</author>
+ <year>2005</year>
+ <price>29.99</price>
+ </book>
+ <book category="WEB">
+ <title lang="en">Learning XML</title>
+ <author>Erik T. Ray</author>
+ <year>2003</year>
+ <price>39.95</price>
+ </book>
+</bookstore>
+
+<!-- Above is a typical XML file.
+ It starts with a declaration, informing some metadata (optional).
+
+ XML uses a tree structure. Above, the root node is 'bookstore', which has
+ three child nodes, all 'books'. Those nodes has more child nodes, and so on...
+
+ Nodes are created using open/close tags, and childs are just nodes between
+ the open and close tags.-->
+
+
+<!-- XML carries two kind of data:
+ 1 - Attributes -> That's metadata about a node.
+ Usually, the XML parser uses this information to store the data properly.
+ It is characterized by appearing in parenthesis within the opening tag
+ 2 - Elements -> That's pure data.
+ That's what the parser will retrieve from the XML file.
+ Elements appear between the open and close tags, without parenthesis. -->
+
+
+<!-- Below, an element with two attributes -->
+<file type="gif" id="4293">computer.gif</file>
+
+
+```
+
+* Well-Formated Document x Validation
+
+A XML document is well-formated if it is syntactically correct.
+However, it is possible to inject more constraints in the document,
+using document definitions, such as DTD and XML Schema.
+
+A XML document which follows a document definition is called valid,
+regarding that document.
+
+With this tool, you can check the XML data outside the application logic.
+
+```xml
+
+<!-- Below, you can see an simplified version of bookstore document,
+ with the addition of DTD definition.-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "Bookstore.dtd">
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+
+<!-- This DTD could be something like:-->
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+
+<!-- The DTD starts with a declaration.
+ Following, the root node is declared, requiring 1 or more child nodes 'book'.
+ Each 'book' should contain exactly one 'title' and 'price' and an attribute
+ called 'category', with "Literature" as its default value.
+ The 'title' and 'price' nodes contain a parsed character data.-->
+
+<!-- The DTD could be declared inside the XML file itself.-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+``` \ No newline at end of file
diff --git a/yaml.html.markdown b/yaml.html.markdown
new file mode 100644
index 00000000..76e430e6
--- /dev/null
+++ b/yaml.html.markdown
@@ -0,0 +1,139 @@
+---
+language: yaml
+filename: learnyaml.yaml
+contributors:
+ - ["Adam Brenecki", "https://github.com/adambrenecki"]
+---
+
+YAML is a data serialisation language designed to be directly writable and
+readable by humans.
+
+It's a strict superset of JSON, with the addition of syntactically
+significant newlines and indentation, like Python. Unlike Python, however,
+YAML doesn't allow literal tab characters at all.
+
+```yaml
+# Comments in YAML look like this.
+
+################
+# SCALAR TYPES #
+################
+
+# Our root object (which continues for the entire document) will be a map,
+# which is equivalent to a dictionary, hash or object in other languages.
+key: value
+another_key: Another value goes here.
+a_number_value: 100
+scientific_notation: 1e+12
+boolean: true
+null_value: null
+key with spaces: value
+# Notice that strings don't need to be quoted. However, they can be.
+however: "A string, enclosed in quotes."
+"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
+
+# Multiple-line strings can be written either as a 'literal block' (using |),
+# or a 'folded block' (using '>').
+literal_block: |
+ This entire block of text will be the value of the 'literal_block' key,
+ with line breaks being preserved.
+
+ The literal continues until de-dented, and the leading indentation is
+ stripped.
+
+ Any lines that are 'more-indented' keep the rest of their indentation -
+ these lines will be indented by 4 spaces.
+folded_style: >
+ This entire block of text will be the value of 'folded_style', but this
+ time, all newlines will be replaced with a single space.
+
+ Blank lines, like above, are converted to a newline character.
+
+ 'More-indented' lines keep their newlines, too -
+ this text will appear over two lines.
+
+####################
+# COLLECTION TYPES #
+####################
+
+# Nesting is achieved by indentation.
+a_nested_map:
+ key: value
+ another_key: Another Value
+ another_nested_map:
+ hello: hello
+
+# Maps don't have to have string keys.
+0.25: a float key
+
+# Keys can also be multi-line objects, using ? to indicate the start of a key.
+? |
+ This is a key
+ that has multiple lines
+: and this is its value
+
+# YAML also allows collection types in keys, but many programming languages
+# will complain.
+
+# Sequences (equivalent to lists or arrays) look like this:
+a_sequence:
+ - Item 1
+ - Item 2
+ - 0.5 # sequences can contain disparate types
+ - Item 4
+ - key: value
+ another_key: another_value
+ -
+ - This is a sequence
+ - inside another sequence
+
+# Since YAML is a superset of JSON, you can also write JSON-style maps and
+# sequences:
+json_map: {"key": "value"}
+json_seq: [3, 2, 1, "takeoff"]
+
+#######################
+# EXTRA YAML FEATURES #
+#######################
+
+# YAML also has a handy feature called 'anchors', which let you easily duplicate
+# content across your document. Both of these keys will have the same value:
+anchored_content: &anchor_name This string will appear as the value of two keys.
+other_anchor: *anchor_name
+
+# YAML also has tags, which you can use to explicitly declare types.
+explicit_string: !!str 0.5
+# Some parsers implement language specific tags, like this one for Python's
+# complex number type.
+python_complex_number: !!python/complex 1+2j
+
+####################
+# EXTRA YAML TYPES #
+####################
+
+# Strings and numbers aren't the only scalars that YAML can understand.
+# ISO-formatted date and datetime literals are also parsed.
+datetime: 2001-12-15T02:59:43.1Z
+datetime_with_spaces: 2001-12-14 21:59:43.10 -5
+date: 2002-12-14
+
+# The !!binary tag indicates that a string is actually a base64-encoded
+# representation of a binary blob.
+gif_file: !!binary |
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
+
+# YAML also has a set type, which looks like this:
+set:
+ ? item1
+ ? item2
+ ? item3
+
+# Like Python, sets are just maps with null values; the above is equivalent to:
+set2:
+ item1: null
+ item2: null
+ item3: null
+```
diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown
index 2e885833..6afa659a 100644
--- a/zh-cn/bash-cn.html.markdown
+++ b/zh-cn/bash-cn.html.markdown
@@ -17,7 +17,7 @@ Bash 是一个为 GNU 计划编写的 Unix shell,是 Linux 和 Mac OS X 下的
[更多信息](http://www.gnu.org/software/bash/manual/bashref.html)
```bash
-#!/bin/sh
+#!/bin/bash
# 脚本的第一行叫 shebang,用来告知系统如何执行该脚本:
# 参见: http://en.wikipedia.org/wiki/Shebang_(Unix)
# 如你所见,注释以 # 开头,shebang 也是注释。
diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown
index b4bff8fc..223f6e35 100644
--- a/zh-cn/c-cn.html.markdown
+++ b/zh-cn/c-cn.html.markdown
@@ -5,37 +5,52 @@ contributors:
- ["Adam Bard", "http://adambard.com/"]
translators:
- ["Chenbo Li", "http://binarythink.net/"]
+ - ["Jakukyo Friel", "http://weakish.github.io"]
lang: zh-cn
---
C语言在今天仍然是高性能计算的主要选择。
-C大概是大多数程序员用到的最接近底层的语言了,但是C语言本身不仅可以用来提升程序运行的速度
-注意看看C语言的文档,你就会知道C语言在内存管理方面的强大也是其他语言无法比拟的。
+C大概是大多数程序员用到的最接近底层的语言了,C语言原生的速度就很高了,但是别忘了C的手动内存管理,它会让你将性能发挥到极致。
```c
-// 用“//”来实现单行注释
+// 单行注释以//开始。(仅适用于C99或更新的版本。)
/*
-多行注释是这个样子的
+多行注释是这个样子的。(C89也适用。)
*/
+// 常数: #define 关键词
+#define DAYS_IN_YEAR 365
+
+// 以枚举的方式定义常数
+enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
+// MON自动被定义为2,TUE被定义为3,以此类推。
+
// 用#include来导入头文件
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
-// 函数的标签(signature)应该放在.h文件中,并且引入到程序顶部
-// 也可以直接放到你的.c文件的最上面
-void function_1();
-void function_2();
+// <尖括号>间的文件名是C标准库的头文件。
+// 标准库以外的头文件,使用双引号代替尖括号。
+#include "my_header.h"
+
+// 函数的签名可以事先在.h文件中定义,
+// 也可以直接在.c文件的头部定义。
+void function_1(char c);
+void function_2(void);
-// c程序的入口是一个返回值为int型的函数,名字叫做main
+// 如果函数出现在main()之后,那么必须在main()之前
+// 先声明一个函数原型
+int add_two_ints(int x1, int x2); // 函数原型
+
+// 你的程序的入口是一个返回值为整型的main函数
int main() {
-// 用printf来实现标准输出,这种输出也可以用格式来控制
-// %d 代表一个整数, \n 代表一个新行
-printf("%d\n", 0); // => 输出 0
+// 用printf打印到标准输出,可以设定格式,
+// %d 代表整数, \n 代表换行
+printf("%d\n", 0); // => 打印 0
// 所有的语句都要以分号结束
///////////////////////////////////////
@@ -69,18 +84,29 @@ double x_double = 0.0;
// 整数类型也可以有无符号的类型表示。这样这些变量就无法表示负数
// 但是无符号整数所能表示的范围就可以比原来的整数大一些
-unsigned char ux_char;
unsigned short ux_short;
unsigned int ux_int;
unsigned long long ux_long_long;
+// 单引号内的字符是机器的字符集中的整数。
+'0' // => 在ASCII字符集中是48
+'A' // => 在ASCII字符集中是65
+
// char类型一定会占用1个字节,但是其他的类型却会因具体机器的不同而各异
// sizeof(T) 可以返回T类型在运行的机器上占用多少个字节
// 这样你的代码就可以在各处正确运行了
-// 比如
-printf("%lu\n", sizeof(int)); // => 4 (字长为4的机器上)
-
-// 数组必须要在开始被初始化为特定的长度
+// sizeof(obj)返回表达式(变量、字面量等)的尺寸
+printf("%zu\n", sizeof(int)); // => 4 (大多数的机器字长为4)
+
+// 如果`sizeof`的参数是一个表达式,那么这个参数不会被演算(VLA例外,见下)
+// 它产生的值是编译期的常数
+int a = 1;
+// size_t是一个无符号整型,表示对象的尺寸,至少2个字节
+size_t size = sizeof(a++); // a++ 不会被演算
+printf("sizeof(a++) = %zu where a = %d\n", size, a);
+// 打印 "sizeof(a++) = 4 where a = 1" (在32位架构上)
+
+// 数组必须要被初始化为具体的长度
char my_char_array[20]; // 这个数组占据 1 * 20 = 20 个字节
int my_int_array[20]; // 这个数组占据 4 * 20 = 80 个字节
// (这里我们假设字长为4)
@@ -89,48 +115,83 @@ int my_int_array[20]; // 这个数组占据 4 * 20 = 80 个字节
// 可以用下面的方法把数组初始化为0:
char my_array[20] = {0};
-// 对数组任意存取就像其他语言的方式 -- 其实是其他的语言像C
+// 索引数组和其他语言类似 -- 好吧,其实是其他的语言像C
my_array[0]; // => 0
// 数组是可变的,其实就是内存的映射!
my_array[1] = 2;
printf("%d\n", my_array[1]); // => 2
+// 在C99 (C11中是可选特性),变长数组(VLA)也可以声明长度。
+// 其长度不用是编译期常量。
+printf("Enter the array size: "); // 询问用户数组长度
+char buf[0x100];
+fgets(buf, sizeof buf, stdin);
+
+// stroul 将字符串解析为无符号整数
+size_t size = strtoul(buf, NULL, 10);
+int var_length_array[size]; // 声明VLA
+printf("sizeof array = %zu\n", sizeof var_length_array);
+
+// 上述程序可能的输出为:
+// > Enter the array size: 10
+// > sizeof array = 40
+
// 字符串就是以 NUL (0x00) 这个字符结尾的字符数组,
-// 这个字符可以用'\0'来表示.
-// (在字符串字面值中我们不必输入这个字符,编译器会自动添加的)
+// NUL可以用'\0'来表示.
+// (在字符串字面量中我们不必输入这个字符,编译器会自动添加的)
char a_string[20] = "This is a string";
printf("%s\n", a_string); // %s 可以对字符串进行格式化
-
/*
也许你会注意到 a_string 实际上只有16个字节长.
第17个字节是一个空字符(NUL)
-而第18, 19 和 20 个字符的值是不确定的。
+而第18, 19 和 20 个字符的值是未定义。
*/
printf("%d\n", a_string[16]); // => 0
+// byte #17值为0(18,19,20同样为0)
+
+// 单引号间的字符是字符字面量
+// 它的类型是`int`,而 *不是* `char`
+// (由于历史原因)
+int cha = 'a'; // 合法
+char chb = 'a'; // 同样合法 (隐式类型转换
+
+// 多维数组
+int multi_array[2][5] = {
+ {1, 2, 3, 4, 5},
+ {6, 7, 8, 9, 0}
+ }
+// 获取元素
+int array_int = multi_array[0][2]; // => 3
///////////////////////////////////////
// 操作符
///////////////////////////////////////
-int i1 = 1, i2 = 2; // 多个变量声明的简写
+// 多个变量声明的简写
+int i1 = 1, i2 = 2;
float f1 = 1.0, f2 = 2.0;
-// 算数运算
+int a, b, c;
+a = b = c = 0;
+
+// 算数运算直截了当
i1 + i2; // => 3
i2 - i1; // => 1
i2 * i1; // => 2
-i1 / i2; // => 0 (0.5 会被化整为 0)
+i1 / i2; // => 0 (0.5,但会被化整为 0)
f1 / f2; // => 0.5, 也许会有很小的误差
+// 浮点数和浮点数运算都是近似值
// 取余运算
11 % 3; // => 2
-// 比较操作符我们也很熟悉, 但是有一点,C中没有布尔类型
+// 你多半会觉得比较操作符很熟悉, 不过C中没有布尔类型
// 而是用整形替代
-// 0 就是 false, 其他的就是 true. (比较操作符的返回值则仅有0和1)
+// (C99中有_Bool或bool。)
+// 0为假, 其他均为真. (比较操作符的返回值总是返回0或1)
3 == 2; // => 0 (false)
3 != 2; // => 1 (true)
3 > 2; // => 1
@@ -138,7 +199,14 @@ f1 / f2; // => 0.5, 也许会有很小的误差
2 <= 2; // => 1
2 >= 2; // => 1
-// 逻辑运算符需要作用于整数
+// C不是Python —— 连续比较不合法
+int a = 1;
+// 错误
+int between_0_and_2 = 0 < a < 2;
+// 正确
+int between_0_and_2 = 0 < a && a < 2;
+
+// 逻辑运算符适用于整数
!3; // => 0 (非)
!0; // => 1
1 && 1; // => 1 (且)
@@ -146,6 +214,20 @@ f1 / f2; // => 0.5, 也许会有很小的误差
0 || 1; // => 1 (或)
0 || 0; // => 0
+// 条件表达式 ( ? : )
+int a = 5;
+int b = 10;
+int z;
+z = (a > b) ? a : b; // 10 “若a > b返回a,否则返回b。”
+
+// 增、减
+char *s = "iLoveC"
+int j = 0;
+s[j++]; // "i" 返回s的第j项,然后增加j的值。
+j = 0;
+s[++j]; // => "L" 增加j的值,然后返回s的第j项。
+// j-- 和 --j 同理
+
// 位运算
~0x0F; // => 0xF0 (取反)
0x0F & 0xF0; // => 0x00 (和)
@@ -154,6 +236,13 @@ f1 / f2; // => 0.5, 也许会有很小的误差
0x01 << 1; // => 0x02 (左移1位)
0x02 >> 1; // => 0x01 (右移1位)
+// 对有符号整数进行移位操作要小心 —— 以下未定义:
+// 有符号整数位移至符号位 int a = 1 << 32
+// 左移位一个负数 int a = -1 << 2
+// 移位超过或等于该类型数值的长度
+// int a = 1 << 32; // 假定int32位
+
+
///////////////////////////////////////
// 控制结构
///////////////////////////////////////
@@ -168,17 +257,17 @@ if (0) {
// While循环
int ii = 0;
-while (ii < 10) {
+while (ii < 10) { // 任何非0的值均为真
printf("%d, ", ii++); // ii++ 在取值过后自增
-} // => 输出 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+} // => 打印 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
printf("\n");
int kk = 0;
do {
printf("%d, ", kk);
-} while (++kk < 10); // ++kk 先自增,在被取值
-// => 输出 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+} while (++kk < 10); // ++kk 先自增,再被取值
+// => 打印 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
printf("\n");
@@ -186,29 +275,55 @@ printf("\n");
int jj;
for (jj=0; jj < 10; jj++) {
printf("%d, ", jj);
-} // => 输出 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
+} // => 打印 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
printf("\n");
+// *****注意*****:
+// 循环和函数必须有主体部分,如果不需要主体部分:
+int i;
+ for (i = 0; i <= 5; i++) {
+ ; // 使用分号表达主体(null语句)
+}
+
+// 多重分支:switch()
+switch (some_integral_expression) {
+case 0: // 标签必须是整数常量表达式
+ do_stuff();
+ break; // 如果不使用break,控制结构会继续执行下面的标签
+case 1:
+ do_something_else();
+ break;
+default:
+ // 假设 `some_integral_expression` 不匹配任何标签
+ fputs("error!\n", stderr);
+ exit(-1);
+ break;
+ }
+
///////////////////////////////////////
// 类型转换
///////////////////////////////////////
// 在C中每个变量都有类型,你可以将变量的类型进行转换
+// (有一定限制)
-int x_hex = 0x01; // 可以用16进制赋值
+int x_hex = 0x01; // 可以用16进制字面量赋值
// 在类型转换时,数字本身的值会被保留下来
-printf("%d\n", x_hex); // => 输出 1
-printf("%d\n", (short) x_hex); // => 输出 1
-printf("%d\n", (char) x_hex); // => 输出 1
+printf("%d\n", x_hex); // => 打印 1
+printf("%d\n", (short) x_hex); // => 打印 1
+printf("%d\n", (char) x_hex); // => 打印 1
// 类型转换时可能会造成溢出,而且不会抛出警告
-printf("%d\n", (char) 257); // => 1 (char的最大值为255)
+printf("%d\n", (char) 257); // => 1 (char的最大值为255,假定char为8位长)
+
+// 使用<limits.h>提供的CHAR_MAX、SCHAR_MAX和UCHAR_MAX宏可以确定`char`、`signed_char`和`unisigned char`的最大值。
+
// 整数型和浮点型可以互相转换
-printf("%f\n", (float)100); // %f 表示单精度浮点
-printf("%lf\n", (double)100); // %lf 表示双精度浮点
+printf("%f\n", (float)100); // %f 格式化单精度浮点
+printf("%lf\n", (double)100); // %lf 格式化双精度浮点
printf("%d\n", (char)100.0);
///////////////////////////////////////
@@ -216,67 +331,89 @@ printf("%d\n", (char)100.0);
///////////////////////////////////////
// 指针变量是用来储存内存地址的变量
-// 指针变量的定义也会告诉你指向的地址的变量的类型
-// 你也可以得到某个变量的地址,并对它们进行操作
+// 指针变量的声明也会告诉它所指向的数据的类型
+// 你可以使用得到你的变量的地址,并把它们搞乱,;-)
int x = 0;
printf("%p\n", &x); // 用 & 来获取变量的地址
-// (%p 表示一个指针)
-// => 输出某个内存地址
+// (%p 格式化一个类型为 void *的指针)
+// => 打印某个内存地址
-// 指针类型在定义是需要以*结束
-int* px; // px是一个指向int型的指针
+// 指针类型在声明中以*开头
+int* px, not_a_pointer; // px是一个指向int型的指针
px = &x; // 把x的地址保存到px中
-printf("%p\n", px); // => 输出内存中的某个地址
+printf("%p\n", (void *)px); // => 输出内存中的某个地址
+printf("%zu, %zu\n", sizeof(px), sizeof(not_a_pointer));
+// => 在64位系统上打印“8, 4”。
-// 要得到某个指针指向的内容的值,可以在指针前加一个*来取得(去引用)
+// 要得到某个指针指向的内容的值,可以在指针前加一个*来取得(取消引用)
+// 注意: 是的,这可能让人困惑,'*'在用来声明一个指针的同时取消引用它。
printf("%d\n", *px); // => 输出 0, 即x的值
// 你也可以改变指针所指向的值
-// 此时你需要在*运算符后添加一个括号,因为++比*的优先级更高
-(*px)++; // 把px所指向的值增加2
+// 此时你需要取消引用上添加括号,因为++比*的优先级更高
+(*px)++; // 把px所指向的值增加1
printf("%d\n", *px); // => 输出 1
printf("%d\n", x); // => 输出 1
-int x_array[20]; // 数组是分配一系列连续空间的常用方式
+// 数组是分配一系列连续空间的常用方式
+int x_array[20];
int xx;
for (xx=0; xx<20; xx++) {
x_array[xx] = 20 - xx;
} // 初始化 x_array 为 20, 19, 18,... 2, 1
-// 生命一个变量为指向整型的指针类型,并初始化为指向x_array
+// 声明一个整型的指针,并初始化为指向x_array
int* x_ptr = x_array;
// x_ptr现在指向了数组的第一个元素(即整数20).
-
-// 事实上数组本身就是指向它的第一个元素的指针
-printf("%d\n", *(x_ptr)); // => 输出 20
-printf("%d\n", x_array[0]); // => 输出 20
+// 这是因为数组通常衰减为指向它们的第一个元素的指针。
+// 例如,当一个数组被传递给一个函数或者绑定到一个指针时,
+//它衰减为(隐式转化为)一个指针。
+// 例外: 当数组是`&`操作符的参数:
+int arr[10];
+int (*ptr_to_arr)[10] = &arr; // &arr的类型不是`int *`!
+ // 它的类型是指向数组的指针(数组由10个int组成)
+// 或者当数组是字符串字面量(初始化字符数组)
+char arr[] = "foobarbazquirk";
+// 或者当它是`sizeof`或`alignof`操作符的参数时:
+int arr[10];
+int *ptr = arr; // 等价于 int *ptr = &arr[0];
+printf("%zu, %zu\n", sizeof arr, sizeof ptr); // 应该会输出"40, 4"或"40, 8"
// 指针的增减多少是依据它本身的类型而定的
-printf("%d\n", *(x_ptr + 1)); // => 输出 19
-printf("%d\n", x_array[1]); // => 输出 19
+// (这被称为指针算术)
+printf("%d\n", *(x_ptr + 1)); // => 打印 19
+printf("%d\n", x_array[1]); // => 打印 19
// 你也可以通过标准库函数malloc来实现动态分配
-// 这个函数接受一个代表容量的参数
-// 系统会从堆区分配指定容量字节大小的空间
-int* my_ptr = (int*) malloc(sizeof(int) * 20);
+// 这个函数接受一个代表容量的参数,参数类型为`size_t`
+// 系统一般会从堆区分配指定容量字节大小的空间
+// (在一些系统,例如嵌入式系统中这点不一定成立
+// C标准对此未置一词。)
+int *my_ptr = malloc(sizeof(*my_ptr) * 20);
for (xx=0; xx<20; xx++) {
- *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx 也可以
-} // 初始化内存为 20, 19, 18, 17... 2, 1 (as ints)
+ *(my_ptr + xx) = 20 - xx; // my_ptr[xx] = 20-xx
+} // 初始化内存为 20, 19, 18, 17... 2, 1 (类型为int)
-// 如果对一些未分配的内存取值则会得到未知的结果
+// 对未分配的内存进行取消引用会产生未定义的结果
printf("%d\n", *(my_ptr + 21)); // => 谁知道会输出什么
-// 当你通过malloc得到一块区域后,你需要释放它
+// malloc分配的区域需要手动释放
// 否则没人能够再次使用这块内存,直到程序结束为止
free(my_ptr);
// 字符串通常是字符数组,但是经常用字符指针表示
-// 指针:
-char* my_str = "This is my very own string";
-
+// (它是指向数组的第一个元素的指针)
+// 一个优良的实践是使用`const char *`来引用一个字符串字面量,
+// 因为字符串字面量不应当被修改(即"foo"[0] = 'a'犯了大忌)
+const char* my_str = "This is my very own string";
printf("%c\n", *my_str); // => 'T'
+// 如果字符串是数组,(多半是用字符串字面量初始化的)
+// 情况就不一样了,字符串位于可写的内存中
+char foo[] = "foo";
+foo[0] = 'a'; // 这是合法的,foo现在包含"aoo"
+
function_1();
} // main函数结束
@@ -292,16 +429,21 @@ int add_two_ints(int x1, int x2){
}
/*
-函数是按值传递的, 但是你可以通过传递参数来传递引用,这样函数就可以更改值
+函数是按值传递的。当调用一个函数的时候,传递给函数的参数
+是原有值的拷贝(数组除外)。你在函数内对参数所进行的操作
+不会改变该参数原有的值。
+
+但是你可以通过指针来传递引用,这样函数就可以更改值
例子:字符串本身翻转
*/
// 类型为void的函数没有返回值
-void str_reverse(char* str_in){
+void str_reverse(char *str_in){
char tmp;
- int ii=0, len = strlen(str_in); // Strlen 是C标准库函数
- for(ii=0; ii<len/2; ii++){
+ int ii = 0;
+ size_t len = strlen(str_in); // `strlen()`` 是C标准库函数
+ for(ii = 0; ii < len / 2; ii++){
tmp = str_in[ii];
str_in[ii] = str_in[len - ii - 1]; // 从倒数第ii个开始
str_in[len - ii - 1] = tmp;
@@ -314,6 +456,20 @@ str_reverse(c);
printf("%s\n", c); // => ".tset a si sihT"
*/
+// 如果引用函数之外的变量,必须使用extern关键字
+int i = 0;
+void testFunc() {
+ extern int i; // 使用外部变量 i
+}
+
+// 使用static确保external变量为源文件私有
+static int i = 0; // 其他使用 testFunc()的文件无法访问变量i
+void testFunc() {
+ extern int i;
+}
+//**你同样可以声明函数为static**
+
+
///////////////////////////////////////
// 用户自定义类型和结构
///////////////////////////////////////
@@ -322,12 +478,16 @@ printf("%s\n", c); // => ".tset a si sihT"
typedef int my_type;
my_type my_type_var = 0;
-// 结构是一系列数据的集合
+// struct是数据的集合,成员依序分配,按照
+// 编写的顺序
struct rectangle {
int width;
int height;
};
+// 一般而言,以下断言不成立:
+// sizeof(struct rectangle) == sizeof(int) + sizeof(int)
+//这是因为structure成员之间可能存在潜在的间隙(为了对齐)[1]
void function_1(){
@@ -338,12 +498,12 @@ void function_1(){
my_rec.height = 20;
// 你也可以声明指向结构体的指针
- struct rectangle* my_rec_ptr = &my_rec;
+ struct rectangle *my_rec_ptr = &my_rec;
- // 通过取值来改变结构体的成员...
+ // 通过取消引用来改变结构体的成员...
(*my_rec_ptr).width = 30;
- // ... 或者用 -> 操作符作为简写
+ // ... 或者用 -> 操作符作为简写提高可读性
my_rec_ptr->height = 10; // Same as (*my_rec_ptr).height = 10;
}
@@ -354,18 +514,25 @@ int area(rect r){
return r.width * r.height;
}
+// 如果struct较大,你可以通过指针传递,避免
+// 复制整个struct。
+int area(const rect *r)
+{
+ return r->width * r->height;
+}
+
///////////////////////////////////////
// 函数指针
///////////////////////////////////////
/*
在运行时,函数本身也被存放到某块内存区域当中
-函数指针就像其他指针一样, 但却可以被用来直接调用函数,
-并且可以被四处传递(就像回调函数那样)
-但是,定义的语法有可能在一开始会有些误解
+函数指针就像其他指针一样(不过是存储一个内存地址) 但却可以被用来直接调用函数,
+并且可以四处传递回调函数
+但是,定义的语法初看令人有些迷惑
例子:通过指针调用str_reverse
*/
-void str_reverse_through_pointer(char * str_in) {
+void str_reverse_through_pointer(char *str_in) {
// 定义一个函数指针 f.
void (*f)(char *); // 签名一定要与目标函数相同
f = &str_reverse; // 将函数的地址在运行时赋给指针
@@ -374,7 +541,7 @@ void str_reverse_through_pointer(char * str_in) {
}
/*
-只要函数签名是正确的,任何时候都能将正确的函数赋给某个函数指针
+只要函数签名是正确的,任何时候都能将任何函数赋给某个函数指针
为了可读性和简洁性,函数指针经常和typedef搭配使用:
*/
@@ -384,12 +551,73 @@ typedef void (*my_fnp_type)(char *);
// ...
// my_fnp_type f;
+// 特殊字符
+'\a' // bell
+'\n' // 换行
+'\t' // tab
+'\v' // vertical tab
+'\f' // formfeed
+'\r' // 回车
+'\b' // 退格
+'\0' // null,通常置于字符串的最后。
+ // hello\n\0. 按照惯例,\0用于标记字符串的末尾。
+'\\' // 反斜杠
+'\?' // 问号
+'\'' // 单引号
+'\"' // 双引号
+'\xhh' // 十六进制数字. 例子: '\xb' = vertical tab
+'\ooo' // 十进制数字. 例子: '\013' = vertical tab
+
+// 打印格式:
+"%d" // 整数
+"%3d" // 3位以上整数 (右对齐文本)
+"%s" // 字符串
+"%f" // float
+"%ld" // long
+"%3.2f" // 左3位以上、右2位以上十进制浮
+"%7.4s" // (字符串同样适用)
+"%c" // 字母
+"%p" // 指针
+"%x" // 十六进制
+"%o" // 十进制
+"%%" // 打印 %
+
+///////////////////////////////////////
+// 演算优先级
+///////////////////////////////////////
+//---------------------------------------------------//
+// 操作符 | 组合 //
+//---------------------------------------------------//
+// () [] -> . | 从左到右 //
+// ! ~ ++ -- + = *(type)sizeof | 从右到左 //
+// * / % | 从左到右 //
+// + - | 从左到右 //
+// << >> | 从左到右 //
+// < <= > >= | 从左到右 //
+// == != | 从左到右 //
+// & | 从左到右 //
+// ^ | 从左到右 //
+// | | 从左到右 //
+// && | 从左到右 //
+// || | 从左到右 //
+// ?: | 从右到左 //
+// = += -= *= /= %= &= ^= |= <<= >>= | 从右到左 //
+// , | 从左到右 //
+//---------------------------------------------------//
+
```
## 更多阅读
-最好找一本 [K&R, aka "The C Programming Language", “C程序设计语言”](https://en.wikipedia.org/wiki/The_C_Programming_Language)
+最好找一本 [K&R, aka "The C Programming Language", “C程序设计语言”](https://en.wikipedia.org/wiki/The_C_Programming_Language)。它是关于C最重要的一本书,由C的创作者撰写。不过需要留意的是它比较古老了,因此有些不准确的地方。
+
-其他一些比较好的资源 [Learn C the hard way](http://c.learncodethehardway.org/book/)
+另一个比较好的资源是 [Learn C the hard way](http://c.learncodethehardway.org/book/)
+如果你有问题,请阅读[compl.lang.c Frequently Asked Questions](http://c-faq.com/)。
+
+使用合适的空格、缩进,保持一致的代码风格非常重要。可读性强的代码比聪明的代码、高速的代码更重要。可以参考下[Linux内核编码风格](https://www.kernel.org/doc/Documentation/CodingStyle)
+。
除了这些,多多Google吧
+
+[1] http://stackoverflow.com/questions/119123/why-isnt-sizeof-for-a-struct-equal-to-the-sum-of-sizeof-of-each-member
diff --git a/zh-cn/clojure-cn.html.markdown b/zh-cn/clojure-cn.html.markdown
index d5d8232b..fa241384 100644
--- a/zh-cn/clojure-cn.html.markdown
+++ b/zh-cn/clojure-cn.html.markdown
@@ -2,6 +2,8 @@
language: clojure
filename: learnclojure-cn.clj
contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+translators:
- ["Bill Zhang", "http://jingege.github.io/"]
lang: zh-cn
---
diff --git a/zh-cn/clojure-macro-cn.html.markdown b/zh-cn/clojure-macro-cn.html.markdown
new file mode 100644
index 00000000..9324841e
--- /dev/null
+++ b/zh-cn/clojure-macro-cn.html.markdown
@@ -0,0 +1,152 @@
+---
+language: "clojure macros"
+filename: learnclojuremacros-zh.clj
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+translators:
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+lang: zh-cn
+---
+
+和所有Lisp一样,Clojure内在的[同构性](https://en.wikipedia.org/wiki/Homoiconic)使得你可以穷尽语言的特性,编写生成代码的子过程——“宏”。宏是一种按需调制语言的强大方式。
+
+小心!可以用函数完成的事用宏去实现可不是什么好事。你应该仅在需要控制参数是否或者何时eval的时候使用宏。
+
+你应该熟悉Clojure.确保你了解[Y分钟学Clojure](http://learnxinyminutes.com/docs/zh-cn/clojure-cn/)中的所有内容。
+
+```clojure
+;; 使用defmacro定义宏。宏应该输出一个可以作为clojure代码演算的列表。
+;;
+;; 以下宏的效果和直接写(reverse "Hello World")一致。
+
+(defmacro my-first-macro []
+ (list reverse "Hello World"))
+
+;; 使用macroexpand或macroexpand-1查看宏的结果。
+;;
+;; 注意,调用需要引用。
+(macroexpand '(my-first-macro))
+;; -> (#<core$reverse clojure.core$reverse@xxxxxxxx> "Hello World")
+
+;; 你可以直接eval macroexpand的结果
+(eval (macroexpand '(my-first-macro)))
+; -> (\d \l \o \r \W \space \o \l \l \e \H)
+
+;; 不过一般使用以下形式,更简短,更像函数:
+(my-first-macro) ; -> (\d \l \o \r \W \space \o \l \l \e \H)
+
+;; 创建宏的时候可以使用更简短的引用形式来创建列表
+(defmacro my-first-quoted-macro []
+ '(reverse "Hello World"))
+
+(macroexpand '(my-first-quoted-macro))
+;; -> (reverse "Hello World")
+;; 注意reverse不再是一个函数对象,而是一个符号。
+
+;; 宏可以传入参数。
+(defmacro inc2 [arg]
+ (list + 2 arg))
+
+(inc2 2) ; -> 4
+
+;; 不过,如果你尝试配合使用引用列表,会导致错误,
+;; 因为参数也会被引用。
+;; 为了避免这个问题,clojure提供了引用宏的另一种方式:`
+;; 在`之内,你可以使用~获得外圈作用域的变量。
+(defmacro inc2-quoted [arg]
+ `(+ 2 ~arg))
+
+(inc2-quoted 2)
+
+;; 你可以使用通常的析构参数。用~@展开列表中的变量。
+(defmacro unless [arg & body]
+ `(if (not ~arg)
+ (do ~@body))) ; 别忘了 do!
+
+(macroexpand '(unless true (reverse "Hello World")))
+
+;; ->
+;; (if (clojure.core/not true) (do (reverse "Hello World")))
+
+;; 当第一个参数为假时,(unless)会演算、返回主体。
+;; 否则返回nil。
+
+(unless true "Hello") ; -> nil
+(unless false "Hello") ; -> "Hello"
+
+;; 需要小心,宏会搞乱你的变量
+(defmacro define-x []
+ '(do
+ (def x 2)
+ (list x)))
+
+(def x 4)
+(define-x) ; -> (2)
+(list x) ; -> (2)
+
+;; 使用gensym来获得独有的标识符
+(gensym 'x) ; -> x1281 (or some such thing)
+
+(defmacro define-x-safely []
+ (let [sym (gensym 'x)]
+ `(do
+ (def ~sym 2)
+ (list ~sym))))
+
+(def x 4)
+(define-x-safely) ; -> (2)
+(list x) ; -> (4)
+
+;; 你可以在 ` 中使用 # 为每个符号自动生成gensym
+(defmacro define-x-hygenically []
+ `(do
+ (def x# 2)
+ (list x#)))
+
+(def x 4)
+(define-x-hygenically) ; -> (2)
+(list x) ; -> (4)
+
+;; 通常会配合宏使用帮助函数。
+;; 让我们创建一些帮助函数来支持(无聊的)算术语法:
+
+(declare inline-2-helper)
+(defn clean-arg [arg]
+ (if (seq? arg)
+ (inline-2-helper arg)
+ arg))
+
+(defn apply-arg
+ "Given args [x (+ y)], return (+ x y)"
+ [val [op arg]]
+ (list op val (clean-arg arg)))
+
+(defn inline-2-helper
+ [[arg1 & ops-and-args]]
+ (let [ops (partition 2 ops-and-args)]
+ (reduce apply-arg (clean-arg arg1) ops)))
+
+;; 在创建宏前,我们可以先测试
+(inline-2-helper '(a + (b - 2) - (c * 5))) ; -> (- (+ a (- b 2)) (* c 5))
+
+; 然而,如果我们希望它在编译期执行,就需要创建宏
+(defmacro inline-2 [form]
+ (inline-2-helper form)))
+
+(macroexpand '(inline-2 (1 + (3 / 2) - (1 / 2) + 1)))
+; -> (+ (- (+ 1 (/ 3 2)) (/ 1 2)) 1)
+
+(inline-2 (1 + (3 / 2) - (1 / 2) + 1))
+; -> 3 (事实上,结果是3N, 因为数字被转化为带/的有理分数)
+```
+
+## 扩展阅读
+
+[Clojure for the Brave and True](http://www.braveclojure.com/)系列的编写宏
+http://www.braveclojure.com/writing-macros/
+
+官方文档
+http://clojure.org/macros
+
+何时使用宏?
+http://dunsmor.com/lisp/onlisp/onlisp_12.html
diff --git a/zh-cn/coffeescript-cn.html.markdown b/zh-cn/coffeescript-cn.html.markdown
new file mode 100644
index 00000000..44561541
--- /dev/null
+++ b/zh-cn/coffeescript-cn.html.markdown
@@ -0,0 +1,101 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+filename: coffeescript-cn.coffee
+lang: zh-cn
+---
+
+CoffeeScript是逐句编译为JavaScript的一种小型语言,且没有运行时的解释器。
+作为JavaScript的替代品之一,CoffeeScript旨在编译人类可读、美观优雅且速度不输原生的代码,
+且编译后的代码可以在任何JavaScript运行时正确运行。
+
+参阅 [CoffeeScript官方网站](http://coffeescript.org/)以获取CoffeeScript的完整教程。
+
+``` coffeescript
+# CoffeeScript是一种很潮的编程语言,
+# 它紧随众多现代编程语言的趋势。
+# 因此正如Ruby和Python,CoffeeScript使用井号标记注释。
+
+###
+大段落注释以此为例,可以被直接编译为 '/ *' 和 '* /' 包裹的JavaScript代码。
+
+在继续之前你需要了解JavaScript的基本概念。
+
+示例中 => 后为编译后的JavaScript代码
+###
+
+# 赋值:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# 条件:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# 函数:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+fill = (container, liquid = "coffee") ->
+ "Filling the #{container} with #{liquid}..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "coffee";
+# }
+# return "Filling the " + container + " with " + liquid + "...";
+#};
+
+# 区间:
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# 对象:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Splats:
+race = (winner, runners...) ->
+ print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
+
+# 存在判断:
+alert "I knew it!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
+
+# 数组推导:
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['broccoli', 'spinach', 'chocolate']
+eat food for food in foods when food isnt 'chocolate'
+#=>foods = ['broccoli', 'spinach', 'chocolate'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'chocolate') {
+# eat(food);
+# }
+#}
+```
diff --git a/zh-cn/common-lisp-cn.html.markdown b/zh-cn/common-lisp-cn.html.markdown
index f005dd58..c4dc3274 100644
--- a/zh-cn/common-lisp-cn.html.markdown
+++ b/zh-cn/common-lisp-cn.html.markdown
@@ -56,11 +56,11 @@ t ;还是一个原子,代表逻辑真值。
;; 有很多不同的Common Lisp的实现;并且大部分的实现是一致(可移植)的。
;; 对于入门学习来说,CLISP是个不错的选择。
-;; 可以通过QuickLisp.org's Quicklisp系统可以管理你的库。
+;; 可以通过QuickLisp.org的Quicklisp系统管理你的库。
-;; 通常,使用一个文本编辑器和一个的“REPL”来开发Common Lisp;
+;; 通常,使用文本编辑器和“REPL”来开发Common Lisp;
;; (译者注:“REPL”指读取-求值-打印循环)。
-;; “REPL”允许对程序进行交互式的运行、调试,就好像在系统中这是一场“现场直播”。
+;; “REPL”允许对程序进行交互式的运行、调试,就好像在系统“现场”操作。
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -329,7 +329,7 @@ nil ; 逻辑假,或者空列表
;; 或者使用`apply`
(apply (lambda () "Hello World") nil) ; => "Hello World"
-;; 显示地定义一个函数(译者注:即非匿名的)
+;; 显式地定义一个函数(译者注:即非匿名的)
(defun hello-world ()
"Hello World")
(hello-world) ; => "Hello World"
@@ -537,7 +537,7 @@ nil ; 逻辑假,或者空列表
;; 注意到这些有用的返回信息——Common Lisp一直是一个交互式的系统。
;; 若要定义一个方法;
-;; 先让我们注意到我们计算自行车轮子周长时使用了这样一个公式:C = d * pi
+;; 注意,我们计算自行车轮子周长时使用了这样一个公式:C = d * pi
(defmethod circumference ((object bicycle))
(* pi (wheel-size object)))
@@ -593,7 +593,7 @@ nil ; 逻辑假,或者空列表
;; 然而,在一个比较现代化的编译环境下,这样的WHILE是没有必要的;
;; LOOP形式的循环和这个WHILE同样的好,并且更易于阅读。
-;; 注意到反引号'`',逗号','以及'@'符号,这三个符号;
+;; 注意反引号'`',逗号','以及'@'这三个符号;
;; 反引号'`'是一种所谓“quasiquote”的引用类型的运算符,有了它,之后的逗号“,”才有意义。
;; 逗号“,”意味着解除引用(unquote,即开始求值);
;; “@”符号则表示将当前的参数插入到当前整个列表中。
diff --git a/zh-cn/csharp-cn.html.markdown b/zh-cn/csharp-cn.html.markdown
new file mode 100644
index 00000000..a3cda5b3
--- /dev/null
+++ b/zh-cn/csharp-cn.html.markdown
@@ -0,0 +1,798 @@
+---
+language: c#
+contributors:
+ - ["Irfan Charania", "https://github.com/irfancharania"]
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Melvyn Laïly", "http://x2a.yt"]
+ - ["Shaun McCarthy", "http://www.shaunmccarthy.com"]
+translators:
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+filename: LearnCSharp-cn.cs
+lang: zh-cn
+---
+
+
+C#是一个优雅的、类型安全的面向对象语言。使用C#,开发者可以在.NET框架下构建安全、健壮的应用程序。
+
+[更多关于C#的介绍](http://msdn.microsoft.com/en-us/library/vstudio/z1zx9t92.aspx)
+
+```c#
+// 单行注释以 // 开始
+/*
+多行注释是这样的
+*/
+/// <summary>
+/// XML文档注释
+/// </summary>
+
+// 声明应用用到的命名空间
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Dynamic;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Net;
+using System.Threading.Tasks;
+using System.IO;
+
+// 定义作用域,将代码组织成包
+namespace Learning
+{
+ // 每个 .cs 文件至少需要包含一个和文件名相同的类
+ // 你可以不这么干,但是这样不好。
+ public class LearnCSharp
+ {
+ // 基本语法 - 如果你以前用过 Java 或 C++ 的话,可以直接跳到后文「有趣的特性」
+ public static void Syntax()
+ {
+ // 使用 Console.WriteLine 打印信息
+ Console.WriteLine("Hello World");
+ Console.WriteLine(
+ "Integer: " + 10 +
+ " Double: " + 3.14 +
+ " Boolean: " + true);
+
+ // 使用 Console.Write 打印,不带换行符号
+ Console.Write("Hello ");
+ Console.Write("World");
+
+ ///////////////////////////////////////////////////
+ // 类型和变量
+ //
+ // 使用 <type> <name> 定义变量
+ ///////////////////////////////////////////////////
+
+ // Sbyte - 有符号 8-bit 整数
+ // (-128 <= sbyte <= 127)
+ sbyte fooSbyte = 100;
+
+ // Byte - 无符号 8-bit 整数
+ // (0 <= byte <= 255)
+ byte fooByte = 100;
+
+ // Short - 16-bit 整数
+ // 有符号 - (-32,768 <= short <= 32,767)
+ // 无符号 - (0 <= ushort <= 65,535)
+ short fooShort = 10000;
+ ushort fooUshort = 10000;
+
+ // Integer - 32-bit 整数
+ int fooInt = 1; // (-2,147,483,648 <= int <= 2,147,483,647)
+ uint fooUint = 1; // (0 <= uint <= 4,294,967,295)
+
+ // Long - 64-bit 整数
+ long fooLong = 100000L; // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
+ ulong fooUlong = 100000L; // (0 <= ulong <= 18,446,744,073,709,551,615)
+ // 数字默认为 int 或 uint (取决于尺寸)
+ // 使用 L 标明变量值类型为long 或 ulong
+
+ // Double - 双精度 64-bit IEEE 754 浮点数
+ double fooDouble = 123.4; // 精度: 15-16 位
+
+ // Float - 单精度 32-bit IEEE 754 浮点数
+ float fooFloat = 234.5f; // 精度: 7 位
+ // 使用 f 标明变量值类型为float
+
+ // Decimal - 128-bits 数据类型,比其他浮点类型精度更高
+ // 适合财务、金融
+ decimal fooDecimal = 150.3m;
+
+ // 布尔值 - true & false
+ bool fooBoolean = true; // 或 false
+
+ // Char - 单个 16-bit Unicode 字符
+ char fooChar = 'A';
+
+ // 字符串 -- 和前面的基本类型不同,字符串不是值,而是引用。
+ // 这意味着你可以将字符串设为null。
+ string fooString = "\"escape\" quotes and add \n (new lines) and \t (tabs)";
+ Console.WriteLine(fooString);
+
+ // 你可以通过索引访问字符串的每个字符:
+ char charFromString = fooString[1]; // => 'e'
+ // 字符串不可修改: fooString[1] = 'X' 是行不通的;
+
+ // 根据当前的locale设定比较字符串,大小写不敏感
+ string.Compare(fooString, "x", StringComparison.CurrentCultureIgnoreCase);
+
+ // 基于sprintf的字符串格式化
+ string fooFs = string.Format("Check Check, {0} {1}, {0} {1:0.0}", 1, 2);
+
+ // 日期和格式
+ DateTime fooDate = DateTime.Now;
+ Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
+
+ // 使用 @ 符号可以创建跨行的字符串。使用 "" 来表示 "
+ string bazString = @"Here's some stuff
+on a new line! ""Wow!"", the masses cried";
+
+ // 使用const或read-only定义常量
+ // 常量在编译期演算
+ const int HOURS_I_WORK_PER_WEEK = 9001;
+
+ ///////////////////////////////////////////////////
+ // 数据结构
+ ///////////////////////////////////////////////////
+
+ // 数组 - 从0开始计数
+ // 声明数组时需要确定数组长度
+ // 声明数组的格式如下:
+ // <datatype>[] <var name> = new <datatype>[<array size>];
+ int[] intArray = new int[10];
+
+ // 声明并初始化数组的其他方式:
+ int[] y = { 9000, 1000, 1337 };
+
+ // 访问数组的元素
+ Console.WriteLine("intArray @ 0: " + intArray[0]);
+ // 数组可以修改
+ intArray[1] = 1;
+
+ // 列表
+ // 列表比数组更常用,因为列表更灵活。
+ // 声明列表的格式如下:
+ // List<datatype> <var name> = new List<datatype>();
+ List<int> intList = new List<int>();
+ List<string> stringList = new List<string>();
+ List<int> z = new List<int> { 9000, 1000, 1337 }; // i
+ // <>用于泛型 - 参考下文
+
+ // 列表无默认值
+ // 访问列表元素时必须首先添加元素
+ intList.Add(1);
+ Console.WriteLine("intList @ 0: " + intList[0]);
+
+ // 其他数据结构:
+ // 堆栈/队列
+ // 字典 (哈希表的实现)
+ // 哈希集合
+ // 只读集合
+ // 元组 (.Net 4+)
+
+ ///////////////////////////////////////
+ // 操作符
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Operators");
+
+ int i1 = 1, i2 = 2; // 多重声明的简写形式
+
+ // 算术直截了当
+ Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
+
+ // 取余
+ Console.WriteLine("11%3 = " + (11 % 3)); // => 2
+
+ // 比较操作符
+ 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
+
+ // 位操作符
+ /*
+ ~ 取反
+ << 左移(有符号)
+ >> 右移(有符号)
+ & 与
+ ^ 异或
+ | 或
+ */
+
+ // 自增、自减
+ int i = 0;
+ Console.WriteLine("\n->Inc/Dec-rementation");
+ Console.WriteLine(i++); //i = 1. 事后自增
+ Console.WriteLine(++i); //i = 2. 事先自增
+ Console.WriteLine(i--); //i = 1. 事后自减
+ Console.WriteLine(--i); //i = 0. 事先自减
+
+ ///////////////////////////////////////
+ // 控制结构
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Control Structures");
+
+ // 类似C的if语句
+ 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");
+ }
+
+ // 三元表达式
+ // 简单的 if/else 语句可以写成:
+ // <条件> ? <真> : <假>
+ string isTrue = (true) ? "True" : "False";
+
+ // While 循环
+ int fooWhile = 0;
+ while (fooWhile < 100)
+ {
+ //迭代 100 次, fooWhile 0->99
+ fooWhile++;
+ }
+
+ // Do While 循环
+ int fooDoWhile = 0;
+ do
+ {
+ //迭代 100 次, fooDoWhile 0->99
+ fooDoWhile++;
+ } while (fooDoWhile < 100);
+
+ //for 循环结构 => for(<初始条件>; <条件>; <步>)
+ for (int fooFor = 0; fooFor < 10; fooFor++)
+ {
+ //迭代10次, fooFor 0->9
+ }
+
+ // foreach循环
+ // foreach 循环结构 => foreach(<迭代器类型> <迭代器> in <可枚举结构>)
+ // foreach 循环适用于任何实现了 IEnumerable 或 IEnumerable<T> 的对象。
+ // .Net 框架下的集合类型(数组, 列表, 字典...)
+ // 都实现了这些接口
+ // (下面的代码中,ToCharArray()可以删除,因为字符串同样实现了IEnumerable)
+ foreach (char character in "Hello World".ToCharArray())
+ {
+ //迭代字符串中的所有字符
+ }
+
+ // Switch 语句
+ // switch 适用于 byte、short、char和int 数据类型。
+ // 同样适用于可枚举的类型
+ // 包括字符串类, 以及一些封装了原始值的类:
+ // Character、Byte、Short和Integer。
+ int month = 3;
+ string monthString;
+ switch (month)
+ {
+ case 1:
+ monthString = "January";
+ break;
+ case 2:
+ monthString = "February";
+ break;
+ case 3:
+ monthString = "March";
+ break;
+ // 你可以一次匹配多个case语句
+ // 但是你在添加case语句后需要使用break
+ // (否则你需要显式地使用goto case x语句)
+ case 6:
+ case 7:
+ case 8:
+ monthString = "Summer time!!";
+ break;
+ default:
+ monthString = "Some other month";
+ break;
+ }
+
+ ///////////////////////////////////////
+ // 转换、指定数据类型
+ ///////////////////////////////////////
+
+ // 转换类型
+
+ // 转换字符串为整数
+ // 转换失败会抛出异常
+ int.Parse("123");//返回整数类型的"123"
+
+ // TryParse会尝试转换类型,失败时会返回缺省类型
+ // 例如 0
+ int tryInt;
+ if (int.TryParse("123", out tryInt)) // Funciton is boolean
+ Console.WriteLine(tryInt); // 123
+
+ // 转换整数为字符串
+ // Convert类提供了一系列便利转换的方法
+ Convert.ToString(123);
+ // or
+ tryInt.ToString();
+ }
+
+ ///////////////////////////////////////
+ // 类
+ ///////////////////////////////////////
+ public static void Classes()
+ {
+ // 参看文件尾部的对象声明
+
+ // 使用new初始化对象
+ Bicycle trek = new Bicycle();
+
+ // 调用对象的方法
+ trek.SpeedUp(3); // 你应该一直使用setter和getter方法
+ trek.Cadence = 100;
+
+ // 查看对象的信息.
+ Console.WriteLine("trek info: " + trek.Info());
+
+ // 实例化一个新的Penny Farthing
+ PennyFarthing funbike = new PennyFarthing(1, 10);
+ Console.WriteLine("funbike info: " + funbike.Info());
+
+ Console.Read();
+ } // 结束main方法
+
+ // 终端程序 终端程序必须有一个main方法作为入口
+ public static void Main(string[] args)
+ {
+ OtherInterestingFeatures();
+ }
+
+ //
+ // 有趣的特性
+ //
+
+ // 默认方法签名
+
+ public // 可见性
+ static // 允许直接调用类,无需先创建实例
+ int, //返回值
+ MethodSignatures(
+ int maxCount, // 第一个变量,类型为整型
+ int count = 0, // 如果没有传入值,则缺省值为0
+ int another = 3,
+ params string[] otherParams // 捕获其他参数
+ )
+ {
+ return -1;
+ }
+
+ // 方法可以重名,只要签名不一样
+ public static void MethodSignature(string maxCount)
+ {
+ }
+
+ //泛型
+ // TKey和TValue类由用用户调用函数时指定。
+ // 以下函数模拟了Python的SetDefault
+ public static TValue SetDefault<TKey, TValue>(
+ IDictionary<TKey, TValue> dictionary,
+ TKey key,
+ TValue defaultItem)
+ {
+ TValue result;
+ if (!dictionary.TryGetValue(key, out result))
+ return dictionary[key] = defaultItem;
+ return result;
+ }
+
+ // 你可以限定传入值的范围
+ public static void IterateAndPrint<T>(T toPrint) where T: IEnumerable<int>
+ {
+ // 我们可以进行迭代,因为T是可枚举的
+ foreach (var item in toPrint)
+ // ittm为整数
+ Console.WriteLine(item.ToString());
+ }
+
+ public static void OtherInterestingFeatures()
+ {
+ // 可选参数
+ MethodSignatures(3, 1, 3, "Some", "Extra", "Strings");
+ MethodSignatures(3, another: 3); // 显式指定参数,忽略可选参数
+
+ // 扩展方法
+ int i = 3;
+ i.Print(); // 参见下面的定义
+
+ // 可为null的类型 对数据库交互、返回值很有用
+ // 任何值类型 (i.e. 不为类) 添加后缀 ? 后会变为可为null的值
+ // <类型>? <变量名> = <值>
+ int? nullable = null; // Nullable<int> 的简写形式
+ Console.WriteLine("Nullable variable: " + nullable);
+ bool hasValue = nullable.HasValue; // 不为null时返回真
+ // ?? 是用于指定默认值的语法糖
+ // 以防变量为null的情况
+ int notNullable = nullable ?? 0; // 0
+
+ // 变量类型推断 - 你可以让编译器推断变量类型:
+ var magic = "编译器确定magic是一个字符串,所以仍然是类型安全的";
+ // magic = 9; // 不工作,因为magic是字符串,而不是整数。
+
+ // 泛型
+ //
+ var phonebook = new Dictionary<string, string>() {
+ {"Sarah", "212 555 5555"} // 在电话簿中加入新条目
+ };
+
+ // 调用上面定义为泛型的SETDEFAULT
+ Console.WriteLine(SetDefault<string,string>(phonebook, "Shaun", "No Phone")); // 没有电话
+ // 你不用指定TKey、TValue,因为它们会被隐式地推导出来
+ Console.WriteLine(SetDefault(phonebook, "Sarah", "No Phone")); // 212 555 5555
+
+ // lambda表达式 - 允许你用一行代码搞定函数
+ Func<int, int> square = (x) => x * x; // 最后一项为返回值
+ Console.WriteLine(square(3)); // 9
+
+ // 可抛弃的资源管理 - 让你很容易地处理未管理的资源
+ // 大多数访问未管理资源 (文件操作符、设备上下文, etc.)的对象
+ // 都实现了IDisposable接口。
+ // using语句会为你清理IDisposable对象。
+ using (StreamWriter writer = new StreamWriter("log.txt"))
+ {
+ writer.WriteLine("这里没有什么可疑的东西");
+ // 在作用域的结尾,资源会被回收
+ // (即使有异常抛出,也一样会回收)
+ }
+
+ // 并行框架
+ // http://blogs.msdn.com/b/csharpfaq/archive/2010/06/01/parallel-programming-in-net-framework-4-getting-started.aspx
+ var websites = new string[] {
+ "http://www.google.com", "http://www.reddit.com",
+ "http://www.shaunmccarthy.com"
+ };
+ var responses = new Dictionary<string, string>();
+
+ // 为每个请求新开一个线程
+ // 在运行下一步前合并结果
+ Parallel.ForEach(websites,
+ new ParallelOptions() {MaxDegreeOfParallelism = 3}, // max of 3 threads
+ website =>
+ {
+ // Do something that takes a long time on the file
+ using (var r = WebRequest.Create(new Uri(website)).GetResponse())
+ {
+ responses[website] = r.ContentType;
+ }
+ });
+
+ // 直到所有的请求完成后才会运行下面的代码
+ foreach (var key in responses.Keys)
+ Console.WriteLine("{0}:{1}", key, responses[key]);
+
+ // 动态对象(配合其他语言使用很方便)
+ dynamic student = new ExpandoObject();
+ student.FirstName = "First Name"; // 不需要先定义类!
+
+ // 你甚至可以添加方法(接受一个字符串,输出一个字符串)
+ student.Introduce = new Func<string, string>(
+ (introduceTo) => string.Format("Hey {0}, this is {1}", student.FirstName, introduceTo));
+ Console.WriteLine(student.Introduce("Beth"));
+
+ // IQUERYABLE<T> - 几乎所有的集合都实现了它,
+ // 带给你 Map / Filter / Reduce 风格的方法
+ var bikes = new List<Bicycle>();
+ bikes.Sort(); // Sorts the array
+ bikes.Sort((b1, b2) => b1.Wheels.CompareTo(b2.Wheels)); // 根据车轮数排序
+ var result = bikes
+ .Where(b => b.Wheels > 3) // 筛选 - 可以连锁使用 (返回IQueryable)
+ .Where(b => b.IsBroken && b.HasTassles)
+ .Select(b => b.ToString()); // Map - 这里我们使用了select,所以结果是IQueryable<string>
+
+ var sum = bikes.Sum(b => b.Wheels); // Reduce - 计算集合中的轮子总数
+
+ // 创建一个包含基于自行车的一些参数生成的隐式对象的列表
+ var bikeSummaries = bikes.Select(b=>new { Name = b.Name, IsAwesome = !b.IsBroken && b.HasTassles });
+ // 很难演示,但是编译器在代码编译完成前就能推导出以上对象的类型
+ foreach (var bikeSummary in bikeSummaries.Where(b => b.IsAwesome))
+ Console.WriteLine(bikeSummary.Name);
+
+ // ASPARALLEL
+ // 邪恶的特性 —— 组合了linq和并行操作
+ var threeWheelers = bikes.AsParallel().Where(b => b.Wheels == 3).Select(b => b.Name);
+ // 以上代码会并发地运行。会自动新开线程,分别计算结果。
+ // 适用于多核、大数据量的场景。
+
+ // LINQ - 将IQueryable<T>映射到存储,延缓执行
+ // 例如 LinqToSql 映射数据库, LinqToXml 映射XML文档
+ var db = new BikeRespository();
+
+ // 执行被延迟了,这对于查询数据库来说很好
+ var filter = db.Bikes.Where(b => b.HasTassles); // 不运行查询
+ if (42 > 6) // 你可以不断地增加筛选,包括有条件的筛选,例如用于“高级搜索”功能
+ filter = filter.Where(b => b.IsBroken); // 不运行查询
+
+ var query = filter
+ .OrderBy(b => b.Wheels)
+ .ThenBy(b => b.Name)
+ .Select(b => b.Name); // 仍然不运行查询
+
+ // 现在运行查询,运行查询的时候会打开一个读取器,所以你迭代的是一个副本
+ foreach (string bike in query)
+ Console.WriteLine(result);
+
+
+
+ }
+
+ } // 结束LearnCSharp类
+
+ // 你可以在同一个 .cs 文件中包含其他类
+
+ public static class Extensions
+ {
+ // 扩展函数
+ public static void Print(this object obj)
+ {
+ Console.WriteLine(obj.ToString());
+ }
+ }
+ // 声明类的语法:
+ // <public/private/protected/internal> class <类名>{
+ // //数据字段, 构造器, 内部函数.
+ / // 在Java中函数被称为方法。
+ // }
+
+ public class Bicycle
+ {
+ // 自行车的字段、变量
+ public int Cadence // Public: 任何地方都可以访问
+ {
+ get // get - 定义获取属性的方法
+ {
+ return _cadence;
+ }
+ set // set - 定义设置属性的方法
+ {
+ _cadence = value; // value是被传递给setter的值
+ }
+ }
+ private int _cadence;
+
+ protected virtual int Gear // 类和子类可以访问
+ {
+ get; // 创建一个自动属性,无需成员字段
+ set;
+ }
+
+ internal int Wheels // Internal:在同一程序集内可以访问
+ {
+ get;
+ private set; // 可以给get/set方法添加修饰符
+ }
+
+ int _speed; // 默认为private: 只可以在这个类内访问,你也可以使用`private`关键词
+ public string Name { get; set; }
+
+ // enum类型包含一组常量
+ // 它将名称映射到值(除非特别说明,是一个整型)
+ // enmu元素的类型可以是byte、sbyte、short、ushort、int、uint、long、ulong。
+ // enum不能包含相同的值。
+ public enum BikeBrand
+ {
+ AIST,
+ BMC,
+ Electra = 42, //你可以显式地赋值
+ Gitane // 43
+ }
+ // 我们在Bicycle类中定义的这个类型,所以它是一个内嵌类型。
+ // 这个类以外的代码应当使用`Bicycle.Brand`来引用。
+
+ public BikeBrand Brand; // 声明一个enum类型之后,我们可以声明这个类型的字段
+
+ // 静态方法的类型为自身,不属于特定的对象。
+ // 你无需引用对象就可以访问他们。
+ // Console.WriteLine("Bicycles created: " + Bicycle.bicyclesCreated);
+ static public int BicyclesCreated = 0;
+
+ // 只读值在运行时确定
+ // 它们只能在声明或构造器内被赋值
+ readonly bool _hasCardsInSpokes = false; // read-only private
+
+ // 构造器是创建类的一种方式
+ // 下面是一个默认的构造器
+ public Bicycle()
+ {
+ this.Gear = 1; // 你可以使用关键词this访问对象的成员
+ Cadence = 50; // 不过你并不总是需要它
+ _speed = 5;
+ Name = "Bontrager";
+ Brand = BikeBrand.AIST;
+ BicyclesCreated++;
+ }
+
+ // 另一个构造器的例子(包含参数)
+ public Bicycle(int startCadence, int startSpeed, int startGear,
+ string name, bool hasCardsInSpokes, BikeBrand brand)
+ : base() // 首先调用base
+ {
+ Gear = startGear;
+ Cadence = startCadence;
+ _speed = startSpeed;
+ Name = name;
+ _hasCardsInSpokes = hasCardsInSpokes;
+ Brand = brand;
+ }
+
+ // 构造器可以连锁使用
+ public Bicycle(int startCadence, int startSpeed, BikeBrand brand) :
+ this(startCadence, startSpeed, 0, "big wheels", true, brand)
+ {
+ }
+
+ // 函数语法
+ // <public/private/protected> <返回值> <函数名称>(<参数>)
+
+ // 类可以为字段实现 getters 和 setters 方法 for their fields
+ // 或者可以实现属性(C#推荐使用这个)
+ // 方法的参数可以有默认值
+ // 在有默认值的情况下,调用方法的时候可以省略相应的参数
+ public void SpeedUp(int increment = 1)
+ {
+ _speed += increment;
+ }
+
+ public void SlowDown(int decrement = 1)
+ {
+ _speed -= decrement;
+ }
+
+ // 属性可以访问和设置值
+ // 当只需要访问数据的时候,考虑使用属性。
+ // 属性可以定义get和set,或者是同时定义两者
+ private bool _hasTassles; // private variable
+ public bool HasTassles // public accessor
+ {
+ get { return _hasTassles; }
+ set { _hasTassles = value; }
+ }
+
+ // 你可以在一行之内定义自动属性
+ // 这个语法会自动创建后备字段
+ // 你可以给getter或setter设置访问修饰符
+ // 以便限制它们的访问
+ public bool IsBroken { get; private set; }
+
+ // 属性的实现可以是自动的
+ public int FrameSize
+ {
+ get;
+ // 你可以给get或set指定访问修饰符
+ // 以下代码意味着只有Bicycle类可以调用Framesize的set
+ private set;
+ }
+
+ //显示对象属性的方法
+ public virtual string Info()
+ {
+ return "Gear: " + Gear +
+ " Cadence: " + Cadence +
+ " Speed: " + _speed +
+ " Name: " + Name +
+ " Cards in Spokes: " + (_hasCardsInSpokes ? "yes" : "no") +
+ "\n------------------------------\n"
+ ;
+ }
+
+ // 方法可以是静态的。通常用于辅助方法。
+ public static bool DidWeCreateEnoughBycles()
+ {
+ // 在静态方法中,你只能引用类的静态成员
+ return BicyclesCreated > 9000;
+ } // 如果你的类只需要静态成员,考虑将整个类作为静态类。
+
+
+ } // Bicycle类结束
+
+ // PennyFarthing是Bicycle的一个子类
+ class PennyFarthing : Bicycle
+ {
+ // (Penny Farthings是一种前轮很大的自行车。没有齿轮。)
+
+ // 调用父构造器
+ public PennyFarthing(int startCadence, int startSpeed) :
+ base(startCadence, startSpeed, 0, "PennyFarthing", true, BikeBrand.Electra)
+ {
+ }
+
+ protected override int Gear
+ {
+ get
+ {
+ return 0;
+ }
+ set
+ {
+ throw new ArgumentException("你不可能在PennyFarthing上切换齿轮");
+ }
+ }
+
+ public override string Info()
+ {
+ string result = "PennyFarthing bicycle ";
+ result += base.ToString(); // 调用父方法
+ return result;
+ }
+ }
+
+ // 接口只包含成员的签名,而没有实现。
+ interface IJumpable
+ {
+ void Jump(int meters); // 所有接口成员是隐式地公开的
+ }
+
+ interface IBreakable
+ {
+ bool Broken { get; } // 接口可以包含属性、方法和事件
+ }
+
+ // 类只能继承一个类,但是可以实现任意数量的接口
+ {
+ int damage = 0;
+
+ public void Jump(int meters)
+ {
+ damage += meters;
+ }
+
+ public bool Broken
+ {
+ get
+ {
+ return damage > 100;
+ }
+ }
+ }
+
+ /// <summary>
+ /// 连接数据库,一个 LinqToSql的示例。
+ /// EntityFramework Code First 很棒 (类似 Ruby的 ActiveRecord, 不过是双向的)
+ /// http://msdn.microsoft.com/en-us/data/jj193542.aspx
+ /// </summary>
+ public class BikeRespository : DbSet
+ {
+ public BikeRespository()
+ : base()
+ {
+ }
+
+ public DbSet<Bicycle> Bikes { get; set; }
+ }
+} // 结束 Namespace
+```
+
+## 没有涉及到的主题
+
+ * Flags
+ * Attributes
+ * 静态属性
+ * Exceptions, Abstraction
+ * ASP.NET (Web Forms/MVC/WebMatrix)
+ * Winforms
+ * Windows Presentation Foundation (WPF)
+
+## 扩展阅读
+
+ * [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/zh-cn/css-cn.html.markdown b/zh-cn/css-cn.html.markdown
new file mode 100644
index 00000000..dc6dcc4f
--- /dev/null
+++ b/zh-cn/css-cn.html.markdown
@@ -0,0 +1,212 @@
+---
+language: css
+contributors:
+ - ["Mohammad Valipour", "https://github.com/mvalipour"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["Jakukyo Friel", "https://weakish.github.io"]
+lang: zh-cn
+filename: learncss-cn.css
+---
+
+早期的web没有样式,只是单纯的文本。通过CSS,可以实现网页样式和内容的分离。
+
+简单来说,CSS可以指定HTML页面上的元素所使用的样式。
+
+和其他语言一样,CSS有很多版本。最新的版本是CSS 3. CSS 2.0兼容性最好。
+
+你可以使用[dabblet](http://dabblet.com/)来在线测试CSS的效果。
+
+```css
+/* 注释 */
+
+/* ####################
+ ## 选择器
+ ####################*/
+
+/* 一般而言,CSS的声明语句非常简单。 */
+选择器 { 属性: 值; /* 更多属性...*/ }
+
+/* 选择器用于指定页面上的元素。
+
+针对页面上的所有元素。 */
+* { color:red; }
+
+/*
+假定页面上有这样一个元素
+
+<div class='some-class class2' id='someId' attr='value' />
+*/
+
+/* 你可以通过类名来指定它 */
+.some-class { }
+
+/* 给出所有类名 */
+.some-class.class2 { }
+
+/* 标签名 */
+div { }
+
+/* id */
+#someId { }
+
+/* 由于元素包含attr属性,因此也可以通过这个来指定 */
+[attr] { font-size:smaller; }
+
+/* 以及有特定值的属性 */
+[attr='value'] { font-size:smaller; }
+
+/* 通过属性的值的开头指定 */
+[attr^='val'] { font-size:smaller; }
+
+/* 通过属性的值的结尾来指定 */
+[attr$='ue'] { font-size:smaller; }
+
+/* 通过属性的值的部分来指定 */
+[attr~='lu'] { font-size:smaller; }
+
+
+/* 你可以把这些全部结合起来,注意不同部分间不应该有空格,否则会改变语义 */
+div.some-class[attr$='ue'] { }
+
+/* 你也可以通过父元素来指定。*/
+
+/* 某个元素是另一个元素的直接子元素 */
+div.some-parent > .class-name {}
+
+/* 或者通过该元素的祖先元素 */
+div.some-parent .class-name {}
+
+/* 注意,去掉空格后语义就不同了。
+你能说出哪里不同么? */
+div.some-parent.class-name {}
+
+/* 你可以选择某元素前的相邻元素 */
+.i-am-before + .this-element { }
+
+/* 某元素之前的同级元素(相邻或不相邻) */
+.i-am-any-before ~ .this-element {}
+
+/* 伪类允许你基于页面的行为指定元素(而不是基于页面结构) */
+
+/* 例如,当鼠标悬停在某个元素上时 */
+:hover {}
+
+/* 已访问过的链接*/
+:visited {}
+
+/* 未访问过的链接*/
+:link {}
+
+/* 当前焦点的input元素 */
+:focus {}
+
+
+/* ####################
+ ## 属性
+ ####################*/
+
+选择器 {
+
+ /* 单位 */
+ width: 50%; /* 百分比 */
+ font-size: 2em; /* 当前字体大小的两倍 */
+ width: 200px; /* 像素 */
+ font-size: 20pt; /* 点 */
+ width: 5cm; /* 厘米 */
+ width: 50mm; /* 毫米 */
+ width: 5in; /* 英尺 */
+
+ /* 颜色 */
+ background-color: #F6E; /* 短16位 */
+ background-color: #F262E2; /* 长16位 */
+ background-color: tomato; /* 颜色名称 */
+ background-color: rgb(255, 255, 255); /* rgb */
+ background-color: rgb(10%, 20%, 50%); /* rgb 百分比 */
+ background-color: rgba(255, 0, 0, 0.3); /* rgb 加透明度 */
+
+ /* 图片 */
+ background-image: url(/path-to-image/image.jpg);
+
+ /* 字体 */
+ font-family: Arial;
+ font-family: "Courier New"; /* 使用双引号包裹含空格的字体名称 */
+ font-family: "Courier New", Trebuchet, Arial; /* 如果第一个
+ 字体没找到,浏览器会使用第二个字体,一次类推 */
+}
+
+```
+
+## 使用
+
+CSS文件使用 `.css` 后缀。
+
+```xml
+<!-- 你需要在文件的 <head> 引用CSS文件 -->
+<link rel='stylesheet' type='text/css' href='filepath/filename.css' />
+
+<!-- 你也可以在标记中内嵌CSS。不过强烈建议不要这么干。 -->
+<style>
+ 选择器 { 属性:值; }
+</style>
+
+<!-- 也可以直接使用元素的style属性。
+这是你最不该干的事情。 -->
+<div style='property:value;'>
+</div>
+
+```
+
+## 优先级
+
+同一个元素可能被多个不同的选择器指定,因此可能会有冲突。
+
+假定CSS是这样的:
+
+```css
+/*A*/
+p.class1[attr='value']
+
+/*B*/
+p.class1 {}
+
+/*C*/
+p.class2 {}
+
+/*D*/
+p {}
+
+/*E*/
+p { property: value !important; }
+
+```
+
+然后标记语言为:
+
+```xml
+<p style='/*F*/ property:value;' class='class1 class2' attr='value'>
+</p>
+```
+
+那么将会按照下面的顺序应用风格:
+
+
+* `E` 优先级最高,因为它使用了 `!important`,除非很有必要,尽量避免使用这个。
+* `F` 其次,因为它是嵌入的风格。
+* `A` 其次,因为它比其他指令更具体。
+* `C` 其次,虽然它的具体程度和`B`一样,但是它在`B`之后。
+* 接下来是 `B`。
+* 最后是 `D`。
+
+## 兼容性
+
+CSS2 的绝大部分特性兼容各种浏览器和设备。现在 CSS3 的兼容性也越来越好了。
+但是兼容性问题仍然是需要留意的一个问题。
+
+[QuirksMode CSS](http://www.quirksmode.org/css/)是关于这方面最好的资源。
+
+## 扩展阅读
+
+* [理解CSS的风格优先级: 特定性, 继承和层叠](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
+* [QuirksMode CSS](http://www.quirksmode.org/css/)
+* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
diff --git a/zh-cn/elisp-cn.html.markdown b/zh-cn/elisp-cn.html.markdown
index d303c2e8..06f38d77 100644
--- a/zh-cn/elisp-cn.html.markdown
+++ b/zh-cn/elisp-cn.html.markdown
@@ -132,7 +132,7 @@ lang: zh-cn
;; `C-xC-e' 这时屏幕上会显示两个窗口,而光标此时位于*test* buffer内
;; 用鼠标单击上面的buffer就会使光标移回。
-;; 或者你可以使用 `C-xo' 是的光标跳到另一个窗口中
+;; 或者你可以使用 `C-xo' 使得光标跳到另一个窗口中
;; 你可以用 `progn'命令将s式结合起来:
(progn
@@ -219,7 +219,7 @@ lang: zh-cn
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
-;; 我们将一些名字存到列表中;
+;; 我们将一些名字存到列表中:
(setq list-of-names '("Sarah" "Chloe" "Mathilde"))
;; 用 `car'来取得第一个名字:
diff --git a/zh-cn/elixir-cn.html.markdown b/zh-cn/elixir-cn.html.markdown
new file mode 100644
index 00000000..daee8d3c
--- /dev/null
+++ b/zh-cn/elixir-cn.html.markdown
@@ -0,0 +1,399 @@
+---
+language: elixir
+contributors:
+ - ["Joao Marques", "http://github.com/mrshankly"]
+translators:
+ - ["lidashuang", "http://github.com/lidashuang"]
+filename: learnelixir-cn.ex
+lang: zh-cn
+---
+
+Elixir 是一门构建在Erlang VM 之上的函数式编程语言。Elixir 完全兼容 Erlang,
+另外还提供了更标准的语法,特性。
+
+```elixir
+
+# 这是单行注释, 注释以井号开头
+
+# 没有多行注释
+# 但你可以堆叠多个注释。
+
+# elixir shell 使用命令 `iex` 进入。
+# 编译模块使用 `elixirc` 命令。
+
+# 如果安装正确,这些命令都会在环境变量里
+
+## ---------------------------
+## -- 基本类型
+## ---------------------------
+
+# 数字
+3 # 整型
+0x1F # 整型
+3.0 # 浮点类型
+
+# 原子(Atoms),以 `:`开头
+:hello # atom
+
+# 元组(Tuple) 在内存中的存储是连续的
+{1,2,3} # tuple
+
+# 使用`elem`函数访问元组(tuple)里的元素:
+elem({1, 2, 3}, 0) #=> 1
+
+# 列表(list)
+[1,2,3] # list
+
+# 可以用下面的方法访问列表的头尾元素:
+[head | tail] = [1,2,3]
+head #=> 1
+tail #=> [2,3]
+
+# 在elixir,就像在Erlang, `=` 表示模式匹配 (pattern matching)
+# 不是赋值。
+#
+# 这表示会用左边的模式(pattern)匹配右侧
+#
+# 上面的例子中访问列表的头部和尾部就是这样工作的。
+
+# 当左右两边不匹配时,会返回error, 在这个
+# 例子中,元组大小不一样。
+# {a, b, c} = {1, 2} #=> ** (MatchError) no match of right hand side value: {1,2}
+
+# 还有二进制类型 (binaries)
+<<1,2,3>> # binary
+
+# 字符串(Strings) 和 字符列表(char lists)
+"hello" # string
+'hello' # char list
+
+# 多行字符串
+"""
+I'm a multi-line
+string.
+"""
+#=> "I'm a multi-line\nstring.\n"
+
+# 所有的字符串(Strings)以UTF-8编码:
+"héllò" #=> "héllò"
+
+# 字符串(Strings)本质就是二进制类型(binaries), 字符列表(char lists)本质是列表(lists)
+<<?a, ?b, ?c>> #=> "abc"
+[?a, ?b, ?c] #=> 'abc'
+
+# 在 elixir中,`?a`返回 `a` 的 ASCII 整型值
+?a #=> 97
+
+# 合并列表使用 `++`, 对于二进制类型则使用 `<>`
+[1,2,3] ++ [4,5] #=> [1,2,3,4,5]
+'hello ' ++ 'world' #=> 'hello world'
+
+<<1,2,3>> <> <<4,5>> #=> <<1,2,3,4,5>>
+"hello " <> "world" #=> "hello world"
+
+## ---------------------------
+## -- 操作符(Operators)
+## ---------------------------
+
+# 一些数学运算
+1 + 1 #=> 2
+10 - 5 #=> 5
+5 * 2 #=> 10
+10 / 2 #=> 5.0
+
+# 在 elixir 中,操作符 `/` 返回值总是浮点数。
+
+# 做整数除法使用 `div`
+div(10, 2) #=> 5
+
+# 为了得到余数使用 `rem`
+rem(10, 3) #=> 1
+
+# 还有 boolean 操作符: `or`, `and` and `not`.
+# 第一个参数必须是boolean 类型
+true and true #=> true
+false or true #=> true
+# 1 and true #=> ** (ArgumentError) argument error
+
+# Elixir 也提供了 `||`, `&&` 和 `!` 可以接受任意的类型
+# 除了`false` 和 `nil` 其它都会被当作true.
+1 || true #=> 1
+false && 1 #=> false
+nil && 20 #=> nil
+
+!true #=> false
+
+# 比较有: `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` 和 `>`
+1 == 1 #=> true
+1 != 1 #=> false
+1 < 2 #=> true
+
+# `===` 和 `!==` 在比较整型和浮点类型时更为严格:
+1 == 1.0 #=> true
+1 === 1.0 #=> false
+
+# 我们也可以比较两种不同的类型:
+1 < :hello #=> true
+
+# 总的排序顺序定义如下:
+# number < atom < reference < functions < port < pid < tuple < list < bit string
+
+# 引用Joe Armstrong :“实际的顺序并不重要,
+# 但是,一个整体排序是否经明确界定是非常重要的。”
+
+## ---------------------------
+## -- 控制结构(Control Flow)
+## ---------------------------
+
+# `if` 表达式
+if false do
+ "This will never be seen"
+else
+ "This will"
+end
+
+# 还有 `unless`
+unless true do
+ "This will never be seen"
+else
+ "This will"
+end
+
+# 在Elixir中,很多控制结构都依赖于模式匹配
+
+# `case` 允许我们把一个值与多种模式进行比较:
+case {:one, :two} do
+ {:four, :five} ->
+ "This won't match"
+ {:one, x} ->
+ "This will match and assign `x` to `:two`"
+ _ ->
+ "This will match any value"
+end
+
+# 模式匹配时,如果不需要某个值,通用的做法是把值 匹配到 `_`
+# 例如,我们只需要要列表的头元素:
+[head | _] = [1,2,3]
+head #=> 1
+
+# 下面的方式效果一样,但可读性更好
+[head | _tail] = [:a, :b, :c]
+head #=> :a
+
+# `cond` 可以检测多种不同的分支
+# 使用 `cond` 代替多个`if` 表达式嵌套
+cond do
+ 1 + 1 == 3 ->
+ "I will never be seen"
+ 2 * 5 == 12 ->
+ "Me neither"
+ 1 + 2 == 3 ->
+ "But I will"
+end
+
+# 经常可以看到最后一个条件等于'true',这将总是匹配。
+cond do
+ 1 + 1 == 3 ->
+ "I will never be seen"
+ 2 * 5 == 12 ->
+ "Me neither"
+ true ->
+ "But I will (this is essentially an else)"
+end
+
+# `try/catch` 用于捕获被抛出的值, 它也支持 `after` 子句,
+# 无论是否值被捕获,after 子句都会被调用
+# `try/catch`
+try do
+ throw(:hello)
+catch
+ message -> "Got #{message}."
+after
+ IO.puts("I'm the after clause.")
+end
+#=> I'm the after clause
+# "Got :hello"
+
+## ---------------------------
+## -- 模块和函数(Modules and Functions)
+## ---------------------------
+
+# 匿名函数 (注意点)
+square = fn(x) -> x * x end
+square.(5) #=> 25
+
+
+# 也支持接收多个子句和卫士(guards).
+# Guards 可以进行模式匹配
+# Guards 使用 `when` 关键字指明:
+f = fn
+ x, y when x > 0 -> x + y
+ x, y -> x * y
+end
+
+f.(1, 3) #=> 4
+f.(-1, 3) #=> -3
+
+# Elixir 提供了很多内建函数
+# 在默认作用域都是可用的
+is_number(10) #=> true
+is_list("hello") #=> false
+elem({1,2,3}, 0) #=> 1
+
+# 你可以在一个模块里定义多个函数,定义函数使用 `def`
+defmodule Math do
+ def sum(a, b) do
+ a + b
+ end
+
+ def square(x) do
+ x * x
+ end
+end
+
+Math.sum(1, 2) #=> 3
+Math.square(3) #=> 9
+
+# 保存到 `math.ex`,使用 `elixirc` 编译你的 Math 模块
+# 在终端里: elixirc math.ex
+
+# 在模块中可以使用`def`定义函数,使用 `defp` 定义私有函数
+# 使用`def` 定义的函数可以被其它模块调用
+# 私有函数只能在本模块内调用
+defmodule PrivateMath do
+ def sum(a, b) do
+ do_sum(a, b)
+ end
+
+ defp do_sum(a, b) do
+ a + b
+ end
+end
+
+PrivateMath.sum(1, 2) #=> 3
+# PrivateMath.do_sum(1, 2) #=> ** (UndefinedFunctionError)
+
+
+# 函数定义同样支持 guards 和 多重子句:
+defmodule Geometry do
+ def area({:rectangle, w, h}) do
+ w * h
+ end
+
+ def area({:circle, r}) when is_number(r) do
+ 3.14 * r * r
+ end
+end
+
+Geometry.area({:rectangle, 2, 3}) #=> 6
+Geometry.area({:circle, 3}) #=> 28.25999999999999801048
+# Geometry.area({:circle, "not_a_number"})
+#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1
+
+#由于不变性,递归是Elixir的重要组成部分
+defmodule Recursion do
+ def sum_list([head | tail], acc) do
+ sum_list(tail, acc + head)
+ end
+
+ def sum_list([], acc) do
+ acc
+ end
+end
+
+Recursion.sum_list([1,2,3], 0) #=> 6
+
+# Elixir 模块支持属性,模块内建了一些属性,你也可以自定义属性
+defmodule MyMod do
+ @moduledoc """
+ 内置的属性,模块文档
+ """
+
+ @my_data 100 # 自定义属性
+ IO.inspect(@my_data) #=> 100
+end
+
+## ---------------------------
+## -- 记录和异常(Records and Exceptions)
+## ---------------------------
+
+# 记录就是把特定值关联到某个名字的结构体
+defrecord Person, name: nil, age: 0, height: 0
+
+joe_info = Person.new(name: "Joe", age: 30, height: 180)
+#=> Person[name: "Joe", age: 30, height: 180]
+
+# 访问name的值
+joe_info.name #=> "Joe"
+
+# 更新age的值
+joe_info = joe_info.age(31) #=> Person[name: "Joe", age: 31, height: 180]
+
+# 使用 `try` `rescue` 进行异常处理
+try do
+ raise "some error"
+rescue
+ RuntimeError -> "rescued a runtime error"
+ _error -> "this will rescue any error"
+end
+
+# 所有的异常都有一个message
+try do
+ raise "some error"
+rescue
+ x in [RuntimeError] ->
+ x.message
+end
+
+## ---------------------------
+## -- 并发(Concurrency)
+## ---------------------------
+
+# Elixir 依赖于 actor并发模型。在Elixir编写并发程序的三要素:
+# 创建进程,发送消息,接收消息
+
+# 启动一个新的进程使用`spawn`函数,接收一个函数作为参数
+
+f = fn -> 2 * 2 end #=> #Function<erl_eval.20.80484245>
+spawn(f) #=> #PID<0.40.0>
+
+
+# `spawn` 函数返回一个pid(进程标识符),你可以使用pid向进程发送消息。
+# 使用 `<-` 操作符发送消息。
+# 我们需要在进程内接收消息,要用到 `receive` 机制。
+
+defmodule Geometry do
+ def area_loop do
+ receive do
+ {:rectangle, w, h} ->
+ IO.puts("Area = #{w * h}")
+ area_loop()
+ {:circle, r} ->
+ IO.puts("Area = #{3.14 * r * r}")
+ area_loop()
+ end
+ end
+end
+
+# 编译这个模块,在shell中创建一个进程,并执行 `area_looop` 函数。
+pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0>
+
+# 发送一个消息给 `pid`, 会在receive语句进行模式匹配
+pid <- {:rectangle, 2, 3}
+#=> Area = 6
+# {:rectangle,2,3}
+
+pid <- {:circle, 2}
+#=> Area = 12.56000000000000049738
+# {:circle,2}
+
+# shell也是一个进程(process), 你可以使用`self`获取当前 pid
+self() #=> #PID<0.27.0>
+```
+
+## 参考文献
+
+* [Getting started guide](http://elixir-lang.org/getting_started/1.html) from [elixir webpage](http://elixir-lang.org)
+* [Elixir Documentation](http://elixir-lang.org/docs/master/)
+* ["Learn You Some Erlang for Great Good!"](http://learnyousomeerlang.com/) by Fred Hebert
+* "Programming Erlang: Software for a Concurrent World" by Joe Armstrong
diff --git a/zh-cn/erlang-cn.html.markdown b/zh-cn/erlang-cn.html.markdown
new file mode 100644
index 00000000..32e84278
--- /dev/null
+++ b/zh-cn/erlang-cn.html.markdown
@@ -0,0 +1,259 @@
+---
+language: erlang
+lang: zh-cn
+contributors:
+ - ["Giovanni Cappellotto", "http://www.focustheweb.com/"]
+translators:
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+filename: erlang-cn.erl
+---
+
+```erlang
+% 百分比符号标明注释的开始。
+
+%% 两个符号通常用于注释函数。
+
+%%% 三个符号通常用于注释模块。
+
+% Erlang 里使用三种标点符号:
+% 逗号 (`,`) 分隔函数调用中的参数、数据构建和模式。
+% 句号 (`.`) (后跟空格)分隔函数和 shell 中的表达式。
+% 分号 (`;`) 分隔语句。以下环境中使用语句:
+% 函数定义和`case`、`if`、`try..catch`、`receive`表达式。
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 1. 变量和模式匹配
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+Num = 42. % 变量必须以大写字母开头。
+
+% Erlang 的变量只能赋值一次。如果给变量赋不同的值,会导致错误:
+Num = 43. % ** exception error: no match of right hand side value 43
+
+% 大多数语言中`=`表示赋值语句,在Erlang中,则表示模式匹配。
+% `Lhs = Rhs`实际上意味着:
+% 演算右边(Rhs), 将结果与左边的模式匹配。
+Num = 7 * 6.
+
+% 浮点数
+Pi = 3.14159.
+
+% Atoms 用于表示非数字的常量。
+% Atom 以小写字母开始,包含字母、数字、`_`和`@`。
+Hello = hello.
+OtherNode = example@node.
+
+% Atom 中如果包含特殊字符,可以用单引号括起。
+AtomWithSpace = 'some atom with space'.
+
+% Erlang 的元组类似 C 的 struct.
+Point = {point, 10, 45}.
+
+% 使用模式匹配操作符`=`获取元组的值。
+{point, X, Y} = Point. % X = 10, Y = 45
+
+% 我们可以使用`_`存放我们不感兴趣的变量。
+% `_`被称为匿名变量。和其他变量不同,
+% 同一个模式中的多个`_`变量不必绑定到相同的值。
+Person = {person, {name, {first, joe}, {last, armstrong}}, {footsize, 42}}.
+{_, {_, {_, Who}, _}, _} = Person. % Who = joe
+
+% 列表使用方括号,元素间使用逗号分隔。
+% 列表的元素可以是任意类型。
+% 列表的第一个元素称为列表的 head,其余元素称为列表的 tail。
+ThingsToBuy = [{apples, 10}, {pears, 6}, {milk, 3}].
+
+% 若`T`是一个列表,那么`[H|T]`同样是一个列表,head为`H`,tail为`T`.
+% `|`分隔列表的 head 和 tail.
+% `[]`是空列表。
+% 我们可以使用模式匹配操作来抽取列表中的元素。
+% 如果我们有一个非空的列表`L`,那么`[X|Y] = L`则
+% 抽取 L 的 head 至 X,tail 至 Y (X、Y需为未定义的变量)。
+[FirstThing|OtherThingsToBuy] = ThingsToBuy.
+% FirstThing = {apples, 10}
+% OtherThingsToBuy = {pears, 6}, {milk, 3}
+
+% Erlang 中的字符串其实是由整数组成的数组。字符串使用双引号。
+Name = "Hello".
+[72, 101, 108, 108, 111] = "Hello".
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 2. 循序编程
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Module 是 Erlang 代码的基本单位。我们编写的所有函数都储存在 module 中。
+% Module 存储在后缀为 `.erl` 的文件中。
+% Module 必须事先编译。编译好的 module 以 `.beam` 结尾。
+-module(geometry).
+-export([area/1]). % module 对外暴露的函数列表
+
+% `area`函数包含两个分句,分句间以分号相隔。
+% 最后一个分句以句号加换行结尾。
+% 每个分句由头、体两部门组成。
+% 头部包含函数名称和用括号括起的模式,
+% 体部包含一系列表达式,如果头部的模式和调用时的参数匹配,这些表达式会被演算。
+% 模式匹配依照定义时的顺序依次进行。
+area({rectangle, Width, Ht}) -> Width * Ht;
+area({circle, R}) -> 3.14159 * R * R.
+
+% 编译文件为 geometry.erl.
+c(geometry). % {ok,geometry}
+
+% 调用函数时必须使用 module 名和函数名。
+geometry:area({rectangle, 10, 5}). % 50
+geometry:area({circle, 1.4}). % 6.15752
+
+% 在 Erlang 中,同一模块中,参数数目不同,名字相同的函数是完全不同的函数。
+-module(lib_misc).
+-export([sum/1]). % 对外暴露的`sum`函数接受一个参数:由整数组成的列表。
+sum(L) -> sum(L, 0).
+sum([], N) -> N;
+sum([H|T], N) -> sum(T, H+N).
+
+% fun 是匿名函数。它们没有名字,不过可以赋值给变量。
+Double = fun(X) -> 2*X end. % `Double` 指向匿名函数 #Fun<erl_eval.6.17052888>
+Double(2). % 4
+
+% fun 可以作为函数的参数和返回值。
+Mult = fun(Times) -> ( fun(X) -> X * Times end ) end.
+Triple = Mult(3).
+Triple(5). % 15
+
+% 列表解析是创建列表的表达式(不使用fun、map 或 filter)。
+% `[F(X) || X <- L]` 表示 "由 `F(X)` 组成的列表,其中 `X` 取自列表 `L`。
+L = [1,2,3,4,5].
+[2*X || X <- L]. % [2,4,6,8,10]
+% 列表解析可以使用生成器,也可以使用过滤器,过滤器用于筛选列表的一部分。
+EvenNumbers = [N || N <- [1, 2, 3, 4], N rem 2 == 0]. % [2, 4]
+
+% Guard 是用于增强模式匹配的结构。
+% Guard 可用于简单的测试和比较。
+% Guard 可用于函数定义的头部,以`when`关键字开头,或者其他可以使用表达式的地方。
+max(X, Y) when X > Y -> X;
+max(X, Y) -> Y.
+
+% guard 可以由一系列 guard 表达式组成,这些表达式以逗号分隔。
+% `GuardExpr1, GuardExpr2, ..., GuardExprN` 为真,当且仅当每个 guard 表达式均为真。
+is_cat(A) when is_atom(A), A =:= cat -> true;
+is_cat(A) -> false.
+is_dog(A) when is_atom(A), A =:= dog -> true;
+is_dog(A) -> false.
+
+% guard 序列 `G1; G2; ...; Gn` 为真,当且仅当其中任意一个 guard 表达式为真。
+is_pet(A) when is_dog(A); is_cat(A) -> true;
+is_pet(A) -> false.
+
+% Record 可以将元组中的元素绑定到特定的名称。
+% Record 定义可以包含在 Erlang 源代码中,也可以放在后缀为`.hrl`的文件中(Erlang 源代码中 include 这些文件)。
+-record(todo, {
+ status = reminder, % Default value
+ who = joe,
+ text
+}).
+
+% 在定义某个 record 之前,我们需要在 shell 中导入 record 的定义。
+% 我们可以使用 shell 函数`rr` (read records 的简称)。
+rr("records.hrl"). % [todo]
+
+% 创建和更新 record。
+X = #todo{}.
+% #todo{status = reminder, who = joe, text = undefined}
+X1 = #todo{status = urgent, text = "Fix errata in book"}.
+% #todo{status = urgent, who = joe, text = "Fix errata in book"}
+X2 = X1#todo{status = done}.
+% #todo{status = done,who = joe,text = "Fix errata in book"}
+
+% `case` 表达式。
+% `filter` 返回由列表`L`中所有满足`P(x)`为真的元素`X`组成的列表。
+filter(P, [H|T]) ->
+ case P(H) of
+ true -> [H|filter(P, T)];
+ false -> filter(P, T)
+ end;
+filter(P, []) -> [].
+filter(fun(X) -> X rem 2 == 0 end, [1, 2, 3, 4]). % [2, 4]
+
+% `if` 表达式。
+max(X, Y) ->
+ if
+ X > Y -> X;
+ X < Y -> Y;
+ true -> nil;
+ end.
+
+% 警告: `if` 表达式里至少有一个 guard 为真,否则会触发异常。
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 3. 异常
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% 当遇到内部错误或显式调用时,会触发异常。
+% 显式调用包括 `throw(Exception)`, `exit(Exception)` 和
+% `erlang:error(Exception)`.
+generate_exception(1) -> a;
+generate_exception(2) -> throw(a);
+generate_exception(3) -> exit(a);
+generate_exception(4) -> {'EXIT', a};
+generate_exception(5) -> erlang:error(a).
+
+% Erlang 有两种捕获异常的方法。其一是将调用包裹在`try...catch`表达式中。
+catcher(N) ->
+ try generate_exception(N) of
+ Val -> {N, normal, Val}
+ catch
+ throw:X -> {N, caught, thrown, X};
+ exit:X -> {N, caught, exited, X};
+ error:X -> {N, caught, error, X}
+ end.
+
+% 另一种方式是将调用包裹在`catch`表达式中。
+% 此时异常会被转化为一个描述错误的元组。
+catcher(N) -> catch generate_exception(N).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% 4. 并发
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% Erlang 依赖于 actor并发模型。在 Erlang 编写并发程序的三要素:
+% 创建进程,发送消息,接收消息
+
+% 启动一个新的进程使用`spawn`函数,接收一个函数作为参数
+
+F = fun() -> 2 + 2 end. % #Fun<erl_eval.20.67289768>
+spawn(F). % <0.44.0>
+
+% `spawn` 函数返回一个pid(进程标识符),你可以使用pid向进程发送消息。
+% 使用 `!` 操作符发送消息。
+% 我们需要在进程内接收消息,要用到 `receive` 机制。
+
+-module(caculateGeometry).
+-compile(export_all).
+caculateAera() ->
+ receive
+ {rectangle, W, H} ->
+ W * H;
+ {circle, R} ->
+ 3.14 * R * R;
+ _ ->
+ io:format("We can only caculate area of rectangles or circles.")
+ end.
+
+% 编译这个模块,在 shell 中创建一个进程,并执行 `caculateArea` 函数。
+c(caculateGeometry).
+CaculateAera = spawn(caculateGeometry, caculateAera, []).
+CaculateAera ! {circle, 2}. % 12.56000000000000049738
+
+% shell也是一个进程(process), 你可以使用`self`获取当前 pid
+
+self(). % <0.41.0>
+
+```
+
+## References
+
+* ["Learn You Some Erlang for great good!"](http://learnyousomeerlang.com/)
+* ["Programming Erlang: Software for a Concurrent World" by Joe Armstrong](http://pragprog.com/book/jaerlang/programming-erlang)
+* [Erlang/OTP Reference Documentation](http://www.erlang.org/doc/)
+* [Erlang - Programming Rules and Conventions](http://www.erlang.se/doc/programming_rules.shtml)
diff --git a/zh-cn/json-cn.html.markdown b/zh-cn/json-cn.html.markdown
new file mode 100644
index 00000000..75966595
--- /dev/null
+++ b/zh-cn/json-cn.html.markdown
@@ -0,0 +1,51 @@
+---
+language: json
+contributors:
+ - ["Anna Harren", "https://github.com/iirelu"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnjson-cn.json
+lang: zh-cn
+---
+
+因为JSON是一个极其简单的数据交换形式,这个最有可能将会是曾经最简单
+的Learn X in Y Minutes。
+
+最纯正形式的JSON没有实际的注解,但是大多数解析器将会
+接受C-风格(//, /\* \*/)的注解。为了这个目的,但是,
+一切都将会是100%有效的JSON。幸亏,它是不言自明的。
+
+```json
+{
+ "numbers": 0,
+ "strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
+ "has bools?": true,
+ "nothingness": null,
+
+ "big number": 1.2e+100,
+
+ "objects": {
+ "comment": "Most of your structure will come from objects.",
+
+ "array": [0, 1, 2, 3, "Arrays can have anything in them.", 5],
+
+ "another object": {
+ "comment": "These things can be nested, very useful."
+ }
+ },
+
+ "silliness": [
+ {
+ "sources of potassium": ["bananas"]
+ },
+ [
+ [1, 0, 0, 0],
+ [0, 1, 0, 0],
+ [0, 0, 1, "neo"],
+ [0, 0, 0, 1]
+ ]
+ ],
+
+ "that was short": "And, you're done. You know know everything JSON has to offer."
+}
+```
diff --git a/zh-cn/lua-cn.html.markdown b/zh-cn/lua-cn.html.markdown
new file mode 100644
index 00000000..95a94c76
--- /dev/null
+++ b/zh-cn/lua-cn.html.markdown
@@ -0,0 +1,413 @@
+---
+language: lua
+lang: zh-cn
+contributors:
+ - ["Tyler Neylon", "http://tylerneylon.com/"]
+ - ["Rob Hoelz", "http://hoelz.ro"]
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+ - ["Craig Roddin", "craig.roddin@gmail.com"]
+ - ["Amr Tamimi", "https://amrtamimi.com"]
+translators:
+ - ["Jakukyo Friel", "http://weakish.github.io"]
+---
+
+```lua
+-- 单行注释以两个连字符开头
+
+--[[
+ 多行注释
+--]]
+
+----------------------------------------------------
+-- 1. 变量和流程控制
+----------------------------------------------------
+
+num = 42 -- 所有的数字都是双精度浮点型。
+-- 别害怕,64位的双精度浮点型数字中有52位用于
+-- 保存精确的整型值; 对于52位以内的整型值,
+-- 不用担心精度问题。
+
+s = 'walternate' -- 和Python一样,字符串不可变。
+t = "也可以用双引号"
+u = [[ 多行的字符串
+ 以两个方括号
+ 开始和结尾。]]
+t = nil -- 撤销t的定义; Lua 支持垃圾回收。
+
+-- 块使用do/end之类的关键字标识:
+while num < 50 do
+ num = num + 1 -- 不支持 ++ 或 += 运算符。
+end
+
+-- If语句:
+if num > 40 then
+ print('over 40')
+elseif s ~= 'walternate' then -- ~= 表示不等于。
+ -- 像Python一样,用 == 检查是否相等 ;字符串同样适用。
+ io.write('not over 40\n') -- 默认标准输出。
+else
+ -- 默认全局变量。
+ thisIsGlobal = 5 -- 通常使用驼峰。
+
+ -- 如何定义局部变量:
+ local line = io.read() -- 读取标准输入的下一行。
+
+ -- ..操作符用于连接字符串:
+ print('Winter is coming, ' .. line)
+end
+
+-- 未定义的变量返回nil。
+-- 这不是错误:
+foo = anUnknownVariable -- 现在 foo = nil.
+
+aBoolValue = false
+
+--只有nil和false为假; 0和 ''都均为真!
+if not aBoolValue then print('twas false') end
+
+-- 'or'和 'and'短路
+-- 类似于C/js里的 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('the way of the future')
+ num = num - 1
+until num == 0
+
+----------------------------------------------------
+-- 2. 函数。
+----------------------------------------------------
+
+function fib(n)
+ if n < 2 then return 1 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
+
+-- 返回值、函数调用和赋值都可以
+-- 使用长度不匹配的list。
+-- 不匹配的接收方会被赋值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' --可以工作。
+
+-- 调用函数时,如果只有一个table参数,
+-- 同样可以省略括号(table详情见下):
+print {} -- 一样可以工作。
+
+----------------------------------------------------
+-- 3. Table。
+----------------------------------------------------
+
+-- Table = Lua唯一的组合数据结构;
+-- 它们是关联数组。
+-- 类似于PHP的数组或者js的对象,
+-- 它们是哈希表或者字典,也可以当初列表使用。
+
+-- 按字典/map的方式使用Table:
+
+-- Dict字面量默认使用字符串类型的key:
+t = {key1 = 'value1', key2 = false}
+
+-- 字符串key可以使用类似js的点标记:
+print(t.key1) -- 打印 'value1'.
+t.newKey = {} -- 添加新的键值对。
+t.key2 = nil -- 从table删除 key2。
+
+-- 使用任何非nil的值作为key:
+u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'}
+print(u[6.28]) -- 打印 "tau"
+
+-- 数字和字符串的key按值匹配的
+-- table按id匹配。
+a = u['@!#'] -- 现在 a = 'qbert'.
+b = u[{}] -- 我们或许期待的是 1729, 但是得到的是nil:
+-- b = nil ,因为没有找到。
+-- 之所以没找到,是因为我们用的key与保存数据时用的不是同
+-- 一个对象。
+-- 所以字符串和数字是移植性更好的key。
+
+-- 只需要一个table参数的函数调用不需要括号:
+function h(x) print(x.key1) end
+h{key1 = 'Sonmi~451'} -- 打印'Sonmi~451'.
+
+for key, val in pairs(u) do -- 遍历Table
+ print(key, val)
+end
+
+-- _G 是一个特殊的table,用于保存所有的全局变量
+print(_G['_G'] == _G) -- 打印'true'.
+
+-- 按列表/数组的方式使用:
+
+-- 列表字面量隐式添加整数键:
+v = {'value1', 'value2', 1.21, 'gigawatts'}
+for i = 1, #v do -- #v 是列表的大小
+ print(v[i]) -- 索引从 1 开始!! 太疯狂了!
+end
+-- 'list'并非真正的类型,v 其实是一个table,
+-- 只不过它用连续的整数作为key,可以像list那样去使用。
+
+----------------------------------------------------
+-- 3.1 元表(metatable) 和元方法(metamethod)。
+----------------------------------------------------
+
+-- table的元表提供了一种机制,支持类似操作符重载的行为。
+-- 稍后我们会看到元表如何支持类似js prototype的行为。
+
+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 没有关于元表的key,这点和js的prototype不一样。
+-- 因此你必须用getmetatable(f1)获取元表。
+-- 元表是一个普通的table,
+-- 元表的key是普通的Lua中的key,例如__add。
+
+-- 但是下面一行代码会失败,因为s没有元表:
+-- t = s + s
+-- 下面提供的与类相似的模式可以解决这个问题:
+
+-- 元表的__index 可以重载用于查找的点操作符:
+defaultFavs = {animal = 'gru', food = 'donuts'}
+myFavs = {food = 'pizza'}
+setmetatable(myFavs, {__index = defaultFavs})
+eatenBy = myFavs.animal -- 可以工作!感谢元表
+
+-- 如果在table中直接查找key失败,会使用
+-- 元表的__index 递归地重试。
+
+-- __index的值也可以是function(tbl, key)
+-- 这样可以支持自定义查找。
+
+-- __index、__add等的值,被称为元方法。
+-- 这里是一个table元方法的清单:
+
+-- __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 or a table> for a.b
+-- __newindex(a, b, c) for a.b = c
+-- __call(a, ...) for a(...)
+
+----------------------------------------------------
+-- 3.2 与类相似的table和继承。
+----------------------------------------------------
+
+-- Lua没有内建的类;可以通过不同的方法,利用表和元表
+-- 来实现类。
+
+-- 下面是一个例子,解释在后面:
+
+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看上去像一个类;其实它是一个table。
+-- 2. 函数tablename:fn(...) 等价于
+-- 函数tablename.fn(self, ...)
+-- 冒号(:)只是添加了self作为第一个参数。
+-- 阅读7 & 8条 了解self变量是如何得到其值的。
+-- 3. newObj是类Dog的一个实例。
+-- 4. self = 被继承的类。通常self = Dog,不过继承可以改变它。
+-- 如果把newObj的元表和__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. 因为new()的缘故,self拥有了一个'sound' key,参见第3条。
+-- 3. 等价于LoudDog.new(LoudDog),转换一下就是
+-- Dog.new(LoudDog),这是因为LoudDog没有'new' key,
+-- 但是它的元表中有 __index = Dog。
+-- 结果: seymour的元表是LoudDog,并且
+-- LoudDog.__index = Dog。所以有seymour.key
+-- = seymour.key, LoudDog.key, Dog.key
+-- 从其中第一个有指定key的table获取。
+-- 4. 在LoudDog可以找到'makeSound'的key;
+-- 等价于LoudDog.makeSound(seymour)。
+
+-- 如果有必要,子类也可以有new(),与基类相似:
+function LoudDog:new()
+ newObj = {}
+ -- 初始化newObj
+ self.__index = self
+ return setmetatable(newObj, self)
+end
+
+----------------------------------------------------
+-- 4. 模块
+----------------------------------------------------
+
+
+--[[ 我把这部分给注释了,这样脚本剩下的部分可以运行
+
+-- 假设文件mod.lua的内容类似这样:
+local M = {}
+
+local function sayMyName()
+ print('Hrunkner')
+end
+
+function M.sayHello()
+ print('Why hello there')
+ sayMyName()
+end
+
+return M
+
+-- 另一个文件可以使用mod.lua的功能:
+local mod = require('mod') -- 运行文件mod.lua.
+
+-- require是包含模块的标准做法。
+-- require等价于: (针对没有被缓存的情况;参见后面的内容)
+local mod = (function ()
+ <contents of mod.lua>
+end)()
+-- mod.lua被包在一个函数体中,因此mod.lua的局部变量
+-- 对外不可见。
+
+-- 下面的代码可以工作,因为在这里mod = mod.lua 中的 M:
+mod.sayHello() -- Says hello to Hrunkner.
+
+-- 这是错误的;sayMyName只在mod.lua中存在:
+mod.sayMyName() -- 错误
+
+-- require返回的值会被缓存,所以一个文件只会被运行一次,
+-- 即使它被require了多次。
+
+-- 假设mod2.lua包含代码"print('Hi!')"。
+local a = require('mod2') -- 打印Hi!
+local b = require('mod2') -- 不再打印; a=b.
+
+-- dofile与require类似,但是不缓存:
+dofile('mod2') --> Hi!
+dofile('mod2') --> Hi! (再次运行,与require不同)
+
+-- loadfile加载一个lua文件,但是并不运行它。
+f = loadfile('mod2') -- Calling f() runs mod2.lua.
+
+-- loadstring是loadfile的字符串版本。
+g = loadstring('print(343)') --返回一个函数。
+g() -- 打印343; 在此之前什么也不打印。
+
+--]]
+```
+
+## 参考
+
+
+
+为什么?我非常兴奋地学习lua, 这样我就可以使用[Löve 2D游戏引擎](http://love2d.org/)来编游戏。
+
+怎么做?我从[BlackBulletIV的面向程序员的Lua指南](http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/)入门。接着我阅读了官方的[Lua编程](http://www.lua.org/pil/contents.html)一书。
+
+lua-users.org上的[Lua简明参考](http://lua-users.org/files/wiki_insecure/users/thomasl/luarefv51.pdf)应该值得一看。
+
+本文没有涉及标准库的内容:
+
+* <a href="http://lua-users.org/wiki/StringLibraryTutorial">string library</a>
+* <a href="http://lua-users.org/wiki/TableLibraryTutorial">table library</a>
+* <a href="http://lua-users.org/wiki/MathLibraryTutorial">math library</a>
+* <a href="http://lua-users.org/wiki/IoLibraryTutorial">io library</a>
+* <a href="http://lua-users.org/wiki/OsLibraryTutorial">os library</a>
+
+使用Lua,欢乐常在!
diff --git a/zh-cn/php-cn.html.markdown b/zh-cn/php-cn.html.markdown
index c6ebb515..24939681 100644
--- a/zh-cn/php-cn.html.markdown
+++ b/zh-cn/php-cn.html.markdown
@@ -180,7 +180,7 @@ assert($c >= $d);
// 下面的比较只有在类型相同、值相同的情况下才为真
assert($c === $d);
assert($a !== $d);
-assert(1 == '1');
+assert(1 === '1');
assert(1 !== '1');
// 变量可以根据其使用来进行类型转换
@@ -243,7 +243,7 @@ if ($x === '0') {
-// 下面的语法常用语模板中:
+// 下面的语法常用于模板中:
?>
<?php if ($x): ?>
@@ -333,7 +333,7 @@ function my_function () {
echo my_function(); // => "Hello"
// 函数名需要以字母或者下划线开头,
-// 后面可以跟着任意的字幕、下划线、数字.
+// 后面可以跟着任意的字母、下划线、数字.
function add ($x, $y = 1) { // $y 是可选参数,默认值为 1
$result = $x + $y;
diff --git a/zh-cn/r-cn.html.markdown b/zh-cn/r-cn.html.markdown
index ed8c43b6..19c5f25d 100644
--- a/zh-cn/r-cn.html.markdown
+++ b/zh-cn/r-cn.html.markdown
@@ -6,7 +6,7 @@ contributors:
translators:
- ["小柒", "http://weibo.com/u/2328126220"]
- ["alswl", "https://github.com/alswl"]
-filename: learnr.r
+filename: learnr-zh.r
lang: zh-cn
---
diff --git a/zh-cn/racket-cn.html.markdown b/zh-cn/racket-cn.html.markdown
index d43511ea..8ef3671f 100644
--- a/zh-cn/racket-cn.html.markdown
+++ b/zh-cn/racket-cn.html.markdown
@@ -2,7 +2,7 @@
language: racket
lang: zh-cn
-filename: learnracket.rkt
+filename: learnracket-zh.rkt
contributors:
- ["th3rac25", "https://github.com/voila"]
- ["Eli Barzilay", "https://github.com/elibarzilay"]
diff --git a/zh-cn/scala-cn.html.markdown b/zh-cn/scala-cn.html.markdown
index 1ce41ac6..24f73bb5 100644
--- a/zh-cn/scala-cn.html.markdown
+++ b/zh-cn/scala-cn.html.markdown
@@ -6,7 +6,6 @@ contributors:
- ["Dominic Bou-Samra", "http://dbousamra.github.com"]
translators:
- ["Peiyong Lin", ""]
-filename: learn.scala
lang: zh-cn
---
diff --git a/zh-cn/visualbasic-cn.html.markdown b/zh-cn/visualbasic-cn.html.markdown
new file mode 100644
index 00000000..95f01ed6
--- /dev/null
+++ b/zh-cn/visualbasic-cn.html.markdown
@@ -0,0 +1,274 @@
+---
+language: Visual Basic
+contributors:
+ - ["Brian Martin", "http://brianmartin.biz"]
+translators:
+ - ["Abner Chou", "http://github.com/NoahDragon"]
+lang: zh-cn
+filename: learnvisualbasic.vb-cn
+---
+
+```vb
+Module Module1
+
+ Sub Main()
+ ' 让我们先从简单的终端程序学起。
+ ' 单引号用来生成注释(注意是半角单引号,非全角单引号’)
+ ' 为了方便运行此示例代码,我写了个目录索引。
+ ' 可能你还不了解以下代码的意义,但随着教程的深入,
+ ' 你会渐渐理解其用法。
+ Console.Title = ("Learn X in Y Minutes")
+ Console.WriteLine("NAVIGATION") ' 显示目录
+ Console.WriteLine("")
+ Console.ForegroundColor = ConsoleColor.Green
+ Console.WriteLine("1. Hello World Output") ' Hello world 输出示例
+ Console.WriteLine("2. Hello World Input") ' Hello world 输入示例
+ Console.WriteLine("3. Calculating Whole Numbers") ' 求整数之和
+ Console.WriteLine("4. Calculating Decimal Numbers") ' 求小数之和
+ Console.WriteLine("5. Working Calculator") ' 计算器
+ Console.WriteLine("6. Using Do While Loops") ' 使用 Do While 循环
+ Console.WriteLine("7. Using For While Loops") ' 使用 For While 循环
+ Console.WriteLine("8. Conditional Statements") ' 条件语句
+ Console.WriteLine("9. Select A Drink") ' 选饮料
+ Console.WriteLine("50. About") ' 关于
+ Console.WriteLine("Please Choose A Number From The Above List")
+ Dim selection As String = Console.ReadLine
+ Select Case selection
+ Case "1" ' Hello world 输出示例
+ Console.Clear() ' 清空屏幕
+ HelloWorldOutput() ' 调用程序块
+ Case "2" ' Hello world 输入示例
+ Console.Clear()
+ HelloWorldInput()
+ Case "3" ' 求整数之和
+ Console.Clear()
+ CalculatingWholeNumbers()
+ Case "4" ' 求小数之和
+ Console.Clear()
+ CalculatingDecimalNumbers()
+ Case "5" ' 计算器
+ Console.Clear()
+ WorkingCalculator()
+ Case "6" ' 使用 do while 循环
+ Console.Clear()
+ UsingDoWhileLoops()
+ Case "7" ' 使用 for while 循环
+ Console.Clear()
+ UsingForLoops()
+ Case "8" ' 条件语句
+ Console.Clear()
+ ConditionalStatement()
+ Case "9" ' If/Else 条件语句
+ Console.Clear()
+ IfElseStatement() ' 选饮料
+ Case "50" ' 关于本程序和作者
+ Console.Clear()
+ Console.Title = ("Learn X in Y Minutes :: About")
+ MsgBox("This tutorial is by Brian Martin (@BrianMartinn")
+ Console.Clear()
+ Main()
+ Console.ReadLine()
+
+ End Select
+ End Sub
+
+ ' 一、对应程序目录1,下同
+
+ ' 使用 private subs 声明函数。
+ Private Sub HelloWorldOutput()
+ ' 程序名
+ Console.Title = "Hello World Ouput | Learn X in Y Minutes"
+ ' 使用 Console.Write("") 或者 Console.WriteLine("") 来输出文本到屏幕上
+ ' 对应的 Console.Read() 或 Console.Readline() 用来读取键盘输入
+ Console.WriteLine("Hello World")
+ Console.ReadLine()
+ ' Console.WriteLine()后加Console.ReadLine()是为了防止屏幕输出信息一闪而过
+ ' 类似平时常见的“单击任意键继续”的意思。
+ End Sub
+
+ ' 二
+ Private Sub HelloWorldInput()
+ Console.Title = "Hello World YourName | Learn X in Y Minutes"
+ ' 变量
+ ' 用来存储用户输入的数据
+ ' 变量声明以 Dim 开始,结尾为 As VariableType (变量类型).
+
+ ' 此教程中,我们希望知道你的姓名,并让程序记录并输出。
+ Dim username As String
+ ' 我们定义username使用字符串类型(String)来记录用户姓名。
+ Console.WriteLine("Hello, What is your name? ") ' 询问用户输入姓名
+ username = Console.ReadLine() ' 存储用户名到变量 username
+ Console.WriteLine("Hello " + username) ' 输出将是 Hello + username
+ Console.ReadLine() ' 暂停屏幕并显示以上输出
+ ' 以上程序将询问你的姓名,并和你打招呼。
+ ' 其它变量如整型(Integer)我们用整型来处理整数。
+ End Sub
+
+ ' 三
+ Private Sub CalculatingWholeNumbers()
+ Console.Title = "Calculating Whole Numbers | Learn X in Y Minutes"
+ Console.Write("First number: ") ' 输入一个整数:1,2,50,104,等等
+ Dim a As Integer = Console.ReadLine()
+ Console.Write("Second number: ") ' 输入第二个整数
+ Dim b As Integer = Console.ReadLine()
+ Dim c As Integer = a + b
+ Console.WriteLine(c)
+ Console.ReadLine()
+ ' 以上程序将两个整数相加
+ End Sub
+
+ ' 四
+ Private Sub CalculatingDecimalNumbers()
+ Console.Title = "Calculating with Double | Learn X in Y Minutes"
+ ' 当然,我们还需要能够处理小数。
+ ' 只需要要将整型(Integer)改为小数(Double)类型即可。
+
+ ' 输入一个小数: 1.2, 2.4, 50.1, 104.9,等等
+ Console.Write("First number: ")
+ Dim a As Double = Console.ReadLine
+ Console.Write("Second number: ") ' 输入第二个数
+ Dim b As Double = Console.ReadLine
+ Dim c As Double = a + b
+ Console.WriteLine(c)
+ Console.ReadLine()
+ ' 以上代码能实现两个小数相加
+ End Sub
+
+ ' 五
+ Private Sub WorkingCalculator()
+ Console.Title = "The Working Calculator| Learn X in Y Minutes"
+ ' 但是如果你希望有个能够处理加减乘除的计算器呢?
+ ' 只需将上面代码复制粘帖即可。
+ Console.Write("First number: ") ' 输入第一个数
+ Dim a As Double = Console.ReadLine
+ Console.Write("Second number: ") ' 输入第二个数
+ Dim b As Integer = Console.ReadLine
+ Dim c As Integer = a + b
+ Dim d As Integer = a * b
+ Dim e As Integer = a - b
+ Dim f As Integer = a / b
+
+ ' 通过以下代码我们可以将以上所算的加减乘除结果输出到屏幕上。
+ Console.Write(a.ToString() + " + " + b.ToString())
+ ' 我们希望答案开头能有3个空格,可以使用String.PadLeft(3)方法。
+ Console.WriteLine(" = " + c.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " * " + b.ToString())
+ Console.WriteLine(" = " + d.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " - " + b.ToString())
+ Console.WriteLine(" = " + e.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " / " + b.ToString())
+ Console.WriteLine(" = " + e.ToString.PadLeft(3))
+ Console.ReadLine()
+
+ End Sub
+
+ ' 六
+ Private Sub UsingDoWhileLoops()
+ ' 如同以上的代码一样
+ ' 这次我们将询问用户是否继续 (Yes or No?)
+ ' 我们将使用Do While循环,因为我们不知到用户是否需要使用一次以上。
+ Console.Title = "UsingDoWhileLoops | Learn X in Y Minutes"
+ Dim answer As String ' 我们使用字符串变量来存储answer(答案)
+ Do ' 循环开始
+ Console.Write("First number: ")
+ Dim a As Double = Console.ReadLine
+ Console.Write("Second number: ")
+ Dim b As Integer = Console.ReadLine
+ Dim c As Integer = a + b
+ Dim d As Integer = a * b
+ Dim e As Integer = a - b
+ Dim f As Integer = a / b
+
+ Console.Write(a.ToString() + " + " + b.ToString())
+ Console.WriteLine(" = " + c.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " * " + b.ToString())
+ Console.WriteLine(" = " + d.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " - " + b.ToString())
+ Console.WriteLine(" = " + e.ToString.PadLeft(3))
+ Console.Write(a.ToString() + " / " + b.ToString())
+ Console.WriteLine(" = " + e.ToString.PadLeft(3))
+ Console.ReadLine()
+ ' 询问用户是否继续,注意大小写。
+ Console.Write("Would you like to continue? (yes / no)")
+ ' 程序读入用户输入
+ answer = Console.ReadLine() ' added a bracket here
+ ' 当用户输入"yes"时,程序将跳转到Do,并再次执行
+ Loop While answer = "yes"
+
+ End Sub
+
+ ' 七
+ Private Sub UsingForLoops()
+ ' 有一些程序只需要运行一次。
+ ' 这个程序我们将实现从10倒数计数.
+
+ Console.Title = "Using For Loops | Learn X in Y Minutes"
+ ' 声明变量和Step (步长,即递减的速度,如-1,-2,-3等)。
+ For i As Integer = 10 To 0 Step -1
+ Console.WriteLine(i.ToString) ' 将计数结果输出的屏幕
+ Next i ' 计算新的i值
+ Console.WriteLine("Start")
+ Console.ReadLine()
+ End Sub
+
+ ' 八
+ Private Sub ConditionalStatement()
+ Console.Title = "Conditional Statements | Learn X in Y Minutes"
+ Dim userName As String = Console.ReadLine
+ Console.WriteLine("Hello, What is your name? ") ' 询问用户姓名
+ userName = Console.ReadLine() ' 存储用户姓名
+ If userName = "Adam" Then
+ Console.WriteLine("Hello Adam")
+ Console.WriteLine("Thanks for creating this useful site")
+ Console.ReadLine()
+ Else
+ Console.WriteLine("Hello " + userName)
+ Console.WriteLine("Have you checked out www.learnxinyminutes.com")
+ Console.ReadLine() ' 程序停止,并输出以上文本
+ End If
+ End Sub
+
+ ' 九
+ Private Sub IfElseStatement()
+ Console.Title = "If / Else Statement | Learn X in Y Minutes"
+ ' 有时候我们需要考虑多于两种情况。
+ ' 这时我们就需要使用If/ElesIf条件语句。
+ ' If语句就好似个自动售货机,当用户输入A1,A2,A3,等去选择物品时,
+ ' 所有的选择可以合并到一个If语句中
+
+ Dim selection As String = Console.ReadLine() ' 读入用户选择
+ Console.WriteLine("A1. for 7Up") ' A1 七喜
+ Console.WriteLine("A2. for Fanta") ' A2 芬达
+ Console.WriteLine("A3. for Dr. Pepper") ' A3 胡椒医生
+ Console.WriteLine("A4. for Diet Coke") ' A4 无糖可乐
+ Console.ReadLine()
+ If selection = "A1" Then
+ Console.WriteLine("7up")
+ Console.ReadLine()
+ ElseIf selection = "A2" Then
+ Console.WriteLine("fanta")
+ Console.ReadLine()
+ ElseIf selection = "A3" Then
+ Console.WriteLine("dr. pepper")
+ Console.ReadLine()
+ ElseIf selection = "A4" Then
+ Console.WriteLine("diet coke")
+ Console.ReadLine()
+ Else
+ Console.WriteLine("Please select a product") ' 请选择你需要的产品
+ Console.ReadLine()
+ End If
+
+ End Sub
+
+End Module
+
+```
+
+## 参考
+
+我(译注:原作者)在命令行下学习的VB。命令行编程使我能够更好的了解程序编译运行机制,并使学习其它语言变得容易。
+
+如果希望进一步学习VB,这里还有更深层次的 <a href="http://www.vbbootcamp.co.uk/" Title="VB教学">VB教学(英文)</a>。
+
+所有代码均通过测试。只需复制粘帖到Visual Basic中,并按F5运行即可。
diff --git a/zh-cn/xml-cn.html.markdown b/zh-cn/xml-cn.html.markdown
new file mode 100644
index 00000000..bf0b074f
--- /dev/null
+++ b/zh-cn/xml-cn.html.markdown
@@ -0,0 +1,127 @@
+---
+language: xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnxml-cn.xml
+lang: zh-cn
+---
+
+XML是一种标记语言,被设计用来存储数据和传输数据。
+
+不像HTML, XML不指定怎样显示或格式化数据,只是携带它。
+
+
+* XML 语法
+
+```xml
+<!-- XML中的注解像这样 -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<bookstore>
+ <book category="COOKING">
+ <title lang="en">Everyday Italian</title>
+ <author>Giada De Laurentiis</author>
+ <year>2005</year>
+ <price>30.00</price>
+ </book>
+ <book category="CHILDREN">
+ <title lang="en">Harry Potter</title>
+ <author>J K. Rowling</author>
+ <year>2005</year>
+ <price>29.99</price>
+ </book>
+ <book category="WEB">
+ <title lang="en">Learning XML</title>
+ <author>Erik T. Ray</author>
+ <year>2003</year>
+ <price>39.95</price>
+ </book>
+</bookstore>
+
+<!-- 上面是一个典型的XML文件。
+ 它以一个声明开始,通知一些元数据(自选的)
+
+ XML使用一个树的结构。上面的文件中,根节点是'bookstore',它有三个孩子节点,
+ 所有的'books'。那些节点有更多的孩子节点,等等。。。
+
+ 节点用开放/关闭标签创建, 并且孩子就是在开发和关闭标签之间的节点。-->
+
+
+
+<!-- XML 携带两类信息:
+ 1 - 属性 -> 那是关于一个元素的元数据。
+ 通常,XML解析器使用这些信息去正确地存储数据。
+ 它通过在开放标签里出现在插入语中来表示。
+ 2 - 元素 -> 那是纯数据。
+ 那就是解析器将从XML文件提取的东西。
+ 元素出现在开放和关闭标签之间,没插入语。-->
+
+
+<!-- 下面, 一个有两个属性的元素-->
+<file type="gif" id="4293">computer.gif</file>
+
+
+```
+
+* 良好格式的文件 x 验证
+
+一个XML文件是良好格式的如果它是语法正确的。
+但是, 使用文件定义,比如DTD和XML概要,在文件中插入更多的限制是可能的。
+
+一个遵守一个文件定义的XML文件被叫做有效的,对于那个文件来说。
+
+有了这个工具,你能够在应用逻辑之外检查XML数据。
+
+```xml
+
+<!-- 下面, 你能够看到一个简化版本的增加了DTD定义的bookstore文件。-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "Bookstore.dtd">
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+
+<!-- 这个DTD可能是像这样的:-->
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+
+<!-- 这个DTD以一个声明开始。
+ 接下来, 根节点被声明, 它需要一个或多个孩子节点'book'。
+ 每个 'book' 应该准确包含一个 'title' 和 'price' 和
+ 一个被叫做'category'的缺省值为"Literature"的属性。
+ 这个'title' 和 'price'节点包含一个解析过的字符数据。-->
+
+<!-- 这个DTD可以在XML文件中本身被声明。-->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT bookstore (book+)>
+<!ELEMENT book (title,price)>
+<!ATTLIST book category CDATA "Literature">
+<!ELEMENT title (#PCDATA)>
+<!ELEMENT price (#PCDATA)>
+]>
+
+<bookstore>
+ <book category="COOKING">
+ <title >Everyday Italian</title>
+ <price>30.00</price>
+ </book>
+</bookstore>
+``` \ No newline at end of file
diff --git a/zh-cn/yaml-cn.html.markdown b/zh-cn/yaml-cn.html.markdown
new file mode 100644
index 00000000..bcc41067
--- /dev/null
+++ b/zh-cn/yaml-cn.html.markdown
@@ -0,0 +1,136 @@
+---
+language: yaml
+contributors:
+ - ["Adam Brenecki", "https://github.com/adambrenecki"]
+translators:
+ - ["Zach Zhang", "https://github.com/checkcheckzz"]
+filename: learnyaml-cn.yaml
+lang: zh-cn
+---
+
+YAML是一个数据序列化语言,被设计成人类直接可写可读的。
+
+它是JSON的严格超集,增加了语法显著换行符和缩进,就像Python。但和Python不一样,
+YAML根本不容许文字制表符。
+
+
+```yaml
+# YAML中的注解看起来像这样。
+
+################
+# 标量类型 #
+################
+
+# 我们的根对象 (它们在整个文件里延续) 将会是一个地图,
+# 它等价于在别的语言里的一个字典,哈西表或对象。
+key: value
+another_key: Another value goes here.
+a_number_value: 100
+scientific_notation: 1e+12
+boolean: true
+null_value: null
+key with spaces: value
+# 注意到字符串不需要被引用。但是,它们可以被引用。
+"Keys can be quoted too.": "Useful if you want to put a ':' in your key."
+
+# 多行字符串既可以写成像一个'文字块'(使用 |),
+# 或像一个'折叠块'(使用 '>')。
+literal_block: |
+ This entire block of text will be the value of the 'literal_block' key,
+ with line breaks being preserved.
+
+ The literal continues until de-dented, and the leading indentation is
+ stripped.
+
+ Any lines that are 'more-indented' keep the rest of their indentation -
+ these lines will be indented by 4 spaces.
+folded_style: >
+ This entire block of text will be the value of 'folded_style', but this
+ time, all newlines will be replaced with a single space.
+
+ Blank lines, like above, are converted to a newline character.
+
+ 'More-indented' lines keep their newlines, too -
+ this text will appear over two lines.
+
+####################
+# 集合类型 #
+####################
+
+# 嵌套是通过缩进完成的。
+a_nested_map:
+ key: value
+ another_key: Another Value
+ another_nested_map:
+ hello: hello
+
+# 地图不用有字符串键值。
+0.25: a float key
+
+# 键值也可以是多行对象,用?表明键值的开始。
+? |
+ This is a key
+ that has multiple lines
+: and this is its value
+
+# YAML也容许键值是集合类型,但是很多语言将会抱怨。
+
+# 序列 (等价于表或数组) 看起来像这样:
+a_sequence:
+ - Item 1
+ - Item 2
+ - 0.5 # sequences can contain disparate types
+ - Item 4
+ - key: value
+ another_key: another_value
+ -
+ - This is a sequence
+ - inside another sequence
+
+# 因为YAML是JSON的超集,你也可以写JSON风格的地图和序列:
+json_map: {"key": "value"}
+json_seq: [3, 2, 1, "takeoff"]
+
+#######################
+# 其余的YAML特点 #
+#######################
+
+# YAML还有一个方便的特点叫'锚',它让你简单地在整个文件里重复内容。
+# 两个键值将会有相同的值:
+anchored_content: &anchor_name This string will appear as the value of two keys.
+other_anchor: *anchor_name
+
+# YAML还有标签,你可以用它显示地声明类型。
+explicit_string: !!str 0.5
+# 一些解析器实现特定语言的标签,就像这个为了Python的复数类型。
+python_complex_number: !!python/complex 1+2j
+
+####################
+# 其余的YAML类型 #
+####################
+
+# 字符串和数字不是仅有的YAML可以理解的标量。
+# ISO 格式的日期和日期时间文字也是可以被解析的。
+datetime: 2001-12-15T02:59:43.1Z
+datetime_with_spaces: 2001-12-14 21:59:43.10 -5
+date: 2002-12-14
+
+# 这个!!binary标签表明一个字符串实际上是一个二进制blob的base64编码表示。
+gif_file: !!binary |
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
+
+# YAML还有一个集合类型,它看起来像这样:
+set:
+ ? item1
+ ? item2
+ ? item3
+
+# 像Python一样,集合仅是有null数值的地图;上面的集合等价于:
+set2:
+ item1: null
+ item2: null
+ item3: null
+```