summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--README.markdown27
-rw-r--r--amd.html.markdown212
-rw-r--r--bash.html.markdown87
-rw-r--r--c++.html.markdown593
-rw-r--r--c.html.markdown38
-rw-r--r--coffeescript.html.markdown4
-rw-r--r--common-lisp.html.markdown4
-rw-r--r--compojure.html.markdown280
-rw-r--r--csharp.html.markdown23
-rw-r--r--css.html.markdown91
-rw-r--r--de-de/csharp-de.html.markdown889
-rw-r--r--de-de/css-de.html.markdown179
-rw-r--r--de-de/haskell-de.html.markdown2
-rw-r--r--de-de/javascript-de.html.markdown118
-rw-r--r--de-de/markdown-de.html.markdown256
-rw-r--r--elixir.html.markdown37
-rw-r--r--erlang.html.markdown14
-rw-r--r--es-es/bash-es.html.markdown1
-rw-r--r--es-es/julia-es.html.markdown5
-rw-r--r--es-es/markdown-es.html.markdown2
-rw-r--r--forth.html.markdown225
-rw-r--r--fr-fr/bash-fr.html.markdown230
-rw-r--r--fr-fr/brainfuck-fr.html.markdown87
-rw-r--r--fr-fr/css-fr.html.markdown221
-rw-r--r--fr-fr/haskell.html.markdown2
-rw-r--r--fr-fr/javascript-fr.html.markdown525
-rw-r--r--fr-fr/lua-fr.html.markdown2
-rw-r--r--fr-fr/markdown.html.markdown289
-rw-r--r--fr-fr/objective-c-fr.html.markdown2
-rw-r--r--fr-fr/scala.html.markdown5
-rw-r--r--fr-fr/xml-fr.html.markdown128
-rw-r--r--fr-fr/yaml-fr.html.markdown157
-rw-r--r--git.html.markdown64
-rw-r--r--go.html.markdown53
-rw-r--r--haml.html.markdown155
-rw-r--r--haskell.html.markdown25
-rw-r--r--hy.html.markdown2
-rw-r--r--ja-jp/r-jp.html.markdown4
-rw-r--r--java.html.markdown20
-rw-r--r--javascript.html.markdown27
-rw-r--r--json.html.markdown2
-rw-r--r--julia.html.markdown9
-rw-r--r--ko-kr/lua-kr.html.markdown2
-rw-r--r--ko-kr/php-kr.html.markdown2
-rw-r--r--lua.html.markdown2
-rw-r--r--markdown.html.markdown18
-rw-r--r--matlab.html.markdown58
-rw-r--r--nim.html.markdown265
-rw-r--r--nl-nl/brainfuck-nl.html.markdown86
-rw-r--r--nl-nl/coffeescript-nl.html.markdown110
-rw-r--r--objective-c.html.markdown2
-rw-r--r--ocaml.html.markdown372
-rw-r--r--perl6.html.markdown173
-rw-r--r--php.html.markdown2
-rw-r--r--pl-pl/perl-pl.html.markdown169
-rw-r--r--pt-br/clojure-pt.html.markdown384
-rw-r--r--pt-br/groovy-pt.html.markdown435
-rw-r--r--pt-br/haskell-pt.html.markdown2
-rw-r--r--pt-br/markdown-pt.html.markdown2
-rw-r--r--pt-br/php-pt.html.markdown2
-rw-r--r--pt-br/ruby-pt.html.markdown12
-rw-r--r--pt-br/swift-pt.html.markdown500
-rw-r--r--python.html.markdown84
-rw-r--r--python3.html.markdown40
-rw-r--r--r.html.markdown13
-rw-r--r--ru-ru/coffeescript-ru.html.markdown104
-rw-r--r--ru-ru/go-ru.html.markdown44
-rw-r--r--ru-ru/haskell-ru.html.markdown2
-rw-r--r--ru-ru/java-ru.html.markdown506
-rw-r--r--ru-ru/julia-ru.html.markdown2
-rw-r--r--ru-ru/lua-ru.html.markdown425
-rw-r--r--ru-ru/markdown-ru.html.markdown279
-rw-r--r--ru-ru/objective-c-ru.html.markdown2
-rw-r--r--ru-ru/php-ru.html.markdown2
-rw-r--r--ru-ru/python-ru.html.markdown266
-rw-r--r--ru-ru/python3-ru.html.markdown630
-rw-r--r--ruby.html.markdown116
-rw-r--r--rust.html.markdown4
-rw-r--r--scala.html.markdown545
-rw-r--r--self.html.markdown161
-rw-r--r--swift.html.markdown468
-rw-r--r--tmux.html.markdown243
-rw-r--r--tr-tr/objective-c-tr.html.markdown2
-rw-r--r--tr-tr/php-tr.html.markdown2
-rw-r--r--typescript.html.markdown2
-rw-r--r--vi-vn/git-vi.html.markdown66
-rw-r--r--vi-vn/objective-c-vi.html.markdown2
-rw-r--r--zh-cn/c-cn.html.markdown4
-rw-r--r--zh-cn/common-lisp-cn.html.markdown2
-rw-r--r--zh-cn/haskell-cn.html.markdown2
-rw-r--r--zh-cn/julia-cn.html.markdown2
-rw-r--r--zh-cn/livescript-cn.html.markdown322
-rw-r--r--zh-cn/lua-cn.html.markdown9
-rw-r--r--zh-cn/markdown-cn.html.markdown240
-rw-r--r--zh-cn/php-cn.html.markdown2
-rw-r--r--zh-cn/python3-cn.html.markdown629
-rw-r--r--zh-cn/r-cn.html.markdown2
-rw-r--r--zh-cn/ruby-cn.html.markdown2
-rw-r--r--zh-cn/scala-cn.html.markdown2
-rw-r--r--zh-cn/swift-cn.html.markdown2
100 files changed, 12077 insertions, 847 deletions
diff --git a/README.markdown b/README.markdown
index dc379a9b..774797d5 100644
--- a/README.markdown
+++ b/README.markdown
@@ -14,20 +14,25 @@ properly!
## Contributing
-All contributions welcome, from the tiniest typo to a brand new article. Translations
+All contributions are welcome, from the tiniest typo to a brand new article. Translations
in all languages are welcome (or, for that matter, original articles in any language).
Send a pull request or open an issue any time of day or night.
**Please tag your issues pull requests with [language/lang-code] at the beginning**
-**(e.g. [python/en] for english python).** This will help everyone pick out things they
+**(e.g. [python/en] for English Python).** This will help everyone pick out things they
care about.
+We're happy for any contribution in any form, but if you're making more than one major change
+(i.e. translations for two different languages) it would be super cool of you to make a
+separate pull request for each one so that someone can review them more effectively and/or
+individually.
+
### Style Guidelines
* **Keep lines under 80 chars**
* **Prefer example to exposition**
* **Eschew surplusage**
-* **Use utf-8**
+* **Use UTF-8**
Long version:
@@ -38,28 +43,28 @@ Long version:
* We welcome newcomers, but the target audience for this site is programmers with some experience.
So, try to avoid explaining basic concepts except for those specific to the language in question,
- to keep articles succinct and scannable. We all know how to use google here.
+ to keep articles succinct and scannable. We all know how to use Google here.
-* For translations (or english articles with non-ASCII characters), please make sure your file is
- utf-8 encoded, and try to leave out the byte-order-mark at the start of the file. (`:set nobomb` in vim)
+* For translations (or English articles with non-ASCII characters), please make sure your file is
+ UTF-8 encoded, and try to leave out the byte-order-mark at the start of the file. (`:set nobomb` in Vim)
### Header configuration
-The actual site uses Middleman to generate HTML files from these markdown ones. Middleman, or at least
+The actual site uses Middleman to generate HTML files from these Markdown ones. Middleman, or at least
the custom scripts underpinning the site, required that some key information be defined in the header.
-The following fields are necessary for english articles about programming languages:
+The following fields are necessary for English articles about programming languages:
* **language** The *programming language* in question
-* **contributors** A list of [author, url] lists to credit
+* **contributors** A list of [author, URL] lists to credit
Other fields:
* **filename**: The filename for this article's code. It will be fetched, mashed together, and made downloadable.
- For non-english articles, *filename* should have a language-specific suffix.
+ For non-English articles, *filename* should have a language-specific suffix.
* **lang**: For translations, the human language this article is in. For categorization, mostly.
-Here's an example header for an esperanto translation of Ruby:
+Here's an example header for an Esperanto translation of Ruby:
```yaml
---
diff --git a/amd.html.markdown b/amd.html.markdown
new file mode 100644
index 00000000..b3237dc7
--- /dev/null
+++ b/amd.html.markdown
@@ -0,0 +1,212 @@
+---
+category: tool
+tool: amd
+contributors:
+ - ["Frederik Ring", "https://github.com/m90"]
+filename: learnamd.js
+---
+
+## Getting Started with AMD
+
+The **Asynchronous Module Definition** API specifies a mechanism for defining
+JavaScript modules such that the module and its dependencies can be asynchronously
+loaded. This is particularly well suited for the browser environment where
+synchronous loading of modules incurs performance, usability, debugging, and
+cross-domain access problems.
+
+### Basic concept
+```javascript
+// The basic AMD API consists of nothing but two methods: `define` and `require`
+// and is all about module definition and consumption:
+// `define(id?, dependencies?, factory)` defines a module
+// `require(dependencies, callback)` imports a set of dependencies and
+// consumes them in the passed callback
+
+// Let's start by using define to define a new named module
+// that has no dependencies. We'll do so by passing a name
+// and a factory function to define:
+define('awesomeAMD', function(){
+ var isAMDAwesome = function(){
+ return true;
+ };
+ // The return value of a module's factory function is
+ // what other modules or require calls will receive when
+ // requiring our `awesomeAMD` module.
+ // The exported value can be anything, (constructor) functions,
+ // objects, primitives, even undefined (although that won't help too much).
+ return isAMDAwesome;
+});
+
+// Now, let's define another module that depends upon our `awesomeAMD` module.
+// Notice that there's an additional argument defining our
+// module's dependencies now:
+define('loudmouth', ['awesomeAMD'], function(awesomeAMD){
+ // dependencies will be passed to the factory's arguments
+ // in the order they are specified
+ var tellEveryone = function(){
+ if (awesomeAMD()){
+ alert('This is sOoOo rad!');
+ } else {
+ alert('Pretty dull, isn\'t it?');
+ }
+ };
+ return tellEveryone;
+});
+
+// As we do know how to use define now, let's use `require` to
+// kick off our program. `require`'s signature is `(arrayOfDependencies, callback)`.
+require(['loudmouth'], function(loudmouth){
+ loudmouth();
+});
+
+// To make this tutorial run code, let's implement a very basic
+// (non-asynchronous) version of AMD right here on the spot:
+function define(name, deps, factory){
+ // notice how modules without dependencies are handled
+ define[name] = require(factory ? deps : [], factory || deps);
+}
+
+function require(deps, callback){
+ var args = [];
+ // first let's retrieve all the dependencies needed
+ // by the require call
+ for (var i = 0; i < deps.length; i++){
+ args[i] = define[deps[i]];
+ }
+ // satisfy all the callback's dependencies
+ return callback.apply(null, args);
+}
+// you can see this code in action here: http://jsfiddle.net/qap949pd/
+```
+
+### Real-world usage with require.js
+
+In contrast to the introductory example, `require.js` (the most popular AMD library) actually implements the **A** in **AMD**, enabling you to load modules and their dependencies asynchronously via XHR:
+
+```javascript
+/* file: app/main.js */
+require(['modules/someClass'], function(SomeClass){
+ // the callback is deferred until the dependency is loaded
+ var thing = new SomeClass();
+});
+console.log('So here we are, waiting!'); // this will run first
+```
+
+By convention, you usually store one module in one file. `require.js` can resolve module names based on file paths, so you don't have to name your modules, but can simply reference them using their location. In the example `someClass` is assumed to be in the `modules` folder, relative to your configuration's `baseUrl`:
+
+* app/
+ * main.js
+ * modules/
+ * someClass.js
+ * someHelpers.js
+ * ...
+ * daos/
+ * things.js
+ * ...
+
+This means we can define `someClass` without specifying a module id:
+
+```javascript
+/* file: app/modules/someClass.js */
+define(['daos/things', 'modules/someHelpers'], function(thingsDao, helpers){
+ // module definition, of course, will also happen asynchronously
+ function SomeClass(){
+ this.method = function(){/**/};
+ // ...
+ }
+ return SomeClass;
+});
+```
+To alter the default path mapping behavior use `requirejs.config(configObj)` in your `main.js`:
+
+```javascript
+/* file: main.js */
+requirejs.config({
+ baseUrl : 'app',
+ paths : {
+ // you can also load modules from other locations
+ jquery : '//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min',
+ coolLibFromBower : '../bower_components/cool-lib/coollib'
+ }
+});
+require(['jquery', 'coolLibFromBower', 'modules/someHelpers'], function($, coolLib, helpers){
+ // a `main` file needs to call require at least once,
+ // otherwise no code will ever run
+ coolLib.doFancyStuffWith(helpers.transform($('#foo')));
+});
+```
+`require.js`-based apps will usually have a single entry point (`main.js`) that is passed to the `require.js` script tag as a data-attribute. It will be automatically loaded and executed on pageload:
+
+```html
+<!DOCTYPE html>
+<html>
+<head>
+ <title>A hundred script tags? Never again!</title>
+</head>
+<body>
+ <script src="require.js" data-main="app/main"></script>
+</body>
+</html>
+```
+
+### Optimizing a whole project using r.js
+
+Many people prefer using AMD for sane code organization during development, but still want to ship a single script file in production instead of performing hundreds of XHRs on page load.
+
+`require.js` comes with a script called `r.js` (that you will probably run in node.js, although Rhino is supported too) that can analyse your project's dependency graph, and build a single file containing all your modules (properly named), minified and ready for consumption.
+
+Install it using `npm`:
+```shell
+$ npm install requirejs -g
+```
+
+Now you can feed it with a configuration file:
+```shell
+$ r.js -o app.build.js
+```
+
+For our above example the configuration might look like:
+```javascript
+/* file : app.build.js */
+({
+ name : 'main', // name of the entry point
+ out : 'main-built.js', // name of the file to write the output to
+ baseUrl : 'app',
+ paths : {
+ // `empty:` tells r.js that this should still be loaded from the CDN, using
+ // the location specified in `main.js`
+ jquery : 'empty:',
+ coolLibFromBower : '../bower_components/cool-lib/coollib'
+ }
+})
+```
+
+To use the built file in production, simply swap `data-main`:
+```html
+<script src="require.js" data-main="app/main-built"></script>
+```
+
+An incredibly detailed [overview of build options](https://github.com/jrburke/r.js/blob/master/build/example.build.js) is available in the GitHub repo.
+
+### Topics not covered in this tutorial
+* [Loader plugins / transforms](http://requirejs.org/docs/plugins.html)
+* [CommonJS style loading and exporting](http://requirejs.org/docs/commonjs.html)
+* [Advanced configuration](http://requirejs.org/docs/api.html#config)
+* [Shim configuration (loading non-AMD modules)](http://requirejs.org/docs/api.html#config-shim)
+* [CSS loading and optimizing with require.js](http://requirejs.org/docs/optimization.html#onecss)
+* [Using almond.js for builds](https://github.com/jrburke/almond)
+
+### Further reading:
+
+* [Official Spec](https://github.com/amdjs/amdjs-api/wiki/AMD)
+* [Why AMD?](http://requirejs.org/docs/whyamd.html)
+* [Universal Module Definition](https://github.com/umdjs/umd)
+
+### Implementations:
+
+* [require.js](http://requirejs.org)
+* [dojo toolkit](http://dojotoolkit.org/documentation/tutorials/1.9/modules/)
+* [cujo.js](http://cujojs.com/)
+* [curl.js](https://github.com/cujojs/curl)
+* [lsjs](https://github.com/zazl/lsjs)
+* [mmd](https://github.com/alexlawrence/mmd)
diff --git a/bash.html.markdown b/bash.html.markdown
index 57fb5c55..3b163638 100644
--- a/bash.html.markdown
+++ b/bash.html.markdown
@@ -8,6 +8,8 @@ contributors:
- ["Denis Arh", "https://github.com/darh"]
- ["akirahirose", "https://twitter.com/akirahirose"]
- ["Anton Strömkvist", "http://lutic.org/"]
+ - ["Rahil Momin", "https://github.com/iamrahil"]
+ - ["Gregrory Kielian", "https://github.com/gskielian"]
filename: LearnBash.sh
---
@@ -109,12 +111,45 @@ ls -l # Lists every file and directory on a separate line
# .txt files in the current directory:
ls -l | grep "\.txt"
-# You can also redirect a command, input and error output.
-python2 hello.py < "input.in"
-python2 hello.py > "output.out"
-python2 hello.py 2> "error.err"
-# The output error will overwrite the file if it exists, if you want to
-# concatenate them, use ">>" instead.
+# You can redirect command input and output (stdin, stdout, and stderr).
+# Read from stdin until ^EOF$ and overwrite hello.py with the lines
+# between "EOF":
+cat > hello.py << EOF
+#!/usr/bin/env python
+from __future__ import print_function
+import sys
+print("#stdout", file=sys.stdout)
+print("#stderr", file=sys.stderr)
+for line in sys.stdin:
+ print(line, file=sys.stdout)
+EOF
+
+# Run hello.py with various stdin, stdout, and stderr redirections:
+python hello.py < "input.in"
+python hello.py > "output.out"
+python hello.py 2> "error.err"
+python hello.py > "output-and-error.log" 2>&1
+python hello.py > /dev/null 2>&1
+# The output error will overwrite the file if it exists,
+# if you want to append instead, use ">>":
+python hello.py >> "output.out" 2>> "error.err"
+
+# Overwrite output.txt, append to error.err, and count lines:
+info bash 'Basic Shell Features' 'Redirections' > output.out 2>> error.err
+wc -l output.out error.err
+
+# Run a command and print its file descriptor (e.g. /dev/fd/123)
+# see: man fd
+echo <(echo "#helloworld")
+
+# Overwrite output.txt with "#helloworld":
+cat > output.out <(echo "#helloworld")
+echo "#helloworld" > output.out
+echo "#helloworld" | cat > output.out
+echo "#helloworld" | tee output.out >/dev/null
+
+# Cleanup temporary files verbosely (add '-i' for interactive)
+rm -v output.out error.err output-and-error.log
# Commands can be substituted within other commands using $( ):
# The following command displays the number of files and directories in the
@@ -140,6 +175,12 @@ do
echo "$VARIABLE"
done
+# Or write it the "traditional for loop" way:
+for ((a=1; a <= 3; a++))
+do
+ echo $a
+done
+
# They can also be used to act on files..
# This will run the command 'cat' on file1 and file2
for VARIABLE in file1 file2
@@ -192,4 +233,38 @@ sort file.txt
uniq -d file.txt
# prints only the first column before the ',' character
cut -d ',' -f 1 file.txt
+# replaces every occurrence of 'okay' with 'great' in file.txt, (regex compatible)
+sed -i 's/okay/great/g' file.txt
+# print to stdout all lines of file.txt which match some regex, the example prints lines which begin with "foo" and end in "bar"
+grep "^foo.*bar$" file.txt
+# pass the option "-c" to instead print the number of lines matching the regex
+grep -c "^foo.*bar$" file.txt
+# if you literally want to search for the string, and not the regex, use fgrep (or grep -F)
+fgrep "^foo.*bar$" file.txt
+
+
+# Read Bash shell builtins documentation with the bash 'help' builtin:
+help
+help help
+help for
+help return
+help source
+help .
+
+# Read Bash manpage documentation with man
+apropos bash
+man 1 bash
+man bash
+
+# Read info documentation with info (? for help)
+apropos info | grep '^info.*('
+man info
+info info
+info 5 info
+
+# Read bash info documentation:
+info bash
+info bash 'Bash Features'
+info bash 6
+info --apropos bash
```
diff --git a/c++.html.markdown b/c++.html.markdown
new file mode 100644
index 00000000..5f80f26f
--- /dev/null
+++ b/c++.html.markdown
@@ -0,0 +1,593 @@
+---
+language: c++
+filename: learncpp.cpp
+contributors:
+ - ["Steven Basart", "http://github.com/xksteven"]
+ - ["Matt Kline", "https://github.com/mrkline"]
+lang: en
+---
+
+C++ is a systems programming language that,
+[according to its inventor Bjarne Stroustrup](http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2014/Keynote),
+was designed to
+
+- be a "better C"
+- support data abstraction
+- support object-oriented programming
+- support generic programming
+
+Though its syntax can be more difficult or complex than newer languages,
+it is widely used because it compiles to native instructions that can be
+directly run by the processor and offers tight control over hardware (like C)
+while offering high-level features such as generics, exceptions, and classes.
+This combination of speed and functionality makes C++
+one of the most widely-used programming languages.
+
+```c++
+//////////////////
+// Comparison to C
+//////////////////
+
+// C++ is _almost_ a superset of C and shares its basic syntax for
+// variable declarations, primitive types, and functions.
+// However, C++ varies in some of the following ways:
+
+// A main() function in C++ should return an int,
+// though void main() is accepted by most compilers (gcc, clang, etc.)
+// This value serves as the program's exit status.
+// See http://en.wikipedia.org/wiki/Exit_status for more information.
+int main(int argc, char** argv)
+{
+ // Command line arguments are passed in by argc and argv in the same way
+ // they are in C.
+ // argc indicates the number of arguments,
+ // and argv is an array of C-style strings (char*)
+ // representing the arguments.
+ // The first argument is the name by which the program was called.
+ // argc and argv can be omitted if you do not care about arguments,
+ // giving the function signature of int main()
+
+ // An exit status of 0 indicates success.
+ return 0;
+}
+
+// In C++, character literals are one byte.
+sizeof('c') == 1
+
+// In C, character literals are the same size as ints.
+sizeof('c') == sizeof(10)
+
+
+// C++ has strict prototyping
+void func(); // function which accepts no arguments
+
+// In C
+void func(); // function which may accept any number of arguments
+
+// Use nullptr instead of NULL in C++
+int* ip = nullptr;
+
+// C standard headers are available in C++,
+// but are prefixed with "c" and have no .h suffix.
+#include <cstdio>
+
+int main()
+{
+ printf("Hello, world!\n");
+ return 0;
+}
+
+///////////////////////
+// Function overloading
+///////////////////////
+
+// C++ supports function overloading
+// provided each function takes different parameters.
+
+void print(char const* myString)
+{
+ printf("String %s\n", myString);
+}
+
+void print(int myInt)
+{
+ printf("My int is %d", myInt);
+}
+
+int main()
+{
+ print("Hello"); // Resolves to void print(const char*)
+ print(15); // Resolves to void print(int)
+}
+
+/////////////////////////////
+// Default function arguments
+/////////////////////////////
+
+// You can provide default arguments for a function
+// if they are not provided by the caller.
+
+void doSomethingWithInts(int a = 1, int b = 4)
+{
+ // Do something with the ints here
+}
+
+int main()
+{
+ doSomethingWithInts(); // a = 1, b = 4
+ doSomethingWithInts(20); // a = 20, b = 4
+ doSomethingWithInts(20, 5); // a = 20, b = 5
+}
+
+// Default arguments must be at the end of the arguments list.
+
+void invalidDeclaration(int a = 1, int b) // Error!
+{
+}
+
+
+/////////////
+// Namespaces
+/////////////
+
+// Namespaces provide separate scopes for variable, function,
+// and other declarations.
+// Namespaces can be nested.
+
+namespace First {
+ namespace Nested {
+ void foo()
+ {
+ printf("This is First::Nested::foo\n");
+ }
+ } // end namespace Nested
+} // end namespace First
+
+namespace Second {
+ void foo()
+ {
+ printf("This is Second::foo\n")
+ }
+}
+
+void foo()
+{
+ printf("This is global foo\n");
+}
+
+int main()
+{
+ // Assume everything is from the namespace "Second"
+ // unless otherwise specified.
+ using namespace Second;
+
+ foo(); // prints "This is Second::foo"
+ First::Nested::foo(); // prints "This is First::Nested::foo"
+ ::foo(); // prints "This is global foo"
+}
+
+///////////////
+// Input/Output
+///////////////
+
+// C++ input and output uses streams
+// cin, cout, and cerr represent stdin, stdout, and stderr.
+// << is the insertion operator and >> is the extraction operator.
+
+#include <iostream> // Include for I/O streams
+
+using namespace std; // Streams are in the std namespace (standard library)
+
+int main()
+{
+ int myInt;
+
+ // Prints to stdout (or terminal/screen)
+ cout << "Enter your favorite number:\n";
+ // Takes in input
+ cin >> myInt;
+
+ // cout can also be formatted
+ cout << "Your favorite number is " << myInt << "\n";
+ // prints "Your favorite number is <myInt>"
+
+ cerr << "Used for error messages";
+}
+
+//////////
+// Strings
+//////////
+
+// Strings in C++ are objects and have many member functions
+#include <string>
+
+using namespace std; // Strings are also in the namespace std (standard library)
+
+string myString = "Hello";
+string myOtherString = " World";
+
+// + is used for concatenation.
+cout << myString + myOtherString; // "Hello World"
+
+cout << myString + " You"; // "Hello You"
+
+// C++ strings are mutable and have value semantics.
+myString.append(" Dog");
+cout << myString; // "Hello Dog"
+
+
+/////////////
+// References
+/////////////
+
+// In addition to pointers like the ones in C,
+// C++ has _references_.
+// These are pointer types that cannot be reassigned once set
+// and cannot be null.
+// They also have the same syntax as the variable itself:
+// No * is needed for dereferencing and
+// & (address of) is not used for assignment.
+
+using namespace std;
+
+string foo = "I am foo";
+string bar = "I am bar";
+
+
+string& fooRef = foo; // This creates a reference to foo.
+fooRef += ". Hi!"; // Modifies foo through the reference
+cout << fooRef; // Prints "I am foo. Hi!"
+
+// Doesn't reassign "fooRef". This is the same as "foo = bar", and
+// foo == "I am bar"
+// after this line.
+fooRef = bar;
+
+const string& barRef = bar; // Create a const reference to bar.
+// Like C, const values (and pointers and references) cannot be modified.
+barRef += ". Hi!"; // Error, const references cannot be modified.
+
+//////////////////////////////////////////
+// Classes and object-oriented programming
+//////////////////////////////////////////
+
+// First example of classes
+#include <iostream>
+
+// Declare a class.
+// Classes are usually declared in header (.h or .hpp) files.
+class Dog {
+ // Member variables and functions are private by default.
+ std::string name;
+ int weight;
+
+// All members following this are public
+// until "private:" or "protected:" is found.
+public:
+
+ // Default constructor
+ Dog();
+
+ // Member function declarations (implementations to follow)
+ // Note that we use std::string here instead of placing
+ // using namespace std;
+ // above.
+ // Never put a "using namespace" statement in a header.
+ void setName(const std::string& dogsName);
+
+ void setWeight(int dogsWeight);
+
+ // Functions that do not modify the state of the object
+ // should be marked as const.
+ // This allows you to call them if given a const reference to the object.
+ // Also note the functions must be explicitly declared as _virtual_
+ // in order to be overridden in derived classes.
+ // Functions are not virtual by default for performance reasons.
+ virtual void print() const;
+
+ // Functions can also be defined inside the class body.
+ // Functions defined as such are automatically inlined.
+ void bark() const { std::cout << name << " barks!\n" }
+
+ // Along with constructors, C++ provides destructors.
+ // These are called when an object is deleted or falls out of scope.
+ // This enables powerful paradigms such as RAII
+ // (see below)
+ // Destructors must be virtual to allow classes to be derived from this one.
+ virtual ~Dog();
+
+}; // A semicolon must follow the class definition.
+
+// Class member functions are usually implemented in .cpp files.
+void Dog::Dog()
+{
+ std::cout << "A dog has been constructed\n";
+}
+
+// Objects (such as strings) should be passed by reference
+// if you are modifying them or const reference if you are not.
+void Dog::setName(const std::string& dogsName)
+{
+ name = dogsName;
+}
+
+void Dog::setWeight(int dogsWeight)
+{
+ weight = dogsWeight;
+}
+
+// Notice that "virtual" is only needed in the declaration, not the definition.
+void Dog::print() const
+{
+ std::cout << "Dog is " << name << " and weighs " << weight << "kg\n";
+}
+
+void Dog::~Dog()
+{
+ cout << "Goodbye " << name << "\n";
+}
+
+int main() {
+ Dog myDog; // prints "A dog has been constructed"
+ myDog.setName("Barkley");
+ myDog.setWeight(10);
+ myDog.printDog(); // prints "Dog is Barkley and weighs 10 kg"
+ return 0;
+} // prints "Goodbye Barkley"
+
+// Inheritance:
+
+// This class inherits everything public and protected from the Dog class
+class OwnedDog : public Dog {
+
+ void setOwner(const std::string& dogsOwner)
+
+ // Override the behavior of the print function for all OwnedDogs. See
+ // http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Subtyping
+ // for a more general introduction if you are unfamiliar with
+ // subtype polymorphism.
+ // The override keyword is optional but makes sure you are actually
+ // overriding the method in a base class.
+ void print() const override;
+
+private:
+ std::string owner;
+};
+
+// Meanwhile, in the corresponding .cpp file:
+
+void OwnedDog::setOwner(const std::string& dogsOwner)
+{
+ owner = dogsOwner;
+}
+
+void OwnedDog::print() const
+{
+ Dog::print(); // Call the print function in the base Dog class
+ std::cout << "Dog is owned by " << owner << "\n";
+ // Prints "Dog is <name> and weights <weight>"
+ // "Dog is owned by <owner>"
+}
+
+//////////////////////////////////////////
+// Initialization and Operator Overloading
+//////////////////////////////////////////
+
+// In C++ you can overload the behavior of operators such as +, -, *, /, etc.
+// This is done by defining a function which is called
+// whenever the operator is used.
+
+#include <iostream>
+using namespace std;
+
+class Point {
+public:
+ // Member variables can be given default values in this manner.
+ double x = 0;
+ double y = 0;
+
+ // Define a default constructor which does nothing
+ // but initialize the Point to the default value (0, 0)
+ Point() { };
+
+ // The following syntax is known as an initialization list
+ // and is the proper way to initialize class member values
+ Point (double a, double b) :
+ x(a),
+ y(b)
+ { /* Do nothing except initialize the values */ }
+
+ // Overload the + operator.
+ Point operator+(const Point& rhs) const;
+
+ // Overload the += operator
+ Point& operator+=(const Point& rhs);
+
+ // It would also make sense to add the - and -= operators,
+ // but we will skip those for brevity.
+};
+
+Point Point::operator+(const Point& rhs) const
+{
+ // Create a new point that is the sum of this one and rhs.
+ return Point(x + rhs.x, y + rhs.y);
+}
+
+Point& Point::operator+=(const Point& rhs)
+{
+ x += rhs.x;
+ y += rhs.y;
+ return *this;
+}
+
+int main () {
+ Point up (0,1);
+ Point right (1,0);
+ // This calls the Point + operator
+ // Point up calls the + (function) with right as its paramater
+ Point result = up + right;
+ // Prints "Result is upright (1,1)"
+ cout << "Result is upright (" << result.x << ',' << result.y << ")\n";
+ return 0;
+}
+
+/////////////////////
+// Exception Handling
+/////////////////////
+
+// The standard library provides a few exception types
+// (see http://en.cppreference.com/w/cpp/error/exception)
+// but any type can be thrown an as exception
+#include <exception>
+
+// All exceptions thrown inside the _try_ block can be caught by subsequent
+// _catch_ handlers.
+try {
+ // Do not allocate exceptions on the heap using _new_.
+ throw std::exception("A problem occurred");
+}
+// Catch exceptions by const reference if they are objects
+catch (const std::exception& ex)
+{
+ std::cout << ex.what();
+// Catches any exception not caught by previous _catch_ blocks
+} catch (...)
+{
+ std::cout << "Unknown exception caught";
+ throw; // Re-throws the exception
+}
+
+///////
+// RAII
+///////
+
+// RAII stands for Resource Allocation Is Initialization.
+// It is often considered the most powerful paradigm in C++,
+// and is the simple concept that a constructor for an object
+// acquires that object's resources and the destructor releases them.
+
+// To understand how this is useful,
+// consider a function that uses a C file handle:
+void doSomethingWithAFile(const char* filename)
+{
+ // To begin with, assume nothing can fail.
+
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode.
+
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+
+ fclose(fh); // Close the file handle.
+}
+
+// Unfortunately, things are quickly complicated by error handling.
+// Suppose fopen can fail, and that doSomethingWithTheFile and
+// doSomethingElseWithIt return error codes if they fail.
+// (Exceptions are the preferred way of handling failure,
+// but some programmers, especially those with a C background,
+// disagree on the utility of exceptions).
+// We now have to check each call for failure and close the file handle
+// if a problem occurred.
+bool doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode
+ if (fh == nullptr) // The returned pointer is null on failure.
+ reuturn false; // Report that failure to the caller.
+
+ // Assume each function returns false if it failed
+ if (!doSomethingWithTheFile(fh)) {
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return false; // Propagate the error.
+ }
+ if (!doSomethingElseWithIt(fh)) {
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return false; // Propagate the error.
+ }
+
+ fclose(fh); // Close the file handle so it doesn't leak.
+ return true; // Indicate success
+}
+
+// C programmers often clean this up a little bit using goto:
+bool doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r");
+ if (fh == nullptr)
+ reuturn false;
+
+ if (!doSomethingWithTheFile(fh))
+ goto failure;
+
+ if (!doSomethingElseWithIt(fh))
+ goto failure;
+
+ fclose(fh); // Close the file
+ return true; // Indicate success
+
+failure:
+ fclose(fh);
+ return false; // Propagate the error
+}
+
+// If the functions indicate errors using exceptions,
+// things are a little cleaner, but still sub-optimal.
+void doSomethingWithAFile(const char* filename)
+{
+ FILE* fh = fopen(filename, "r"); // Open the file in read mode
+ if (fh == nullptr)
+ throw std::exception("Could not open the file.");
+
+ try {
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+ }
+ catch (...) {
+ fclose(fh); // Be sure to close the file if an error occurs.
+ throw; // Then re-throw the exception.
+ }
+
+ fclose(fh); // Close the file
+ // Everything succeeded
+}
+
+// Compare this to the use of C++'s file stream class (fstream)
+// fstream uses its destructor to close the file.
+// Recall from above that destructors are automatically called
+// whenver an object falls out of scope.
+void doSomethingWithAFile(const std::string& filename)
+{
+ // ifstream is short for input file stream
+ std::ifstream fh(filename); // Open the file
+
+ // Do things with the file
+ doSomethingWithTheFile(fh);
+ doSomethingElseWithIt(fh);
+
+} // The file is automatically closed here by the destructor
+
+// This has _massive_ advantages:
+// 1. No matter what happens,
+// the resource (in this case the file handle) will be cleaned up.
+// Once you write the destructor correctly,
+// It is _impossible_ to forget to close the handle and leak the resource.
+// 2. Note that the code is much cleaner.
+// The destructor handles closing the file behind the scenes
+// without you having to worry about it.
+// 3. The code is exception safe.
+// An exception can be thrown anywhere in the function and cleanup
+// will still occur.
+
+// All idiomatic C++ code uses RAII extensively for all resources.
+// Additional examples include
+// - Memory using unique_ptr and shared_ptr
+// - Containers - the standard library linked list,
+// vector (i.e. self-resizing array), hash maps, and so on
+// all automatically destroy their contents when they fall out of scope.
+// - Mutexes using lock_guard and unique_lock
+```
+Futher Reading:
+
+An up-to-date language reference can be found at
+<http://cppreference.com/w/cpp>
+
+Additional resources may be found at <http://cplusplus.com>
diff --git a/c.html.markdown b/c.html.markdown
index 8e170300..b5b804af 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -4,6 +4,8 @@ filename: learnc.c
contributors:
- ["Adam Bard", "http://adambard.com/"]
- ["Árpád Goretity", "http://twitter.com/H2CO3_iOS"]
+ - ["Jakub Trzebiatowski", "http://cbs.stgn.pl"]
+ - ["Marco Scannadinari", "https://marcoms.github.io"]
---
@@ -20,13 +22,19 @@ memory management and C will take you as far as you need to go.
Multi-line comments look like this. They work in C89 as well.
*/
- // Constants: #define <keyword>
+/*
+Multi-line comments don't nest /* Be careful */ // comment ends on this line...
+*/ // ...not this one!
+
+// Constants: #define <keyword>
#define DAYS_IN_YEAR 365
- // Enumeration constants are also ways to declare constants.
- enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
+// Enumeration constants are also ways to declare constants.
+// All statements must end with a semicolon
+enum days {SUN = 1, MON, TUE, WED, THU, FRI, SAT};
// MON gets 2 automatically, TUE gets 3, etc.
+
// Import headers with #include
#include <stdlib.h>
#include <stdio.h>
@@ -51,7 +59,6 @@ int main() {
// print output using printf, for "print formatted"
// %d is an integer, \n is a newline
printf("%d\n", 0); // => Prints 0
- // All statements must end with a semicolon
///////////////////////////////////////
// Types
@@ -73,12 +80,12 @@ int main() {
long long x_long_long = 0;
// floats are usually 32-bit floating point numbers
- float x_float = 0.0;
+ float x_float = 0.0f; // 'f' suffix here denotes floating point literal
// doubles are usually 64-bit floating-point numbers
- double x_double = 0.0;
+ double x_double = 0.0; // real numbers without any suffix are doubles
- // Integral types may be unsigned.
+ // integer types may be unsigned (only positive)
unsigned short ux_short;
unsigned int ux_int;
unsigned long long ux_long_long;
@@ -175,6 +182,9 @@ int main() {
i2 * i1; // => 2
i1 / i2; // => 0 (0.5, but truncated towards 0)
+ // You need to cast at least one integer to float to get a floating-point result
+ (float)i1 / i2 // => 0.5f
+ i1 / (double)i2 // => 0.5 // Same with double
f1 / f2; // => 0.5, plus or minus epsilon
// Floating-point numbers and calculations are not exact
@@ -194,9 +204,11 @@ int main() {
2 >= 2; // => 1
// C is not Python - comparisons don't chain.
- // WRONG:
- //int between_0_and_2 = 0 < a < 2;
- // Correct:
+ // Warning: The line below will compile, but it means `(0 < a) < 2`.
+ // This expression is always true, because (0 < a) could be either 1 or 0.
+ // In this case it's 1, because (0 < 1).
+ int between_0_and_2 = 0 < a < 2;
+ // Instead use:
int between_0_and_2 = 0 < a && a < 2;
// Logic works on ints
@@ -211,7 +223,7 @@ int main() {
int e = 5;
int f = 10;
int z;
- z = (a > b) ? a : b; // => 10 "if a > b return a, else return b."
+ z = (e > f) ? e : f; // => 10 "if e > f return e, else return f."
//Increment and decrement operators:
char *s = "iLoveC";
@@ -573,7 +585,7 @@ typedef void (*my_fnp_type)(char *);
'\''; // single quote
'\"'; // double quote
'\xhh'; // hexadecimal number. Example: '\xb' = vertical tab character
-'\ooo'; // octal number. Example: '\013' = vertical tab character
+'\0oo'; // octal number. Example: '\013' = vertical tab character
//print formatting:
"%d"; // integer
@@ -618,7 +630,7 @@ typedef void (*my_fnp_type)(char *);
## Further Reading
Best to find yourself a copy of [K&R, aka "The C Programming Language"](https://en.wikipedia.org/wiki/The_C_Programming_Language)
-It is *the* book about C, written by the creators of C. Be careful, though - it's ancient and it contains some
+It is *the* book about C, written by Dennis Ritchie, the creator of C, and Brian Kernighan. Be careful, though - it's ancient and it contains some
inaccuracies (well, ideas that are not considered good anymore) or now-changed practices.
Another good resource is [Learn C the hard way](http://c.learncodethehardway.org/book/).
diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown
index d96eed39..4c080bc6 100644
--- a/coffeescript.html.markdown
+++ b/coffeescript.html.markdown
@@ -11,7 +11,7 @@ As one of the succeeders of JavaScript, CoffeeScript tries its best to output re
See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript.
-``` coffeescript
+```coffeescript
# CoffeeScript is a hipster language.
# It goes with the trends of many modern languages.
# So comments are like Ruby and Python, they use number symbols.
@@ -20,7 +20,7 @@ See also [the CoffeeScript website](http://coffeescript.org/), which has a compl
Block comments are like these, and they translate directly to '/ *'s and '* /'s
for the resulting JavaScript code.
-You should understand most of JavaScript semantices
+You should understand most of JavaScript semantics
before continuing.
###
diff --git a/common-lisp.html.markdown b/common-lisp.html.markdown
index 8de81549..c4ecb5e8 100644
--- a/common-lisp.html.markdown
+++ b/common-lisp.html.markdown
@@ -17,7 +17,7 @@ Another popular and recent book is
-```scheme
+```common_lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 0. Syntax
@@ -431,7 +431,7 @@ nil ; for false - and the empty list
:walked
(walker (1- n))))
-(walker) ; => :walked
+(walker 5) ; => :walked
;; Most of the time, we use DOLIST or LOOP
diff --git a/compojure.html.markdown b/compojure.html.markdown
new file mode 100644
index 00000000..36a8d123
--- /dev/null
+++ b/compojure.html.markdown
@@ -0,0 +1,280 @@
+---
+category: tool
+tool: compojure
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+filename: learncompojure.clj
+---
+
+## Getting Started with Compojure
+
+Compojure is a DSL for *quickly* creating *performant* web applications
+in Clojure with minimal effort:
+
+```clojure
+(ns myapp.core
+ (:require [compojure.core :refer :all]
+ [org.httpkit.server :refer [run-server]])) ; httpkit is a server
+
+(defroutes myapp
+ (GET "/" [] "Hello World"))
+
+(defn -main []
+ (run-server myapp {:port 5000}))
+```
+
+**Step 1:** Create a project with [Leiningen](http://leiningen.org/):
+
+```
+lein new myapp
+```
+
+**Step 2:** Put the above code in `src/myapp/core.clj`
+
+**Step 3:** Add some dependencies to `project.clj`:
+
+```
+[compojure "1.1.8"]
+[http-kit "2.1.16"]
+```
+
+**Step 4:** Run:
+
+```
+lein run -m myapp.core
+```
+
+View at: <http://localhost:5000/>
+
+Compojure apps will run on any ring-compatible server, but we recommend
+[http-kit](http://http-kit.org/) for its performance and
+[massive concurrency](http://http-kit.org/600k-concurrent-connection-http-kit.html).
+
+### Routes
+
+In compojure, each route is an HTTP method paired with a URL-matching pattern,
+an argument list, and a body.
+
+```clojure
+(defroutes myapp
+ (GET "/" [] "Show something")
+ (POST "/" [] "Create something")
+ (PUT "/" [] "Replace something")
+ (PATCH "/" [] "Modify Something")
+ (DELETE "/" [] "Annihilate something")
+ (OPTIONS "/" [] "Appease something")
+ (HEAD "/" [] "Preview something"))
+```
+
+Compojure route definitions are just functions which
+[accept request maps and return response maps](https://github.com/mmcgrana/ring/blob/master/SPEC):
+
+```clojure
+(myapp {:uri "/" :request-method :post})
+; => {:status 200
+; :headers {"Content-Type" "text/html; charset=utf-8}
+; :body "Create Something"}
+```
+
+The body may be a function, which must accept the request as a parameter:
+
+```clojure
+(defroutes myapp
+ (GET "/" [] (fn [req] "Do something with req")))
+```
+
+Or, you can just use the request directly:
+
+```clojure
+(defroutes myapp
+ (GET "/" req "Do something with req"))
+```
+
+Route patterns may include named parameters:
+
+```clojure
+(defroutes myapp
+ (GET "/hello/:name" [name] (str "Hello " name)))
+```
+
+You can adjust what each parameter matches by supplying a regex:
+
+```clojure
+(defroutes myapp
+ (GET ["/file/:name.:ext" :name #".*", :ext #".*"] [name ext]
+ (str "File: " name ext)))
+```
+
+### Middleware
+
+Clojure uses [Ring](https://github.com/ring-clojure/ring) for routing.
+Handlers are just functions that accept a request map and return a
+response map (Compojure will turn strings into 200 responses for you).
+
+You can easily write middleware that wraps all or part of your
+application to modify requests or responses:
+
+```clojure
+(defroutes myapp
+ (GET "/" req (str "Hello World v" (:app-version req))))
+
+(defn wrap-version [handler]
+ (fn [request]
+ (handler (assoc request :app-version "1.0.1"))))
+
+(defn -main []
+ (run-server (wrap-version myapp) {:port 5000}))
+```
+
+[Ring-Defaults](https://github.com/ring-clojure/ring-defaults) provides some handy
+middlewares for sites and apis, so add it to your dependencies:
+
+```
+[ring/ring-defaults "0.1.1"]
+```
+
+Then, you can import it in your ns:
+
+```
+(ns myapp.core
+ (:require [compojure.core :refer :all]
+ [ring.middleware.defaults :refer :all]
+ [org.httpkit.server :refer [run-server]]))
+```
+
+And use `wrap-defaults` to add the `site-defaults` middleware to your
+app:
+
+```
+(defn -main []
+ (run-server (wrap-defaults myapp site-defaults) {:port 5000}))
+```
+
+Now, your handlers may utilize query parameters:
+
+```clojure
+(defroutes myapp
+ (GET "/posts" req
+ (let [title (get (:params req) "title")
+ author (get (:params req) "author")]
+ (str "Title: " title ", Author: " author))))
+```
+
+Or, for POST and PUT requests, form parameters as well
+
+```clojure
+(defroutes myapp
+ (POST "/posts" req
+ (let [title (get (:params req) "title")
+ author (get (:params req) "author")]
+ (str "Title: " title ", Author: " author))))
+```
+
+
+### Return values
+
+The return value of a route block determines the response body
+passed on to the HTTP client, or at least the next middleware in the
+ring stack. Most commonly, this is a string, as in the above examples.
+But, you may also return a [response map](https://github.com/mmcgrana/ring/blob/master/SPEC):
+
+```clojure
+(defroutes myapp
+ (GET "/" []
+ {:status 200 :body "Hello World"})
+ (GET "/is-403" []
+ {:status 403 :body ""})
+ (GET "/is-json" []
+ {:status 200 :headers {"Content-Type" "application/json"} :body "{}"}))
+```
+
+### Static Files
+
+To serve up static files, use `compojure.route.resources`.
+Resources will be served from your project's `resources/` folder.
+
+```clojure
+(require '[compojure.route :as route])
+
+(defroutes myapp
+ (GET "/")
+ (route/resources "/")) ; Serve static resources at the root path
+
+(myapp {:uri "/js/script.js" :request-method :get})
+; => Contents of resources/public/js/script.js
+```
+
+### Views / Templates
+
+To use templating with Compojure, you'll need a template library. Here are a few:
+
+#### [Stencil](https://github.com/davidsantiago/stencil)
+
+[Stencil](https://github.com/davidsantiago/stencil) is a [Mustache](http://mustache.github.com/) template library:
+
+```clojure
+(require '[stencil.core :refer [render-string]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-string "Hello {{name}}" {:name name})))
+```
+
+You can easily read in templates from your resources directory. Here's a helper function
+
+```clojure
+(require 'clojure.java.io)
+
+(defn read-template [filename]
+ (slurp (clojure.java.io/resource filename)))
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-string (read-template "templates/hello.html") {:name name})))
+```
+
+#### [Selmer](https://github.com/yogthos/Selmer)
+
+[Selmer](https://github.com/yogthos/Selmer) is a Django and Jinja2-inspired templating language:
+
+```clojure
+(require '[selmer.parser :refer [render-file]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (render-file "templates/hello.html" {:name name})))
+```
+
+#### [Hiccup](https://github.com/weavejester/hiccup)
+
+[Hiccup](https://github.com/weavejester/hiccup) is a library for representing HTML as Clojure code
+
+```clojure
+(require '[hiccup.core :as hiccup])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (hiccup/html
+ [:html
+ [:body
+ [:h1 {:class "title"}
+ (str "Hello " name)]]])))
+```
+
+#### [Markdown](https://github.com/yogthos/markdown-clj)
+
+[Markdown-clj](https://github.com/yogthos/markdown-clj) is a Markdown implementation.
+
+```clojure
+(require '[markdown.core :refer [md-to-html-string]])
+
+(defroutes myapp
+ (GET "/hello/:name" [name]
+ (md-to-html-string "## Hello, world")))
+```
+
+Further reading:
+
+* [Official Compojure Documentation](https://github.com/weavejester/compojure/wiki)
+
+* [Clojure for the Brave and True](http://www.braveclojure.com/)
diff --git a/csharp.html.markdown b/csharp.html.markdown
index 136f6c50..47dd9683 100644
--- a/csharp.html.markdown
+++ b/csharp.html.markdown
@@ -508,7 +508,7 @@ on a new line! ""Wow!"", the masses cried";
// LINQ - maps a store to IQueryable<T> objects, with delayed execution
// e.g. LinqToSql - maps to a database, LinqToXml maps to an xml document
- var db = new BikeRespository();
+ var db = new BikeRepository();
// execution is delayed, which is great when querying a database
var filter = db.Bikes.Where(b => b.HasTassles); // no query run
@@ -678,6 +678,23 @@ on a new line! ""Wow!"", the masses cried";
private set;
}
+ // It's also possible to define custom Indexers on objects.
+ // All though this is not entirely useful in this example, you
+ // could do bicycle[0] which yields "chris" to get the first passenger or
+ // bicycle[1] = "lisa" to set the passenger. (of this apparent quattrocycle)
+ private string[] passengers = { "chris", "phil", "darren", "regina" }
+
+ public string this[int i]
+ {
+ get {
+ return passengers[i];
+ }
+
+ set {
+ return passengers[i] = value;
+ }
+ }
+
//Method to display the attribute values of this Object.
public virtual string Info()
{
@@ -767,9 +784,9 @@ on a new line! ""Wow!"", the masses cried";
/// EntityFramework Code First is awesome (similar to Ruby's ActiveRecord, but bidirectional)
/// http://msdn.microsoft.com/en-us/data/jj193542.aspx
/// </summary>
- public class BikeRespository : DbSet
+ public class BikeRepository : DbSet
{
- public BikeRespository()
+ public BikeRepository()
: base()
{
}
diff --git a/css.html.markdown b/css.html.markdown
index cdef50cc..e058d691 100644
--- a/css.html.markdown
+++ b/css.html.markdown
@@ -3,6 +3,7 @@ language: css
contributors:
- ["Mohammad Valipour", "https://github.com/mvalipour"]
- ["Marco Scannadinari", "https://github.com/marcoms"]
+ - ["Geoffrey Liu", "https://github.com/g-liu"]
filename: learncss.css
---
@@ -24,18 +25,19 @@ The main focus of this article is on the syntax and some general tips.
```css
-/* comments appear inside slash-asterisk, just like this line! */
+/* comments appear inside slash-asterisk, just like this line!
+ there are no "one-line comments"; this is the only comment style */
/* ####################
## SELECTORS
- ####################*/
+ #################### */
/* Generally, the primary statement in CSS is very simple */
selector { property: value; /* more properties...*/ }
/* the selector is used to target an element on page.
-You can target all elments on the page! */
+You can target all elments on the page using asterisk! */
* { color:red; }
/*
@@ -62,61 +64,61 @@ div { }
/* or that the attribute has a specific value */
[attr='value'] { font-size:smaller; }
-/* start with a value*/
+/* start with a value (CSS3) */
[attr^='val'] { font-size:smaller; }
-/* or ends with */
+/* or ends with (CSS3) */
[attr$='ue'] { font-size:smaller; }
-/* or even contains a value */
+/* or even contains a value (CSS3) */
[attr~='lu'] { font-size:smaller; }
/* and more importantly you can combine these together -- there shouldn't be
-any spaaace between different parts because that makes it to have another
-meaning.*/
+any space between different parts because that makes it to have another
+meaning. */
div.some-class[attr$='ue'] { }
-/* you can also select an element based on its parent.*/
+/* you can also select an element based on its parent. */
-/*an element which is direct child of an element (selected the same way) */
+/* an element which is direct child of an element (selected the same way) */
div.some-parent > .class-name {}
-/* or any of its parents in the tree */
-/* the following basically means any element that has class "class-name"
-and is child of a div with class name "some-parent" IN ANY DEPTH */
+/* or any of its parents in the tree
+ the following basically means any element that has class "class-name"
+ and is child of a div with class name "some-parent" IN ANY DEPTH */
div.some-parent .class-name {}
/* warning: the same selector wihout spaaace has another meaning.
-can you say what? */
+ can you say what? */
div.some-parent.class-name {}
/* you also might choose to select an element based on its direct
-previous sibling */
+ previous sibling */
.i-am-before + .this-element { }
-/*or any sibling before this */
+/* or any sibling before this */
.i-am-any-before ~ .this-element {}
/* There are some pseudo classes that allows you to select an element
-based on its page behaviour (rather than page structure) */
+ based on its page behaviour (rather than page structure) */
/* for example for when an element is hovered */
-:hover {}
+selector:hover {}
-/* or a visited link*/
-:visited {}
+/* or a visited link */
+selected:visited {}
-/* or not visited link*/
-:link {}
+/* or not visited link */
+selected:link {}
/* or an input element which is focused */
-:focus {}
+selected:focus {}
/* ####################
## PROPERTIES
- ####################*/
+ #################### */
selector {
@@ -126,8 +128,12 @@ selector {
width: 200px; /* in pixels */
font-size: 20pt; /* in points */
width: 5cm; /* in centimeters */
- width: 50mm; /* in millimeters */
- width: 5in; /* in inches */
+ min-width: 50mm; /* in millimeters */
+ max-width: 5in; /* in inches. max-(width|height) */
+ height: 0.2vh; /* times vertical height of browser viewport (CSS3) */
+ width: 0.4vw; /* times horizontal width of browser viewport (CSS3) */
+ min-height: 0.1vmin; /* the lesser of vertical, horizontal dimensions of browser viewport (CSS3) */
+ max-width: 0.3vmax; /* same as above, except the greater of the dimensions (CSS3) */
/* Colors */
background-color: #F6E; /* in short hex */
@@ -135,16 +141,20 @@ selector {
background-color: tomato; /* can be a named color */
background-color: rgb(255, 255, 255); /* in rgb */
background-color: rgb(10%, 20%, 50%); /* in rgb percent */
- background-color: rgba(255, 0, 0, 0.3); /* in semi-transparent rgb */
+ background-color: rgba(255, 0, 0, 0.3); /* in semi-transparent rgb (CSS3) */
+ background-color: transparent; /* see thru */
+ background-color: hsl(0, 100%, 50%); /* hsl format (CSS3). */
+ background-color: hsla(0, 100%, 50%, 0.3); /* Similar to RGBA, specify opacity at end (CSS3) */
+
/* Images */
- background-image: url(/path-to-image/image.jpg);
+ background-image: url(/path-to-image/image.jpg); /* quotes inside url() optional */
/* Fonts */
font-family: Arial;
- font-family: "Courier New"; /* if name has spaaace it appears in double-quote */
- font-family: "Courier New", Trebuchet, Arial; /* if first one was not found
- browser uses the second font, and so forth */
+ font-family: "Courier New"; /* if name has spaaace it appears in single or double quotes */
+ font-family: "Courier New", Trebuchet, Arial, sans-serif; /* if first one was not found
+ browser uses the second font, and so forth */
}
```
@@ -155,17 +165,17 @@ Save any CSS you want in a file with extension `.css`.
```xml
<!-- you need to include the css file in your page's <head>: -->
-<link rel='stylesheet' type='text/css' href='filepath/filename.css' />
+<link rel='stylesheet' type='text/css' href='path/to/style.css' />
<!-- you can also include some CSS inline in your markup. However it is highly
recommended to avoid this. -->
<style>
- selector { property:value; }
+ a { color: purple; }
</style>
<!-- or directly set CSS properties on the element.
This has to be avoided as much as you can. -->
-<div style='property:value;'>
+<div style="border: 1px solid red;">
</div>
```
@@ -207,27 +217,28 @@ The precedence of style is as followed:
Remember, the precedence is for each **property**, not for the entire block.
* `E` has the highest precedence because of the keyword `!important`.
- It is recommended to avoid this unless it is strictly necessary to use.
+ It is recommended to avoid this unless it is strictly necessary to use.
* `F` is next, because it is inline style.
* `A` is next, because it is more "specific" than anything else.
- more specific = more specifiers. here 3 specifiers: 1 tagname `p` +
- class name `class1` + 1 attribute `attr='value'`
+ more specific = more specifiers. here 3 specifiers: 1 tagname `p` +
+ class name `class1` + 1 attribute `attr='value'`
* `C` is next. although it has the same specificness as `B`
- but it appears last.
+ but it appears last.
* Then is `B`
* and lastly is `D`.
## Compatibility
Most of the features in CSS2 (and gradually in CSS3) are compatible across
-all browsers and devices. But it's always vital to have in mind the compatiblity
+all browsers and devices. But it's always vital to have in mind the compatiblity
of what you use in CSS with your target browsers.
[QuirksMode CSS](http://www.quirksmode.org/css/) is one of the best sources for this.
+To run a quick compatibility check, [CanIUse](http://caniuse.com) is a great resource.
+
## Further Reading
* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
* [QuirksMode CSS](http://www.quirksmode.org/css/)
* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
-
diff --git a/de-de/csharp-de.html.markdown b/de-de/csharp-de.html.markdown
new file mode 100644
index 00000000..dc77dda0
--- /dev/null
+++ b/de-de/csharp-de.html.markdown
@@ -0,0 +1,889 @@
+---
+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:
+ - ["Frederik Ring", "https://github.com/m90"]
+filename: LearnCSharp-de.cs
+lang: de-de
+---
+C# ist eine elegante, typsichere und objektorientierte Sprache, mit der Entwickler eine Vielzahl sicherer und robuster Anwendungen erstellen können, die im .NET Framework ausgeführt werden.
+
+[Mehr über C# erfährst du hier.](http://msdn.microsoft.com/de-de/library/vstudio/z1zx9t92.aspx)
+
+```c#
+// Einzeilige Kommentare starten mit zwei Schrägstrichen: //
+/*
+Mehrzeile Kommentare wie in C Schrägstrich / Stern
+*/
+/// <summary>
+/// XML-Kommentare können zur automatisierten Dokumentation verwendet werden
+/// </summary>
+
+// Zu Beginn werden die in der Datei verwendeten Namespaces aufgeführt
+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;
+
+// definiert einen Namespace um Code in "packages" zu organisieren
+namespace Learning
+{
+ // Jede .cs-Datei sollte zumindest eine Klasse mit dem Namen der Datei
+ // enthalten. Das ist zwar nicht zwingend erforderlich, es anders zu
+ // handhaben führt aber unweigerlich ins Chaos (wirklich)!
+ public class LearnCSharp
+ {
+ // Zuerst erklärt dieses Tutorial die Syntax-Grundlagen,
+ // wenn du bereits Java oder C++ programmieren kannst:
+ // lies bei "Interessante Features" weiter!
+ public static void Syntax()
+ {
+ // Mit Console.WriteLine kannst du einfachen Text ausgeben:
+ Console.WriteLine("Hallo Welt");
+ Console.WriteLine(
+ "Integer: " + 10 +
+ " Double: " + 3.14 +
+ " Boolean: " + true);
+
+ // Console.Write erzeugt keinen Zeilenumbruch
+ Console.Write("Hallo ");
+ Console.Write("Welt");
+
+ ///////////////////////////////////////////////////
+ // Typen & Variablen
+ ///////////////////////////////////////////////////
+
+ // Deklariere eine Variable mit <Typ> <Name>
+
+ // Sbyte - Vorzeichenbehaftete 8-Bit Ganzzahl
+ // (-128 <= sbyte <= 127)
+ sbyte fooSbyte = 100;
+
+ // Byte - Vorzeichenlose 8-Bit Ganzzahl
+ // (0 <= byte <= 255)
+ byte fooByte = 100;
+
+ // Short - 16-Bit Ganzzahl
+ // Vorzeichenbehaftet - (-32,768 <= short <= 32,767)
+ // Vorzeichenlos - (0 <= ushort <= 65,535)
+ short fooShort = 10000;
+ ushort fooUshort = 10000;
+
+ // Integer - 32-bit Ganzzahl
+ int fooInt = 1; // (-2,147,483,648 <= int <= 2,147,483,647)
+ uint fooUint = 1; // (0 <= uint <= 4,294,967,295)
+
+ // Long - 64-bit Ganzzahl
+ 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)
+ // Ganze Zahlen werden standardmäßig - je nach Größe - als int oder
+ // uint behandelt. Ein nachgestelltes L markiert den Wert als long
+ // oder ulong.
+
+ // Double - Double-precision 64-bit IEEE 754 Fließkommazahl
+ double fooDouble = 123.4; // Genauigkeit: 15-16 Stellen
+
+ // Float - Single-precision 32-bit IEEE 754 Fließkommazahl
+ float fooFloat = 234.5f; // Genauigkeit: 7 Stellen
+ // Das nachgestellte f zeigt an dass es sich um einen Wert vom Typ
+ // float handelt
+
+ // Decimal - ein 128-Bit-Datentyp mit größerer Genauigkeit als
+ // andere Fließkommatypen, und somit bestens geeignet für
+ // die Berechnung von Geld- und Finanzwerten
+ decimal fooDecimal = 150.3m;
+
+ // Boolean - true & false
+ bool fooBoolean = true; // oder false
+
+ // Char - Ein einzelnes 16-Bit Unicode Zeichen
+ char fooChar = 'A';
+
+ // Strings - im Gegensatz zu allen vorhergehenden Basistypen, die
+ // alle Werttypen sind, ist String ein Referenztyp. Strings sind
+ // somit nullable, Werttypen sind dies nicht.
+ string fooString = "\"maskiere\" Anführungszeichen, und füge \n (Umbrüche) und \t (Tabs) hinzu";
+ Console.WriteLine(fooString);
+
+ // Jeder Buchstabe eines Strings kann über seinen Index
+ // referenziert werden:
+ char charFromString = fooString[1]; // => 'e'
+ // Strings sind unveränderlich:
+ // `fooString[1] = 'X';` funktioniert nicht
+
+ // Ein Vergleich zweier Strings, unter Berücksichtigung der
+ // aktuellen, sprachspezifischen Gegebenheiten (also z.B. a,ä,b,c
+ // in deutschsprachigen Umgebungen), und ohne Beachtung von
+ // Groß- und Kleinschreibung:
+ string.Compare(fooString, "x", StringComparison.CurrentCultureIgnoreCase);
+
+ // Formatierung, genau wie "sprintf"
+ string fooFs = string.Format("Mikrofon Check, {0} {1}, {0} {1:0.0}", 1, 2);
+
+ // Datumsangaben und Formatierung
+ DateTime fooDate = DateTime.Now;
+ Console.WriteLine(fooDate.ToString("hh:mm, dd MMM yyyy"));
+
+ // Durch ein vorangestelltes @ lässt sich ein mehrzeiliger String
+ // schreiben. Um " zu maskieren benutzt man ""
+ string bazString = @"Hier geht es
+zur nächsten Zeile, ""Wahnsinn!"", die Massen waren kaum zu bändigen";
+
+ // Die Keywords const oder readonly kennzeichnen eine
+ // unveränderliche Variable/Konstante. Die Werte von Konstanten
+ // werden übrigens bereits zur Compile-Zeit berechnet.
+ const int HOURS_I_WORK_PER_WEEK = 9001;
+
+ ///////////////////////////////////////////////////
+ // Datenstrukturen
+ ///////////////////////////////////////////////////
+
+ // Arrays - Index beginnt bei Null
+ // Die Größe des Arrays wird bei der Deklaration festgelegt.
+ // Die syntaktische Struktur um ein neues Array zu erzeugen sieht
+ // folgendermaßen aus:
+ // <datatype>[] <varname> = new <datatype>[<array size>];
+ int[] intArray = new int[10];
+
+ // Arrays können auch über ein Array-Literal deklariert werden:
+ int[] y = { 9000, 1000, 1337 };
+
+ // Indizierung eines Arrays - Zugriff auf ein bestimmtes Element
+ Console.WriteLine("intArray @ 0: " + intArray[0]);
+ // Arrays sind veränderbar
+ intArray[1] = 1;
+
+ // Listen
+ // Durch ihre größere Flexibilität kommen Listen in C# weit
+ // häufiger zum Einsatz als Arrays. Eine Liste wird so deklariert:
+ // List<datatype> <varname> = new List<datatype>();
+ List<int> intList = new List<int>();
+ List<string> stringList = new List<string>();
+ List<int> z = new List<int> { 9000, 1000, 1337 };
+ // Die <> kennzeichnen "Generics", mehr dazu unter "Coole Sachen"
+
+ // Listen haben keinen Default-Wert.
+ // Bevor auf einen Index zugegriffen werden kann, muss dieser
+ // auch gesetzt worden sein:
+ intList.Add(1);
+ Console.WriteLine("intList @ 0: " + intList[0]);
+
+ // Andere interessante Datenstrukturen sind:
+ // Stack/Queue
+ // Dictionary (entspricht einer Hash Map)
+ // HashSet
+ // Read-only Collections
+ // Tuple (.Net 4+)
+
+ ///////////////////////////////////////
+ // Operatoren
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Operatoren");
+
+ // kurze Schreibweise um mehrere Deklarationen zusammenzufassen:
+ // (Benutzung vom C# Styleguide aber ausdrücklich abgeraten!)
+ int i1 = 1, i2 = 2;
+
+ // Arithmetik funktioniert wie erwartet:
+ Console.WriteLine(i1 + i2 - i1 * 3 / 7); // => 3
+
+ // Modulo
+ Console.WriteLine("11%3 = " + (11 % 3)); // => 2
+
+ // Vergleiche
+ 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
+
+ // Bitweise Operatoren
+ /*
+ ~ Unäres bitweises NICHT
+ << Verschieben nach links
+ >> Verschieben nach rechts
+ & Bitweises UND
+ ^ Bitweises exklusives ODER
+ | Bitweises inklusives ODER
+ */
+
+ // Inkremente
+ int i = 0;
+ Console.WriteLine("\n->Inkrement / Dekrement");
+ Console.WriteLine(i++); //i = 1. Post-Inkrement
+ Console.WriteLine(++i); //i = 2. Pre-Inkrement
+ Console.WriteLine(i--); //i = 1. Post-Dekrement
+ Console.WriteLine(--i); //i = 0. Pre-Dekrement
+
+ ///////////////////////////////////////
+ // Kontrollstrukturen
+ ///////////////////////////////////////
+ Console.WriteLine("\n->Kontrollstrukturen");
+
+ // If-Statements funktionieren wie in C
+ int j = 10;
+ if (j == 10)
+ {
+ Console.WriteLine("Ich werde ausgegeben");
+ }
+ else if (j > 10)
+ {
+ Console.WriteLine("Ich nicht");
+ }
+ else
+ {
+ Console.WriteLine("Ich leider auch nicht");
+ }
+
+ // Ternärer Operator
+ // Anstatt eines einfachen if/else lässt sich auch folgendes schreiben:
+ // <condition> ? <true> : <false>
+ string isTrue = true ? "Ja" : "Nein";
+
+ // while-Schleife
+ int fooWhile = 0;
+ while (fooWhile < 100)
+ {
+ // Wird 100mal wiederholt, fooWhile 0->99
+ fooWhile++;
+ }
+
+ // do-while-Schleife
+ int fooDoWhile = 0;
+ do
+ {
+ // Wird 100mal wiederholt, fooDoWhile 0->99
+ fooDoWhile++;
+ } while (fooDoWhile < 100);
+
+ //for-Schleifen => for(<start_statement>; <conditional>; <step>)
+ for (int fooFor = 0; fooFor < 10; fooFor++)
+ {
+ // Wird 10mal wiederholt, fooFor 0->9
+ }
+
+ // foreach-Schleife
+ // Die normale Syntax für eine foreach-Schleife lautet:
+ // foreach(<iteratorType> <iteratorName> in <enumerable>)
+ // foreach kann mit jedem Objekt verwendet werden das IEnumerable
+ // oder IEnumerable<T> implementiert. Alle Auflistungs-Typen
+ // (Array, List, Dictionary...) im .NET Framework implementieren
+ // eines dieser beiden Interfaces.
+
+ foreach (char character in "Hallo Welt".ToCharArray())
+ {
+ // Ein Durchgang für jedes Zeichen im String
+ }
+ // (ToCharArray() könnte man hier übrigens auch weglassen,
+ // da String IEnumerable bereits implementiert)
+
+ // Switch Struktur
+ // Ein Switch funktioniert mit byte, short, char und int Datentypen.
+ // Auch Aufzählungstypen können verwendet werden, genau wie
+ // die Klasse String, und ein paar Sonderklassen, die Wrapper für
+ // Primitives sind: Character, Byte, Short und Integer
+ int month = 3;
+ string monthString;
+ switch (month)
+ {
+ case 1:
+ monthString = "Januar";
+ break;
+ case 2:
+ monthString = "Februar";
+ break;
+ case 3:
+ monthString = "März";
+ break;
+ // Man kann für mehrere Fälle auch das selbe Verhalten
+ // definieren. Jeder Block muss aber mit einem break-Statement
+ // abgeschlossen werden. Einzelne Fälle können über
+ // `goto case x` erreicht werden
+ case 6:
+ case 7:
+ case 8:
+ monthString = "Sommer!!";
+ break;
+ default:
+ monthString = "Irgendein anderer Monat";
+ break;
+ }
+
+ ///////////////////////////////////////
+ // Umwandlung von Datentypen und Typecasting
+ ///////////////////////////////////////
+
+ // Umwandlung
+
+ // von String nach Integer
+ // bei einem Fehler wirft diese Code eine Exception
+ int.Parse("123"); //gibt die Ganzzahl 123 zurück
+
+ // TryParse gibt bei einem Fehler den Default-Wert zurück
+ // (im Fall von int: 0)
+ int tryInt;
+ if (int.TryParse("123", out tryInt)) // gibt true oder false zurück
+ {
+ Console.WriteLine(tryInt); // 123
+ }
+
+ // von Integer nach String
+ // Die Klasse Convert stellt Methoden zur Konvertierung von
+ // unterschiedlichsten Daten zur Verfügung:
+ Convert.ToString(123); // "123"
+ // oder
+ tryInt.ToString(); // "123"
+ }
+
+ ///////////////////////////////////////
+ // Klassen
+ ///////////////////////////////////////
+ public static void Classes()
+ {
+
+ // Benutze das new-Keyword um eine Instanz einer Klasse zu erzeugen
+ Bicycle trek = new Bicycle();
+
+ // So werden Methoden der Instanz aufgerufen
+ trek.SpeedUp(3); // Es empfiehlt sich immer Getter und Setter zu benutzen
+ trek.Cadence = 100;
+
+ // ToString ist eine Konvention über die man üblicherweiser
+ // Informationen über eine Instanz erhält
+ Console.WriteLine("Infos zu trek: " + trek.ToString());
+
+ // Wir instantiieren ein neues Hochrad
+ PennyFarthing funbike = new PennyFarthing(1, 10);
+ Console.WriteLine("Infos zu funbike: " + funbike.ToString());
+
+ Console.Read();
+ } // Ende der Methode main
+
+ // Main als Konsolenstartpunkt
+ // Eine Konsolenanwendung muss eine Methode Main als Startpunkt besitzen
+ public static void Main(string[] args)
+ {
+ OtherInterestingFeatures();
+ }
+
+ ///////////////////////////////////////
+ // Interessante Features
+ ///////////////////////////////////////
+
+ // Methodensignaturen
+
+ public // Sichtbarkeit
+ static // Erlaubt einen Zugriff auf der Klasse (nicht auf einer Instanz)
+ int // Typ des Rückgabewerts,
+ MethodSignatures(
+ // Erstes Argument, erwartet int
+ int maxCount,
+ // setzt sich selbst auf 0 wenn kein anderer Wert übergeben wird
+ int count = 0,
+ int another = 3,
+ // enthält alle weiteren der Methode übergebenen Parameter (quasi Splats)
+ params string[] otherParams
+ )
+ {
+ return -1;
+ }
+
+ // Methoden können überladen werden, solange sie eindeutige
+ // Signaturen haben
+ public static void MethodSignatures(string maxCount)
+ {
+ }
+
+ // Generische Typen
+ // Die Typen für TKey und TValue werden erst beim Aufruf der Methode
+ // festgelegt. Diese Methode emuliert z.B. SetDefault aus 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;
+ }
+
+ // Möglichen Typen lassen sich auch über ihr Interface beschränken:
+ public static void IterateAndPrint<T>(T toPrint) where T: IEnumerable<int>
+ {
+ // Da T ein IEnumerable ist können wir foreach benutzen
+ foreach (var item in toPrint)
+ {
+ // Item ist ein int
+ Console.WriteLine(item.ToString());
+ }
+ }
+
+ public static void OtherInterestingFeatures()
+ {
+ // Optionale Parameter
+ MethodSignatures(3, 1, 3, "Ein paar", "extra", "Strings");
+ // setzt explizit einen bestimmten Parameter, andere werden übersprungen
+ MethodSignatures(3, another: 3);
+
+ // Erweiterungsmethoden
+ int i = 3;
+ i.Print(); // Weiter unten definiert
+
+ // Nullables - perfekt für die Interaktion mit
+ // Datenbanken / Rückgabewerten
+ // Jeder Wert (d.h. keine Klassen) kann durch das Nachstellen eines ?
+ // nullable gemacht werden: <type>? <varname> = <value>
+ int? nullable = null; // Die explizite Langform wäre Nullable<int>
+ Console.WriteLine("Mein Nullable: " + nullable);
+ bool hasValue = nullable.HasValue; // true wenn nicht null
+
+ // ?? ist "syntaktischer Zucker" um einen Defaultwert für den Fall
+ // dass die Variable null ist festzulegen.
+ int notNullable = nullable ?? 0; // 0
+
+ // Implizit typisierte Variablen
+ // Man kann auch den Typ einer Variable auch vom Compiler
+ // bestimmen lassen:
+ var magic = "magic ist zur Compile-Zeit ein String, folglich geht keine Typsicherheit verloren";
+ magic = 9; // funktioniert nicht da magic vom Typ String ist
+
+ // Generics
+ var phonebook = new Dictionary<string, string>() {
+ {"Resi", "08822 / 43 67"} // Fügt einen Eintrag zum Telefonbuch hinzu
+ };
+
+ // Hier könnte man auch unser generisches SetDefault von
+ // weiter oben benutzen:
+ Console.WriteLine(SetDefault<string,string>(phonebook, "Xaver", "kein Telefon")); // kein Telefon
+ // TKey und TValue müssen nicht zwingend angegeben werden, da sie
+ // auch implizit vom Compiler ermittelt werden können
+ Console.WriteLine(SetDefault(phonebook, "Resi", "kein Telefon")); // 08822 / 43 67
+
+ // Lambdas - konzise Syntax für Inline-Funktionen
+ Func<int, int> square = (x) => x * x; // Das letzte Element vom Typ T ist der Rückgabewert
+ Console.WriteLine(square(3)); // 9
+
+ // Disposables - einfaches Management von nicht verwalteten Ressourcen
+ // So gut wie alle Objekte die auf nicht verwaltete Ressourcen
+ // (Dateien, Geräte, ...) zugreifen, implementieren das Interface
+ // IDisposable. Das using Statement stellt sicher dass die vom
+ // IDisposable benutzten Ressourcen nach der Benutzung wieder
+ // freigegeben werden:
+ using (StreamWriter writer = new StreamWriter("log.txt"))
+ {
+ writer.WriteLine("Alles bestens!");
+ // Am Ende des Codeblocks werden die Ressourcen wieder
+ // freigegeben - auch im Falle einer Exception
+ }
+
+ // Parallel Klasse
+ // 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>();
+
+ // Für jeden Request wird ein neuer Thread erzeugt, der nächste
+ // Schritt wird erst nach Beendigung aller Tasks ausgeführt
+ Parallel.ForEach(websites,
+ // maximal 3 Threads gleichzeitig
+ new ParallelOptions() {MaxDegreeOfParallelism = 3},
+ website =>
+ {
+ // Hier folgt eine langwierige, asynchrone Operation
+ using (var r = WebRequest.Create(new Uri(website)).GetResponse())
+ {
+ responses[website] = r.ContentType;
+ }
+ });
+
+ // Dieser Code wird erst nach Beendigung aller Requests ausgeführt
+ foreach (var key in responses.Keys)
+ {
+ Console.WriteLine("{0}:{1}", key, responses[key]);
+ }
+
+ // Dynamische Objekte (gut um mit anderen Sprachen zu arbeiten)
+ dynamic student = new ExpandoObject();
+ // hier muss keine Typ angegeben werden
+ student.FirstName = "Christian";
+
+ // Einem solchen Objekt kann man sogar Methoden zuordnen.
+ // Das Beispiel gibt einen String zurück und erwartet einen String
+ student.Introduce = new Func<string, string>(
+ (introduceTo) => string.Format("Hallo {0}, das ist {1}", student.FirstName, introduceTo));
+ Console.WriteLine(student.Introduce("Bettina"));
+
+ // IQueryable<T> - So gut wie alle Aufzählungstypen implementieren
+ // dieses Interface, welches eine Vielzahl von funktionalen Methoden
+ // wie Map / Filter / Reduce zur Verfügung stellt:
+ var bikes = new List<Bicycle>();
+ // sortiert die Liste
+ bikes.Sort();
+ // sortiert nach Anzahl Räder
+ bikes.Sort((b1, b2) => b1.Wheels.CompareTo(b2.Wheels));
+ var result = bikes
+ // diese Filter können auch aneinandergehängt werden
+ .Where(b => b.Wheels > 3) // (gibt ein IQueryable des vorherigen Typs zurück)
+ .Where(b => b.IsBroken && b.HasTassles)
+ // diese Zuordnung gibt ein IQueryable<String> zurück
+ .Select(b => b.ToString());
+
+ // "Reduce" - addiert alle Räder der Aufzählung zu einem Wert
+ var sum = bikes.Sum(b => b.Wheels);
+
+ // So erzeugt man ein implizit typisiertes Objekt, basierend auf
+ // den Parametern der Elemente:
+ var bikeSummaries = bikes.Select(b=>new { Name = b.Name, IsAwesome = !b.IsBroken && b.HasTassles });
+ // Auch wenn wir es hier nicht demonstrieren können:
+ // In einer IDE wie VisualStudio kriegen wir hier sogar TypeAhead,
+ // da der Compiler in der Lage ist, die passenden Typen zu erkennen.
+ foreach (var bikeSummary in bikeSummaries.Where(b => b.IsAwesome))
+ {
+ Console.WriteLine(bikeSummary.Name);
+ }
+
+ // AsParallel-Methode
+ // Jetzt kommen die Schmankerl! Die AsParallel-Methode kombiniert
+ // LINQ und parallele Operationen:
+ var threeWheelers = bikes.AsParallel().Where(b => b.Wheels == 3).Select(b => b.Name);
+ // Diese Berechnung passiert parallel! Benötigte Threads werden
+ // automatisch erzeugt, und die Rechenlast unter ihnen aufgeteilt.
+ // Ein Traum für die Verarbeitung von großen Datenmengen
+ // auf mehreren Cores!
+
+ // LINQ - bildet einen Datenspeicher auf IQueryable<T> Objekte ab
+ // LinqToSql beispielsweise speichert und liest aus einer
+ // SQL-Datenbank, LinqToXml aus einem XML-Dokument.
+ // LINQ-Operationen werden "lazy" ausgeführt.
+ var db = new BikeRepository();
+
+ // Die verzögerte Ausführung ist optimal für Datenbankabfragen
+ var filter = db.Bikes.Where(b => b.HasTassles); // noch keine Abfrage
+ // Es können noch mehr Filter hinzugefügt werden (auch mit
+ // Bedingungen) - ideal für z.B. "erweiterte Suchen"
+ if (42 > 6)
+ {
+ filter = filter.Where(b => b.IsBroken); // immer noch keine Abfrage
+ }
+
+ var query = filter
+ .OrderBy(b => b.Wheels)
+ .ThenBy(b => b.Name)
+ .Select(b => b.Name); // auch hier: immer noch keine Abfrage
+
+ // Erst hier wird die Datenbankabfrage wirklich ausgeführt,
+ // limitiert auf die Elemente die der foreach-Loop verwendet
+ foreach (string bike in query)
+ {
+ Console.WriteLine(result);
+ }
+
+ }
+
+ } // Ende der Klasse LearnCSharp
+
+ // Eine .cs-Datei kann auch mehrere Klassen enthalten
+
+ public static class Extensions
+ {
+ // Erweiterungsmethoden
+ public static void Print(this object obj)
+ {
+ Console.WriteLine(obj.ToString());
+ }
+ }
+
+ // Syntax zur Deklaration einer Klasse:
+ // <public/private/protected/internal> class <class name>{
+ // // Datenfelder, Konstruktoren und Methoden leben alle
+ // // innerhalb dieser Deklaration
+ // }
+
+ public class Bicycle
+ {
+ // Felder/Variablen der Klasse "Bicycle"
+ // Das Keyword public macht das Member von überall zugänglich
+ public int Cadence
+ {
+ get // get definiert eine Methode um die Eigenschaft abzurufen
+ {
+ return _cadence;
+ }
+ set // set definiert eine Methode um die Eigenschaft zu setzen
+ {
+ _cadence = value; // value ist der dem Setter übergebene Wert
+ }
+ }
+ private int _cadence;
+
+ // Das Keyword protected macht das Member nur für die Klasse selbst
+ // und ihre Subklassen zugänglich
+ protected virtual int Gear
+ {
+ get; // erzeugt eine Eigenschaft für die kein "Zwischenwert" benötigt wird
+ set;
+ }
+
+ // Das Keyword internal macht das Member innerhalb der Assembly zugänglich
+ internal int Wheels
+ {
+ get;
+ private set; // get/set kann auch über Keywords modifiziert werden
+ }
+
+ int _speed; // Member ohne vorangestellte Keywords sind standardmäßig
+ // private, sie sind nur innerhalb der Klasse zugänglich.
+ // Man kann aber natürlich auch das Keyword private benutzen.
+ private string Name { get; set; }
+
+ // Ein Enum ist ein klar definierter Satz an benannten Konstanten.
+ // Eigentlich ordnet es diese Konstanten nur bestimmten Werten zu
+ // (einer int-Zahl, solange nicht anders angegeben). Mögliche Typen für
+ // die Werte eines Enums sind byte, sbyte, short, ushort, int, uint,
+ // long, oder ulong. Alle Werte in einem Enum sind eindeutig.
+ public enum BikeBrand
+ {
+ Colnago,
+ EddyMerckx,
+ Bianchi = 42, // so kann man den Wert explizit setzen
+ Kynast // 43
+ }
+ // Nachdem dieser Typ in der Klasse "Bicycle" definiert ist,
+ // sollte Code ausserhalb der Klasse den Typen als Bicycle.Brand referenzieren
+
+ // Nachdem das Enum deklariert ist, können wir den Typen verwenden:
+ public BikeBrand Brand;
+
+ // Als static gekennzeichnete Member gehören dem Typ selbst,
+ // nicht seinen Instanzen. Man kann sie also ohne Referenz zu einem
+ // Objekt benutzen
+ // Console.WriteLine("Schon " + Bicycle.BicyclesCreated + " Fahrräder, nur für dieses Tutorial!");
+ static public int BicyclesCreated = 0;
+
+ // readonly-Werte werden zur Laufzeit gesetzt
+ // Ihr Wert kann nur bei ihrer Deklaration, oder in einem Konstruktor
+ // festgelegt werden
+ readonly bool _hasCardsInSpokes = false; // readonly und private
+
+ // Konstruktoren bestimmen was bei einer Instantiierung passiert.
+ // Das ist ein Default-Konstruktor:
+ public Bicycle()
+ {
+ // Member der Klasse können über das Keyword this erreicht werden
+ this.Gear = 1;
+ // oft ist das aber gar nicht nötig
+ Cadence = 50;
+ _speed = 5;
+ Name = "Bonanzarad";
+ Brand = BikeBrand.Kynast;
+ BicyclesCreated++;
+ }
+
+ // Das ist ein spezifischer Konstruktor (d.h. er erwartet Argumente):
+ public Bicycle(int startCadence, int startSpeed, int startGear,
+ string name, bool hasCardsInSpokes, BikeBrand brand)
+ : base() // ruft zuerst den "base"-Konstruktor auf
+ {
+ Gear = startGear;
+ Cadence = startCadence;
+ _speed = startSpeed;
+ Name = name;
+ _hasCardsInSpokes = hasCardsInSpokes;
+ Brand = brand;
+ }
+
+ // Konstruktoren können aneinandergehängt werden:
+ public Bicycle(int startCadence, int startSpeed, BikeBrand brand) :
+ this(startCadence, startSpeed, 0, "richtig große Räder", true, brand)
+ {
+ }
+
+ // Syntax für Methoden:
+ // <public/private/protected> <return type> <function name>(<args>)
+
+ // Klassen können Getter und Setter für Werte definieren,
+ // oder diese Werte direkt als Eigenschaft implementieren
+ // (in C# der bevorzugte Weg)
+
+ // Parameter von Methoden können Default-Werte haben.
+ // "SpeedUp" kann man also auch ohne Parameter aufrufen:
+ public void SpeedUp(int increment = 1)
+ {
+ _speed += increment;
+ }
+
+ public void SlowDown(int decrement = 1)
+ {
+ _speed -= decrement;
+ }
+
+ // Eigenschaften mit get/set
+ // wenn es nur um den Zugriff auf Daten geht, ist eine Eigenschaft zu
+ // empfehlen. Diese können Getter und Setter haben, oder auch nur
+ // einen Getter bzw. einen Setter
+ private bool _hasTassles; // private Variable
+ public bool HasTassles // öffentliches Interface
+ {
+ get { return _hasTassles; }
+ set { _hasTassles = value; }
+ }
+
+ // Das kann man auch kürzer schreiben:
+ // Dieser Syntax erzeugt automatisch einen hinterlegten Wert,
+ // (entsprechend `private bool _isBroken`) der gesetzt
+ // bzw. zurückgegeben wird:
+ public bool IsBroken { get; private set; }
+ public int FrameSize
+ {
+ get;
+ // für Getter und Setter kann der Zugriff auch einzeln
+ // beschränkt werden, FrameSize kann also nur von innerhalb
+ // der Klasse "Bicycle" gesetzt werden
+ private set;
+ }
+
+ // Diese Methode gibt eine Reihe an Informationen über das Objekt aus:
+ public virtual string ToString()
+ {
+ return "Gang: " + Gear +
+ " Kadenz: " + Cadence +
+ " Geschwindigkeit: " + _speed +
+ " Name: " + Name +
+ " Hipster-Karten zwischen den Speichen: " + (_hasCardsInSpokes ? "Na klar!" : "Bloß nicht!") +
+ "\n------------------------------\n"
+ ;
+ }
+
+ // Auch Methoden können als static gekennzeichnet werden, nützlich
+ // beispielsweise für Helper-Methoden
+ public static bool DidWeCreateEnoughBicyclesYet()
+ {
+ // In einer statischen Methode können wir natürlich auch nur
+ // statische Member der Klasse referenzieren
+ return BicyclesCreated > 9000;
+ }
+ // Wenn eine Klasse nur statische Member enthält, kann es eine gute Idee
+ // sein die Klasse selbst als static zu kennzeichnen
+
+ } // Ende der Klasse "Bicycle"
+
+ // "PennyFarthing" ist eine Unterklasse von "Bicycle"
+ class PennyFarthing : Bicycle
+ {
+ // (Hochräder - englisch Penny Farthing - sind diese antiken Fahrräder
+ // mit riesigem Vorderrad. Sie haben keine Gangschaltung.)
+
+ // hier wird einfach der Elternkonstruktor aufgerufen
+ public PennyFarthing(int startCadence, int startSpeed) :
+ base(startCadence, startSpeed, 0, "Hochrad", true, BikeBrand.EddyMerckx)
+ {
+ }
+
+ protected override int Gear
+ {
+ get
+ {
+ return 0;
+ }
+ set
+ {
+ throw new ArgumentException("Ein Hochrad hat keine Gangschaltung, doh!");
+ }
+ }
+
+ public override string ToString()
+ {
+ string result = "Hochrad ";
+ result += base.ToString(); // ruft die "base"-Version der Methode auf
+ return result;
+ }
+ }
+
+ // Interfaces (auch Schnittstellen genant) definieren nur die Signaturen
+ // ihrer Member, enthalten aber auf keinen Fall ihre Implementierung:
+ interface IJumpable
+ {
+ // Alle Member eines Interfaces sind implizit public
+ void Jump(int meters);
+ }
+
+ interface IBreakable
+ {
+ // Interfaces können Eigenschaften, Methoden und Events definieren
+ bool Broken { get; }
+ }
+
+ // Eine Klasse kann nur von einer Klasse erben, kann aber eine beliebige
+ // Anzahl von Interfaces implementieren
+ class MountainBike : Bicycle, IJumpable, IBreakable
+ {
+ int damage = 0;
+
+ public void Jump(int meters)
+ {
+ damage += meters;
+ }
+
+ public bool Broken
+ {
+ get
+ {
+ return damage > 100;
+ }
+ }
+ }
+
+ // Das hier stellt eine Datenbankverbindung für das LinqToSql-Beispiel her.
+ // EntityFramework Code First ist großartig
+ // (ähnlich zu Ruby's ActiveRecord, aber bidirektional)
+ // http://msdn.microsoft.com/de-de/data/jj193542.aspx
+ public class BikeRepository : DbSet
+ {
+ public BikeRepository()
+ : base()
+ {
+ }
+
+ public DbSet<Bicycle> Bikes { get; set; }
+ }
+} // Ende des Namespaces
+```
+
+## In dieser Übersicht nicht enthalten sind die Themen:
+
+ * Flags
+ * Attributes
+ * Statische Eigenschaften
+ * Exceptions, Abstraction
+ * ASP.NET (Web Forms/MVC/WebMatrix)
+ * Winforms
+ * Windows Presentation Foundation (WPF)
+
+## Zum Weiterlesen gibt es viele gute Anlaufpunkte:
+
+ * [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/de-de/library/vstudio/ff926074.aspx) \ No newline at end of file
diff --git a/de-de/css-de.html.markdown b/de-de/css-de.html.markdown
index 8909b251..23c1df94 100644
--- a/de-de/css-de.html.markdown
+++ b/de-de/css-de.html.markdown
@@ -8,107 +8,106 @@ lang: de-de
filename: learncss-de.css
---
-In den frühen Tagen des Internets gab es keine visuellen Elemente, alles war nur reiner Text. Aber mit der Weiterentwickliung von Browsern wurden auch vollständig visuelle Webseiten zu einem Standard.
-CSS ist die allgemeine Sprache, die dazu da ist, damit man den HTML-Code und die Designelemente von Webseiten (strikt) unterscheiden kann.
+In den frühen Tagen des Internets gab es keine visuellen Elemente, alles war nur reiner Text. Aber mit der Weiterentwicklung von Browsern wurden auch vollständig visuelle Webseiten zu einem Standard.
+Durch Verwendung von CSS lässt sich eine strikte Trennung zwischen HTML-Code und Designelementen erreichen.
-Kurzgefasst, CSS ermöglicht es, verschiedene HTML-Elemente anzuvisieren und ihnen stilistische Eigenschaften zu geben.
+Kurzgefasst, CSS ermöglicht es, verschiedene HTML-Elemente innerhalb eines Dokuments auszuwählen und ihnen visuelle Eigenschaften zu geben.
CSS hat wie jede andere Sprache viele Versionen. Hier fokussieren wir uns auf CSS2.0, welche nicht die neueste, aber die am weitesten verbreitete und unterstützte Version ist.
-**NOTE:** Weil die Ausgabe von CSS visuelle Eigenschaften sind, wirst du wahrscheinlich eine CSS-Sandbox wie [dabblet](http://dabblet.com/) benutzen müssen, um die Sprache richtig zu lernen.
+**HINWEIS:** Weil die Ausgabe von CSS visuelle Eigenschaften sind, wirst du wahrscheinlich eine CSS-Sandbox wie [dabblet](http://dabblet.com/) benutzen müssen, um die Sprache richtig zu lernen.
In diesem Artikel wird am meisten auf generelle Hinweise und die Syntax geachtet.
```css
-/* kommentare werden in sternchen-schrägstrichkombinationen gepackt (genauso wie hier!) */
+/* Kommentare werden in Sternchen-Schrägstrichkombinationen gepackt (genauso wie hier!) */
/* ####################
## SELEKTOREN
####################*/
-/* Eigentlich ist die häufigste Anwendungsweise von CSS sehr simpel */
+/* Eigentlich ist das grundlegende CSS-Statement sehr simpel */
selektor { eigenschaft: wert; /* mehr eigenschaften...*/ }
-/* der selektor wird dazu benutzt, ein element auf der seite anzuvisieren
+/* Der Selektor wird dazu benutzt, ein Element auf der Seite auszuwählen.
-Aber man kann auch alle Elemente auf einer Seite anvisieren! */
+Man kann aber auch alle Elemente auf einer Seite auswählen! */
* { color:red; } /* farbe:rot */
/*
-Wenn wir so ein Element auf einer Seite haben:
+Angenommen wir haben folgendes Element auf einer Seite:
<div class='eine-klasse klasse2' id='eineId' attr='wert' />
*/
-/* kann man es so bei seiner klasse anvisieren */
+/* kann man es so über seine Klasse auswählen */
.eine-klasse { }
-/*oder bei beiden klassen! */
+/* oder über beide Klassen! */
.eine-klasse.klasse2 { }
-/* oder beim namen des tags */
+/* oder über den Namen des Tags */
div { }
-/* oder bei seiner id */
+/* oder über seine Id */
#eineId { }
-/* oder daran, dass es ein Attribut hat! */
+/* oder darüber, dass es ein Attribut hat! */
[attr] { font-size:smaller; }
-/* oder daran, dass das attribut einen bestimmten wert hat*/
+/* oder auch darüber, dass das Attribut einen bestimmten Wert hat */
[attr='wert'] { font-size:smaller; }
-/* beginnt mit einem wert*/
-[attr^='wert'] { font-size:smaller; }
+/* beginnt mit dem übergebenen Wert */
+[attr^='we'] { font-size:smaller; }
-/* oder endet mit */
+/* endet damit */
[attr$='rt'] { font-size:smaller; }
-/* oder sogar nur beinhaltet */
+/* oder beinhaltet einen Teil davon */
[attr~='er'] { font-size:smaller; }
-/* was aber noch wichtiger ist, ist dass man alle diese kombinieren
-kann - man sollte nur mit der leerzeichensetzung vorsichtig sein,
-da es mit einem leerzeichen zwei verschiedene selektoren wären*/
+/* Noch wichtiger ist aber die Möglichkeit, all das miteinander kombinieren
+zu können - man sollte hierbei nur mit der Leerzeichensetzung vorsichtig sein,
+ein Leerzeichen macht es zu zwei verschiedenen Selektoren */
+
div.eine-klasse[attr$='rt'] { } /* so ist es richtig */
-/* man kann auch ein element daran festmachen, wie sich die übergeordneten
-elemente verhalten!*/
+/* Man kann auch ein Element über seine Elternelemente auswählen */
-/*es muss allerdings ein direktes kind sein */
+/* > wählt ein direktes Kind aus */
div.ein-elternteil > .klassen-name {}
-/* oder jeder seiner eltern in der struktur */
-/* das folgende heißt also, dass jedes element mit der klasse 'klassen-name'
-und dem elternteil IN JEDER TIEFE ausgewählt wird */
+/* Mit einem Leerzeichen getrennt kann man alle Elternelemente ansprechen */
+/* Das folgende heißt also, dass jedes Element mit der Klasse 'klassen-name'
+und dem Elternteil IN JEDER TIEFE ausgewählt wird */
div.ein-elternteil .klassen-name {}
-/* achtung: dasselbe ohne das leerzeichen hat eine andere bedeutung,
+/* Achtung: das selbe ohne das Leerzeichen hat eine andere Bedeutung,
kannst du mir sagen, was? */
div.ein-elternteil.klassen-name {}
-/* man kann auch ein element nach seinem direkten vorherigen zwilling
+/* Man kann ein Element auch nach seinem direkten Nachbarelement
auswählen */
.ich-bin-vorher + .dieses-element { }
-/* oder jeden zwilling davor */
+/* Oder über jedes Geschwisterelement davor */
.ich-kann-jeder-davor-sein ~ .dieses-element {}
-/* es gibt ein paar pseudoklassen, die sich basierend auf dem
-seitenverhalten, nämlich nicht auf der seitenstruktur auswählen
-lassen können */
+/* Mit Pseudoklassen lassen sich Elemente anhand ihres momentanen Zustands
+auf der Seite auswählen (anstatt über die Seitenstruktur) */
-/* zum beispiel, wenn über ein element mit dem mauszeiger gefahren wird */
+/* Zum Beispiel, wenn über ein Element mit dem Mauszeiger gefahren wird */
:hover {}
-/* oder einen bereits besuchten link*/
+/* Oder einen bereits besuchten Link*/
:visited {}
-/* oder einen noch nicht besuchten link*/
+/* Oder einen noch nicht besuchten Link*/
:link {}
-/* oder ein eingabeelement, das zurzeit im fokus steht */
+/* Oder ein Eingabeelement, das zurzeit im Fokus steht */
:focus {}
@@ -117,64 +116,64 @@ lassen können */
####################*/
selector {
-
- /* einheiten */
- width: 50%; /* in prozent */
- font-size: 2em; /* mal der derzeitigen schriftgröße */
- width: 200px; /* in pixeln */
- font-size: 20pt; /* in punkten */
- width: 5cm; /* in zentimetern */
- width: 50mm; /* in millimetern */
- width: 5in; /* in zoll */
-
- /* farben */
- background-color: #F6E /* in kurzem hex */
- background-color: #F262E2 /* in langem hex */
- background-color: tomato /* kann auch eine genannte farbe sein */
- background-color: rgb(255, 255, 255) /* in rgb */
- background-color: rgb(10%, 20%, 50%) /* in rgb prozent */
- background-color: rgba(255, 0, 0, 0.3); /* in semi-transparentem rgb */
-
- /* bilder */
+
+ /* Einheiten */
+ width: 50%; /* in Prozent */
+ font-size: 2em; /* mal der derzeitigen Schriftgröße */
+ width: 200px; /* in Pixeln */
+ font-size: 20pt; /* in Punkten */
+ width: 5cm; /* in Zentimetern */
+ width: 50mm; /* in Millimetern */
+ width: 5in; /* in Zoll */
+
+ /* Farben */
+ background-color: #F6E /* in kurzem Hex */
+ background-color: #F262E2 /* in langem Hex */
+ background-color: tomato /* kann auch eine benannte Farbe sein */
+ background-color: rgb(255, 255, 255) /* in RGB */
+ background-color: rgb(10%, 20%, 50%) /* in RGB Prozent */
+ background-color: rgba(255, 0, 0, 0.3); /* in semi-transparentem RGB */
+
+ /* Bilder */
background-image: url(/pfad-zum-bild/image.jpg);
-
- /* schriften */
+
+ /* Schriften */
font-family: Arial;
- font-family: "Courier New"; /* wenn der name ein leerzeichen beinhält, kommt er in
- apostrophe */
- font-family: "Courier New", Trebuchet, Arial; /* wenn der erste nicht gefunden wird, wird
- der zweite benutzt, und so weiter */
+ font-family: "Courier New"; /* wenn der Name ein Leerzeichen beinhält, kommt er in
+ Anführungszeichen */
+ font-family: "Courier New", Trebuchet, Arial; /* wird die erste Schriftart
+ nicht gefunden, wird die zweite benutzt, usw. */
}
```
## Benutzung
-speichere das css, das du benutzen willst mit der endung '.css'.
+Speichere das CSS, das du benutzen willst mit der endung '.css'.
```xml
-<!-- du musst die css-datei im <head>-bereich der seite erwähnen -->
+<!-- du musst die CSS-Datei im <head>-bereich der seite einbinden -->
<link rel='stylesheet' type='text/css' href='filepath/filename.css' />
-<!-- es geht allerdings auch direkt, wobei diese methode nicht
+<!-- Einbindung funktioniert auch inline, wobei diese Methode nicht
empfohlen ist -->
<style>
selector { property:value; }
</style>
-<!-- oder direkt am element (sollte aber gelassen werden) -->
+<!-- Oder direkt auf einem Element (sollte aber vermieden werden) -->
<div style='property:value;'>
</div>
```
-## Wichtigkeit
+## Spezifität
-ein element kann von mehr als einem selektoren angezielt werden.
-und kann auch eine eigenschaft mehr als einmal zugewiesen bekommen.
-in diesen fällen gibt es regeln, die die wichtigkeit von selektoren einführen.
+Ein Element kann natürlich auch von mehr als einer Regel in einem Stylesheet
+angesprochen werdenm und kann eine Eigenschaft auch öfters als einmal zugewiesen
+bekommen. In diesen Fällen gibt es Regeln, die die Spezifität von Selektoren regeln.
-wie haben dieses CSS:
+Wir haben dieses CSS:
```css
/*A*/
@@ -194,34 +193,34 @@ p { property: wert !important; }
```
-und das folgende markup:
+und das folgende Markup:
```xml
<p style='/*F*/ property:value;' class='class1 class2' attr='value'>
</p>
```
-die wichtigkeit der stile ist wie folgt:
-(die wichtigkeit gilt nur für **eigenschaften**, nicht für ganze blöcke)
-
-* `E` hat die größte wichtigkeit wegen dem schlüsselwort `!important`.
- man sollte diese form aber vermeiden.
-* `F` ist als nächstes, da es direkt an dem element definiert ist.
-* `A` ist als nächstes, da es "spezifischer" als alle anderen ist.
- spezifischer = mehr zuweisungen: 1 tagname `p` +
- klassenname `klasse1` + 1 attribut `attr='value'`
-* `C` ist als nächstes obwohl es genau so ist wie `B`
- aber es erscheint als letztes.
-* dann ist `B`
+Die Spezifität der Stile ist wie folgt:
+(die Spezifität gilt nur für **einzelne Eigenschaften**, nicht für ganze Blöcke)
+
+* `E` hat die größte Spezifität wegen dem Schlüsselwort `!important`.
+ man sollte diese Form aber vermeiden.
+* `F` ist als nächstes dran, da es direkt an dem element definiert ist.
+* Dann folgt `A`, da es "spezifischer" als alle anderen ist.
+ spezifischer = mehr Zuweisungen: 1 Tagname `p` +
+ Klassenname `klasse1` + 1 Attribut `attr='value'`
+* `C` kommt als nächstes, obwohl es genau so ist wie `B`,
+ es erscheint aber später im Stylesheet.
+* dann kommt `B`
* und als letztes `D`.
-## Kompabilität
+## Kompatibilität
-die meisten features von CSS sind in allen browsern verfügbar.
-man sollte jedoch immer darauf achten, wenn man etwas mit CSS
-programmiert.
+Die meisten Features von CSS sind in allen Browsern verfügbar. Man sollte
+jedoch immer darauf achten die benutzten Features auf Verfügbarkeit in den
+vom Projekt unterstützten Browser zu überprüfen.
-[QuirksMode CSS](http://www.quirksmode.org/css/) ist eine der besten quellen dafür.
+[QuirksMode CSS](http://www.quirksmode.org/css/) oder [Can I Use](http://caniuse.com/) sind zwei der besten Quellen dafür.
## Weiterlesen
diff --git a/de-de/haskell-de.html.markdown b/de-de/haskell-de.html.markdown
index df6267f9..2c548961 100644
--- a/de-de/haskell-de.html.markdown
+++ b/de-de/haskell-de.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
lang: de-de
contributors:
- ["Adit Bhargava", "http://adit.io"]
diff --git a/de-de/javascript-de.html.markdown b/de-de/javascript-de.html.markdown
index 38ce28e2..a295c1c2 100644
--- a/de-de/javascript-de.html.markdown
+++ b/de-de/javascript-de.html.markdown
@@ -9,11 +9,11 @@ lang: de-de
---
(Anmerkungen des Original-Autors:)
-JavaScript wurde im Jahr 1995 von Brendan Eich bei Netscape entwickelt. Ursprünglich war es als einfachere Skriptsprache für Websites gedacht, ergänzent zu Java, das für komplexere Webanwendungen verwendet wird. Die enge Integration in Websites und der in Browser eingebaute Support der Sprache haben dafür gesorgt, dass JavaScript weit häufiger für Web-Frontends verwendet wird als Java.
+JavaScript wurde im Jahr 1995 von Brendan Eich bei Netscape entwickelt. Ursprünglich war es als einfachere Skriptsprache für Websites gedacht, ergänzend zu Java, das für komplexere Webanwendungen verwendet wird. Die enge Integration in Websites und der in Browser eingebaute Support der Sprache haben dafür gesorgt, dass JavaScript weit häufiger für Web-Frontends verwendet wird als Java.
-Dabei ist JavaScript inzwischen nicht mehr auf Browser beschränkt: Node.js, ein Projekt, dass eine eigene Laufzeitumgebung auf Grundlage von Google Chromes V8 mitbringt, wird derzeit immer populärer.
+Dabei ist JavaScript inzwischen nicht mehr auf Browser beschränkt: Node.js, ein Projekt, das eine eigene Laufzeitumgebung auf Grundlage von Google Chromes V8 mitbringt, wird derzeit immer populärer.
-Feedback ist herzlich Willkommen! Der ursprüngliche Autor ist unter [@adambrenecki](https://twitter.com/adambrenecki) oder [adam@brenecki.id.au](mailto:adam@brenecki.id.au) zu erreichen. Der Übersetzer unter [gregorbg@web.de](mailto:gregorbg@web.id.au).
+Feedback ist herzlich Willkommen! Der ursprüngliche Autor ist unter [@adambrenecki](https://twitter.com/adambrenecki) oder [adam@brenecki.id.au](mailto:adam@brenecki.id.au) zu erreichen. Der Übersetzer unter [gregorbg@web.de](mailto:gregorbg@web.de).
```js
// Kommentare werden wie in C gesetzt: Einzeilige Kommentare starten mit zwei
@@ -38,9 +38,9 @@ machWas()
3; // = 3
1.5; // = 1.5
-// Alle grundlegenden arithmetischen Operationen arbeiten wie erwartet.
+// Beinahe alle grundlegenden arithmetischen Operationen arbeiten wie erwartet.
1 + 1; // = 2
-8 - 1; // = 7
+0.1 + 0.2; // = 0.30000000000000004
10 * 2; // = 20
35 / 5; // = 7
@@ -72,13 +72,13 @@ false;
!true; // = false
!false; // = true
-// Gleichheit wird mit == geprüft.
-1 == 1; // = true
-2 == 1; // = false
+// Gleichheit wird mit === geprüft.
+1 === 1; // = true
+2 === 1; // = false
-// Ungleichheit wird mit != überprüft.
-1 != 1; // = false
-2 != 1; // = true
+// Ungleichheit wird mit !== überprüft.
+1 !== 1; // = false
+2 !== 1; // = true
// Andere Vergleichsoperatoren sind
1 < 10; // = true
@@ -92,16 +92,22 @@ false;
// und mit < und > verglichen werden.
"a" < "b"; // = true
-// Für den Vergleich von Werten wird eine Typumwandlung erzwungen...
+// Für den Vergleich von Werten mit "==" wird eine Typumwandlung erzwungen...
"5" == 5; // = true
// ...solange man nicht === verwendet.
"5" === 5; // = false
// Auf einzelne Buchstaben innerhalb eines Strings kann mit der Methode
-// charAt zugegriffen werden
+// 'charAt' zugegriffen werden
"This is a string".charAt(0); // = "T"
+// Die Methode 'substring' gibt Teilbereiche eines Strings zurück
+"Hello world".substring(0, 5); // = "Hello"
+
+// 'length' ist eine Eigenschaft und wird folglich ohne '()' benutzt
+"Hello".length; // = 5
+
// Es gibt außerdem die Werte 'null' und 'undefined'
null; // wird verwendet um einen vorsätzlich gewählten 'Nicht'-Wert anzuzeigen
undefined; // wird verwendet um anzuzeigen, dass der Wert (aktuell) nicht
@@ -147,6 +153,13 @@ var myArray = ["Hello", 45, true];
// beginnt bei 0.
myArray[1]; // = 45
+// Arrays haben keine feste Länge
+myArray.push("World");
+myArray.length; // = 4
+
+// und sind veränderlich
+myArray[3] = "Hello";
+
// Die Objekte in JavaScript entsprechen 'dictionaries' oder 'maps' in anderen
// Sprachen: es handelt sich um ungeordnete Schlüssel-Wert-Paare.
var myObj = { key1: "Hello", key2: "World" };
@@ -218,15 +231,47 @@ if (colour == "red" || colour == "blue"){
// nützlich, um einen Default-Wert zu setzen.
var name = otherName || "default";
+// Ein 'switch' Statement prüft Gleichheit mit ===
+// ohne ein 'break' nach jedem Fall
+// werden auch die Fälle nach dem korrekten aufgerufen
+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. Funktionen, Geltungsbereich und Closures
-// In JavaScript werden Funktionen mit dem Schlüsselwort 'function' deklariert.
+// In JavaScript werden Funktionen mit dem Schlüsselwort 'function' deklariert.
function myFunction(thing){
return thing.toUpperCase();
}
myFunction("foo"); // = "FOO"
+// Vorsicht: der Ausdruck der den Rückgabewert einer Funktion bildet muss
+// auf der selben Zeile beginnen auf der auch das 'return' Keyword steht
+// Sonst wird hier ein automatisches Semikolon eingefügt und die Funktion
+// gibt 'undefined' zurück
+function myFunction()
+{
+ return // <- Hier wird automatisch ein Semikolon eingefügt
+ {
+ thisIsAn: 'object literal'
+ }
+}
+myFunction(); // = undefined
+
// In JavaScript sind Funktionen 'Bürger erster Klasse', also können sie wie
// Variablen verwendet und als Parameter anderen Funktionen übergeben werden
// - zum Beispiel, um einen 'event handler' zu 'beliefern'.
@@ -236,9 +281,9 @@ function myFunction() {
setTimeout(myFunction, 5000);
// Funktionen können auch deklariert werden, ohne ihnen einen Namen zuzuweisen.
-// Es ist möglich diese anonymen Funktionen direkt als (oder im) Argument
+// Es ist möglich diese anonymen Funktionen direkt als (oder im) Argument
// einer anderen Funktion zu definieren.
-setTimeout(function() {
+setTimeout(function(){
// wird ausgeführt, nachdem 5 Sekunden vergangen sind
}, 5000);
@@ -275,7 +320,7 @@ function sayHelloInFiveSeconds(name){
}
setTimeout(inner, 5000);
// setTimeout wird asynchron ausgeführt. Also wird sayHelloInFiveSeconds
- // sofort verlassen und setTimeout wird die innere Funktion 'im nachhinein'
+ // sofort verlassen und setTimeout wird die innere Funktion 'im nachhinein'
// aufrufen. Dennoch: Weil sayHelloInFiveSeconds eine Hülle um die innere
// Funktion bildet, hat die innere Funktion immer noch Zugriff auf die
// Variable prompt.
@@ -320,6 +365,37 @@ var myOtherFunc = function(){
myObj.myOtherFunc = myOtherFunc;
myObj.myOtherFunc(); // = "HELLO WORLD!"
+// Mit den Methoden 'call' und 'apply' kann der Kontext eines Funktionsaufrufs
+// verändert werden
+
+var anotherFunc = function(s){
+ return this.myString + s;
+}
+anotherFunc.call(myObj, " And Hello Moon!"); // = "Hello World! And Hello Moon!"
+
+// 'apply' funktioniert beiahe identisch, erwartet die übergebenen Argumente
+// aber in einem Array
+
+anotherFunc.apply(myObj, [" And Hello Sun!"]); // = "Hello World! And Hello Sun!"
+
+// Das ist hilfreich wenn man einer Funktion eine beliebige Zahl Argumente
+// übergeben kann
+
+Math.min(42, 6, 27); // = 6
+Math.min([42, 6, 27]); // = NaN (uh-oh!)
+Math.min.apply(Math, [42, 6, 27]); // = 6
+
+// 'call' und 'apply' beeinflussen aber nur den spezifischen Aufruf.
+// Um den Kontext einer Funktion dauerhaft zu ändern wird 'bind' benutzt.
+
+var boundFunc = anotherFunc.bind(myObj);
+boundFunc(" And Hello Saturn!"); // = "Hello World! And Hello Saturn!"
+
+// Mit 'bind' lassen sich Funktionen auch teilweise anwenden / "curryen".
+var product = function(a, b){ return a * b; }
+var doubler = product.bind(this, 2);
+doubler(8); // = 16
+
// Wenn eine Funktion mit dem Schlüsselwort 'new' aufgerufen wird, dann wird
// ein neues Objekt erzeugt. Funktionen, die darauf ausgelegt sind in dieser
// Art aufgerufen zu werden, werden Konstruktoren genannt.
@@ -382,15 +458,15 @@ myObj.meaningOfLife; // = 43
// sich *nicht* um den Prototypen der Konstruktor-Funktion; stattdessen handelt
// es sich um den Prototypen, der einem neuen Objekt mitgegeben wird, wenn es
// mit dem Konstruktor und dem Schlüsselwort 'new' erzeugt wird.
-myConstructor.prototype = {
+MyConstructor.prototype = {
getMyNumber: function(){
return this.myNumber
}
};
-var myNewObj2 = new myConstructor();
+var myNewObj2 = new MyConstructor();
myNewObj2.getMyNumber(); // = 5
-// Die eingebauten Typen, also strings und numbers, haben auch Konstruktoren,
+// Alle primitiven Typen, also strings und numbers, haben auch Konstruktoren,
// die zu dem Typ äquivalente Wrapper-Objekte erzeugen.
var myNumber = 12;
var myNumberObj = new Number(12);
@@ -447,4 +523,6 @@ Dieses Tutorial hat nur die Sprache JavaScript vorgestellt; um mehr über den E
[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) ist eine tiefgehende Einführung in die kontra-intuitiven Parts der Sprache.
+[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) ist ein Klassiker unter den Referenzen.
+
Zusätzlich zu direkten Beiträgen zu diesem Artikel ist der Inhalt in Anlehnung an Louie Dinh's Python-Tutorial auf dieser Seite und das [JS Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) des Mozilla Developer Network entstanden.
diff --git a/de-de/markdown-de.html.markdown b/de-de/markdown-de.html.markdown
new file mode 100644
index 00000000..6a90980b
--- /dev/null
+++ b/de-de/markdown-de.html.markdown
@@ -0,0 +1,256 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators :
+ - ["Frederik Ring", "https://github.com/m90"]
+ - ["Philipp Fischbeck", "https://github.com/PFischbeck"]
+filename: markdown-de.md
+lang: de-de
+---
+
+Markdown wurde im Jahr 2004 von John Gruber kreiert. Ziel ist und war eine
+Syntax, in der sich Dokumente leicht schreiben *und* lesen lassen. Außerdem
+sollte Markdown sich leicht nach HTML (und in andere Formate) konvertieren
+lassen.
+
+```markdown
+<!-- Markdown ist eine Obermenge von HTML - jede valide HTML-Datei ist also
+automatisch valides Markdown - was heisst dass wir jedes HTML-Element (also auch
+Kommentare) in Markdown benutzen können, ohne dass der Parser sie verändert.
+Jedoch kann man innerhalb eines solchen HTML-Elements dann kein Markdown
+mehr verwenden. -->
+
+<!-- Es existieren unterschiedliche Markdown-Parser und -Dialekte, die sich in
+manchen Punkten unterscheiden. Diese Einführung wird versuchen, zu erläutern,
+welche Features überall verfügbar sind, und welche davon parser-spezifisch sind -->
+
+<!-- Überschriften -->
+<!-- HTML-Überschriften <h1> bis <h6> lassen sich einfach durch ein Voranstellen
+der entsprechenden Anzahl an Hashes (#) auszeichnen -->
+# Das ist eine <h1>
+## Das ist eine <h2>
+### Das ist eine <h3>
+#### Das ist eine <h4>
+##### Das ist eine <h5>
+###### Das ist eine <h6>
+
+<!-- Für die Elemente <h1> und <h2> gibt es in Markdown noch Sonderformen -->
+Das ist eine h1
+=============
+
+Das ist eine h2
+-------------
+
+<!-- Einfaches Textstyling -->
+<!-- Jeglicher Text lässt sich mit Markdown leicht als kursiv oder
+auch als fett auszeichnen -->
+
+*Dieser Text ist kursiv.*
+_Genau wie dieser._
+
+**Dieser Text ist fett.**
+__Genau wie dieser.__
+
+***Dieser Text ist beides***
+**_Dieser auch!_**
+*__Und dieser genau so!__*
+
+<!-- In "Github Flavored Markdown", dem von Github verwendeten Dialekt / Parser,
+gibt es auch noch durchgestrichenen Text: -->
+
+~~Dieser Text wird durchgestrichen dargestellt.~~
+
+<!-- Absätze sind eine oder mehrere zusammenhängende Zeilen Text, und werden
+durch eine oder mehrere Leerzeilen voneinander abgesetzt. -->
+
+Das ist ein Absatz. Ich kann immer noch nicht glauben, wie viel Spaß das macht !?!
+
+Jetzt bin ich schon bei Absatz 2.
+Hier ist dann immer noch Absatz 2!
+
+
+Jetzt ist das dann Nummer drei!
+
+<!-- Sollte man jemals ein <br />-Tag einfügen wollen, kann man einen Absatz
+mit zwei oder mehr Leerzeichen beenden, und danach einen neuen Absatz beginnen. -->
+
+Ich höre mit zwei Leerzeichen auf (markiere mich, und du siehst es).
+
+Über mir ist wohl ein <br />!
+
+<!-- Zitate werden ganz einfach mit einem > ausgezeichnet. -->
+
+> Das ist ein Zitat. Du kannst Zeilenumbrüche
+> entweder manuell hinzufügen und ein `>` vor jeder Zeile einfügen, oder du kannst deine Zeilen einfach immer länger und länger werden lassen, die Umbrüche werden dann automatisch erzeugt.
+> Solange sie mit einem `>` beginnen, macht das keinen Unterschied.
+
+> Auch möglich ist es, den Text
+>> mehrstufig einzurücken.
+> Nicht schlecht, oder?
+
+<!-- Listen -->
+<!-- <ul>s können mit Sternen, Pluszeichen oder Minuszeichen erzeugt werden -->
+
+* Punkt auf der Liste
+* Punkt auf der Liste
+* Anderer Punkt auf der Liste
+
+oder
+
++ Punkt auf der Liste
++ Punkt auf der Liste
++ Noch ein Punkt auf der Liste
+
+oder
+
+- Punkt auf der Liste
+- Punkt auf der Liste
+- Ein letzter Punkt auf der Liste
+
+<!-- <ol>s werden mit einer Zahl gefolgt von einem Punkt erzeugt -->
+
+1. Punkt eins
+2. Punkt zwei
+3. Punkt drei
+
+<!-- Auch wenn es keine gute Idee sein mag: du müsstest die einzelnen Punkte
+nicht mal korrekt numerieren -->
+
+1. Punkt eins
+1. Punkt zwei
+1. Punkt drei
+<!-- (Das sieht genau so aus wie das Beispiel eins weiter oben) -->
+
+<!-- Man kann Listen auch verschachteln -->
+
+1. Punkt eins
+2. Punkt zwei
+3. Punkt drei
+ * Unterpunkt
+ * Unterpunkt
+4. Punkt vier
+
+<!-- Code-Blöcke -->
+<!-- Blöcke von Programmcode (also ein <code>-Element) kannst du auszeichnen,
+indem du eine Zeile mit vier Leerzeichen oder einem Tabulator einrückst -->
+
+ Das ist Quellcode
+ Das hier auch
+
+<!-- Der Code kann natürlich auch wiederum eingerückt sein -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Innerhalb normalen Texts kannst du Code mit Backticks ` auszeichnen -->
+
+Hermann hatte nicht die leiseste Ahnung, was dieses `go_to()` bedeuten könnte!
+
+<!-- In "Github Flavored Markdown" gibt es für Code nocheinmal eine
+besondere Syntax -->
+
+\`\`\`ruby <!-- in "echt" musst du die Backslashes entfernen: ```ruby ! -->
+def foobar
+ puts "Hallo Welt!"
+end
+\`\`\` <!-- hier auch keine Backslashes, nur ``` -->
+
+<-- der obige Block muss nicht extra eingerückt werden, außerdem fügt Github
+Syntax-Highlighting für die nach dem ``` angegebene Sprache hinzu -->
+
+<!-- Horizontale Linie (<hr />) -->
+<!-- Trenner lassen sich einfach mit drei (oder mehr) Sternen oder Bindestrichen
+erzeugen (egal ob mit oder ohne Leerzeichen dazwischen)-->
+
+***
+---
+- - -
+****************
+
+<!-- Hyperlinks -->
+<!-- Eines der besten Features von Markdown ist das kinderleichte Erzeugen von
+Hyperlinks: Einfach den Linktext in eckige Klammern [] setzen, gefolgt von
+einer mit runden Klammern () umschlossenen URL. -->
+
+[Klick mich!](http://test.de/)
+
+<!-- Man kann dem Link auch noch ein title-Attribut geben -->
+
+[Klick mich!](http://test.at/ "Link zu Test.at")
+
+<!-- Relative Pfade funktionieren natürlich auch -->
+
+[Zu meiner Musiksammlung](/music/).
+
+<!-- URLs lassen sich auch über Referenzen festlegen -->
+
+[Klick mich][link1], um mehr über mich herauszufinden!
+[Hier kannst du auch mal draufklicken][foobar], wenn es dich interessiert.
+
+[link1]: http://test.de/ "Wahnsinn!"
+[foobar]: http://foobar.ch/ "Erstaunlich!"
+
+<!-- Das title-Attribut wird entweder mit Anführungszeichen oder Klammern
+umschlossen (oder gleich ganz weggelassen). Die Referenzen können an jeder
+Stelle im gesamtem Dokument vorkommen, als ID kann alles verwendet werden, solange
+es dokumentweit eindeutig ist. -->
+
+<!-- Man kann den Linktext auch als implizite Referenz benutzen -->
+
+[Das][] ist ein Link.
+
+[das]: http://dasisteinlink.at/
+
+<!-- Das ist aber eher unüblich. -->
+
+<!-- Bilder -->
+<!-- Bilder funktionieren genau wie Links, nur dass man noch ein Ausrufezeichen
+voranstellt! -->
+
+![Das ist das alt-Attribut für mein Bild](http://imgur.com/myimage.jpg "Hier noch ein title-Attribut")
+
+<!-- Referenzen funktionieren auch hier genau wie erwartet -->
+
+![Das ist das alt-Attribut][meinbild]
+
+[meinbild]: relative/urls/gehen/auch.jpg "hier wäre noch Platz für einen title"
+
+<!-- Bonusfeatures -->
+<!-- Auto-Links -->
+
+<http://testwebseite.de/> ist das selbe wie
+[http://testwebseite.de/](http://testwebseite.de/)
+
+<!-- Automatische Links für E-Mail-Addressen -->
+
+<foo@bar.com>
+
+<!-- Maskieren -->
+
+Ich würde *diesen Teil gerne mit Sternen umschließen*, doch ohne dass er kursiv
+wird. Also mache ich folgendes: \*Ich umschließe diesen Text mit Sternen\*!
+
+<!-- Tabellen -->
+<!-- Tabellen gibt es bis jetzt nur in "Github Flavored Markdown".
+Zudem sind sie ziemlich mühselig, aber wenn du es wirklich wissen willst: -->
+
+| Spalte1 | Spalte2 | Spalte3 |
+| :----------- | :------: | ------------: |
+| linksbündig | mittig | rechtsbündig |
+| blah | blah | blah |
+
+<!-- oder das selbe in grün: -->
+
+Spalte1 | Spalte2 | Spalte3
+:-- | :-: | --:
+Ganz schön hässlich | vielleicht doch lieber | wieder aufhören
+
+<!-- Das war's! -->
+
+```
+
+Mehr Informationen gibt es in [John Gruber's offiziellem Blog-Post](http://daringfireball.net/projects/markdown/syntax)
+und bei Adam Pritchards [grandiosem Cheatsheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet).
+Infos zu Github Flavored Markdown [gibt es hier](https://help.github.com/articles/github-flavored-markdown). \ No newline at end of file
diff --git a/elixir.html.markdown b/elixir.html.markdown
index 946c0a1b..0a20e3df 100644
--- a/elixir.html.markdown
+++ b/elixir.html.markdown
@@ -2,6 +2,7 @@
language: elixir
contributors:
- ["Joao Marques", "http://github.com/mrshankly"]
+ - ["Dzianis Dashkevich", "https://github.com/dskecse"]
filename: learnelixir.ex
---
@@ -59,7 +60,7 @@ tail #=> [2,3]
# the tuples have different sizes.
# {a, b, c} = {1, 2} #=> ** (MatchError) no match of right hand side value: {1,2}
-# There's also binaries
+# There are also binaries
<<1,2,3>> # binary
# Strings and char lists
@@ -108,7 +109,7 @@ div(10, 2) #=> 5
# To get the division remainder use `rem`
rem(10, 3) #=> 1
-# There's also boolean operators: `or`, `and` and `not`.
+# There are also boolean operators: `or`, `and` and `not`.
# These operators expect a boolean as their first argument.
true and true #=> true
false or true #=> true
@@ -119,7 +120,6 @@ false or true #=> true
1 || true #=> 1
false && 1 #=> false
nil && 20 #=> nil
-
!true #=> false
# For comparisons we have: `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` and `>`
@@ -165,12 +165,12 @@ case {:one, :two} do
{:four, :five} ->
"This won't match"
{:one, x} ->
- "This will match and assign `x` to `:two`"
+ "This will match and bind `x` to `:two`"
_ ->
"This will match any value"
end
-# It's common practice to assign a value to `_` if we don't need it.
+# It's common to bind the value to `_` if we don't need it.
# For example, if only the head of a list matters to us:
[head | _] = [1,2,3]
head #=> 1
@@ -190,7 +190,7 @@ cond do
"But I will"
end
-# It is common to see a last condition equal to `true`, which will always match.
+# It is common to see the last condition equal to `true`, which will always match.
cond do
1 + 1 == 3 ->
"I will never be seen"
@@ -301,7 +301,7 @@ end
Recursion.sum_list([1,2,3], 0) #=> 6
# Elixir modules support attributes, there are built-in attributes and you
-# may also add custom attributes.
+# may also add custom ones.
defmodule MyMod do
@moduledoc """
This is a built-in attribute on a example module.
@@ -312,21 +312,24 @@ defmodule MyMod do
end
## ---------------------------
-## -- Records and Exceptions
+## -- Structs and Exceptions
## ---------------------------
-# Records are basically structures that allow you to associate a name with
-# a particular value.
-defrecord Person, name: nil, age: 0, height: 0
+# Structs are extensions on top of maps that bring default values,
+# compile-time guarantees and polymorphism into Elixir.
+defmodule Person do
+ defstruct name: nil, age: 0, height: 0
+end
-joe_info = Person.new(name: "Joe", age: 30, height: 180)
-#=> Person[name: "Joe", age: 30, height: 180]
+joe_info = %Person{ name: "Joe", age: 30, height: 180 }
+#=> %Person{age: 30, height: 180, name: "Joe"}
# Access the value of name
joe_info.name #=> "Joe"
# Update the value of age
-joe_info = joe_info.age(31) #=> Person[name: "Joe", age: 31, height: 180]
+older_joe_info = %{ joe_info | age: 31 }
+#=> %Person{age: 31, height: 180, name: "Joe"}
# The `try` block with the `rescue` keyword is used to handle exceptions
try do
@@ -360,7 +363,7 @@ 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 `send` operator.
# For all of this to be useful we need to be able to receive messages. This is
-# achived with the `receive` mechanism:
+# achieved with the `receive` mechanism:
defmodule Geometry do
def area_loop do
receive do
@@ -394,5 +397,7 @@ self() #=> #PID<0.27.0>
* [Getting started guide](http://elixir-lang.org/getting_started/1.html) from [elixir webpage](http://elixir-lang.org)
* [Elixir Documentation](http://elixir-lang.org/docs/master/)
+* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) by Dave Thomas
+* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf)
* ["Learn You Some Erlang for Great Good!"](http://learnyousomeerlang.com/) by Fred Hebert
-* "Programming Erlang: Software for a Concurrent World" by Joe Armstrong
+* ["Programming Erlang: Software for a Concurrent World"](https://pragprog.com/book/jaerlang2/programming-erlang) by Joe Armstrong
diff --git a/erlang.html.markdown b/erlang.html.markdown
index 64b62f05..04086aeb 100644
--- a/erlang.html.markdown
+++ b/erlang.html.markdown
@@ -260,22 +260,22 @@ spawn(F). % <0.44.0>
% For all of this to be useful we need to be able to receive messages. This is
% achieved with the `receive` mechanism:
--module(caculateGeometry).
+-module(calculateGeometry).
-compile(export_all).
-caculateAera() ->
+calculateArea() ->
receive
{rectangle, W, H} ->
W * H;
{circle, R} ->
3.14 * R * R;
_ ->
- io:format("We can only caculate area of rectangles or circles.")
+ io:format("We can only calculate 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
+% Compile the module and create a process that evaluates `calculateArea` in the shell
+c(calculateGeometry).
+CalculateArea = spawn(calculateGeometry, calculateArea, []).
+CalculateArea ! {circle, 2}. % 12.56000000000000049738
% The shell is also a process, you can use `self` to get the current pid
self(). % <0.41.0>
diff --git a/es-es/bash-es.html.markdown b/es-es/bash-es.html.markdown
index 489fd39e..fb89b2a0 100644
--- a/es-es/bash-es.html.markdown
+++ b/es-es/bash-es.html.markdown
@@ -11,6 +11,7 @@ contributors:
translators:
- ["Daniel Zendejas", "https://github.com/danielzendejas"]
filename: LearnBash-es.sh
+lang: es-es
---
Tutorial de Shell en español.
diff --git a/es-es/julia-es.html.markdown b/es-es/julia-es.html.markdown
index 41a7c68b..203ee3bb 100644
--- a/es-es/julia-es.html.markdown
+++ b/es-es/julia-es.html.markdown
@@ -1,8 +1,9 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
- - ["Guillermo Garza" ]
+translators:
+ - ["Guillermo Garza", "http://github.com/ggarza"]
filename: learnjulia-es.jl
lang: es-es
---
diff --git a/es-es/markdown-es.html.markdown b/es-es/markdown-es.html.markdown
index 3865126c..d90e3eb5 100644
--- a/es-es/markdown-es.html.markdown
+++ b/es-es/markdown-es.html.markdown
@@ -14,7 +14,7 @@ fácilmente a HTML (y, actualmente, otros formatos también).
¡Denme todo la retroalimentación que quieran! / ¡Sientanse en la libertad de hacer forks o pull requests!
-```
+```markdown
<!-- Markdown está basado en HTML, así que cualquier archivo HTML es Markdown
válido, eso significa que podemos usar elementos HTML en Markdown como, por
ejemplo, el comentario y no serán afectados por un parseador Markdown. Aún
diff --git a/forth.html.markdown b/forth.html.markdown
new file mode 100644
index 00000000..570e12ed
--- /dev/null
+++ b/forth.html.markdown
@@ -0,0 +1,225 @@
+---
+language: forth
+contributors:
+ - ["Horse M.D.", "http://github.com/HorseMD/"]
+filename: learnforth.fs
+---
+
+Forth was created by Charles H. Moore in the 70s. It is an imperative,
+stack-based language and programming environment, being used in projects
+such as Open Firmware. It's also used by NASA.
+
+Note: This article focuses predominantly on the Gforth implementation of
+Forth, but most of what is written here should work elsewhere.
+
+```forth
+\ This is a comment
+( This is also a comment but it's only used when defining words )
+
+\ --------------------------------- Precursor ----------------------------------
+
+\ All programming in Forth is done by manipulating the parameter stack (more
+\ commonly just referred to as "the stack").
+5 2 3 56 76 23 65 \ ok
+
+\ Those numbers get added to the stack, from left to right.
+.s \ <7> 5 2 3 56 76 23 65 ok
+
+\ In Forth, everything is either a word or a number.
+
+\ ------------------------------ Basic Arithmetic ------------------------------
+
+\ Arithmetic (in fact most words requiring data) works by manipulating data on
+\ the stack.
+5 4 + \ ok
+
+\ `.` pops the top result from the stack:
+. \ 9 ok
+
+\ More examples of arithmetic:
+6 7 * . \ 42 ok
+1360 23 - . \ 1337 ok
+12 12 / . \ 1 ok
+13 2 mod . \ 1 ok
+
+99 negate . \ -99 ok
+-99 abs . \ 99 ok
+52 23 max . \ 52 ok
+52 23 min . \ 23 ok
+
+\ ----------------------------- Stack Manipulation -----------------------------
+
+\ Naturally, as we work with the stack, we'll want some useful methods:
+
+3 dup - \ duplicate the top item (1st now equals 2nd): 3 - 3
+2 5 swap / \ swap the top with the second element: 5 / 2
+6 4 5 rot .s \ rotate the top 3 elements: 4 5 6
+4 0 drop 2 / \ remove the top item (dont print to screen): 4 / 2
+1 2 3 nip .s \ remove the second item (similar to drop): 1 3
+
+\ ---------------------- More Advanced Stack Manipulation ----------------------
+
+1 2 3 4 tuck \ duplicate the top item into the second slot: 1 2 4 3 4 ok
+1 2 3 4 over \ duplicate the second item to the top: 1 2 3 4 3 ok
+1 2 3 4 2 roll \ *move* the item at that position to the top: 1 3 4 2 ok
+1 2 3 4 2 pick \ *duplicate* the item at that position to the top: 1 2 3 4 2 ok
+
+\ When referring to stack indexes, they are zero-based.
+
+\ ------------------------------ Creating Words --------------------------------
+
+\ The `:` word sets Forth into compile mode until it sees the `;` word.
+: square ( n -- n ) dup * ; \ ok
+5 square . \ 25 ok
+
+\ We can view what a word does too:
+see square \ : square dup * ; ok
+
+\ -------------------------------- Conditionals --------------------------------
+
+\ -1 == true, 0 == false. However, any non-zero value is usually treated as
+\ being true:
+42 42 = \ -1 ok
+12 53 = \ 0 ok
+
+\ `if` is a compile-only word. `if` <stuff to do> `then` <rest of program>.
+: ?>64 ( n -- n ) dup 64 > if ." Greater than 64!" then ; \ ok
+100 ?>64 \ Greater than 64! ok
+
+\ Else:
+: ?>64 ( n -- n ) dup 64 > if ." Greater than 64!" else ." Less than 64!" then ;
+100 ?>64 \ Greater than 64! ok
+20 ?>64 \ Less than 64! ok
+
+\ ------------------------------------ Loops -----------------------------------
+
+\ `do` is also a compile-only word.
+: myloop ( -- ) 5 0 do cr ." Hello!" loop ; \ ok
+myloop
+\ Hello!
+\ Hello!
+\ Hello!
+\ Hello!
+\ Hello! ok
+
+\ `do` expects two numbers on the stack: the end number and the start number.
+
+\ We can get the value of the index as we loop with `i`:
+: one-to-12 ( -- ) 12 0 do i . loop ; \ ok
+one-to-12 \ 0 1 2 3 4 5 6 7 8 9 10 11 12 ok
+
+\ `?do` works similarly, except it will skip the loop if the end and start
+\ numbers are equal.
+: squares ( n -- ) 0 ?do i square . loop ; \ ok
+10 squares \ 0 1 4 9 16 25 36 49 64 81 ok
+
+\ Change the "step" with `+loop`:
+: threes ( n n -- ) ?do i . 3 +loop ; \ ok
+15 0 threes \ 0 3 6 9 12 ok
+
+\ Indefinite loops with `begin` <stuff to do> <flag> `unil`:
+: death ( -- ) begin ." Are we there yet?" 0 until ; \ ok
+
+\ ---------------------------- Variables and Memory ----------------------------
+
+\ Use `variable` to declare `age` to be a variable.
+variable age \ ok
+
+\ Then we write 21 to age with the word `!`.
+21 age ! \ ok
+
+\ Finally we can print our variable using the "read" word `@`, which adds the
+\ value to the stack, or use `?` that reads and prints it in one go.
+age @ . \ 21 ok
+age ? \ 21 ok
+
+\ Constants are quite simiar, except we don't bother with memory addresses:
+100 constant WATER-BOILING-POINT \ ok
+WATER-BOILING-POINT . \ 100 ok
+
+\ ----------------------------------- Arrays -----------------------------------
+
+\ Creating arrays is similar to variables, except we need to allocate more
+\ memory to them.
+
+\ You can use `2 cells allot` to create an array that's 3 cells long:
+variable mynumbers 2 cells allot \ ok
+
+\ Initialize all the values to 0
+mynumbers 3 cells erase \ ok
+
+\ Alternatively we could use `fill`:
+mynumbers 3 cells 0 fill
+
+\ or we can just skip all the above and initialize with specific values:
+create mynumbers 64 , 9001 , 1337 , \ ok (the last `,` is important!)
+
+\ ...which is equivalent to:
+
+\ Manually writing values to each index:
+64 mynumbers 0 cells + ! \ ok
+9001 mynumbers 1 cells + ! \ ok
+1337 mynumbers 2 cells + ! \ ok
+
+\ Reading values at certain array indexes:
+0 cells mynumbers + ? \ 64 ok
+1 cells mynumbers + ? \ 9001 ok
+
+\ We can simplify it a little by making a helper word for manipulating arrays:
+: of-arr ( n n -- n ) cells + ; \ ok
+mynumbers 2 of-arr ? \ 1337 ok
+
+\ Which we can use for writing too:
+20 mynumbers 1 of-arr ! \ ok
+mynumbers 1 of-arr ? \ 20 ok
+
+\ ------------------------------ The Return Stack ------------------------------
+
+\ The return stack is used to the hold pointers to things when words are
+\ executing other words, e.g. loops.
+
+\ We've already seen one use of it: `i`, which duplicates the top of the return
+\ stack. `i` is equivalent to `r@`.
+: myloop ( -- ) 5 0 do r@ . loop ; \ ok
+
+\ As well as reading, we can add to the return stack and remove from it:
+5 6 4 >r swap r> .s \ 6 5 4 ok
+
+\ NOTE: Because Forth uses the return stack for word pointers, `>r` should
+\ always be followed by `r>`.
+
+\ ------------------------- Floating Point Operations --------------------------
+
+\ Most Forths tend to eschew the use of floating point operations.
+8.3e 0.8e f+ f. \ 9.1 ok
+
+\ Usually we simply prepend words with 'f' when dealing with floats:
+variable myfloatingvar \ ok
+4.4e myfloatingvar f! \ ok
+myfloatingvar f@ f. \ 4.4 ok
+
+\ --------------------------------- Final Notes --------------------------------
+
+\ Typing a non-existent word will empty the stack. However, there's also a word
+\ specifically for that:
+clearstack
+
+\ Clear the screen:
+page
+
+\ Loading Forth files:
+\ s" forthfile.fs" included
+
+\ You can list every word that's in Forth's dictionary (but it's a huge list!):
+\ words
+
+\ Exiting Gforth:
+\ bye
+
+```
+
+##Ready For More?
+
+* [Starting Forth](http://www.forth.com/starting-forth/)
+* [Simple Forth](http://www.murphywong.net/hello/simple.htm)
+* [Thinking Forth](http://thinking-forth.sourceforge.net/)
diff --git a/fr-fr/bash-fr.html.markdown b/fr-fr/bash-fr.html.markdown
new file mode 100644
index 00000000..0e764d7d
--- /dev/null
+++ b/fr-fr/bash-fr.html.markdown
@@ -0,0 +1,230 @@
+---
+category: tool
+tool: bash
+contributors:
+ - ["Max Yankov", "https://github.com/golergka"]
+ - ["Darren Lin", "https://github.com/CogBear"]
+ - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"]
+ - ["Denis Arh", "https://github.com/darh"]
+ - ["akirahirose", "https://twitter.com/akirahirose"]
+ - ["Anton Strömkvist", "http://lutic.org/"]
+ - ["Rahil Momin", "https://github.com/iamrahil"]
+ - ["Gregrory Kielian", "https://github.com/gskielian"]
+translators:
+ - ["Baptiste Fontaine", "http://bfontaine.net"]
+filename: LearnBash-fr.sh
+lang: fr-fr
+---
+
+Bash est le nom du shell UNIX, qui était aussi distribué avec le système
+d’exploitation GNU et est le shell par défaut sur Linux et Mac OS X.
+
+Presque tous les exemples ci-dessous peuvent être écrits dans un script shell
+ou exécutés directement dans le terminal.
+
+[Plus d’informations ici.](http://www.gnu.org/software/bash/manual/bashref.html)
+
+```bash
+#!/bin/bash
+# La première ligne du script s’appelle le « shebang, » qui indique au système
+# comment exécuter le script : http://fr.wikipedia.org/wiki/Shebang
+# Comme vous pouvez le remarquer, les commentaires commencent par #. Le shebang
+# est aussi un commentaire
+
+# Un exemple simple qui affiche « Hello world! » :
+echo Hello world!
+
+# Chaque commande commence sur une nouvelle ligne ou après un point-virgule :
+echo 'Ceci est la première ligne'; echo 'Ceci est la seconde ligne'
+
+# La déclaration d’une variable ressemble à ça :
+VARIABLE="Du texte"
+
+# Mais pas comme ça :
+VARIABLE = "Du texte"
+# Bash va penser que VARIABLE est une commande qu’il doit exécuter et va
+# afficher une erreur parce qu’elle est introuvable.
+
+# Utiliser une variable :
+echo $VARIABLE
+echo "$VARIABLE"
+echo '$VARIABLE'
+# Quand vous utilisez la variable en elle-même – en lui assignant une valeur,
+# en l’exportant ou autre – vous écrivez son nom sans $. Si vous voulez
+# utiliser sa valeur, vous devez utiliser $.
+# Notez qu’entourer une variable de deux guillemets simples (') empêche
+# l’expansion des variables !
+
+# Substitution de chaîne de caractères dans une variable
+echo ${VARIABLE/Some/A}
+# Ceci va remplacer la première occurrence de « Some » par « A »
+
+# Sous-chaîne d’une variable
+echo ${VARIABLE:0:7}
+# Ceci va retourner seulement les 7 premiers caractères de la valeur
+
+# Valeur par défaut d’une variable
+echo ${FOO:-"ValeurParDefautSiFOOestVideOuInexistant"}
+# Ceci marche pour null (FOO=), la chaîne de caractères vide (FOO=""). Zéro
+# (FOO=0) retourne 0
+
+# Variables pré-remplies :
+# Il y a quelques variables pré-remplies utiles, comme :
+echo "La valeur de retour du dernier programme : $?"
+echo "Le PID du script : $$"
+echo "Nombre d’arguments : $#"
+echo "Arguments du script : $@"
+echo "Arguments du script séparés en plusieurs variables : $1 $2..."
+
+# Lire une valeur depuis l’entrée standard :
+echo "Quel est votre nom ?"
+read NAME # Notez que l’on n’a pas eu à déclarer une nouvelle variable
+echo Bonjour, $NAME!
+
+# Nous avons l’habituelle structure « if » :
+# Utilisez 'man test' pour plus d’informations à propos des conditions
+if [ $NAME -ne $USER ]
+then
+ echo "Votre nom n’est pas votre pseudo"
+else
+ echo "Votre nom est votre pseudo"
+fi
+
+# Il y a aussi l’exécution conditionnelle
+echo "Toujours exécuté" || echo "Exécuté si la première commande ne réussit pas"
+echo "Toujours exécuté" && echo "Exécuté si la première commande réussit"
+
+# Pour utiliser && et || avec des commandes « if, » vous devez utiliser
+# plusieurs paires de crochets :
+if [ $NAME == "Steve" ] && [ $AGE -eq 15 ]
+then
+ echo "Ceci sera exécuté si $NAME est Steve ET $AGE est 15."
+fi
+
+if [ $NAME == "Daniya" ] || [ $NAME == "Zach" ]
+then
+ echo "Ceci sera exécuté si $NAME est Daniya OU Zach."
+fi
+
+# Les expressions sont écrites dans le format suivant :
+echo $(( 10 + 5 ))
+
+# Contrairement aux autres langages de programmation, Bash est un shell — il
+# est donc exécuté dans le contexte du répertoire courant. Vous pouvez lister
+# les fichiers et dossiers dans le répertoire courant avec la commande `ls` :
+ls
+
+# Ces commandes ont des options qui contrôlent leur exécution :
+ls -l # Liste tous les fichiers et répertoires sur des lignes séparées
+
+# Les résultat de la commande précédente peuvent être passés à la commande
+# suivante en entrée.
+# La commande grep filtre l’entrée avec les motifs donnés. On peut ainsi lister
+# les fichiers .txt dans le répertoire courant :
+ls -l | grep "\.txt"
+
+# Vous pouvez aussi rediriger l’entrée et les sorties standards et d’erreur
+# d’une commande :
+python2 hello.py < "entrée.in"
+python2 hello.py > "sortie.out"
+python2 hello.py 2> "erreur.err"
+# Ceci va écraser le fichier s'il existe; si vous préférez écrire à la fin de
+# celui-ci, utilisez >> à la place.
+
+# Les commandes peuvent se substituer à l’intérieur d’autres commandes en
+# utilisant $( ) :
+# La commande ci-dessous affiche le nombre de fichiers et répertoires dans le
+# répertoire courant :
+echo "Il y a $(ls | wc -l) choses ici."
+
+# On peut faire la même chose avec les accents graves `` mais on ne peut pas
+# les imbriquer — la façon la plus courante est d’utiliser $( ).
+echo "There are `ls | wc -l` items here."
+
+# Bash a une commande case qui marche de façon similaire au switch de Java et
+# C++ :
+case "$VARIABLE" in
+ #List patterns for the conditions you want to meet
+ 0) echo "There is a zero.";;
+ 1) echo "There is a one.";;
+ *) echo "It is not null.";;
+esac
+
+# La boucle for itère autant de fois qu’elle a d’arguments :
+# Le contenu de $VARIABLE est affiché trois fois.
+for VARIABLE in {1..3}
+do
+ echo "$VARIABLE"
+done
+
+# Ou écrivez-la de façon « traditionnelle » :
+for ((a=1; a <= 3; a++))
+do
+ echo $a
+done
+
+# Elles peuvent aussi être utilisées pour agir sur des fichiers :
+# Cette boucle va exécuter la commande 'cat' sur fichier1 et fichier2
+for VARIABLE in fichier1 fichier2
+do
+ cat "$VARIABLE"
+done
+
+# …ou la sortie d’une commande :
+# Ceci va afficher la sortie de ls.
+for OUTPUT in $(ls)
+do
+ cat "$OUTPUT"
+done
+
+# Boucle while :
+while [ true ]
+do
+ echo "corps de la boucle ..."
+ break
+done
+
+# Vous pouvez aussi définir des fonctions
+# Définition :
+function foo ()
+{
+ echo "Les arguments fonctionnent comme les arguments de script : $@"
+ echo "Et : $1 $2..."
+ echo "Ceci est une fonction"
+ return 0
+}
+
+# Ou plus simplement :
+bar ()
+{
+ echo "Une autre façon de définir des fonctions !"
+ return 0
+}
+
+# Appeler votre fonction
+foo "Mon nom est" $NAME
+
+# Il y a plein de commandes utiles que vous devriez apprendre :
+# affiche les 10 dernières lignes de fichier.txt
+tail -n 10 fichier.txt
+# affiche les 10 premières lignes de fichier.txt
+head -n 10 fichier.txt
+# trie les lignes de fichier.txt
+sort fichier.txt
+# montre ou omet les lignes répétées, avec -d pour les montrer
+uniq -d fichier.txt
+# affiche uniquement la première colonne avant le caractère « , »
+cut -d ',' -f 1 fichier.txt
+# remplace chaque occurrence de 'okay' par 'super' dans fichier.txt
+# (compatible avec les expression rationnelles)
+sed -i 's/okay/super/g' fichier.txt
+# affiche toutes les lignes de fichier.txt qui correspondent à une expression
+# rationnelle, dans cet exemple les lignes qui commencent par « foo » et
+# finissent par « bar »
+grep "^foo.*bar$" fichier.txt
+# ajoutez l’option « -c » pour afficher le nombre de lignes concernées
+grep -c "^foo.*bar$" fichier.txt
+# Si vous voulez vraiment chercher une chaîne de caractères, et non
+# l’expression rationnelle, utilisez fgrep (ou grep -F)
+fgrep "^foo.*bar$" fichier.txt
+```
diff --git a/fr-fr/brainfuck-fr.html.markdown b/fr-fr/brainfuck-fr.html.markdown
new file mode 100644
index 00000000..545e407e
--- /dev/null
+++ b/fr-fr/brainfuck-fr.html.markdown
@@ -0,0 +1,87 @@
+---
+language: brainfuck
+filename: learnbrainfuck-fr.bf
+contributors:
+ - ["Prajit Ramachandran", "http://prajitr.github.io/"]
+ - ["Mathias Bynens", "http://mathiasbynens.be/"]
+translators:
+ - ["Baptiste Fontaine", "http://bfontaine.net"]
+lang: fr-fr
+---
+
+Brainfuck (sans majuscule à part au début d’une phrase) est un langage
+Turing-complet extrêmement simple avec seulement 8 commandes.
+
+```
+Tout caractère en dehors de "><+-.,[]" (en dehors des guillemets) est ignoré.
+
+Brainfuck est représenté par un tableau de 30 000 cellules initialisées à 0 et
+un pointeur de données pointant sur la cellule courante.
+
+Il y a huit commandes :
++ : Incrémente la valeur de la cellule courante de un.
+- : Décrémente la valeur de la cellule courante de un.
+> : Déplace le pointeur de données sur la cellule suivante (à droite).
+< : Déplace le pointeur de données sur la cellule précédente (à gauche).
+. : Affiche la valeur ASCII de la cellule courante (par ex. 65 = 'A').
+, : Lit un caractère et le place dans la cellule courante.
+[ : Si la valeur dans la cellule courante vaut 0, saute au ] correspondant.
+ Sinon, continue avec la commande suivante.
+] : Si la valeur dans la cellule courante vaut 0, continue avec la commande
+ suivante. Sinon, retourne au [ correspondant.
+
+[ et ] forment une boucle « tant que » (« while »). Ils doivent évidemment
+aller par paires.
+
+Regardons quelques programmes simples en brainfuck.
+
+++++++ [ > ++++++++++ < - ] > +++++ .
+
+Ce programme affiche la lettre 'A'. Il commence par incrémenter la première
+cellule à 6. Il entre ensuite dans une boucle et se déplace sur la seconde
+cellule. Il l’incrémente 10 fois, retourne sur la première cellule, et la
+décrémente. Cette boucle est exécutée 6 fois (ce qui correspond aux 6
+décrémentations de la première cellule pour la faire atteindre 0, ce qui fait
+sortir de la boucle).
+
+À ce moment-là, nous sommes sur la première cellule, qui a une valeur de 0,
+tandis que la seconde cellule a une valeur de 60. Nous nous déplaçons sur
+celle-ci, l’incrémentons 5 fois, pour une valeur de 65, et affichons sa valeur.
+En ASCII, 65 correspond à 'A' donc le programme affiche 'A' dans le terminal.
+
+, [ > + < - ] > .
+
+Ce programme lit un caractère sur l’entrée standard et le copie dans la
+première cellule. Il commence ensuite une boucle : il bouge sur la seconde
+cellule, incrémente sa valeur, retourne sur la première et décrémente sa
+valeur. Il continue jusqu’à ce que la valeur de la première cellule soit à 0,
+et que la seconde cellule contienne l’ancienne valeur de la première. Comme
+nous sommes sur la première cellule à la fin de la boucle, il bouge sur la
+seconde et affiche sa valeur en ASCII.
+
+Souvenez-vous que les espaces sont uniquement là pour favoriser la lisibilité,
+vous pourriez tout aussi aisément écrire le programme comme ceci :
+
+,[>+<-]>.
+
+Essayez et devinez ce que ce programme fait :
+
+,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
+
+Ce programme prend deux nombres en entrée, et les multiplie.
+
+Il commence par lire deux entrées, puis commence une boucle externe, qui a une
+condition sur la première cellule. Il bouge ensuite sur la seconde, et commence
+une boucle interne sur celle-ci, en incrémentant la troisième cellule. Il y a
+cependant un problème : à la fin de la boucle interne, la valeur de la seconde
+cellule est à zéro. Dans ce cas, la boucle interne ne fonctionnera pas une
+seconde fois. Pour régler le problème, nous incrémentons aussi la quatrième
+cellule, puis recopions sa valeur dans la seconde cellule.
+À la fin, la troisième cellule contient le résultat de la multiplication.
+```
+
+Et voilà ce qu’est le brainfuck. Pas très dur, hein ? Pour le fun, vous pouvez
+écrire vos propres programmes en brainfuck, ou écrire un interpréteur brainfuck
+dans un autre langage. L’interpréteur est relativement simple à implémenter,
+mais si vous êtes un masochiste, essayez d’écrire un interpréteur brainfuck en…
+brainfuck.
diff --git a/fr-fr/css-fr.html.markdown b/fr-fr/css-fr.html.markdown
new file mode 100644
index 00000000..bdab9715
--- /dev/null
+++ b/fr-fr/css-fr.html.markdown
@@ -0,0 +1,221 @@
+---
+language: css
+contributors:
+ - ["Mohammad Valipour", "https://github.com/mvalipour"]
+ - ["Marco Scannadinari", "https://github.com/marcoms"]
+translators:
+ - ["@prrrnd", "https://github.com/prrrnd"]
+lang: fr-fr
+---
+
+Au début du web, il n'y avait pas d'élements visuels, simplement du texte pure. Mais avec le dévelopement des navigateurs,
+des pages avec du contenu visuel sont arrivées.
+CSS est le langage standard qui existe et permet de garder une séparation entre
+le contenu (HTML) et le style d'une page web.
+
+En résumé, CSS fournit une syntaxe qui vous permet de cibler des élements présents
+sur une page HTML afin de leur donner des propriétés visuelles différentes.
+
+Comme tous les autres langages, CSS a plusieurs versions. Ici, nous allons parlons de CSS2.0
+qui n'est pas le plus récent, mais qui reste le plus utilisé et le plus compatible avec les différents navigateur.
+
+**NOTE :** Vous pouvez tester les effets visuels que vous ajoutez au fur et à mesure du tutoriel sur des sites comme [dabblet](http://dabblet.com/) afin de voir les résultats, comprendre, et vous familiariser avec le langage.
+Cet article porte principalement sur la syntaxe et quelques astuces.
+
+
+```css
+/* Les commentaires sont entourés par slash-étoile, comme cette ligne! */
+
+/* ####################
+ ## SÉLECTEURS
+ ####################*/
+
+/* Généralement, la première déclaration en CSS est très simple */
+selecteur { propriete: valeur; /* autres proprietés...*/ }
+
+/* Le sélécteur sert à cibler un élément du HTML
+
+Vous pouvez cibler tous les éléments d'une page! */
+* { color:red; }
+
+/*
+Voici un élément dans notre HTML :
+
+<div class='une-classe classe2' id='unId' attr='valeur' />
+*/
+
+/* Vous pouvez le cibler par une classe */
+.une-classe { }
+
+/* ou par deux */
+.une-classe.classe2 { }
+
+/* ou par son type */
+div { }
+
+/* ou son id */
+#unId { }
+
+/* ou par le fait qu'il a un attribut */
+[attr] { font-size:smaller; }
+
+/* ou que l'attribut a une valeur spécifique */
+[attr='valeur'] { font-size:smaller; }
+
+/* commence avec une valeur */
+[attr^='val'] { font-size:smaller; }
+
+/* termine avec une valeur */
+[attr$='eur'] { font-size:smaller; }
+
+/* contient une valeur */
+[attr~='leu'] { font-size:smaller; }
+
+
+/* Ce qu'il faut bien comprendre, c'est que vous pouvez combiner ceci -- Il ne doit pas y avoir
+d'espaces entre. */
+div.une-classe[attr$='eu'] { }
+
+/* Vous pouvez aussi cibler un élément par son parent. */
+
+/* Un élément qui est en enfant direct */
+div.un-parent > .enfant {}
+
+/* Cela cible aussi les .enfants plus profonds dans la structure HTML */
+div.un-parent .enfants {}
+
+/* Attention : le même sélecteur sans espace a un autre sens. */
+div.un-parent.classe {}
+
+/* Vous pouvez cibler un élément basé sur un enfant de même parent */
+.je-suis-avant + .cet-element { }
+
+/* ou n'importe quel enfant de même parent avec celui ci */
+.je-suis-tout-avant ~ .cet-element {}
+
+/* Il y a des pseudo-classes qui permettent de cibler un élément
+basé sur le comportement, en plus de la structure de la page */
+
+/* élément avec le curseur au-dessus */
+:hover {}
+
+/* lien visité */
+:visited {}
+
+/* lien non visité */
+:link {}
+
+/* élément avec le focus */
+:focus {}
+
+
+/* ####################
+ ## PROPRIÉTÉS
+ ####################*/
+
+selecteur {
+
+ /* Units */
+ width: 50%; /* pourcentage */
+ font-size: 2em; /* taille de la police multipliée par X */
+ width: 200px; /* pixels */
+ font-size: 20pt; /* points */
+ width: 5cm; /* centimetres */
+ width: 50mm; /* millimetres */
+ width: 5in; /* pouces */
+
+ /* Couleurs */
+ background-color: #F6E; /* court hex */
+ background-color: #F262E2; /* long hex */
+ background-color: tomato; /* couleur nommée */
+ background-color: rgb(255, 255, 255); /* rouge, vert, bleu */
+ background-color: rgb(10%, 20%, 50%); /* rouge, vert, bleu en pourcent */
+ background-color: rgba(255, 0, 0, 0.3); /* rouge, vert, bleu avec transparence */
+
+ /* Images */
+ background-image: url(/chemin-vers-image/image.jpg);
+
+ /* Polices */
+ font-family: Arial;
+ font-family: "Courier New"; /* Si espace, entre guillemets */
+ font-family: "Courier New", Trebuchet, Arial; /* Si la première n'est pas trouvée, la deuxième est utilisée, etc... */
+}
+
+```
+
+## Utilisation
+
+Le CSS s'écrit dans des fichiers `.css`.
+
+```xml
+<!-- Vous devez inclure le CSS dans la balise <head> : -->
+<link rel='stylesheet' type='text/css' href='chemin/style.css' />
+
+<!-- Vous pouvez inclure du CSS dans le HTML directement, mais ce n'est vraiment pas recommandé. -->
+<style>
+ selecteur { propriete:valeur; }
+</style>
+
+<!-- ou directement sur l'élément HTML.
+PS : à ne pas faire. -->
+<div style='propriete:valeur;'>
+</div>
+
+```
+
+## Priorités
+
+Comme on vient de le voir, un élément peut être ciblé par plus qu'un seul sélecteur
+et une même propriété peut être définie plusieurs fois.
+Dans ces cas, une des propriétés devient prioritaire.
+
+Voici du code CSS :
+
+```css
+/*A*/
+p.classe1[attr='valeur']
+
+/*B*/
+p.classe1 {}
+
+/*C*/
+p.classe2 {}
+
+/*D*/
+p {}
+
+/*E*/
+p { propriete: valeur !important; }
+
+```
+
+et le code HTML:
+
+```xml
+<p style='/*F*/ propriete:valeur;' class='classe1 classe2' attr='valeur'>
+</p>
+```
+
+Les priorités de style sont :
+Attention, les priorités s'appliquent aux **propriétés**, pas aux blocs entiers.
+
+* `E` a la priorité grâce à `!important`.
+* `F` vient ensuite, car le code se trouve directement dans le HTML.
+* `A` vient ensuite, car il est le plus spécifique.
+ plus spécifique veut dire, celui qui cible le plus l'élément
+* `C` vient ensuite. Il est aussi spécifique que `B`, mais est écrit après.
+* Puis `B`
+* Et enfin `D`.
+
+## Compatibilité
+
+La plupart des fonctionnalités de CSS2 (et de plus en plus CSS3) sont compatibles
+avec tous les navigateurs. Mais il est important de vérifier la compatibilité.
+
+[QuirksMode CSS](http://www.quirksmode.org/css/) est une très bonne source pour cela.
+
+## En savoir plus (en anglais)
+
+* [Understanding Style Precedence in CSS: Specificity, Inheritance, and the Cascade](http://www.vanseodesign.com/css/css-specificity-inheritance-cascaade/)
+* [QuirksMode CSS](http://www.quirksmode.org/css/)
+* [Z-Index - The stacking context](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Understanding_z_index/The_stacking_context)
diff --git a/fr-fr/haskell.html.markdown b/fr-fr/haskell.html.markdown
index 989db1d5..d9d3151f 100644
--- a/fr-fr/haskell.html.markdown
+++ b/fr-fr/haskell.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
translators:
diff --git a/fr-fr/javascript-fr.html.markdown b/fr-fr/javascript-fr.html.markdown
new file mode 100644
index 00000000..2e18d0be
--- /dev/null
+++ b/fr-fr/javascript-fr.html.markdown
@@ -0,0 +1,525 @@
+---
+language: javascript
+contributors:
+ - ['Adam Brenecki', 'http://adam.brenecki.id.au']
+ - ['Ariel Krakowski', 'http://www.learneroo.com']
+filename: javascript-fr.js
+translators:
+ - ['@nbrugneaux', 'https://nicolasbrugneaux.me']
+lang: fr-fr
+---
+
+JavaScript a été créé par Brendan Eich, travaillant alors a Netscape, en 1995.
+Le langage avait à l'origine pour but d'être un langage de scripting simple
+pour les sites web, complétant le Java (à ne pas confondre avec JavaScript)
+pour des applications web complexes. Mais son intégration très proche et
+simple des pages web, ainsi que le support natif des navigateurs a rendu
+le JavaScript incontournable aujourd'hui tant bien dans le front-end que
+dans le back-end.
+
+En effet, le JavaScript n'est plus uniquement limité aux navigateurs, grâce à
+Node.JS, un projet qui offre un environnement indépendant dans lequel un
+interpréteur Javascript, basé sur le célèbre moteur V8 de Google Chrome,
+peut être utilisé directement côté serveur pour exécuter des programmes écrits
+en JavaScript.
+
+```js
+// Les commentaires sont comme en C. Les commentaires mono-ligne commencent par 2 slashs,
+/* et les commentaires sur plusieurs lignes commencent avec slash-étoile
+ et finissent avec étoile-slash */
+
+// Toutes les expressions peuvent finir par ;
+doStuff();
+
+// ... mais n'en n'ont pas forcément besoin, les point-virgules sont ajoutés
+// lors de l’interprétation aux sauts de ligne, sauf exceptions
+doStuff()
+
+// Parce que ces cas peuvent produire des effets inattendus, nous utiliserons
+// des point-virgules dans ce guide.
+
+
+///////////////////////////////////
+// 1. Nombres, Chaines de caractères et Opérateurs
+
+// JavaScript a un seul type de nombre (qui est un 64-bit IEEE 754 double (décimaux))
+// Comme avec le Lua, ne paniquez pas à cause du manque d'int (entiers) : les
+// doubles ont un mantisse de 52 bits, ce qui est assez pour stocker des int jusqu'à
+// 9 x 10¹⁵ exactement.
+3; // = 3
+1.5; // = 1.5
+
+// L'arithmétique de base fonctionne comme vous vous y attendriez
+1 + 1; // = 2
+8 - 1; // = 7
+10 * 2; // = 20
+35 / 5; // = 7
+
+// Ainsi que les divisions non-entières
+5 / 2; // = 2.5
+
+// Les opérations bits à bits fonctionnent aussi, quand vous effectuez une opération
+// bits à bits, votre nombre décimal est converti en entier *jusqu'à* 32 bits.
+1 << 2; // = 4
+
+// Comme en mathématiques, la priorité est donnée aux parenthèses.
+(1 + 3) * 2; // = 8
+
+// Il existe 3 valeurs spéciales pour les nombres:
+Infinity; // le résultat de 1/0 par exemple
+-Infinity; // le résultat de -1/0 par exemple
+NaN; // le résultat de 0/0 par exemple
+
+// Il existe également le type booléen.
+true; // vrai
+false; // faux
+
+// Les chaines de caractères (strings) sont créees avec " ou ' indifféremment, la seule
+// raison de choisir l'un ou l'autre est la cohérence dans votre code.
+"abc";
+'Hello, world';
+
+// La négation utilise le symbole !
+!true; // = false
+!false; // = true
+
+// L'égalité est === ou ==
+// === compare la valeur exacte 2 === '2' // = false
+// == convertit la valeur pour comparer 2 === '2' // = true
+// En général, il vaut mieux utiliser === pour ne pas faire d'erreur.
+1 === 1; // = true
+2 === 1; // = false
+
+// L'inégalité est !== ou !=, basé sur le même principe qu'avant.
+1 !== 1; // = false
+2 !== 1; // = true
+
+// Plus de comparaisons :
+1 < 10; // = true
+1 > 10; // = false
+2 <= 2; // = true
+2 >= 2; // = true
+
+// Les chaines de caractères se concatènent avec +
+'Hello ' + 'world!'; // = 'Hello world!'
+
+// et peuvent être comparées alphabétiquement avec < et >
+'a' < 'b'; // = true
+
+// Vous pouvez accéder les caractères dans une string avec charAt
+'This is a string'.charAt(0); // = 'T'
+
+// ... ou utiliser substring pour avoir un plus gros morceau
+'Hello world'.substring(0, 5); // = 'Hello'
+
+// la longueur, length, est une propriété, donc n'utilisez pas de ()
+'Hello'.length; // = 5
+
+// Il y a également null et undefined
+null; // utilisé pour une non-valeur
+undefined; // utilisé pour une valeur actuellement non présente (cependant,
+ // undefined est aussi une valeur valide)
+
+// false, null, undefined, NaN, 0 and '' sont 'presque-faux' (falsy), tout le reste
+// est 'presque-vrai' (truthy)
+// Notez que 0 est falsy mais '0' est truthy, alors même que 0 == '0' (mais 0 !== '0')
+
+
+///////////////////////////////////
+// 2. Variables, Tableaux et Objets
+
+// Les variables sont déclarées avec le mot clé var. Le typage en JavaScript est
+// dynamique, donc pas besoin de spécifier le type. L'assignement utilise un seul =.
+var someVar = 5;
+
+// si vous oubliez le mot clé var, vous n'aurez pas d'erreur (sauf en mode strict)
+someOtherVar = 10;
+
+// ... mais la variable aura une portée globale (plus communément trouvé en tant
+// que "global scope" en anglais), et non pas une portée limitée à la fonction
+// dans laquelle vous l'aviez définie.
+
+// Les variables déclarées et non assignées sont undefined par défaut
+var someThirdVar;
+var someThirdVar = undefined;
+
+// ... sont deux déclarations identiques.
+
+// Il y a des raccourcis pour les opérations mathématiques:
+someVar += 5; // équivalent pour someVar = someVar + 5;
+someVar *= 10; // de même, someVar = someVar * 100;
+someVar++; // = someVar += 1;
+someVar--; // = someVar -= 1;
+
+// Les tableaux (Arrays) sont des listes ordonnées de valeurs, de tous types.
+var myArray = ['Hello', 45, true];
+
+// Leurs membres peuvent être accédés en utilisant les crochets
+// Les indices commencent à 0.
+myArray[1]; // = 45
+
+// Les tableaux sont modifiables, ainsi que leurs longueurs
+myArray.push( 'World' );
+myArray.length; // = 4
+
+// Ajout/Modification à un index spécifique
+myArray[3] = 'Hello';
+
+// Les objets JavaScript sont appelés 'dictionnaires' ou 'maps' dans certains autres
+// langages : ils sont une liste non-ordonnée de paires clé-valeur.
+var myObj = {key1: 'Hello', key2: 'World'};
+
+// Les clés sont des strings, mais les ' ou " sont optionels si elles sont des
+// noms valides en JavaScript. Les valeurs peuvent être de n'importe quel type.
+var myObj = {myKey: 'myValue', 'my other key': 4};
+
+// Les attributs d'objets peuvent être accédés avec les crochets
+myObj['my other key']; // = 4
+
+// .. ou avec un point si la clé est un identifiant valide.
+myObj.myKey; // = 'myValue'
+
+// Les objets sont eux aussi modifiables.
+myObj.myThirdKey = true;
+
+// Si vous essayez d'accéder à une valeur non-définie, vous obtiendrez undefined
+myObj.myFourthKey; // = undefined
+
+
+///////////////////////////////////
+// 3. Logique et structures de contrôle
+
+// Les si (if) fonctionnent comme vous vous y attendez.
+var count = 1;
+if (count === 3) {
+ // seulement quand count est 3
+}
+else if (count === 4) {
+ // uniquement quand count est 4
+}
+else {
+ // le reste du temps, si ni 3, ni 4.
+}
+
+// De même pour while.
+while (true) {
+ // Une boucle infinie !
+}
+
+// Les boucles do-while sont pareilles, mais sont exécutées au moins une fois.
+var input
+do {
+ input = getInput();
+} while (!isValid(input))
+
+// La boucle for est la même qu'en C ou en Java:
+// initialisation; condition pour continuer; itération
+for (var i = 0; i < 5; i++){
+ // sera exécutée 5 fois
+}
+
+// && est le "et" logique, || est le "ou" logique
+if (house.size === 'big' && house.colour === 'blue'){
+ house.contains = 'bear';
+}
+if (colour === 'red' || colour === 'blue'){
+ // colour est soit 'red' soit 'blue'
+}
+
+// Les raccourcis && et || sont pratiques pour instancier des valeurs par defaut.
+var name = otherName || 'default';
+
+// Ceci est l'équivalent de
+var name = otherName;
+if (!name){
+ name = 'default';
+}
+
+// Le switch vérifie les égalités avec ===
+// utilisez un "break" à la fin de chaque cas
+// ou les cas suivants seront eux aussi exécutés
+grade = 'B';
+switch (grade) {
+ case 'A':
+ console.log('Great job');
+ break;
+ case 'B':
+ console.log('OK job');
+ break;
+ case 'C':
+ console.log('You can do better');
+ break;
+ default:
+ console.log('Oy vey');
+ break;
+}
+
+
+///////////////////////////////////
+// 4. Fonctions, Scope (Environnement) et Closures
+
+// Les fonctions sont déclarées avec le mot clé function
+function myFunction(thing){
+ return thing.toUpperCase();
+}
+myFunction('foo'); // = 'FOO'
+
+// Les fonctions JavaScript sont des objets de première classe, donc peuvent
+// être réassignées à d'autres variables et passées en tant que paramètres pour
+// d'autres fonctions
+function myFunction(){
+ // ce code s'exécutera dans 5 secondes
+}
+setTimeout(myFunction, 5000);
+// Note: setTimeout ne fait pas parti du langage, mais les navigateurs ainsi
+// que Node.js le rendent disponible
+
+// Les fonctions n'ont pas nécessairement besoin d'un nom, elles peuvent être
+// anonymes
+setTimeout(function(){
+ // ce code s'exécutera dans 5 secondes
+}, 5000);
+
+// Le Javascript crée uniquement un scope, une portée d'action limitée, pour
+// les fonctions, et pas dans les autres blocs.
+if (true){
+ var i = 5;
+}
+i; // = 5 - et non undefined comme vous pourriez vous y attendre
+
+// Cela a mené à un style commun de fonctions anonymes immédiatement exécutée;
+// ou "immediately-executing anonymous functions"
+(function(){
+ var temporary = 5;
+ // Nous pouvons accéder au scope global en assignant à l'objet global,
+ // qui dans les navigateurs est "window". Il est différent dans Node.js,
+ // le scope global sera en fait local au module dans lequel vous
+ // vous trouvez. http://nodejs.org/api/globals.html
+ window.permanent = 10;
+})();
+// Cela permet de ne pas avoir de fuites de variables qui polluent
+// l’environnement global.
+temporary; // raises ReferenceError
+permanent; // = 10
+
+// Une des fonctionnalités les plus puissantes de Javascript est le système de
+// closures. Si une fonction est définie dans une autre fonction, alors la
+// fonction interne aura accès aux variables de la fonction parente, même si
+// celle-ci a déjà finie son exécution.
+function sayHelloInFiveSeconds(name){
+ var prompt = 'Hello, ' + name + '!';
+ // Fonction interne
+ function inner(){
+ alert(prompt);
+ }
+ setTimeout(inner, 5000);
+ // setTimeout is asynchrone, donc la fonction sayHelloInFiveSeconds quittera
+ // immédiatement, et setTimeout appelera inner après.
+}
+sayHelloInFiveSeconds('Adam'); // ouvre un popup avec 'Hello, Adam!' dans 5sec
+
+
+///////////////////////////////////
+// 5. Encore plus à propos des Objets; Constructeurs and Prototypes
+
+// Les objets peuvent contenir des fonctions.
+var myObj = {
+ myFunc: function(){
+ return 'Hello world!';
+ }
+};
+myObj.myFunc(); // = 'Hello world!'
+
+// Lorsqu'une fonction attachée à un objet est appelée, elle peut accéder à
+// l'objet avec le mot clé this.
+myObj = {
+ myString: 'Hello world!',
+ myFunc: function(){
+ return this.myString;
+ }
+};
+myObj.myFunc(); // = 'Hello world!'
+
+// La valeur de "this" change de par l'endroit où la fonction est appelée, et
+// non de l'endroit où elle est définie. Donc elle ne fonctionnera pas si elle
+// est appelée hors du contexte l'objet.
+var myFunc = myObj.myFunc;
+myFunc(); // = undefined
+
+// A l'inverse, une fonction peut être attachée à un objet et y gagner l'accès
+// au travers de "this"
+var myOtherFunc = function(){
+ return this.myString.toUpperCase();
+}
+
+myObj.myOtherFunc = myOtherFunc;
+myObj.myOtherFunc(); // = 'HELLO WORLD!'
+
+// Le contexte correspond à la valeur de "this".
+// Nous pouvons aussi spécifier un contexte, forcer la valeur de "this,
+// pour une fonction quand elle est appelée grâce à "call" ou "apply".
+var anotherFunc = function(s){
+ return this.myString + s;
+}
+anotherFunc.call(myObj, ' And Hello Moon!'); // = 'Hello World! And Hello Moon!'
+
+// 'apply' est presque identique, mais prend un tableau comme liste d’arguments.
+
+anotherFunc.apply(myObj, [' And Hello Sun!']); // = 'Hello World! And Hello Sun!'
+
+Math.min(42, 6, 27); // = 6
+Math.min([42, 6, 27]); // = NaN (uh-oh!)
+Math.min.apply(Math, [42, 6, 27]); // = 6
+
+// Mais, "call" and "apply" fonctionnenent uniquement au moment de l'appel de la
+// fonction. Pour lier le contexte de façon permanente, nous pouvons utiliser
+// "bind" pour garder une référence à la fonction avec ce "this".
+var boundFunc = anotherFunc.bind(myObj);
+boundFunc(' And Hello Saturn!'); // = 'Hello World! And Hello Saturn!'
+
+// "bind" peut aussi être utilisé pour créer une application partielle de la
+// fonction (curry)
+var product = function(a, b){ return a * b; }
+var doubler = product.bind(this, 2);
+doubler(8); // = 16
+
+// Lorsque vous appelez une fonction avec le mot clé "new", un nouvel objet est
+// crée et mis à disposition de la fonction via "this". Ces fonctions sont
+// communément appelées constructeurs.
+var MyConstructor = function(){
+ this.myNumber = 5;
+}
+myNewObj = new MyConstructor(); // = {myNumber: 5}
+myNewObj.myNumber; // = 5
+
+// Chaque objet en Javascript a un "prototype". Quand vous essayez d'accéder à
+// une propriété que l'objet n'a pas, l'interpréteur va regarder son prototype.
+
+// Quelques implémentations de JS vous laissent accéder au prototype avec la
+// propriété "magique" __proto__. Ceci peut être utile, mais n'est pas standard
+// et ne fonctionne pas dans certains des navigateurs actuels.
+var myObj = {
+ myString: 'Hello world!'
+};
+var myPrototype = {
+ meaningOfLife: 42,
+ myFunc: function(){
+ return this.myString.toLowerCase()
+ }
+};
+
+myObj.__proto__ = myPrototype;
+myObj.meaningOfLife; // = 42
+myObj.myFunc(); // = 'hello world!'
+
+myPrototype.__proto__ = {
+ myBoolean: true
+};
+myObj.myBoolean; // = true
+
+
+// Pour obtenir le prototype il existe également Object.getPrototypeOf
+Object.getPrototypeOf( myObj ) // = {meaningOfLife: 42, myFunc: function}
+
+// Il n'y a pas de copie ici. Chacun des objets stocke une référence à son
+// prototype. Cela veut dire que l'on peut le modifier et cela se répercutera
+// partout.
+myPrototype.meaningOfLife = 43;
+myObj.meaningOfLife; // = 43
+
+// L'inverse n'est cependant pas vrai. Changer la propriété d'un objet ne change
+// pas la chaine prototypale.
+myObj.meaningOfLife = 42;
+myPrototype.meaningOfLife; // = 43
+
+// Comme précédemment dit, __proto__ n'est pas standard et ne devrait pas être
+// utilisé. Il y a deux autres moyen de créer un nouvel objet avec un prototype
+// donné.
+
+// Le premier est Object.create, mais c'est assez récent et risque de ne pas
+// fonctionner dans tous les navigateurs.
+var myObj = Object.create(myPrototype);
+myObj.meaningOfLife; // = 43
+
+// Le deuxième moyen, qui marche partout, fonctionne avec les constructeurs.
+// Les constructeurs ont un propriété appelée prototype. Ce n'est *pas* le
+// prototype du constructeur de la fonction elle-même, c'est le prototype que
+// les nouveaux objets crées grâce à ce constructeur avec "new" auront.
+MyConstructor.prototype = {
+ myNumber: 5,
+ getMyNumber: function(){
+ return this.myNumber;
+ }
+};
+var myNewObj2 = new MyConstructor();
+myNewObj2.getMyNumber(); // = 5
+myNewObj2.myNumber = 6
+myNewObj2.getMyNumber(); // = 6
+
+// Les types pré-définis tels que les strings ou nombres ont aussi des
+// constructeurs
+var myNumber = 12;
+var myNumberObj = new Number(12);
+myNumber == myNumberObj; // = true
+
+// ... mais ils ne sont pas exactement équivalent.
+typeof myNumber; // = 'number'
+typeof myNumberObj; // = 'object'
+myNumber === myNumberObj; // = false
+if (0){
+ // 0 est falsy, le code ne fonctionnera pas.
+}
+if (Number(0)){
+ // Parce que Number(0) est truthy, le code fonctionnera
+}
+
+// Cependant, vous pouvez ajouter des fonctionnalités aux types de bases grâce à
+// cette particularité.
+String.prototype.firstCharacter = function(){
+ return this.charAt(0);
+}
+'abc'.firstCharacter(); // = 'a'
+
+// C'est très souvent utilisé pour le "polyfilling", qui implémente des nouvelles
+// fonctionnalités de JavaScript dans de plus anciens environnements, tels que
+// les vieux navigateurs.
+
+//Par exemple, Object.create est assez récent, mais peut être implémenté grâce à
+// ce polyfill
+if (Object.create === undefined){ // pour ne pas reécrire si la fonction existe déjà
+ Object.create = function(proto){
+ // on crée un constructeur temporaire avec le bon prototype
+ var Constructor = function(){};
+ Constructor.prototype = proto;
+ // puis on utilise "new" pour créer un object avec ce même prototype
+ return new Constructor();
+ }
+}
+```
+
+## Pour aller plus loin (en anglais)
+
+The [Mozilla Developer
+Network](https://developer.mozilla.org/fr-FR/docs/Web/JavaScript) expose une
+excellente documentation pour le Javascript dans les navigateurs. Et contient
+également un wiki pour s'entraider.
+
+MDN's [A re-introduction to
+JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
+recouvre les principaux sujets vus ici. Le guide est délibérément uniquement
+à propos du JavaScript, et ne parle pas des navigateurs; pour cela, dirigez vous
+plutôt ici :
+[Document Object
+Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core)
+
+[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) quelques challenges.
+
+[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth
+un guide pour vous éviter les faux-amis dans le JavaScript.
+
+[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) un classique. A lire.
+
+En addition aux contributeurs de cet article, du contenu provient du
+"Python tutorial" de Louie Dinh, et de [JS
+Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript)
+sur le réseau Mozilla.
diff --git a/fr-fr/lua-fr.html.markdown b/fr-fr/lua-fr.html.markdown
index 922d6ebc..b4e2a161 100644
--- a/fr-fr/lua-fr.html.markdown
+++ b/fr-fr/lua-fr.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
filename: learnlua-fr.lua
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
diff --git a/fr-fr/markdown.html.markdown b/fr-fr/markdown.html.markdown
new file mode 100644
index 00000000..29c0d65d
--- /dev/null
+++ b/fr-fr/markdown.html.markdown
@@ -0,0 +1,289 @@
+---
+language: markdown
+contributors:
+- ["Andrei Curelaru", "http://www.infinidad.fr"]
+filename: markdown.md
+lang: fr-fr
+---
+
+Markdown a été créé par John Gruber en 2004. Il se veut être d'une syntaxe
+facile à lire et à écrire, aisément convertible en HTML
+ (et beaucoup d'autres formats aussi à présent).
+
+Faites moi autant de retours que vous voulez! Sentez vous libre de "forker"
+et envoyer des pull request!
+
+
+```markdown
+<!-- Markdown est une sorte de cousin du HTML, si bien que tout document HTML
+est un document Markdown valide. Autrement dit, vous pouvez utiliser des
+balises HTML dans un fichier Markdown, comme la balise commentaire dans
+laquelle nous sommes à présent, car celle-ci ne sera pas affectée par
+le parser( analyseur syntaxique ) Markdown. -->
+
+<!-- Toutefois, si vous voulez créer un élément HTML dans un fichier Markdown,
+ vous ne pourrez pas utiliser du Markdown à l'intérieur de ce dernier. -->
+
+<!-- Le Markdown est implémenté de différentes manières, selon le parser.
+Ce guide va alors tenter de trier les fonctionnalités universelles de celles
+spécifiques à un parser. -->
+
+<!-- Headers ( En-têtes ) -->
+<!-- Vous pouvez facilement créer des éléments HTML <h1> à <h6> en précédant
+ le texte de votre futur titre par un ou plusieurs dièses ( # ), de un à six,
+ selon le niveau de titre souhaité. -->
+# Ceci est un <h1>
+## Ceci est un <h2>
+### Ceci est un <h3>
+#### Ceci est un <h4>
+##### Ceci est un <h5>
+###### Ceci est un <h6>
+
+<!--
+Markdown fournit également une façon alternative de marquer les h1 et h2
+-->
+
+Ceci est un h1
+=============
+
+Ceci est un h2
+-------------
+
+<!-- Styles basiques pour du texte -->
+<!-- On peut facilement rendre un texte "gras" ou "italique" en Markdown -->
+
+*Ce texte est en italique.*
+_Celui-ci aussi._
+
+**Ce texte est en gras.**
+__Celui-là aussi.__
+
+***Ce texte a les deux styles.***
+**_Pareil ici_**
+*__Et là!__*
+
+<!-- Dans le "Github Flavored Markdown", utilisé pour interpréter le Markdown
+sur Github, on a également le strikethrough ( texte barré ) : -->
+
+~~Ce texte est barré avec strikethrough.~~
+
+<!-- Les Paragraphes sont représentés par une ou plusieurs lignes de texte
+séparées par une ou plusieurs lignes vides. -->
+
+Ceci est un paragraphe. Là, je suis dans un paragraphe, facile non?
+
+Maintenant je suis dans le paragraphe 2.
+Je suis toujours dans le paragraphe 2!
+
+
+Puis là, eh oui, le paragraphe 3!
+
+<!--
+Si jamais vous souhaitez insérer une balise HTML <br />, vous pouvez ajouter
+un ou plusieurs espaces à la fin de votre paragraphe, et en commencer
+un nouveau.
+-->
+
+J'ai deux espaces vides à la fin (sélectionnez moi pour les voir).
+
+Bigre, il y a un <br /> au dessus de moi!
+
+<!-- Les 'Blocs de Citations' sont générés aisément, grâce au caractère > -->
+
+> Ceci est une superbe citation. Vous pouvez même
+> revenir à la ligne quand ça vous chante, et placer un `>`
+> devant chaque bout de ligne faisant partie
+> de la citation.
+> La taille ne compte pas^^ tant que chaque ligne commence par un `>`.
+
+> Vous pouvez aussi utiliser plus d'un niveau
+>> d'imbrication!
+> Classe et facile, pas vrai?
+
+<!-- les Listes -->
+<!-- les Listes non ordonnées sont marquées par des asterisques,
+signes plus ou signes moins. -->
+
+* Item
+* Item
+* Un autre item
+
+ou
+
++ Item
++ Item
++ Encore un item
+
+ou
+
+- Item
+- Item
+- Un dernier item
+
+<!-- les Listes Ordonnées sont générées via un nombre suivi d'un point -->
+
+1. Item un
+2. Item deux
+3. Item trois
+
+<!-- Vous pouvez même vous passer de tout numéroter, et Markdown générera
+les bons chiffres. Ceci dit, cette variante perd en clarté.-->
+
+1. Item un
+1. Item deux
+1. Item trois
+<!-- ( cette liste sera interprétée de la même façon que celle au dessus ) -->
+
+<!-- Vous pouvez également utiliser des sous-listes -->
+
+1. Item un
+2. Item deux
+3. Item trois
+* Sub-item
+* Sub-item
+4. Item quatre
+
+<!-- Il y a même des "listes de Taches". Elles génèrent des champs HTML
+de type checkbox. -->
+
+Les [ ] ci dessous, n'ayant pas de [ x ],
+deviendront des cases à cocher HTML non-cochées.
+
+- [ ] Première tache à réaliser.
+- [ ] Une autre chose à faire.
+La case suivante sera une case à cocher HTML cochée.
+- [x] Ça ... c'est fait!
+
+<!-- les Blocs de Code -->
+<!-- Pour marquer du texte comme étant du code, il suffit de commencer
+chaque ligne en tapant 4 espaces (ou un Tab) -->
+
+ echo "Ça, c'est du Code!";
+ var Ça = "aussi !";
+
+<!-- L'indentation par tab ou série de quatre espaces
+fonctionne aussi à l'intérieur du bloc de code -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Des bouts de code en mode 'inline' s'ajoutent en les entourant de ` -->
+
+La fonction `run()` ne vous oblige pas à aller courir!
+
+<!-- Via Github Flavored Markdown, vous pouvez utiliser
+des syntaxes spécifiques -->
+
+\`\`\`ruby
+<!-- mais enlevez les backslashes quand vous faites ça,
+gardez juste ```ruby ( ou nom de la synatxe correspondant à votre code )-->
+def foobar
+puts "Hello world!"
+end
+\`\`\` <!-- pareil, pas de backslashes, juste ``` en guise de fin -->
+
+<-- Pas besoin d'indentation pour le code juste au dessus, de plus, Github
+va utiliser une coloration syntaxique pour le langage indiqué après les ``` -->
+
+<!-- Ligne Horizontale (<hr />) -->
+<!-- Pour en insérer une, utilisez trois ou plusieurs astérisques ou tirets,
+avec ou sans espaces entre chaque un. -->
+
+***
+---
+- - -
+****************
+
+<!-- Liens -->
+<!-- Une des fonctionnalités sympathiques du Markdown est la facilité
+d'ajouter des liens. Le texte du lien entre [ ], l'url entre ( ),
+et voilà l'travail.
+-->
+
+[Clic moi!](http://test.com/)
+
+<!--
+Pour ajouter un attribut Title, collez le entre guillemets, avec le lien.
+-->
+
+[Clic moi!](http://test.com/ "Lien vers Test.com")
+
+<!-- les Liens Relatifs marchent aussi -->
+
+[En avant la musique](/music/).
+
+<!-- Les liens façon "références" sont eux aussi disponibles en Markdown -->
+
+[Cliquez ici][link1] pour plus d'information!
+[Regardez aussi par ici][foobar] si vous voulez.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- Le titre peut aussi être entouré de guillemets simples,
+entre parenthèses ou absent. Les références peuvent être placées
+un peu où vous voulez dans le document, et les identifiants
+(link1, foobar, ...) quoi que ce soit tant qu'ils sont uniques -->
+
+<!-- Il y a également le "nommage implicite" qui transforme le texte du lien
+ en identifiant -->
+
+[Ceci][] est un lien.
+
+[ceci]: http://ceciestunlien.com/
+
+<!-- mais ce n'est pas beaucoup utilisé. -->
+
+<!-- Images -->
+<!-- Pour les images, la syntaxe est identique aux liens, sauf que précédée
+ d'un point d'exclamation! -->
+
+![Attribut ALT de l'image](http://imgur.com/monimage.jpg "Titre optionnel")
+
+<!-- Là aussi, on peut utiliser le mode "références" -->
+
+![Ceci est l'attribut ALT de l'image][monimage]
+
+[monimage]: relative/urls/cool/image.jpg "si vous voulez un titre, c'est ici."
+
+<!-- Divers -->
+<!-- Liens Automatiques -->
+
+<http://testwebsite.com/> est équivalent à :
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Liens Automatiques pour emails -->
+
+<foo@bar.com>
+
+<!-- Escaping -->
+Il suffit de précéder les caractères spécifiques à ignorer par des backslash \
+
+Pour taper *ce texte* entouré d'astérisques mais pas en italique :
+Tapez \*ce texte\*.
+
+<!-- Tableaux -->
+<!-- les Tableaux ne sont disponibles que dans le Github Flavored Markdown
+ et c'est ce n'est pas super agréable d'utilisation.
+ Mais si vous en avez besoin :
+ -->
+
+| Col1 | Col2 | Col3 |
+| :----------- | :------: | ------------: |
+| Alignement Gauche | Centé | Alignement Droite |
+| bla | bla | bla |
+
+<!-- ou bien, pour un résultat équivalent : -->
+
+Col 1 | Col2 | Col3
+:-- | :-: | --:
+Ough que c'est moche | svp | arrêtez
+
+<!-- Fin! -->
+
+```
+
+Pour plus d'information :
+ consultez [ici](http://daringfireball.net/projects/markdown/syntax) le post officiel de Jhon Gruber à propos de la syntaxe,
+ et [là](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) la superbe cheatsheet de Adam Pritchard.
diff --git a/fr-fr/objective-c-fr.html.markdown b/fr-fr/objective-c-fr.html.markdown
index b98d161e..69f4d8f9 100644
--- a/fr-fr/objective-c-fr.html.markdown
+++ b/fr-fr/objective-c-fr.html.markdown
@@ -14,7 +14,7 @@ lang: fr-fr
L'Objective-C est un langage de programmation orienté objet réflexif principalement utilisé par Apple pour les systèmes d'exploitations Mac OS X et iOS et leurs frameworks respectifs, Cocoa et Cocoa Touch.
-```cpp
+```objective_c
// Les commentaires sur une seule ligne commencent par //
/*
diff --git a/fr-fr/scala.html.markdown b/fr-fr/scala.html.markdown
index da562138..a43edf16 100644
--- a/fr-fr/scala.html.markdown
+++ b/fr-fr/scala.html.markdown
@@ -1,12 +1,11 @@
---
language: Scala
-filename: learnscala.scala
contributors:
- ["George Petrov", "http://github.com/petrovg"]
- ["Dominic Bou-Samra", "http://dbousamra.github.com"]
translators:
- - ["Anne-Catherine Dehier", "https://github.com/spellart"]
-filename: learn.scala
+ - ["Anne-Catherine Dehier", "https://github.com/spellart"]
+filename: learnscala-fr.scala
lang: fr-fr
---
diff --git a/fr-fr/xml-fr.html.markdown b/fr-fr/xml-fr.html.markdown
new file mode 100644
index 00000000..ed5f55ff
--- /dev/null
+++ b/fr-fr/xml-fr.html.markdown
@@ -0,0 +1,128 @@
+---
+language: xml
+contributors:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+translators:
+ - ["Geoffrey Liu", "https://github.com/g-liu"]
+filename: learnxml-fr.xml
+lang: fr-fr
+---
+
+XML est un langage de balisage conçu pour stocker et transporter les informations.
+
+Contrairement à HTML, XML ne spécifie pas comment afficher ou formater les informations, juste comment les porter.
+
+* La syntaxe XML
+
+```xml
+<!-- Les commentaires en XML ressemblent ceci -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<librairie>
+ <livre categorie="CUISINE">
+ <titre lang="en">Everyday Italian</titre>
+ <auteur>Giada De Laurentiis</auteur>
+ <an>2005</an>
+ <prix>30.00</prix>
+ </livre>
+ <livre categorie="ENFANTS">
+ <titre lang="en">Harry Potter</titre>
+ <auteur>J. K. Rowling</auteur>
+ <an>2005</an>
+ <prix>29.99</prix>
+ </livre>
+ <livre categorie="WEB">
+ <titre lang="en">Learning XML</titre>
+ <auteur>Erik T. Ray</auteur>
+ <an>2003</an>
+ <prix>39.95</prix>
+ </livre>
+</librairie>
+
+<!-- Ce qui suit est un fichier XML typique.
+ Il commence par une déclaration, qui informe certaines métadonnées (en option).
+
+XML utilise une structure arborescente. Ci-dessus, le nœud racine est «librairie», qui a
+   trois nœuds enfants, qui sont appelés «livres». Ces nœuds ont plus de nœuds enfants, et ainsi de suite ...
+
+On crée les nœuds avec des balises d'ouverture / fermeture, et les enfants sont les nœuds juste entre
+   les balises d'ouverture et de fermeture. -->
+
+
+<!-- XML porte deux types d'informations:
+ 1 - Les attributs -> les métadonnées sur un nœud.
+ Habituellement, l'analyseur XML utilise cette information pour bien stocker les données.
+ 2 - Les éléments -> les informations pures.
+ C'est ce que l'analyseur retrouvera du fichier XML.
+ Les éléments apparaissent entre les balises d'ouverture et de fermeture, sans parenthèses. -->
+
+
+<!-- Ci-dessous, un élément avec deux attributs -->
+<fichier type="gif" id="4293">ordinateur.gif</fichier>
+
+
+```
+
+* Un document bien formaté & le validation
+
+Un document XML est bien formaté s'il est syntaxiquement correct.
+Cependant, il est possible d'injecter plus de contraintes dans le document,
+en utilisant les définitions de documents, tels que les schémas DTD et XML.
+
+Un document XML qui suit une définition de document est dit valide,
+en ce qui concerne ce document.
+
+Avec cet outil, vous pouvez vérifier les données XML en dehors de la logique de l'application.
+
+```xml
+
+<!-- Ci-dessous, vous pouvez voir une version simplifiée du document de librairie,
+   avec l'addition de définition DTD. -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE note SYSTEM "Librairie.dtd">
+<librairie>
+ <livre categorie="CUISINE">
+ <titre>Everyday Italian</titre>
+ <prix>30.00</prix>
+ </livre>
+</librairie>
+
+<!-- Cette DTD pourrait être quelque chose comme: -->
+
+<!DOCTYPE note
+[
+<!ELEMENT librairie (livre+)>
+<!ELEMENT livre (titre,prix)>
+<!ATTLIST livre categorie CDATA "Littérature">
+<!ELEMENT titre (#PCDATA)>
+<!ELEMENT prix (#PCDATA)>
+]>
+
+<!-- La DTD commence par une déclaration.
+   Après, le nœud racine est déclaré, qui exige un ou plusieurs nœuds enfants.
+   Chaque «livre» doit contenir exactement un «titre» et «prix» et un attribut
+   appelé «catégorie», avec «littérature» comme valeur par défaut.
+   Les nœuds de «titre» et «prix» contiennent des informations de caractère analysés
+ (Anglais: «parsed character data») -->
+
+<!-- La DTD pourrait être déclarée dans le fichier XML lui-même -->
+
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!DOCTYPE note
+[
+<!ELEMENT librairie (livre+)>
+<!ELEMENT livre (titre,prix)>
+<!ATTLIST livre categorie CDATA "Littérature">
+<!ELEMENT titre (#PCDATA)>
+<!ELEMENT prix (#PCDATA)>
+]>
+
+<librairie>
+ <livre categorie="CUISINE">
+ <titre>Everyday Italian</titre>
+ <prix>30.00</prix>
+ </livre>
+</librairie>
+```
diff --git a/fr-fr/yaml-fr.html.markdown b/fr-fr/yaml-fr.html.markdown
new file mode 100644
index 00000000..43b1df54
--- /dev/null
+++ b/fr-fr/yaml-fr.html.markdown
@@ -0,0 +1,157 @@
+---
+language: yaml
+filename: learnyaml.yaml
+contributors:
+ - ["Andrei Curelaru", "http://www.infinidad.fr"]
+lang: fr-fr
+---
+
+Proposé à l'origine par Clark Evans en Mai 2001, YAML est un un format de
+représentation de données par sérialisation, conçu pour être aisément
+éditable et lisible par nous même, les humains.
+
+YAML est plus concis que le XML auquel il est parfois comparé par ceux qui le découvre, plus lisible et clair que le CSV, et emprunte beaucoup au JSON dont il est un parent naturel. Toutefois, YAML emprunte également des idées et concepts de chez Python, et s'intègre bien avec bon nombre de langages.
+
+
+```yaml
+# les Commentaires sont précédés d'un signe "#", comme cette ligne.
+
+#############
+# SCALAIRES #
+#############
+
+# Les scalaires sont l'ensemble des types YAML qui ne sont pas des collections
+# ( listes ou tableaux associatifs ).
+
+# Notre objet root ( racine ), sera une map ( carte ) et englobera
+# l'intégralité du document. Cette map est l'équivalent d'un dictionnaire,
+# hash ou objet dans d'autres langages.
+clé: valeur
+aurtre_clé: une autre valeur
+valeur_numérique: 100
+notation_scientifique: 1e+12
+boolean: true
+valeur_null: null
+clé avec espaces: valeur
+# Bien qu'il ne soit pas nécessaire d'enfermer les chaînes de caractères
+# entre guillemets, cela reste possible, et parfois utile.
+toutefois: "Une chaîne, peut être contenue entre guillemets."
+"Une clé entre guillemets.": "Utile si on veut utiliser ':' dans la clé."
+
+# Les chaînes couvrant plusieurs lignes, peuvent être écrites au choix,
+# comme un 'bloc littéral' ( avec | ) ou bien 'bloc replié' avec ( > ).
+bloc_littéral: |
+ Tout ce bloc de texte sera la valeur de la clé 'bloc_littéral',
+ avec préservation des retours à la ligne. ( chaque ligne vide à
+ l'intérieur du même bloc, sera remplacée par "\n\n" )
+
+ Le littéral continue jusqu'à ce que l'indentation soit annulée.
+
+ Toutes lignes qui serait "d'avantage indentées" conservent leur
+ indentation, constituée de 4 espaces.
+bloc_replié: >
+ Tout ce bloc de texte sera la valeur de la clé 'bloc_replié', mais
+ cette fois ci, toutes les nouvelles lignes deviendront un simple espace.
+
+ Les lignes vides, comme ci-dessus, seront converties en caractère "\n".
+
+ Les lignes 'plus-indentées' gardent leurs retours à la ligne -
+ ce texte apparaîtra sur deux lignes.
+
+###############
+# COLLECTIONS #
+###############
+
+# l'Imbrication est créée par indentation.
+une_map_imbriquée:
+ clé: valeur
+ autre_clé: autre valeur
+ autre_map_imbriquée:
+ bonjour: bonjour
+
+# les Clés des Maps ne sont pas nécessairement des chaînes de caractères.
+0.25: une clé de type float
+
+# les Clés peuvent également être des objets s'étendant sur plusieurs lignes,
+# en utilisant le signe "?" pour indiquer le début de la clé.
+? |
+ ceci est une Clé
+ sur de multiples lignes
+: et ceci est sa Valeur
+
+# YAML autorise aussi l'usage des collections à l'intérieur des clés,
+# mais certains langages de programmation ne le tolère pas si bien.
+
+# les Séquences (équivalent des listes ou tableaux) ressemblent à cela:
+une_séquence:
+ - Item 1
+ - Item 2
+ - 0.5 # les séquences peuvent contenir des types variés.
+ - Item 4
+ - clé: valeur
+ autre_clé: autre_valeur
+ -
+ - Ceci est une séquence
+ - dans une autre séquence
+
+# YAML étant un proche parent de JSON, vous pouvez écrire directement
+# des maps et séquences façon JSON
+json_map: {"clé": "valeur"}
+json_seq: [1, 2, 3, "soleil"]
+
+#################################
+# AUTRES FONCTIONNALITÉES YAML #
+#################################
+
+# YAML possède une fonctionnalité fort utile nommée 'ancres'. Celle-ci
+# vous permet de dupliquer aisément du contenu au sein de votre document.
+
+# Les deux clés suivantes auront la même valeur:
+contenu_ancré: &nom_ancre Cette chaîne sera la valeur des deux clés.
+autre_ancre: *nom_ancre
+
+# Avec les Tags YAML, vous pouvez explicitement déclarer des types de données.
+chaine_explicite: !!str 0.5
+
+# Certains parsers implémentent des tags spécifiques à d'autres langages,
+# comme par exemple le "complex number" de Python.
+python_complex_number: !!python/complex 1+2j
+
+#####################
+# AUTRES TYPES YAML #
+#####################
+
+# YAML interprète également les données formatées ISO de type date et datetime,
+# pas seulement les chaînes et nombres.
+datetime: 2001-12-15T02:59:43.1Z
+datetime_avec_espaces: 2001-12-14 21:59:43.10 -5
+date: 2002-12-14
+
+# Le tag !!binary indique que la chaîne à suivre est la représentation binaire
+# d'un blob encodé en base64. En clair ? Une image !
+fichier_gif: !!binary |
+ R0lGODlhDAAMAIQAAP//9/X17unp5WZmZgAAAOfn515eXvPz7Y6OjuDg4J+fn5
+ OTk6enp56enmlpaWNjY6Ojo4SEhP/++f/++f/++f/++f/++f/++f/++f/++f/+
+ +f/++f/++f/++f/++f/++SH+Dk1hZGUgd2l0aCBHSU1QACwAAAAADAAMAAAFLC
+ AgjoEwnuNAFOhpEMTRiggcz4BNJHrv/zCFcLiwMWYNG84BwwEeECcgggoBADs=
+
+# YAML a de même un type "set", qui ressemble à cela:
+set:
+ ? item1
+ ? item2
+ ? item3
+
+# Comme dans Python, les sets ne sont que des maps contenant des valeurs null ;
+# le set précédent est l'équivalent du suivant:
+set2:
+ item1: null
+ item2: null
+ item3: null
+
+```
+
+Quelques références et outils :
+
+- Doc officielle [YAML 1.2](http://www.yaml.org/spec/1.2/spec.html) *anglais*,
+- Une [Introduction à YAML](http://sweetohm.net/html/introduction-yaml.html) très bien construite et claire,
+- Un outil pour tester [live](http://yaml-online-parser.appspot.com/) la syntaxe YAML, avec des exemples.
diff --git a/git.html.markdown b/git.html.markdown
index 618d1906..04350dd5 100644
--- a/git.html.markdown
+++ b/git.html.markdown
@@ -3,6 +3,8 @@ category: tool
tool: git
contributors:
- ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Leo Rudberg" , "http://github.com/LOZORD"]
+ - ["Betsy Lorton" , "http://github.com/schbetsy"]
filename: LearnGit.txt
---
@@ -334,6 +336,66 @@ $ git push -u origin master
$ git push
```
+### stash
+
+Stashing takes the dirty state of your working directory and saves it on a stack of unfinished changes that you can reapply at any time.
+
+Let's say you've been doing some work in your git repo, but you want to pull from the remote.
+Since you have dirty (uncommited) changes to some files, you are not able to run `git pull`.
+Instead, you can run `git stash` to save your changes onto a stack!
+
+```bash
+$ git stash
+Saved working directory and index state \
+ "WIP on master: 049d078 added the index file"
+ HEAD is now at 049d078 added the index file
+ (To restore them type "git stash apply")
+```
+
+Now you can pull!
+
+```bash
+git pull
+```
+`...changes apply...`
+
+Now check that everything is OK
+
+```bash
+$ git status
+# On branch master
+nothing to commit, working directory clean
+```
+
+You can see what "hunks" you've stashed so far using `git stash list`.
+Since the "hunks" are stored in a Last-In-First-Out stack, our most recent change will be at top.
+
+```bash
+$ git stash list
+stash@{0}: WIP on master: 049d078 added the index file
+stash@{1}: WIP on master: c264051 Revert "added file_size"
+stash@{2}: WIP on master: 21d80a5 added number to log
+```
+
+Now let's apply our dirty changes back by popping them off the stack.
+
+```bash
+$ git stash pop
+# On branch master
+# Changes not staged for commit:
+# (use "git add <file>..." to update what will be committed)
+#
+# modified: index.html
+# modified: lib/simplegit.rb
+#
+```
+
+`git stash apply` does the same thing
+
+Now you're ready to get back to work on your stuff!
+
+[Additional Reading.](http://git-scm.com/book/en/v1/Git-Tools-Stashing)
+
### rebase (caution)
Take all changes that were committed on one branch, and replay them onto another branch.
@@ -396,4 +458,4 @@ $ git rm /pather/to/the/file/HelloWorld.c
* [GitGuys](http://www.gitguys.com/)
-* [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html) \ No newline at end of file
+* [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html)
diff --git a/go.html.markdown b/go.html.markdown
index c85209e0..17f10bd9 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -12,7 +12,7 @@ contributors:
- ["Alexej Friesen", "https://github.com/heyalexej"]
---
-Go was created out of the need to get work done. It's not the latest trend
+Go was created out of the need to get work done. It's not the latest trend
in computer science, but it is the newest fastest way to solve real-world
problems.
@@ -26,7 +26,7 @@ Go comes with a great standard library and an enthusiastic community.
```go
// Single line comment
/* Multi-
- line comment */
+ line comment */
// A package clause starts every source file.
// Main is a special name declaring an executable rather than a library.
@@ -41,8 +41,8 @@ import (
"strconv" // String conversions.
)
-// A function definition. Main is special. It is the entry point for the
-// executable program. Love it or hate it, Go uses brace brackets.
+// A function definition. Main is special. It is the entry point for the
+// executable program. Love it or hate it, Go uses brace brackets.
func main() {
// Println outputs a line to stdout.
// Qualify it with the package name, fmt.
@@ -72,12 +72,12 @@ func learnMultiple(x, y int) (sum, prod int) {
// Some built-in types and literals.
func learnTypes() {
// Short declaration usually gives you what you want.
- s := "Learn Go!" // string type.
+ str := "Learn Go!" // string type.
s2 := `A "raw" string literal
can include line breaks.` // Same string type.
- // Non-ASCII literal. Go source is UTF-8.
+ // Non-ASCII literal. Go source is UTF-8.
g := 'Σ' // rune type, an alias for int32, holds a unicode code point.
f := 3.14195 // float64, an IEEE-754 64-bit floating point number.
@@ -92,11 +92,12 @@ can include line breaks.` // Same string type.
// 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.
+ a3 := [...]int{3, 1, 5} // An array initialized with a fixed size of three
+ // elements, with values 3, 1, and 5.
- // Slices have dynamic size. Arrays and slices each have advantages
+ // 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.
+ 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.
@@ -116,7 +117,7 @@ can include line breaks.` // Same string type.
fmt.Println(s) // Updated slice is now [1 2 3 4 5 6 7 8 9]
p, q := learnMemory() // Declares p, q to be type pointer to int.
- fmt.Println(*p, *q) // * follows a pointer. This prints two ints.
+ fmt.Println(*p, *q) // * follows a pointer. This prints two ints.
// Maps are a dynamically growable associative array type, like the
// hash or dictionary types of some other languages.
@@ -125,7 +126,7 @@ can include line breaks.` // Same string type.
// Unused variables are an error in Go.
// The underbar lets you "use" a variable but discard its value.
- _, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
+ _, _, _, _, _, _, _, _, _, _ = str, s2, g, f, u, pi, n, a3, s4, bs
// Output of course counts as using a variable.
fmt.Println(s, c, a4, s3, d2, m)
@@ -142,7 +143,7 @@ func learnNamedReturns(x, y int) (z int) {
return // z is implicit here, because we named it earlier.
}
-// Go is fully garbage collected. It has pointers but no pointer arithmetic.
+// Go is fully garbage collected. It has pointers but no pointer arithmetic.
// You can make a mistake with a nil pointer, but not by incrementing a pointer.
func learnMemory() (p, q *int) {
// Named return values p and q have type pointer to int.
@@ -220,7 +221,7 @@ func learnFlowControl() {
func(a, b int) int {
return (a + b) * 2
}(10, 2)) // Called with args 10 and 2
- // => Add + double two numbers: 24
+ // => Add + double two numbers: 24
// When you need it, you'll love it.
goto love
@@ -267,7 +268,7 @@ type pair struct {
x, y int
}
-// Define a method on type pair. Pair now implements Stringer.
+// Define a method on type pair. Pair now implements Stringer.
func (p pair) String() string { // p is called the "receiver"
// Sprintf is another public function in package fmt.
// Dot syntax references fields of p.
@@ -275,13 +276,13 @@ func (p pair) String() string { // p is called the "receiver"
}
func learnInterfaces() {
- // Brace syntax is a "struct literal." It evaluates to an initialized
- // struct. The := syntax declares and initializes p to this struct.
+ // Brace syntax is a "struct literal". It evaluates to an initialized
+ // struct. The := syntax declares and initializes p to this struct.
p := pair{3, 4}
fmt.Println(p.String()) // Call String method of p, of type pair.
var i Stringer // Declare i of interface type Stringer.
i = p // Valid because pair implements Stringer
- // Call String method of i, of type Stringer. Output same as above.
+ // 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
@@ -319,7 +320,7 @@ func learnErrorHandling() {
// prints 'strconv.ParseInt: parsing "non-int": invalid syntax'
fmt.Println(err)
}
- // We'll revisit interfaces a little later. Meanwhile,
+ // We'll revisit interfaces a little later. Meanwhile,
learnConcurrency()
}
@@ -330,12 +331,12 @@ func inc(i int, c chan int) {
// We'll use inc to increment some numbers concurrently.
func learnConcurrency() {
- // Same make function used earlier to make a slice. Make allocates and
+ // Same make function used earlier to make a slice. Make allocates and
// initializes slices, maps, and channels.
c := make(chan int)
- // Start three concurrent goroutines. Numbers will be incremented
+ // Start three concurrent goroutines. Numbers will be incremented
// concurrently, perhaps in parallel if the machine is capable and
- // properly configured. All three send to the same channel.
+ // properly configured. All three send to the same channel.
go inc(0, c) // go is a statement that starts a new goroutine.
go inc(10, c)
go inc(-805, c)
@@ -348,7 +349,7 @@ func learnConcurrency() {
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
+ // 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,
@@ -358,7 +359,7 @@ func learnConcurrency() {
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
+ // 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.
@@ -397,15 +398,15 @@ func requestServer() {
The root of all things Go is the [official Go web site](http://golang.org/).
There you can follow the tutorial, play interactively, and read lots.
-The language definition itself is highly recommended. It's easy to read
+The language definition itself is highly recommended. It's easy to read
and amazingly short (as language definitions go these days.)
You can play around with the code on [Go playground](https://play.golang.org/p/tnWMjr16Mm). Try to change it and run it from your browser! Note that you can use [https://play.golang.org](https://play.golang.org) as a [REPL](https://en.wikipedia.org/wiki/Read-eval-print_loop) to test things and code in your browser, without even installing Go.
On the reading list for students of Go is the [source code to the standard
-library](http://golang.org/src/pkg/). Comprehensively documented, it
+library](http://golang.org/src/pkg/). Comprehensively documented, it
demonstrates the best of readable and understandable Go, Go style, and Go
-idioms. Or you can click on a function name in [the
+idioms. Or you can click on a function name in [the
documentation](http://golang.org/pkg/) and the source code comes up!
Another great resource to learn Go is [Go by example](https://gobyexample.com/).
diff --git a/haml.html.markdown b/haml.html.markdown
new file mode 100644
index 00000000..aed3dcae
--- /dev/null
+++ b/haml.html.markdown
@@ -0,0 +1,155 @@
+---
+language: haml
+filename: learnhaml.haml
+contributors:
+ - ["Simon Neveu", "https://github.com/sneveu"]
+---
+
+Haml is a markup language predominantly used with Ruby that cleanly and simply describes the HTML of any web document without the use of inline code. It is a popular alternative to using Rails templating language (.erb) and allows you to embed Ruby code into your markup.
+
+It aims to reduce repetition in your markup by closing tags for you based on the structure of the indents in your code. The result is markup that is well-structured, DRY, logical, and easier to read.
+
+You can also use Haml on a project independent of Ruby, by installing the Haml gem on your machine and using the command line to convert it to html.
+
+$ haml input_file.haml output_file.html
+
+
+```haml
+/ -------------------------------------------
+/ Indenting
+/ -------------------------------------------
+
+/
+ Because of the importance indentation has on how your code is rendered, the
+ indents should be consistent throughout the document. Any differences in
+ indentation will throw an error. It's common-practice to use two spaces,
+ but it's really up to you, as long as they're constant.
+
+
+/ -------------------------------------------
+/ Comments
+/ -------------------------------------------
+
+/ This is what a comment looks like in Haml.
+
+/
+ To write a multi line comment, indent your commented code to be
+ wrapped by the forward slash
+
+-# This is a silent comment, which means it wont be rendered into the doc at all
+
+
+/ -------------------------------------------
+/ Html elements
+/ -------------------------------------------
+
+/ To write your tags, use the percent sign followed by the name of the tag
+%body
+ %header
+ %nav
+
+/ Notice no closing tags. The above code would output
+ <body>
+ <header>
+ <nav></nav>
+ </header>
+ </body>
+
+/ The div tag is the default element, so they can be written simply like this
+.foo
+
+/ To add content to a tag, add the text directly after the declaration
+%h1 Headline copy
+
+/ To write multiline content, nest it instead
+%p
+ This is a lot of content that we could probably split onto two
+ separate lines.
+
+/
+ You can escape html by using the ampersand and equals sign ( &= ). This
+ converts html-sensitive characters (&, /, :) into their html encoded
+ equivalents. For example
+
+%p
+ &= "Yes & yes"
+
+/ would output 'Yes &amp; yes'
+
+/ You can unescape html by using the bang and equals sign ( != )
+%p
+ != "This is how you write a paragraph tag <p></p>"
+
+/ which would output 'This is how you write a paragraph tag <p></p>'
+
+/ CSS classes can be added to your tags either by chaining .classnames to the tag
+%div.foo.bar
+
+/ or as part of a Ruby hash
+%div{:class => 'foo bar'}
+
+/ Attributes for any tag can be added in the hash
+%a{:href => '#', :class => 'bar', :title => 'Bar'}
+
+/ For boolean attributes assign the value 'true'
+%input{:selected => true}
+
+/ To write data-attributes, use the :data key with its value as another hash
+%div{:data => {:attribute => 'foo'}}
+
+
+/ -------------------------------------------
+/ Inserting Ruby
+/ -------------------------------------------
+
+/
+ To output a Ruby value as the contents of a tag, use an equals sign followed
+ by the Ruby code
+
+%h1= book.name
+
+%p
+ = book.author
+ = book.publisher
+
+
+/ To run some Ruby code without rendering it to the html, use a hyphen instead
+- books = ['book 1', 'book 2', 'book 3']
+
+/ Allowing you to do all sorts of awesome, like Ruby blocks
+- books.shuffle.each_with_index do |book, index|
+ %h1= book
+
+ if book do
+ %p This is a book
+
+/
+ Again, no need to add the closing tags to the block, even for the Ruby.
+ Indentation will take care of that for you.
+
+
+/ -------------------------------------------
+/ Inline Ruby / Ruby interpolation
+/ -------------------------------------------
+
+/ Include a Ruby variable in a line of plain text using #{}
+%p Your highest scoring game is #{best_game}
+
+
+/ -------------------------------------------
+/ Filters
+/ -------------------------------------------
+
+/
+ Use the colon to define Haml filters, one example of a filter you can
+ use is :javascript, which can be used for writing inline js
+
+:javascript
+ console.log('This is inline <script>');
+
+```
+
+## Additional resources
+
+- [What is HAML?](http://haml.info/) - A good introduction that does a much better job of explaining the benefits of using HAML.
+- [Official Docs](http://haml.info/docs/yardoc/file.REFERENCE.html) - If you'd like to go a little deeper.
diff --git a/haskell.html.markdown b/haskell.html.markdown
index e0489710..748a29da 100644
--- a/haskell.html.markdown
+++ b/haskell.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
---
@@ -110,7 +110,7 @@ last [1..5] -- 5
-- A tuple:
("haskell", 1)
--- accessing elements of a tuple
+-- accessing elements of a pair (i.e. a tuple of length 2)
fst ("haskell", 1) -- "haskell"
snd ("haskell", 1) -- 1
@@ -171,8 +171,8 @@ foldl1 (\acc x -> acc + x) [1..5] -- 15
-- 4. More functions
----------------------------------------------------
--- currying: if you don't pass in all the arguments to a function,
--- it gets "curried". That means it returns a function that takes the
+-- partial application: if you don't pass in all the arguments to a function,
+-- it gets "partially applied". That means it returns a function that takes the
-- rest of the arguments.
add a b = a + b
@@ -195,8 +195,8 @@ foo 5 -- 75
-- fixing precedence
-- Haskell has another function called `$`. This changes the precedence
-- so that everything to the left of it gets computed first and then applied
--- to everything on the right. You can use `.` and `$` to get rid of a lot
--- of parentheses:
+-- to everything on the right. You can use `$` (often in combination with `.`)
+-- to get rid of a lot of parentheses:
-- before
(even (fib 7)) -- true
@@ -204,6 +204,9 @@ foo 5 -- 75
-- after
even . fib $ 7 -- true
+-- equivalently
+even $ fib 7 -- true
+
----------------------------------------------------
-- 5. Type signatures
----------------------------------------------------
@@ -227,24 +230,24 @@ double :: Integer -> Integer
double x = x * 2
----------------------------------------------------
--- 6. Control Flow and If Statements
+-- 6. Control Flow and If Expressions
----------------------------------------------------
--- if statements
+-- if expressions
haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome"
--- if statements can be on multiple lines too, indentation is important
+-- if expressions can be on multiple lines too, indentation is important
haskell = if 1 == 1
then "awesome"
else "awful"
--- case statements: Here's how you could parse command line arguments
+-- case expressions: Here's how you could parse command line arguments
case args of
"help" -> printHelp
"start" -> startProgram
_ -> putStrLn "bad args"
--- Haskell doesn't have loops because it uses recursion instead.
+-- Haskell doesn't have loops; it uses recursion instead.
-- map applies a function over every element in an array
map (*2) [1..5] -- [2, 4, 6, 8, 10]
diff --git a/hy.html.markdown b/hy.html.markdown
index 04bd05c9..9beaff0c 100644
--- a/hy.html.markdown
+++ b/hy.html.markdown
@@ -83,7 +83,7 @@ True ; => True
(greet "bilbo") ;=> "hello bilbo"
; functions can take optional arguments as well as keyword arguments
-(defn foolist [arg1 &optional [arg2 2]]
+(defn foolists [arg1 &optional [arg2 2]]
[arg1 arg2])
(foolists 3) ;=> [3 2]
diff --git a/ja-jp/r-jp.html.markdown b/ja-jp/r-jp.html.markdown
index 3e6621f5..a8dd7c9c 100644
--- a/ja-jp/r-jp.html.markdown
+++ b/ja-jp/r-jp.html.markdown
@@ -14,7 +14,7 @@ R は統計計算用の言語です。
データの取得やクリーニング、統計処理やグラフ作成をするために便利な、たくさんのライブラリがあります。また、LaTeX文書からRコマンドを呼び出すこともできます
-```python
+```r
# コメント行は、#で開始します
@@ -772,4 +772,4 @@ pp + geom_point()
* RとR GUIはこちら [http://www.r-project.org/](http://www.r-project.org/)
-* [RStudio](http://www.rstudio.com/ide/) 別のGUI \ No newline at end of file
+* [RStudio](http://www.rstudio.com/ide/) 別のGUI
diff --git a/java.html.markdown b/java.html.markdown
index dffc3828..4661d4f9 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -49,7 +49,7 @@ public class LearnJava {
// Types & Variables
///////////////////////////////////////
- // Declare a variable using <type> <name> [
+ // Declare a variable using <type> <name>
// Byte - 8-bit signed two's complement integer
// (-128 <= byte <= 127)
byte fooByte = 100;
@@ -123,9 +123,15 @@ public class LearnJava {
// Others to check out
// ArrayLists - Like arrays except more functionality is offered,
// and the size is mutable
- // LinkedLists
- // Maps
- // HashMaps
+ // LinkedLists - Implementation of doubly-linked list. All of the
+ // operations perform as could be expected for
+ // a doubly-linked list.
+ // Maps - A set of objects that maps keys to values. A map cannot contain
+ // duplicate keys; each key can map to at most one value.
+ // HashMaps - This class uses a hashtable to implement the Map interface.
+ // This allows the execution time of basic operations,
+ // such as get and insert element, to remain constant even
+ // for large sets.
///////////////////////////////////////
// Operators
@@ -262,9 +268,9 @@ public class LearnJava {
System.out.println(bar); // Prints A, because the statement is true
- ///////////////////////////////////////
- // Converting Data Types And Typcasting
- ///////////////////////////////////////
+ ////////////////////////////////////////
+ // Converting Data Types And Typecasting
+ ////////////////////////////////////////
// Converting data
diff --git a/javascript.html.markdown b/javascript.html.markdown
index 7c869b28..aabd5e43 100644
--- a/javascript.html.markdown
+++ b/javascript.html.markdown
@@ -39,13 +39,14 @@ doStuff()
// 1. Numbers, Strings and Operators
// 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.
+// Doubles have a 52-bit mantissa, which is enough to store integers
+// up to about 9✕10¹⁵ precisely.
3; // = 3
1.5; // = 1.5
-// All the basic arithmetic works as you'd expect.
+// Some basic arithmetic works as you'd expect.
1 + 1; // = 2
+0.1 + 0.2; // = 0.30000000000000004
8 - 1; // = 7
10 * 2; // = 20
35 / 5; // = 7
@@ -77,13 +78,13 @@ false;
!true; // = false
!false; // = true
-// Equality is ==
-1 == 1; // = true
-2 == 1; // = false
+// Equality is ===
+1 === 1; // = true
+2 === 1; // = false
-// Inequality is !=
-1 != 1; // = false
-2 != 1; // = true
+// Inequality is !==
+1 !== 1; // = false
+2 !== 1; // = true
// More comparisons
1 < 10; // = true
@@ -97,11 +98,17 @@ false;
// and are compared with < and >
"a" < "b"; // = true
-// Type coercion is performed for comparisons...
+// Type coercion is performed for comparisons with double equals...
"5" == 5; // = true
+null == undefined; // = true
// ...unless you use ===
"5" === 5; // = false
+null === undefined; // = false
+
+// ...which can result in some weird behaviour...
+13 + !0; // 14
+"13" + !0; // '13true'
// You can access characters in a string with charAt
"This is a string".charAt(0); // = 'T'
diff --git a/json.html.markdown b/json.html.markdown
index 9041eaa2..f5287138 100644
--- a/json.html.markdown
+++ b/json.html.markdown
@@ -17,7 +17,7 @@ going to be 100% valid JSON. Luckily, it kind of speaks for itself.
{
"key": "value",
- "keys": "must always be enclosed in quotes (either double or single)",
+ "keys": "must always be enclosed in double quotes",
"numbers": 0,
"strings": "Hellø, wørld. All unicode is allowed, along with \"escaping\".",
"has bools?": true,
diff --git a/julia.html.markdown b/julia.html.markdown
index e9d3a162..3a52018c 100644
--- a/julia.html.markdown
+++ b/julia.html.markdown
@@ -1,5 +1,5 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
filename: learnjulia.jl
@@ -12,7 +12,7 @@ This is based on the current development version of Julia, as of October 18th, 2
```ruby
-# Single line comments start with a number symbol.
+# Single line comments start with a hash (pound) symbol.
#= Multiline comments can be written
by putting '#=' before the text and '=#'
after the text. They can also be nested.
@@ -125,8 +125,9 @@ SomeOtherVar123! = 6 # => 6
# A note on naming conventions in Julia:
#
-# * Names of variables are in lower case, with word separation indicated by
-# underscores ('\_').
+# * Word separation can be indicated by underscores ('_'), but use of
+# underscores is discouraged unless the name would be hard to read
+# otherwise.
#
# * Names of Types begin with a capital letter and word separation is shown
# with CamelCase instead of underscores.
diff --git a/ko-kr/lua-kr.html.markdown b/ko-kr/lua-kr.html.markdown
index 850587a0..b4a018ef 100644
--- a/ko-kr/lua-kr.html.markdown
+++ b/ko-kr/lua-kr.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
category: language
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
diff --git a/ko-kr/php-kr.html.markdown b/ko-kr/php-kr.html.markdown
index 80f324f3..1f53221f 100644
--- a/ko-kr/php-kr.html.markdown
+++ b/ko-kr/php-kr.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
category: language
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
diff --git a/lua.html.markdown b/lua.html.markdown
index be9f3141..0809215f 100644
--- a/lua.html.markdown
+++ b/lua.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
filename: learnlua.lua
diff --git a/markdown.html.markdown b/markdown.html.markdown
index 9a863bac..7541f904 100644
--- a/markdown.html.markdown
+++ b/markdown.html.markdown
@@ -10,7 +10,7 @@ Markdown was created by John Gruber in 2004. It's meant to be an easy to read an
Give me as much feedback as you want! / Feel free to fork and pull request!
-```
+```markdown
<!-- Markdown is a superset of HTML, so any HTML file is valid Markdown, that
means we can use HTML elements in Markdown, such as the comment element, and
they won't be affected by a markdown parser. However, if you create an HTML
@@ -39,7 +39,7 @@ This is an h2
-------------
<!-- Simple text styles -->
-<!-- Text can be easily styled as italic, bold, or strikethrough using markdown -->
+<!-- Text can be easily styled as italic or bold using markdown -->
*This text is in italics.*
_And so is this text._
@@ -52,7 +52,7 @@ __And so is this text.__
*__And this!__*
<!-- In Github Flavored Markdown, which is used to render markdown files on
-Github, we also have: -->
+Github, we also have strikethrough: -->
~~This text is rendered with strikethrough.~~
@@ -126,6 +126,14 @@ render the numbers in order, but this may not be a good idea -->
* Sub-item
4. Item four
+<!-- There are even task lists. This creates HTML checkboxes. -->
+
+Boxes below without the 'x' are unchecked HTML checkboxes.
+- [ ] First task to complete.
+- [ ] Second task that needs done
+This checkbox below will be a checked HTML checkbox.
+- [x] This task has been completed
+
<!-- Code blocks -->
<!-- You can indicate a code block (which uses the <code> element) by indenting
a line with four spaces or a tab -->
@@ -201,11 +209,11 @@ can be anything so long as they are unique. -->
<!-- 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")
+![This is the alt-attribute for my image](http://imgur.com/myimage.jpg "An optional title")
<!-- And reference style works as expected -->
-![This is the hover-text.][myimage]
+![This is the alt-attribute.][myimage]
[myimage]: relative/urls/cool/image.jpg "if you need a title, it's here"
diff --git a/matlab.html.markdown b/matlab.html.markdown
index d9a82890..9de41275 100644
--- a/matlab.html.markdown
+++ b/matlab.html.markdown
@@ -15,10 +15,12 @@ If you have any feedback please feel free to reach me at
```matlab
% Comments start with a percent sign.
-%{ Multi line comments look
+%{
+Multi line comments look
something
like
-this %}
+this
+%}
% commands can span multiple lines, using '...':
a = 1 + 2 + ...
@@ -40,36 +42,41 @@ ctrl-c % Abort current computation
edit('myfunction.m') % Open function/script in editor
type('myfunction.m') % Print the source of function/script to Command Window
-profile viewer % Open profiler
+profile on % turns on the code profiler
+profile of % turns off the code profiler
+profile viewer % Open profiler
-help command % Displays documentation for command in Command Window
-doc command % Displays documentation for command in Help Window
-lookfor command % Searches for a given command
+help command % Displays documentation for command in Command Window
+doc command % Displays documentation for command in Help Window
+lookfor command % Searches for command in the first commented line of all functions
+lookfor command -all % searches for command in all functions
% Output formatting
-format short % 4 decimals in a floating number
-format long % 15 decimals
-format bank % only two digits after decimal point - for financial calculations
-fprintf
+format short % 4 decimals in a floating number
+format long % 15 decimals
+format bank % only two digits after decimal point - for financial calculations
+fprintf('text') % print "text" to the screen
+disp('text') % print "text" to the screen
% Variables & Expressions
-myVariable = 4 % Notice Workspace pane shows newly created variable
+myVariable = 4 % Notice Workspace pane shows newly created variable
myVariable = 4; % Semi colon suppresses output to the Command Window
-4 + 6 % ans = 10
-8 * myVariable % ans = 32
-2 ^ 3 % ans = 8
+4 + 6 % ans = 10
+8 * myVariable % ans = 32
+2 ^ 3 % ans = 8
a = 2; b = 3;
c = exp(a)*sin(pi/2) % c = 7.3891
% Calling functions can be done in either of two ways:
% Standard function syntax:
-load('myFile.mat', 'y')
+load('myFile.mat', 'y') % arguments within parantheses, spererated by commas
% Command syntax:
-load myFile.mat y % no parentheses, and spaces instead of commas
+load myFile.mat y % no parentheses, and spaces instead of commas
% Note the lack of quote marks in command form: inputs are always passed as
% literal text - cannot pass variable values. Also, can't receive output:
-[V,D] = eig(A) % this has no equivalent in command form
+[V,D] = eig(A); % this has no equivalent in command form
+[~,D] = eig(A); % if you only want D and not V
@@ -85,7 +92,7 @@ load myFile.mat y % no parentheses, and spaces instead of commas
% Logicals can be applied to matrices:
A > 5
% for each element, if condition is true, that element is 1 in returned matrix
-A[ A > 5 ]
+A( A > 5 )
% returns a vector containing the elements in A for which condition is true
% Strings
@@ -100,6 +107,10 @@ a = {'one', 'two', 'three'}
a(1) % ans = 'one' - returns a cell
char(a(1)) % ans = one - returns a string
+% Structures
+A.b = {'one','two'};
+A.c = [1 2];
+A.d.e = false;
% Vectors
x = [4 32 53 7 1]
@@ -160,6 +171,10 @@ A(1,:) % All columns in row 1
% 4 5 42
% 7 8 9
+% this is the same as
+vertcat(A,A);
+
+
[A , A] % Concatenation of matrices (horizontally)
%ans =
@@ -168,6 +183,8 @@ A(1,:) % All columns in row 1
% 4 5 42 4 5 42
% 7 8 9 7 8 9
+% this is the same as
+horzcat(A,A);
A(:, [3 1 2]) % Rearrange the columns of original matrix
@@ -180,10 +197,13 @@ A(:, [3 1 2]) % Rearrange the columns of original matrix
size(A) % ans = 3 3
A(1, :) =[] % Delete the first row of the matrix
+A(:, 1) =[] % Delete the first column of the matrix
+transpose(A) % Transpose the matrix, which is the same as:
+A one
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/nim.html.markdown b/nim.html.markdown
new file mode 100644
index 00000000..c74fece7
--- /dev/null
+++ b/nim.html.markdown
@@ -0,0 +1,265 @@
+---
+language: Nim
+filename: learnNim.nim
+contributors:
+ - ["Jason J. Ayala P.", "http://JasonAyala.com"]
+---
+
+Nim (formally Nimrod) is a statically typed, imperative programming language
+that gives the programmer power without compromises on runtime efficiency.
+
+Nim is efficient, expressive, and elegant.
+
+```ruby
+var # Declare (and assign) variables,
+ letter: char = 'n' # with or without type annotations
+ lang = "N" & "im"
+ nLength : int = len(lang)
+ boat: float
+ truth: bool = false
+
+let # Use let to declare and bind variables *once*.
+ legs = 400 # legs is immutable.
+ arms = 2_000 # _ are ignored and are useful for long numbers.
+ aboutPi = 3.15
+
+const # Constants are computed at compile time. This provides
+ debug = true # performance and is useful in compile time expressions.
+ compileBadCode = false
+
+when compileBadCode: # `when` is a compile time `if`
+ legs = legs + 1 # This error will never be compiled.
+ const input = readline(stdin) # Const values must be known at compile time.
+
+discard 1 > 2 # Note: The compiler will complain if the result of an expression
+ # is unused. `discard` bypasses this.
+
+discard """
+This can work as a multiline comment.
+Or for unparsable, broken code
+"""
+
+#
+# Data Structures
+#
+
+# Tuples
+
+var
+ child: tuple[name: string, age: int] # Tuples have *both* field names
+ today: tuple[sun: string, temp: float] # *and* order.
+
+child = (name: "Rudiger", age: 2) # Assign all at once with literal ()
+today.sun = "Overcast" # or individual fields.
+today.temp = 70.1
+
+# Sequences
+
+var
+ drinks: seq[string]
+
+drinks = @["Water", "Juice", "Chocolate"] # @[V1,..,Vn] is the sequence literal
+
+#
+# Defining Types
+#
+
+# Defining your own types puts the compiler to work for you. It's what makes
+# static typing powerful and useful.
+
+type
+ Name = string # A type alias gives you a new type that is interchangable
+ Age = int # with the old type but is more descriptive.
+ Person = tuple[name: Name, age: Age] # Define data structures too.
+ AnotherSyntax = tuple
+ fieldOne: string
+ secondField: int
+
+var
+ john: Person = (name: "John B.", age: 17)
+ newage: int = 18 # It would be better to use Age than int
+
+john.age = newage # But still works because int and Age are synonyms
+
+type
+ Cash = distinct int # `distinct` makes a new type incompatible with its
+ Desc = distinct string # base type.
+
+var
+ money: Cash = 100.Cash # `.Cash` converts the int to our type
+ description: Desc = "Interesting".Desc
+
+when compileBadCode:
+ john.age = money # Error! age is of type int and money is Cash
+ john.name = description # Compiler says: "No way!"
+
+#
+# More Types and Data Structures
+#
+
+# Enumerations allow a type to have one of a limited number of values
+
+type
+ Color = enum cRed, cBlue, cGreen
+ Direction = enum # Alternative formating
+ dNorth
+ dWest
+ dEast
+ dSouth
+var
+ orient = dNorth # `orient` is of type Direction, with the value `dNorth`
+ pixel = cGreen # `pixel` is of type Color, with the value `cGreen`
+
+discard dNorth > dEast # Enums are usually an "ordinal" type
+
+# Subranges specify a limited valid range
+
+type
+ DieFaces = range[1..20] # Only an int from 1 to 20 is a valid value
+var
+ my_roll: DieFaces = 13
+
+when compileBadCode:
+ my_roll = 23 # Error!
+
+# Arrays
+
+type
+ RollCounter = array[DieFaces, int] # Array's are fixed length and
+ DirNames = array[Direction, string] # indexed by any ordinal type.
+ Truths = array[42..44, bool]
+var
+ counter: RollCounter
+ directions: DirNames
+ possible: Truths
+
+possible = [false, false, false] # Literal arrays are created with [V1,..,Vn]
+possible[42] = true
+
+directions[dNorth] = "Ahh. The Great White North!"
+directions[dWest] = "No, don't go there."
+
+my_roll = 13
+counter[my_roll] += 1
+counter[my_roll] += 1
+
+var anotherArray = ["Default index", "starts at", "0"]
+
+# More data structures are available, including tables, sets, lists, queues,
+# and crit bit trees.
+# http://nimrod-lang.org/lib.html#collections-and-algorithms
+
+#
+# IO and Control Flow
+#
+
+# `case`, `readLine()`
+
+echo "Read any good books lately?"
+case readLine(stdin)
+of "no", "No":
+ echo "Go to your local library."
+of "yes", "Yes":
+ echo "Carry on, then."
+else:
+ echo "That's great; I assume."
+
+# `while`, `if`, `continue`, `break`
+
+import strutils as str # http://nimrod-lang.org/strutils.html
+echo "I'm thinking of a number between 41 and 43. Guess which!"
+let number: int = 42
+var
+ raw_guess: string
+ guess: int
+while guess != number:
+ raw_guess = readLine(stdin)
+ if raw_guess == "": continue # Skip this iteration
+ guess = str.parseInt(raw_guess)
+ if guess == 1001:
+ echo("AAAAAAGGG!")
+ break
+ elif guess > number:
+ echo("Nope. Too high.")
+ elif guess < number:
+ echo(guess, " is too low")
+ else:
+ echo("Yeeeeeehaw!")
+
+#
+# Iteration
+#
+
+for i, elem in ["Yes", "No", "Maybe so"]: # Or just `for elem in`
+ echo(elem, " is at index: ", i)
+
+for k, v in items(@[(person: "You", power: 100), (person: "Me", power: 9000)]):
+ echo v
+
+let myString = """
+an <example>
+`string` to
+play with
+""" # Multiline raw string
+
+for line in splitLines(myString):
+ echo(line)
+
+for i, c in myString: # Index and letter. Or `for j in` for just letter
+ if i mod 2 == 0: continue # Compact `if` form
+ elif c == 'X': break
+ else: echo(c)
+
+#
+# Procedures
+#
+
+type Answer = enum aYes, aNo
+
+proc ask(question: string): Answer =
+ echo(question, " (y/n)")
+ while true:
+ case readLine(stdin)
+ of "y", "Y", "yes", "Yes":
+ return Answer.aYes # Enums can be qualified
+ of "n", "N", "no", "No":
+ return Answer.aNo
+ else: echo("Please be clear: yes or no")
+
+proc addSugar(amount: int = 2) = # Default amount is 2, returns nothing
+ assert(amount > 0 or amount < 9000, "Crazy Sugar")
+ for a in 1..amount:
+ echo(a, " sugar...")
+
+case ask("Would you like sugar in your tea?")
+of aYes:
+ addSugar(3)
+of aNo:
+ echo "Oh do take a little!"
+ addSugar()
+# No need for an `else` here. Only `yes` and `no` are possible.
+
+#
+# FFI
+#
+
+# Because Nim compiles to C, FFI is easy:
+
+proc strcmp(a, b: cstring): cint {.importc: "strcmp", nodecl.}
+
+let cmp = strcmp("C?", "Easy!")
+```
+
+Additionally, Nim separates itself from its peers with metaprogramming,
+performance, and compile-time features.
+
+## Further Reading
+
+* [Home Page](http://nimrod-lang.org)
+* [Download](http://nimrod-lang.org/download.html)
+* [Community](http://nimrod-lang.org/community.html)
+* [FAQ](http://nimrod-lang.org/question.html)
+* [Documentation](http://nimrod-lang.org/documentation.html)
+* [Manual](http://nimrod-lang.org/manual.html)
+* [Standard Libray](http://nimrod-lang.org/lib.html)
+* [Rosetta Code](http://rosettacode.org/wiki/Category:Nimrod)
diff --git a/nl-nl/brainfuck-nl.html.markdown b/nl-nl/brainfuck-nl.html.markdown
new file mode 100644
index 00000000..cd12b1d0
--- /dev/null
+++ b/nl-nl/brainfuck-nl.html.markdown
@@ -0,0 +1,86 @@
+---
+language: brainfuck
+contributors:
+ - ["Prajit Ramachandran", "http://prajitr.github.io/"]
+ - ["Mathias Bynens", "http://mathiasbynens.be/"]
+translators:
+ - ["Jelle Besseling", "https://github.com/Jell-E"]
+lang: nl-nl
+---
+
+Brainfuck (schrijf je niet met een hoofdletter behalve aan het begin van een
+zin) is een extreem
+minimalistische Turing-complete programmeertaal met maar acht commando's.
+
+```
+Elk karakter behalve "><+-.,[]" (en de quotes) wordt genegeerd.
+
+Brainfuck wordt gerepresenteerd door een array met 30,000 cellen die initieel
+gevuld is met nullen en een pointer die wijst naar de huidige cel.
+
+Dit zijn de acht commando's:
++ : Verhoog de huidige cell met 1.
+- : Verminder de huidige cell met 1.
+> : Beweeg de pointer naar de volgende cell (één naar rechts).
+< : Beweeg de pointer naar de vorige cell (één naar links).
+. : Print de huidige cell als een ASCII karakter(d.w.z. 65 = 'A').
+, : Lees een karakter in de huidige cell.
+[ : Als de huidige cell nul is ga dan naar de bijbehorende ] .
+ Als het geen nul is, ga dan gewoon verder.
+] : Als de huidige cell nul is ga dan gewoon verder.
+ Als het geen nul is, ga dan terug naar de bijbehorende [ .
+
+[ en ] maken een while loop. Ze moeten uiteraard wel gebalanceerd zijn
+
+Laten we een kijkje nemen naar een paar brainfuck programma's.
+
+++++++ [ > ++++++++++ < - ] > +++++ .
+
+Dit programma print het karakter 'A'. Eerst verhoogt het cell #1 tot 6.
+Cell #1 wordt gebruikt om te loopen. Dan begint het de loop ([) en gaat
+naar cell #2. Het verhoogt cell #2 tien keer, gaat terug naar cell #1, en
+verlaagt cell #1. Deze loop gebeurt zes keer (na zes keer staat cell #1
+weer op nul, waarna het doorgaat naar het einde van de loop (]) en
+verder gaat).
+
+De pointer staat nu weer op cell #1, deze heeft een waarde van 0, en cell #2
+heeft een waarde van 60. > beweegt de pointer naar cell #2, daarna verhoogt
+het de cell vijf keer, waardoor het een waarde van 65 bevat, en print dan
+de waarde van cell #2. 65 is 'A' in ASCII, dus 'A' wordt geprint in de terminal.
+
+
+, [ > + < - ] > .
+
+Dit programma leest een karakter van de gebruiker in put en kopieert dat
+karakter in cel #1. Dan start de loop. Ga naar cel #2, verhoog de waarde in
+cel #2, ga terug naar cel #1, en verklein de waarde in cel #1. Dit gaat door
+totdat cel #1 nul is en cel #2 de oude waarde heeft van cell #1. Omdat we
+op cel #1 staan verplaatst > de pointer één naar rechts en . print het
+karakter in cel #2.
+
+Houd wel in gedachten dat de spaties alleen zijn voor leesbaarheid, je kan het
+bovenstaande programma net zo goed schrijven als:
+
+,[>+<-]>.
+
+Probeer maar eens te bedenken wat het volgende programma doet:
+
+,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
+
+Dit programma neemt twee getallen als input, en vermenigvuldigt ze.
+
+In het begin leest het twee karakters in cel #1 en #2. Dan start het de
+buitenste loop, met als teller cel #1. Het beweegt naar cel #2, dan start het
+de binnenste loop met als teller cel #2, daar verhoogd het cel #3. Maar
+dan is er een probleem als cel #2 nul wordt aan het einde van de binnenste loop.
+Om dit op te lossen wordt ook cel #4 verhoogd naar het oorspronkelijke getal
+uit cel #2 en daarna wordt cel #4 weer gekopieerd naar cell #2.
+Het resultaat komt in cel #3 te staan.
+```
+
+En dat is dan brainfuck. Niet heel moeilijk, toch? Je kan zelf voor de lol
+brainfuck programma's gaan schrijven, of je kan een interpreter schrijven
+voor brainfuck in een andere taal. Het is namelijk redelijk makkelijk om te
+implementeren aangezien brainfuck maar acht commando's heeft. En als je een
+masochist bent kan je ook nog proberen om brainfuck te implementeren… in
+brainfuck.
diff --git a/nl-nl/coffeescript-nl.html.markdown b/nl-nl/coffeescript-nl.html.markdown
new file mode 100644
index 00000000..dc0b1e19
--- /dev/null
+++ b/nl-nl/coffeescript-nl.html.markdown
@@ -0,0 +1,110 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["Jelle Besseling", "https://github.com/Jell-E"]
+ - ["D.A.W. de Waal", "http://github.com/diodewaal"]
+filename: coffeescript-nl.coffee
+lang: nl-nl
+---
+
+CoffeeScript is een kleine programmeertaal die direct compileert naar
+JavaScript en er is geen interpretatie tijdens het uitvoeren.
+CoffeeScript probeert om leesbare, goed geformatteerde en goed draaiende
+JavaScript code te genereren, die in elke JavaScript runtime werkt, als een
+opvolger van JavaScript.
+
+Op [de CoffeeScript website](http://coffeescript.org/), staat een
+volledigere tutorial voor CoffeeScript.
+
+``` coffeescript
+# CoffeeScript is een taal voor hipsters.
+# Het gaat mee met alle trends van moderne talen.
+# Commentaar begint dus met een hekje, net zoals bij Python en Ruby.
+
+###
+Blokken commentaar maak je zo, ze vertalen naar JavaScripts */ en /*
+in de uitvoer van de CoffeeScript compiler.
+
+Het is belangrijk dat je ongeveer snapt hoe JavaScript
+werkt voordat je verder gaat.
+###
+
+# Toewijzing:
+getal = 42 #=> var getal = 42;
+tegengestelde = true #=> var tegengestelde = true;
+
+# Voorwaarden:
+getal = -42 if tegengestelde #=> if(tegengestelde) { getal = -42; }
+
+# Functies:
+kwadraat = (x) -> x * x #=> var kwadraat = function(x) { return x * x; }
+
+vul = (houder, vloeistof = "koffie") ->
+ "Nu de #{houder} met #{koffie} aan het vullen..."
+#=>var vul;
+#
+#vul = function(houder, vloeistof) {
+# if (vloeistof == null) {
+# vloeistof = "koffie";
+# }
+# return "Nu de " + houder + " met " + vloeistof + " aan het vullen...";
+#};
+
+# Reeksen:
+lijst = [1..5] #=> var lijst = [1, 2, 3, 4, 5];
+
+# Objecten:
+wiskunde =
+ wortel: Math.sqrt
+ kwadraat: kwadraat
+ derdemacht: (x) -> x * kwadraat x
+#=> var wiskunde = {
+# "wortel": Math.sqrt,
+# "kwadraat": kwadraat,
+# "derdemacht": function(x) { return x * kwadraat(x); }
+#}
+
+# "Splats":
+wedstrijd = (winnaar, lopers...) ->
+ print winnaar, lopers
+#=>wedstrijd = function() {
+# var lopers, winnaar;
+# winnaar = arguments[0], lopers = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winnaar, lopers);
+#};
+
+# Aanwezigheid:
+alert "Ik wist het!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
+
+# Lijst abstractie:
+derdemachten = (wiskunde.derdemacht num for num in lijst)
+#=>derdemachten = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = lijst.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(wiskunde.derdemacht(num));
+# }
+# return _results;
+# })();
+
+etenswaren = ['broccoli', 'spinazie', 'chocolade']
+eet eten for eten in etenswaren when eten isnt 'chocolade'
+#=>etenswaren = ['broccoli', 'spinazie', 'chocolade'];
+#
+#for (_k = 0, _len2 = etenswaren.length; _k < _len2; _k++) {
+# eten = etenswaren[_k];
+# if (eten !== 'chocolade') {
+# eet(eten);
+# }
+#}
+```
+
+## Handige links (in het Engels):
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
diff --git a/objective-c.html.markdown b/objective-c.html.markdown
index 772e72ca..caad49a5 100644
--- a/objective-c.html.markdown
+++ b/objective-c.html.markdown
@@ -12,7 +12,7 @@ filename: LearnObjectiveC.m
Objective-C is the main programming language used by Apple for the OS X and iOS operating systems and their respective frameworks, Cocoa and Cocoa Touch.
It is a general-purpose, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.
-```cpp
+```objective_c
// Single-line comments start with //
/*
diff --git a/ocaml.html.markdown b/ocaml.html.markdown
new file mode 100644
index 00000000..f9db7080
--- /dev/null
+++ b/ocaml.html.markdown
@@ -0,0 +1,372 @@
+---
+language: OCaml
+contributors:
+ - ["Daniil Baturin", "http://baturin.org/"]
+---
+
+OCaml is a strictly evaluated functional language with some imperative
+features.
+
+Along with StandardML and its dialects it belongs to ML language family.
+F# is also heavily influenced by OCaml.
+
+Just like StandardML, OCaml features both an interpreter, that can be
+used interactively, and a compiler.
+The interpreter binary is normally called "ocaml" and the compiler is "ocamlopt".
+There is also a bytecode compiler, "ocamlc", but there are few reasons to use it.
+
+It is strongly and statically typed, but instead of using manually written
+type annotations, it infers types of expressions using Hindley-Milner algorithm.
+It makes type annotations unnecessary in most cases, but can be a major
+source of confusion for beginners.
+
+When you are in the top level loop, OCaml will print the inferred type
+after you enter an expression.
+
+```
+# let inc x = x + 1 ;;
+val inc : int -> int = <fun>
+# let a = 99 ;;
+val a : int = 99
+```
+
+For a source file you can use "ocamlc -i /path/to/file.ml" command
+to print all names and type signatures.
+
+```
+$ cat sigtest.ml
+let inc x = x + 1
+let add x y = x + y
+
+let a = 1
+
+$ ocamlc -i ./sigtest.ml
+val inc : int -> int
+val add : int -> int -> int
+val a : int
+```
+
+Note that type signatures of functions of multiple arguments are
+written in curried form. A function that takes multiple arguments can be
+represented as a composition of functions that take only one argument.
+The "f(x,y) = x + y" function from the example above applied to
+arguments 2 and 3 is equivalent to the "f0(y) = 2 + y" function applied to 3.
+Hence the "int -> int -> int" signature.
+
+
+```ocaml
+(*** Comments ***)
+
+(* Comments are enclosed in (* and *). It's fine to nest comments. *)
+
+(* There are no single-line comments. *)
+
+
+(*** Variables and functions ***)
+
+(* Expressions can be separated by a double semicolon symbol, ";;".
+ In many cases it's redundant, but in this tutorial we use it after
+ every expression for easy pasting into the interpreter shell.
+ Unnecessary use of expression separators in source code files
+ is often considered to be a bad style. *)
+
+(* Variable and function declarations use "let" keyword. *)
+let x = 10 ;;
+
+(* OCaml allows single quote characters in identifiers.
+ Single quote doesn't have a special meaning in this case, it's often used
+ in cases when in other languages one would use names like "foo_tmp". *)
+let foo = 1 ;;
+let foo' = foo * 2 ;;
+
+(* Since OCaml compiler infers types automatically, you normally don't need to
+ specify argument types explicitly. However, you can do it if
+ you want or need to. *)
+let inc_int (x: int) : int = x + 1 ;;
+
+(* One of the cases when explicit type annotations may be needed is
+ resolving ambiguity between two record types that have fields with
+ the same name. The alternative is to encapsulate those types in
+ modules, but both topics are a bit out of scope of this
+ tutorial. *)
+
+(* You need to mark recursive function definitions as such with "rec" keyword. *)
+let rec factorial n =
+ if n = 0 then 1
+ else n * factorial (n-1)
+;;
+
+(* Function application usually doesn't need parentheses around arguments *)
+let fact_5 = factorial 5 ;;
+
+(* ...unless the argument is an expression. *)
+let fact_4 = factorial (5-1) ;;
+let sqr2 = sqr (-2) ;;
+
+(* Every function must have at least one argument.
+ Since some funcions naturally don't take any arguments, there's
+ "unit" type for it that has the only one value written as "()" *)
+let print_hello () = print_endline "hello world" ;;
+
+(* Note that you must specify "()" as argument when calling it. *)
+print_hello () ;;
+
+(* Calling a function with insufficient number of arguments
+ does not cause an error, it produces a new function. *)
+let make_inc x y = x + y ;; (* make_inc is int -> int -> int *)
+let inc_2 = make_inc 2 ;; (* inc_2 is int -> int *)
+inc_2 3 ;; (* Evaluates to 5 *)
+
+(* You can use multiple expressions in function body.
+ The last expression becomes the return value. All other
+ expressions must be of the "unit" type.
+ This is useful when writing in imperative style, the simplest
+ form of it is inserting a debug print. *)
+let print_and_return x =
+ print_endline (string_of_int x);
+ x
+;;
+
+(* Since OCaml is a functional language, it lacks "procedures".
+ Every function must return something. So functions that
+ do not really return anything and are called solely for their
+ side effects, like print_endline, return value of "unit" type. *)
+
+
+(* Definitions can be chained with "let ... in" construct.
+ This is roughly the same to assigning values to multiple
+ variables before using them in expressions in imperative
+ languages. *)
+let x = 10 in
+let y = 20 in
+x + y ;;
+
+(* Alternatively you can use "let ... and ... in" construct.
+ This is especially useful for mutually recursive functions,
+ with ordinary "let .. in" the compiler will complain about
+ unbound values.
+ It's hard to come up with a meaningful but self-contained
+ example of mutually recursive functions, but that syntax
+ works for non-recursive definitions too. *)
+let a = 3 and b = 4 in a * b ;;
+
+(* Anonymous functions use the following syntax: *)
+let my_lambda = fun x -> x * x ;;
+
+(*** Operators ***)
+
+(* There is little distintion between operators and functions.
+ Every operator can be called as a function. *)
+
+(+) 3 4 (* Same as 3 + 4 *)
+
+(* There's a number of built-in operators. One unusual feature is
+ that OCaml doesn't just refrain from any implicit conversions
+ between integers and floats, it also uses different operators
+ for floats. *)
+12 + 3 ;; (* Integer addition. *)
+12.0 +. 3.0 ;; (* Floating point addition. *)
+
+12 / 3 ;; (* Integer division. *)
+12.0 /. 3.0 ;; (* Floating point division. *)
+5 mod 2 ;; (* Remainder. *)
+
+(* Unary minus is a notable exception, it's polymorphic.
+ However, it also has "pure" integer and float forms. *)
+- 3 ;; (* Polymorphic, integer *)
+- 4.5 ;; (* Polymorphic, float *)
+~- 3 (* Integer only *)
+~- 3.4 (* Type error *)
+~-. 3.4 (* Float only *)
+
+(* You can define your own operators or redefine existing ones.
+ Unlike SML or Haskell, only selected symbols can be used
+ for operator names and first symbol defines associativity
+ and precedence rules. *)
+let (+) a b = a - b ;; (* Surprise maintenance programmers. *)
+
+(* More useful: a reciprocal operator for floats.
+ Unary operators must start with "~". *)
+let (~/) x = 1.0 /. x ;;
+~/4.0 (* = 0.25 *)
+
+
+(*** Built-in datastructures ***)
+
+(* Lists are enclosed in square brackets, items are separated by
+ semicolons. *)
+let my_list = [1; 2; 3] ;;
+
+(* Tuples are (optionally) enclosed in parentheses, items are separated
+ by commas. *)
+let first_tuple = 3, 4 ;; (* Has type "int * int". *)
+let second_tuple = (4, 5) ;;
+
+(* Corollary: if you try to separate list items by commas, you get a list
+ with a tuple inside, probably not what you want. *)
+let bad_list = [1, 2] ;; (* Becomes [(1, 2)] *)
+
+(* You can access individual list items with the List.nth function. *)
+List.nth my_list 1 ;;
+
+(* There are higher-order functions for lists such as map and filter. *)
+List.map (fun x -> x * 2) [1; 2; 3] ;;
+List.filter (fun x -> if x mod 2 = 0 then true else false) [1; 2; 3; 4] ;;
+
+(* You can add an item to the beginning of a list with the "::" constructor
+ often referred to as "cons". *)
+1 :: [2; 3] ;; (* Gives [1; 2; 3] *)
+
+(* Arrays are enclosed in [| |] *)
+let my_array = [| 1; 2; 3 |] ;;
+
+(* You can access array items like this: *)
+my_array.(0) ;;
+
+
+(*** Strings and characters ***)
+
+(* Use double quotes for string literals. *)
+let my_str = "Hello world" ;;
+
+(* Use single quotes for character literals. *)
+let my_char = 'a' ;;
+
+(* Single and double quotes are not interchangeable. *)
+let bad_str = 'syntax error' ;; (* Syntax error. *)
+
+(* This will give you a single character string, not a character. *)
+let single_char_str = "w" ;;
+
+(* Strings can be concatenated with the "^" operator. *)
+let some_str = "hello" ^ "world" ;;
+
+(* Strings are not arrays of characters.
+ You can't mix characters and strings in expressions.
+ You can convert a character to a string with "String.make 1 my_char".
+ There are more convenient functions for this purpose in additional
+ libraries such as Core.Std that may not be installed and/or loaded
+ by default. *)
+let ocaml = (String.make 1 'O') ^ "Caml" ;;
+
+(* There is a printf function. *)
+Printf.printf "%d %s" 99 "bottles of beer" ;;
+
+(* Unformatted read and write functions are there too. *)
+print_string "hello world\n" ;;
+print_endline "hello world" ;;
+let line = read_line () ;;
+
+
+(*** User-defined data types ***)
+
+(* You can define types with the "type some_type =" construct. Like in this
+ useless type alias: *)
+type my_int = int ;;
+
+(* More interesting types include so called type constructors.
+ Constructors must start with a capital letter. *)
+type ml = OCaml | StandardML ;;
+let lang = OCaml ;; (* Has type "ml". *)
+
+(* Type constructors don't need to be empty. *)
+type my_number = PlusInfinity | MinusInfinity | Real of float ;;
+let r0 = Real (-3.4) ;; (* Has type "my_number". *)
+
+(* Can be used to implement polymorphic arithmetics. *)
+type number = Int of int | Float of float ;;
+
+(* Point on a plane, essentially a type-constrained tuple *)
+type point2d = Point of float * float ;;
+let my_point = Point (2.0, 3.0) ;;
+
+(* Types can be parameterized, like in this type for "list of lists
+ of anything". 'a can be substituted with any type. *)
+type 'a list_of_lists = 'a list list ;;
+type int_list_list = int list_of_lists ;;
+
+(* Types can also be recursive. Like in this type analogous to
+ built-in list of integers. *)
+type my_int_list = EmptyList | IntList of int * my_int_list ;;
+let l = Cons (1, EmptyList) ;;
+
+
+(*** Pattern matching ***)
+
+(* Pattern matching is somewhat similar to switch statement in imperative
+ languages, but offers a lot more expressive power.
+
+ Even though it may look complicated, it really boils down to matching
+ an argument against an exact value, a predicate, or a type constructor.
+ The type system is what makes it so powerful. *)
+
+(** Matching exact values. **)
+
+let is_zero x =
+ match x with
+ | 0 -> true
+ | _ -> false (* The "_" pattern means "anything else". *)
+;;
+
+(* Alternatively, you can use the "function" keyword. *)
+let is_one = function
+| 1 -> true
+| _ -> false
+;;
+
+(* Matching predicates, aka "guarded pattern matching". *)
+let abs x =
+ match x with
+ | x when x < 0 -> -x
+ | _ -> x
+;;
+
+abs 5 ;; (* 5 *)
+abs (-5) (* 5 again *)
+
+(** Matching type constructors **)
+
+type animal = Dog of string | Cat of string ;;
+
+let say x =
+ match x with
+ | Dog x -> x ^ " says woof"
+ | Cat x -> x ^ " says meow"
+;;
+
+say (Cat "Fluffy") ;; (* "Fluffy says meow". *)
+
+(** Traversing datastructures with pattern matching **)
+
+(* Recursive types can be traversed with pattern matching easily.
+ Let's see how we can traverse a datastructure of the built-in list type.
+ Even though the built-in cons ("::") looks like an infix operator,
+ it's actually a type constructor and can be matched like any other. *)
+let rec sum_list l =
+ match l with
+ | [] -> 0
+ | head :: tail -> head + (sum_list tail)
+;;
+
+sum_list [1; 2; 3] ;; (* Evaluates to 6 *)
+
+(* Built-in syntax for cons obscures the structure a bit, so we'll make
+ our own list for demonstration. *)
+
+type int_list = Nil | Cons of int * int_list ;;
+let rec sum_int_list l =
+ match l with
+ | Nil -> 0
+ | Cons (head, tail) -> head + (sum_int_list tail)
+;;
+
+let t = Cons (1, Cons (2, Cons (3, Nil))) ;;
+sum_int_list t ;;
+
+```
+
+## Further reading
+
+* Visit the official website to get the compiler and read the docs: <http://ocaml.org/>
+* Try interactive tutorials and a web-based interpreter by OCaml Pro: <http://try.ocamlpro.com/>
+* Read "OCaml for the skeptical" course: <http://www2.lib.uchicago.edu/keith/ocaml-class/home.html>
diff --git a/perl6.html.markdown b/perl6.html.markdown
index fe5b197c..b178de1e 100644
--- a/perl6.html.markdown
+++ b/perl6.html.markdown
@@ -46,18 +46,36 @@ my $inverse = !$bool; # You can invert a bool with the prefix `!` operator
my $forced-bool = so $str; # And you can use the prefix `so` operator
# which turns its operand into a Bool
-## * Arrays. They represent multiple values. Their name start with `@`.
+## * Lists. They represent multiple values. Their name start with `@`.
-my @array = 1, 2, 3;
my @array = 'a', 'b', 'c';
# equivalent to :
-my @array = <a b c>; # array of words, delimited by space.
+my @letters = <a b c>; # array of words, delimited by space.
# Similar to perl5's qw, or Ruby's %w.
+my @array = 1, 2, 3;
say @array[2]; # Array indices start at 0 -- This is the third element
say "Interpolate an array using [] : @array[]";
-#=> Interpolate an array using [] : a b c
+#=> Interpolate an array using [] : 1 2 3
+
+@array[0] = -1; # Assign a new value to an array index
+@array[0, 1] = 5, 6; # Assign multiple values
+
+my @keys = 0, 2;
+@array[@keys] = @letters; # Assign using an array
+say @array; #=> a 6 b
+
+# There are two more kinds of lists: Parcel and Arrays.
+# Parcels are immutable lists (you can't modify a list that's not assigned).
+# This is a parcel:
+(1, 2, 3); # Not assigned to anything. Changing an element would provoke an error
+# This is a list:
+my @a = (1, 2, 3); # Assigned to `@a`. Changing elements is okay!
+
+# Lists flatten (in list context). You'll see below how to apply item context
+# or use arrays to have real nested lists.
+
## * Hashes. Key-Value Pairs.
# Hashes are actually arrays of Pairs (`Key => Value`),
@@ -303,6 +321,37 @@ if long-computation() -> $result {
say "The result is $result";
}
+## Loops can also have a label, and be jumped to through these.
+OUTER: while 1 {
+ say "hey";
+ while 1 {
+ OUTER.last; # All the control keywords must be called on the label itself
+ }
+}
+
+# Now that you've seen how to traverse a list, you need to be aware of something:
+# List context (@) flattens. If you traverse nested lists, you'll actually be traversing a
+# shallow list (except if some sub-list were put in item context ($)).
+for 1, 2, (3, (4, ((5)))) {
+ say "Got $_.";
+} #=> Got 1. Got 2. Got 3. Got 4. Got 5.
+
+# ... However: (forcing item context with `$`)
+for 1, 2, $(3, 4) {
+ say "Got $_.";
+} #=> Got 1. Got 2. Got 3 4.
+
+# Note that the last one actually joined 3 and 4.
+# While `$(...)` will apply item to context to just about anything, you can also create
+# an array using `[]`:
+for [1, 2, 3, 4] {
+ say "Got $_.";
+} #=> Got 1 2 3 4.
+
+# The other difference between `$()` and `[]` is that `[]` always returns a mutable Array
+# whereas `$()` will return a Parcel when given a Parcel.
+
+
### Operators
## Since Perl languages are very much operator-based languages
@@ -359,9 +408,9 @@ $arg ~~ &bool-returning-function; # `True` if the function, passed `$arg`
# This also works as a shortcut for `0..^N`:
^10; # means 0..^10
-# This also allows us to demonstrate that Perl 6 has lazy arrays,
+# This also allows us to demonstrate that Perl 6 has lazy/infinite arrays,
# using the Whatever Star:
-my @array = 1..*; # 1 to Infinite !
+my @array = 1..*; # 1 to Infinite ! `1..Inf` is the same.
say @array[^10]; # you can pass arrays as subscripts and it'll return
# an array of results. This will print
# "1 2 3 4 5 6 7 8 9 10" (and not run out of memory !)
@@ -372,6 +421,13 @@ say @array[^10]; # you can pass arrays as subscripts and it'll return
# Perl 6 will be forced to try and evaluate the whole array (to print it),
# so you'll end with an infinite loop.
+# You can use that in most places you'd expect, even assigning to an array
+my @numbers = ^20;
+@numbers[5..*] = 3, 9 ... * > 90; # The right hand side could be infinite as well.
+ # (but not both, as this would be an infinite loop)
+say @numbers; #=> 3 9 15 21 27 [...] 81 87
+
+
## * And, Or
3 && 4; # 4, which is Truthy. Calls `.Bool` on `4` and gets `True`.
0 || False; # False. Calls `.Bool` on `0`
@@ -700,15 +756,37 @@ try {
open 'foo';
CATCH {
when X::AdHoc { say "unable to open file !" }
- # any other exception will be re-raised, since we don't have a `default`
+ # Any other exception will be re-raised, since we don't have a `default`
+ # Basically, if a `when` matches (or there's a `default`) marks the exception as
+ # "handled" so that it doesn't get re-thrown from the `CATCH`.
+ # You still can re-throw the exception (see below) by hand.
}
}
# You can throw an exception using `die`:
die X::AdHoc.new(payload => 'Error !');
-# TODO warn
-# TODO fail
-# TODO CONTROL
+
+# You can access the last exception with `$!` (usually used in a `CATCH` block)
+
+# There are also some subtelties to exceptions. Some Perl 6 subs return a `Failure`,
+# which is a kind of "unthrown exception". They're not thrown until you tried to look
+# at their content, unless you call `.Bool`/`.defined` on them - then they're handled.
+# (the `.handled` method is `rw`, so you can mark it as `False` back yourself)
+#
+# You can throw a `Failure` using `fail`. Note that if the pragma `use fatal` is on,
+# `fail` will throw an exception (like `die`).
+fail "foo"; # We're not trying to access the value, so no problem.
+try {
+ fail "foo";
+ CATCH {
+ default { say "It threw because we try to get the fail's value!" }
+ }
+}
+
+# There is also another kind of exception: Control exceptions.
+# Those are "good" exceptions, which happen when you change your program's flow,
+# using operators like `return`, `next` or `last`.
+# You can "catch" those with `CONTROL` (not 100% working in Rakudo yet).
### Packages
# Packages are a way to reuse code. Packages are like "namespaces", and any
@@ -1071,7 +1149,7 @@ my @list = 1, 3, 9 ... * > 30; # you can use a predicate
# (with the Whatever Star, here).
my @list = 1, 3, 9 ... { $_ > 30 }; # (equivalent to the above)
-my @fib = 1, 1, *+* ... *; # lazy infinite list of prime numbers,
+my @fib = 1, 1, *+* ... *; # lazy infinite list of fibonacci series,
# computed using a closure!
my @fib = 1, 1, -> $a, $b { $a + $b } ... *; # (equivalent to the above)
my @fib = 1, 1, { $^a + $^b } ... *; #(... also equivalent to the above)
@@ -1099,7 +1177,7 @@ $obj eqv $obj2; # sort comparison using eqv semantics
## * Short-circuit default operator
# Like `or` and `||`, but instead returns the first *defined* value :
-say Any // Nil // 0 // 5; #=> 5
+say Any // Nil // 0 // 5; #=> 0
## * Short-circuit exclusive or (XOR)
# Returns `True` if one (and only one) of its arguments is true
@@ -1246,7 +1324,7 @@ so 'abc' ~~ / a b* c /; # `True`
so 'abbbbc' ~~ / a b* c /; # `True`
so 'aec' ~~ / a b* c /; # `False`. "b"(s) are optional, not replaceable.
-# - `**` - "Quantify It Yourself".
+# - `**` - (Unbound) Quantifier
# If you squint hard enough, you might understand
# why exponentation is used for quantity.
so 'abc' ~~ / a b ** 1 c /; # `True` (exactly one time)
@@ -1255,6 +1333,27 @@ so 'abbbc' ~~ / a b ** 1..3 c /; # `True`
so 'abbbbbbc' ~~ / a b ** 1..3 c /; # `False` (too much)
so 'abbbbbbc' ~~ / a b ** 3..* c /; # `True` (infinite ranges are okay)
+# - `<[]>` - Character classes
+# Character classes are the equivalent of PCRE's `[]` classes, but
+# they use a more perl6-ish syntax:
+say 'fooa' ~~ / f <[ o a ]>+ /; #=> 'fooa'
+# You can use ranges:
+say 'aeiou' ~~ / a <[ e..w ]> /; #=> 'aeiou'
+# Just like in normal regexes, if you want to use a special character, escape it
+# (the last one is escaping a space)
+say 'he-he !' ~~ / 'he-' <[ a..z \! \ ]> + /; #=> 'he-he !'
+# You'll get a warning if you put duplicate names
+# (which has the nice effect of catching the wrote quoting:)
+'he he' ~~ / <[ h e ' ' ]> /; # Warns "Repeated characters found in characters class"
+
+# You can also negate them ... (equivalent to `[^]` in PCRE)
+so 'foo' ~~ / <-[ f o ]> + /; # False
+
+# ... and compose them: :
+so 'foo' ~~ / <[ a..z ] - [ f o ]> + /; # False (any letter except f and o)
+so 'foo' ~~ / <-[ a..z ] + [ f o ]> + /; # True (no letter except f and o)
+so 'foo!' ~~ / <-[ a..z ] + [ f o ]> + /; # True (the + doesn't replace the left part)
+
## Grouping and capturing
# Group: you can group parts of your regexp with `[]`.
# These groups are *not* captured (like PCRE's `(?:)`).
@@ -1282,7 +1381,7 @@ say $0; # The same as above.
# You might be wondering why it's an array, and the answer is simple:
# Some capture (indexed using `$0`, `$/[0]` or a named one) will be an array
# IFF it can have more than one element
-# (so, with `*`, `+` and any `**`, but not with `?`).
+# (so, with `*`, `+` and `**` (whatever the operands), but not with `?`).
# Let's use examples to see that:
so 'fooABCbar' ~~ / foo ( A B C )? bar /; # `True`
say $/[0]; #=> 「ABC」
@@ -1296,28 +1395,66 @@ say $0.WHAT; #=> (Array)
# A specific quantifier will always capture an Array,
# may it be a range or a specific value (even 1).
-# If you're wondering how the captures are numbered, here's an explanation:
-TODO use graphs from s05
+# The captures are indexed per nesting. This means a group in a group will be nested
+# under its parent group: `$/[0][0]`, for this code:
+'hello-~-world' ~~ / ( 'hello' ( <[ \- \~ ]> + ) ) 'world' /;
+say $/[0].Str; #=> hello~
+say $/[0][0].Str; #=> ~
+# This stems from a very simple fact: `$/` does not contain strings, integers or arrays,
+# it only contains match objects. These contain the `.list`, `.hash` and `.Str` methods.
+# (but you can also just use `match<key>` for hash access and `match[idx]` for array access)
+say $/[0].list.perl; #=> (Match.new(...),).list
+ # We can see it's a list of Match objects. Those contain a bunch of infos:
+ # where the match started/ended, the "ast" (see actions later), etc.
+ # You'll see named capture below with grammars.
## Alternatives - the `or` of regexps
# WARNING: They are DIFFERENT from PCRE regexps.
so 'abc' ~~ / a [ b | y ] c /; # `True`. Either "b" or "y".
so 'ayc' ~~ / a [ b | y ] c /; # `True`. Obviously enough ...
+# The difference between this `|` and the one you're used to is LTM.
+# LTM means "Longest Token Matching". This means that the engine will always
+# try to match as much as possible in the strng
+'foo' ~~ / fo | foo /; # `foo`, because it's longer.
+# To decide which part is the "longest", it first splits the regex in two parts:
+# The "declarative prefix" (the part that can be statically analyzed)
+# and the procedural parts.
+# Declarative prefixes include alternations (`|`), conjuctions (`&`),
+# sub-rule calls (not yet introduced), literals, characters classes and quantifiers.
+# The latter include everything else: back-references, code assertions,
+# and other things that can't traditionnaly be represented by normal regexps.
+#
+# Then, all the alternatives are tried at once, and the longest wins.
+# Exemples:
+# DECLARATIVE | PROCEDURAL
+/ 'foo' \d+ [ <subrule1> || <subrule2> ] /;
+# DECLARATIVE (nested groups are not a problem)
+/ \s* [ \w & b ] [ c | d ] /;
+# However, closures and recursion (of named regexps) are procedural.
+# ... There are also more complicated rules, like specificity
+# (literals win over character classes)
+
+# Note: the first-matching `or` still exists, but is now spelled `||`
+'foo' ~~ / fo || foo /; # `fo` now.
+
+
+
+
### Extra: the MAIN subroutime
# The `MAIN` subroutine is called when you run a Perl 6 file directly.
# It's very powerful, because Perl 6 actually parses the argument
# and pass them as such to the sub. It also handles named argument (`--foo`)
# and will even go as far as to autogenerate a `--help`
-sub MAIN($name) { say "Hello, you !" }
+sub MAIN($name) { say "Hello, $name !" }
# This produces:
# $ perl6 cli.pl
# Usage:
# t.pl <name>
# And since it's a regular Perl 6 sub, you can haz multi-dispatch:
-# (using a "Bool" for the named argument so that we get `--replace`
+# (using a "Bool" for the named argument so that we can do `--replace`
# instead of `--replace=1`)
subset File of Str where *.IO.d; # convert to IO object to check the file exists
diff --git a/php.html.markdown b/php.html.markdown
index e1bb86a0..039288a0 100644
--- a/php.html.markdown
+++ b/php.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/pl-pl/perl-pl.html.markdown b/pl-pl/perl-pl.html.markdown
new file mode 100644
index 00000000..9e8ade5b
--- /dev/null
+++ b/pl-pl/perl-pl.html.markdown
@@ -0,0 +1,169 @@
+---
+name: perl
+category: language
+language: perl
+filename: learnperl.pl
+contributors:
+ - ["Korjavin Ivan", "http://github.com/korjavin"]
+ - ["Michał Kupczyński", "http://github.com/ukoms"]
+lang: pl-pl
+---
+
+Perl 5 jest wysoce użytecznym, bogatym w wiele opcji językiem programowania
+z ponad 25 latami nieustannego rozwoju.
+
+Perl 5 używany jest na ponad 100 różnych platformach (od przenośnych do w
+pełni stacjonarnych) i nadaje się zarówno do szybkiego prototypowania jak
+i projektów deweloperskich prowadzonych na szeroką skalę.
+
+```perl
+
+# Pojedyncza linia komentarza zaczyna się od znaku hasha (płotka) "#".
+
+#### Typy zmiennych w Perlu
+
+# Zmienna zaczyna się od symbolu dolara "$".
+# Prawidłowa nazwa zmiennej zaczyna się od litery lub podkreślnika "_",
+# po których następuje dowolna ilość liter, cyfr i podkreślników.
+
+### W Perlu występują trzy główne typy zmiennych: skalary, tablice i hasze.
+
+## Skalary
+# Skalar przechowuje pojedynczą wartość:
+my $zwierze = "wielbłąd";
+my $odpowiedź = 42;
+
+# Wartości skalarne mogą być ciągami znaków, liczbami całkowitymi lub
+# zmiennoprzecinkowymi, zaś Perl automatycznie dokonuje konwersji pomiędzy nimi,
+# w zależności od wykonywanego kodu/kontekstu.
+
+## Tablice
+# Tablica przechowuje listę wartości:
+my @zwierzęta = ("wielbłąd", "alpaka", "sowa");
+my @liczby = (23, 42, 69);
+my @mieszanka = ("wielbłąd", 42, 1.23);
+
+## Hasze
+# Hasz przechowuje zestawy par klucz-wartość:
+my %kolor_owocu = ('jabłko', 'czerwony', 'banan', 'żółty');
+
+# Możesz używać białych znaków (spacje, tabulatory) i operatora strzałki "=>"
+# by czytelniej sformatować zapis hasza:
+my %kolor_owocu = (
+ jabłko => 'czerwony',
+ banan => 'żółty',
+);
+
+# Skalary, tablice i hasze są bardziej wyczerpująco udokumentowane w dokumencie
+# [perldoc perldata](http://perldoc.perl.org/perldata.html).
+
+# Bardziej złożone typy danych mogą być stworzone poprzez używanie referencji,
+# które pozwalają Ci zbudować listy i hasze wewnątrz list i haszy.
+
+#### Warunki logiczne i pętle
+
+# W Perlu występują typowe warunki i pętle.
+if ($var) {
+ ...
+} elsif ($var eq 'bar') {
+ ...
+} else {
+ ...
+}
+
+unless (warunek) {
+ ...
+}
+# Powyższy zapis jest równoznaczny zapisowi "if (!warunek)"
+
+# Perlowy skrócony zapis warunków:
+print "Siema!" if $rozochocony;
+print "Nie mamy bananów" unless $banany;
+
+# Pętla while
+while (warunek) {
+ ...
+}
+
+# Pętle for oraz foreach
+for ($i = 0; $i <= $max; $i++) {
+ ...
+}
+
+foreach (@tablica) {
+ print "Tym elementem jest $_\n";
+}
+
+# lub
+
+foreach my $iterator (@tablica) {
+ print "Iterowanym elementem jest $iterator\n";
+}
+
+#### Wyrażenia regularne
+
+# Perlowe wyrażenia regularne są tematem tak rozległym, jak wymagającym.
+# Istnieje ogromna ilość dokumentacji w artykułach takich jak
+# [perlrequick](http://perldoc.perl.org/perlrequick.html),
+# [perlretut](http://perldoc.perl.org/perlretut.html) i inne.
+# W dużym skrócie, podstawy perlowych wyrażeń regularnych są następujące:
+
+# Proste dopasowanie:
+if (/foo/) { ... } # prawda jeżeli $_ zawiera "foo"
+if ($a =~ /foo/) { ... } # prawda jeżeli $a zawiera "foo"
+
+# Prosta zamiana:
+# Zamienia "foo" na "bar" w zmiennej $a
+$a =~ s/foo/bar/;
+# Zamienia WSZYSTKIE WYSTĄPIENIA "foo" na "bar" w zmiennej $a
+$a =~ s/foo/bar/g;
+
+#### Pliki i I/O
+
+# Możesz otworzyć plik do odczytu lub zapisu używając funkcji "open ()".
+open (my $odczyt, "<", "odczyt.txt") or die "Błąd otwierania input.txt: $!";
+open (my $zapis, ">", "zapis.txt") or die "Błąd otwierania output.txt: $!";
+open (my $dopisanie, ">>", "my.log") or die "Błąd otwierania my.log: $!";
+
+# Pliki możesz odczytywać z otworzonego handlera używając operatora "<>"
+# (operator diamentowy). W kontekście skalarnym (przypisanie wyniku do skalara)
+# operator ten zczytuje pojedynczą linię pliku, w kontekście listowym
+# (przypisanie wyniku do tablicy) zczytuje całą zawartość pliku, przypisując
+# każdą linię jako kolejny element listy:
+my $linia = <$in>;
+my @linie = <$in>;
+
+#### Perlowe funkcje (procedury)
+
+# Pisanie funkcji (procedur) jest proste:
+sub logger {
+ my $wiadomosc_do_loga = shift;
+ open (my HANDLER, ">>", "my.log") or die "Błąd otwierania my.log: $!";
+ print HANDLER $wiadomosc_do_loga;
+}
+
+# Teraz można używać napisanej funkcji, tak jak każdej innej wbudowanej
+# funkcji perlowej:
+logger ("Mamy funkcję perlową");
+
+```
+
+#### Używanie modułów perlowych
+
+Moduły perlowe dostarczają szeroki wachlarz możliwości, byś nie musiał
+wynajdywać koła na nowo. Moduły te można pobrać z [CPAN](http://www.cpan.org).
+Sam Perl zawiera w swoich dystrybucjach kilka najpopularniejszych modułów
+z repozytorium [CPAN](http://www.cpan.org).
+
+Najczęściej zadawane pytania [perlfaq](http://perldoc.perl.org/perlfaq.html)
+- zawierają pytania i odpowiedzi dotyczące wielu typowo realizowanych zadań.
+Często znajdziesz tam również sugestie dotyczące użycia najlepszego modułu
+z repozytorium CPAN do zrealizowania konkretnego zadania.
+
+
+#### Do doczytania
+
+ - [perl-tutorial](http://perl-tutorial.org/)
+ - [Naucz się Perla na www.perl.com](http://www.perl.org/learn.html)
+ - [perldoc](http://perldoc.perl.org/)
+ - wbudowane w Perla: `perldoc perlintro` \ No newline at end of file
diff --git a/pt-br/clojure-pt.html.markdown b/pt-br/clojure-pt.html.markdown
new file mode 100644
index 00000000..7e8b3f7b
--- /dev/null
+++ b/pt-br/clojure-pt.html.markdown
@@ -0,0 +1,384 @@
+---
+language: clojure
+filename: learnclojure-pt.clj
+contributors:
+ - ["Adam Bard", "http://adambard.com/"]
+translators:
+ - ["Mariane Siqueira Machado", "https://twitter.com/mariane_sm"]
+lang: pt-br
+---
+
+Clojure é uma linguagem da família do Lisp desenvolvida para a JVM (máquina virtual Java). Possui uma ênfase muito mais forte em [programação funcional] (https://pt.wikipedia.org/wiki/Programa%C3%A7%C3%A3o_funcional) pura do que Common Lisp, mas inclui diversas utilidades [STM](https://en.wikipedia.org/wiki/Software_transactional_memory) para lidar com estado a medida que isso se torna necessário.
+
+Essa combinação permite gerenciar processamento concorrente de maneira muito simples, e frequentemente de maneira automática.
+
+(Sua versão de clojure precisa ser pelo menos 1.2)
+
+
+```clojure
+; Comentários começam por ponto e vírgula
+
+; Clojure é escrito em "forms", os quais são simplesmente
+; listas de coisas dentro de parênteses, separados por espaços em branco.
+
+; O "reader" (leitor) de Clojure presume que o primeiro elemento de
+; uma par de parênteses é uma função ou macro, e que os resto são argumentos.
+
+: A primeira chamada de um arquivo deve ser ns, para configurar o namespace (espaço de nomes)
+(ns learnclojure)
+
+; Alguns exemplos básicos:
+
+; str cria uma string concatenando seus argumentos
+(str "Hello" " " "World") ; => "Hello World"
+
+; Cálculos são feitos de forma direta e intuitiva
+(+ 1 1) ; => 2
+(- 2 1) ; => 1
+(* 1 2) ; => 2
+(/ 2 1) ; => 2
+
+; Você pode comparar igualdade utilizando =
+(= 1 1) ; => true
+(= 2 1) ; => false
+
+; Negação para operações lógicas
+(not true) ; => false
+
+; Aninhar "forms" funciona como esperado
+(+ 1 (- 3 2)) ; = 1 + (3 - 2) => 2
+
+; Tipos
+;;;;;;;;;;;;;
+
+; Clojure usa os tipos de objetos de Java para booleanos, strings e números.
+; Use `class` para inspecioná-los
+(class 1) ; Literais Integer são java.lang.Long por padrão
+(class 1.); Literais Float são java.lang.Double
+(class ""); Strings são sempre com aspas duplas, e são java.lang.String
+(class false) ; Booleanos são java.lang.Boolean
+(class nil); O valor "null" é chamado nil
+
+; Se você quiser criar um lista de literais, use aspa simples para
+; ela não ser avaliada
+'(+ 1 2) ; => (+ 1 2)
+; (que é uma abreviação de (quote (+ 1 2)))
+
+; É possível avaliar uma lista com aspa simples
+(eval '(+ 1 2)) ; => 3
+
+; Coleções e sequências
+;;;;;;;;;;;;;;;;;;;
+
+; Listas são estruturas encadeadas, enquanto vetores são implementados como arrays.
+; Listas e Vetores são classes Java também!
+(class [1 2 3]); => clojure.lang.PersistentVector
+(class '(1 2 3)); => clojure.lang.PersistentList
+
+; Uma lista é escrita como (1 2 3), mas temos que colocar a aspa
+; simples para impedir o leitor (reader) de pensar que é uma função.
+; Também, (list 1 2 3) é o mesmo que '(1 2 3)
+
+; "Coleções" são apenas grupos de dados
+; Listas e vetores são ambos coleções:
+(coll? '(1 2 3)) ; => true
+(coll? [1 2 3]) ; => true
+
+; "Sequências" (seqs) são descrições abstratas de listas de dados.
+; Apenas listas são seqs.
+(seq? '(1 2 3)) ; => true
+(seq? [1 2 3]) ; => false
+
+; Um seq precisa apenas prover uma entrada quando é acessada.
+; Portanto, já que seqs podem ser avaliadas sob demanda (lazy) -- elas podem definir séries infinitas:
+(range 4) ; => (0 1 2 3)
+(range) ; => (0 1 2 3 4 ...) (uma série infinita)
+(take 4 (range)) ; (0 1 2 3)
+
+; Use cons para adicionar um item no início de uma lista ou vetor
+(cons 4 [1 2 3]) ; => (4 1 2 3)
+(cons 4 '(1 2 3)) ; => (4 1 2 3)
+
+; Conj adiciona um item em uma coleção sempre do jeito mais eficiente.
+; Para listas, elas inserem no início. Para vetores, é inserido no final.
+(conj [1 2 3] 4) ; => [1 2 3 4]
+(conj '(1 2 3) 4) ; => (4 1 2 3)
+
+; Use concat para concatenar listas e vetores
+(concat [1 2] '(3 4)) ; => (1 2 3 4)
+
+; Use filter, map para interagir com coleções
+(map inc [1 2 3]) ; => (2 3 4)
+(filter even? [1 2 3]) ; => (2)
+
+; Use reduce para reduzi-los
+(reduce + [1 2 3 4])
+; = (+ (+ (+ 1 2) 3) 4)
+; => 10
+
+; Reduce pode receber um argumento para o valor inicial
+(reduce conj [] '(3 2 1))
+; = (conj (conj (conj [] 3) 2) 1)
+; => [3 2 1]
+
+; Funções
+;;;;;;;;;;;;;;;;;;;;;
+
+; Use fn para criar novas funções. Uma função sempre retorna
+; sua última expressão.
+(fn [] "Hello World") ; => fn
+
+; (É necessário colocar parênteses para chamá-los)
+((fn [] "Hello World")) ; => "Hello World"
+
+; Você pode atribuir valores a variáveis utilizando def
+(def x 1)
+x ; => 1
+
+; Atribua uma função para uma var
+(def hello-world (fn [] "Hello World"))
+(hello-world) ; => "Hello World"
+
+; Você pode abreviar esse processo usando defn
+(defn hello-world [] "Hello World")
+
+; O [] é uma lista de argumentos para um função.
+(defn hello [name]
+ (str "Hello " name))
+(hello "Steve") ; => "Hello Steve"
+
+; Você pode ainda usar essa abreviação para criar funcões:
+(def hello2 #(str "Hello " %1))
+(hello2 "Fanny") ; => "Hello Fanny"
+
+; Vocé pode ter funções multi-variadic, isto é, com um número variável de argumentos
+(defn hello3
+ ([] "Hello World")
+ ([name] (str "Hello " name)))
+(hello3 "Jake") ; => "Hello Jake"
+(hello3) ; => "Hello World"
+
+; Funções podem agrupar argumentos extras em uma seq
+(defn count-args [& args]
+ (str "You passed " (count args) " args: " args))
+(count-args 1 2 3) ; => "You passed 3 args: (1 2 3)"
+
+; Você pode misturar argumentos regulares e argumentos em seq
+(defn hello-count [name & args]
+ (str "Hello " name ", you passed " (count args) " extra args"))
+(hello-count "Finn" 1 2 3)
+; => "Hello Finn, you passed 3 extra args"
+
+
+; Mapas
+;;;;;;;;;;
+
+; Hash maps e array maps compartilham uma mesma interface. Hash maps são mais
+; rápidos para pesquisa mas não mantém a ordem da chave.
+(class {:a 1 :b 2 :c 3}) ; => clojure.lang.PersistentArrayMap
+(class (hash-map :a 1 :b 2 :c 3)) ; => clojure.lang.PersistentHashMap
+
+; Arraymaps pode automaticamente se tornar hashmaps através da maioria das
+; operações se eles ficarem grandes o suficiente, portanto não há necessida de
+; se preocupar com isso.
+
+;Mapas podem usar qualquer valor que se pode derivar um hash como chave
+
+
+; Mapas podem usar qualquer valor em que se pode derivar um hash como chave,
+; mas normalmente palavras-chave (keywords) são melhores.
+; Keywords são como strings mas com algumas vantagens.
+(class :a) ; => clojure.lang.Keyword
+
+(def stringmap {"a" 1, "b" 2, "c" 3})
+stringmap ; => {"a" 1, "b" 2, "c" 3}
+
+(def keymap {:a 1, :b 2, :c 3})
+keymap ; => {:a 1, :c 3, :b 2}
+
+; A propósito, vírgulas são sempre tratadas como espaçoes em branco e não fazem nada.
+
+; Recupere o valor de um mapa chamando ele como uma função
+(stringmap "a") ; => 1
+(keymap :a) ; => 1
+
+; Uma palavra-chave pode ser usada pra recuperar os valores de um mapa
+(:b keymap) ; => 2
+
+; Não tente isso com strings
+;("a" stringmap)
+; => Exception: java.lang.String cannot be cast to clojure.lang.IFn
+
+; Buscar uma chave não presente retorna nil
+(stringmap "d") ; => nil
+
+; Use assoc para adicionar novas chaves para hash-maps
+(def newkeymap (assoc keymap :d 4))
+newkeymap ; => {:a 1, :b 2, :c 3, :d 4}
+
+; Mas lembre-se, tipos em Clojure são sempre imutáveis!
+keymap ; => {:a 1, :b 2, :c 3}
+
+; Use dissoc para remover chaves
+(dissoc keymap :a :b) ; => {:c 3}
+
+; Conjuntos
+;;;;;;
+
+(class #{1 2 3}) ; => clojure.lang.PersistentHashSet
+(set [1 2 3 1 2 3 3 2 1 3 2 1]) ; => #{1 2 3}
+
+; Adicione um membro com conj
+(conj #{1 2 3} 4) ; => #{1 2 3 4}
+
+; Remova um membro com disj
+(disj #{1 2 3} 1) ; => #{2 3}
+
+; Test por existência usando set como função:
+(#{1 2 3} 1) ; => 1
+(#{1 2 3} 4) ; => nil
+
+; Existem muitas outras funções no namespace clojure.sets
+
+; Forms úteis
+;;;;;;;;;;;;;;;;;
+
+; Construções lógicas em Clojure são como macros, e
+; se parecem com as demais
+(if false "a" "b") ; => "b"
+(if false "a") ; => nil
+
+; Use let para criar um novo escopo associando sîmbolos a valores (bindings)
+(let [a 1 b 2]
+ (> a b)) ; => false
+
+; Agrupe comandos juntos com "do"
+(do
+ (print "Hello")
+ "World") ; => "World" (prints "Hello")
+
+; Funções tem um do implícito
+(defn print-and-say-hello [name]
+ (print "Saying hello to " name)
+ (str "Hello " name))
+(print-and-say-hello "Jeff") ;=> "Hello Jeff" (prints "Saying hello to Jeff")
+
+; Assim como let
+(let [name "Urkel"]
+ (print "Saying hello to " name)
+ (str "Hello " name)) ; => "Hello Urkel" (prints "Saying hello to Urkel")
+
+; Módulos
+;;;;;;;;;;;;;;;
+
+; Use "use" para poder usar todas as funções de um modulo
+(use 'clojure.set)
+
+; Agora nós podemos usar operações com conjuntos
+(intersection #{1 2 3} #{2 3 4}) ; => #{2 3}
+(difference #{1 2 3} #{2 3 4}) ; => #{1}
+
+; Você pode escolher um subconjunto de funções para importar
+(use '[clojure.set :only [intersection]])
+
+; Use require para importar um módulo
+(require 'clojure.string)
+
+; Use / para chamar funções de um módulo
+; Aqui, o módulo é clojure.string e a função é blank?
+(clojure.string/blank? "") ; => true
+
+; Você pode dar para um módulo um nome mais curto no import
+(require '[clojure.string :as str])
+(str/replace "This is a test." #"[a-o]" str/upper-case) ; => "THIs Is A tEst."
+; (#"" denota uma expressão regular literal)
+
+; Você pode usar require (e até "use", mas escolha require) de um namespace utilizando :require.
+; Não é necessário usar aspa simples nos seus módulos se você usar desse jeito.
+(ns test
+ (:require
+ [clojure.string :as str]
+ [clojure.set :as set]))
+
+; Java
+;;;;;;;;;;;;;;;;;
+
+; Java tem uma biblioteca padrão enorme e muito útil,
+; portanto é importante aprender como utiliza-la.
+
+; Use import para carregar um modulo java
+(import java.util.Date)
+
+; Você pode importar usando ns também.
+(ns test
+ (:import java.util.Date
+ java.util.Calendar))
+
+; Use o nome da clase com um "." no final para criar uma nova instância
+(Date.) ; <a date object>
+
+; Use . para chamar métodos. Ou, use o atalho ".method"
+(. (Date.) getTime) ; <a timestamp>
+(.getTime (Date.)) ; exatamente a mesma coisa.
+
+; Use / para chamar métodos estáticos
+(System/currentTimeMillis) ; <a timestamp> (o módulo System está sempre presente)
+
+; Use doto para pode lidar com classe (mutáveis) de forma mais tolerável
+(import java.util.Calendar)
+(doto (Calendar/getInstance)
+ (.set 2000 1 1 0 0 0)
+ .getTime) ; => A Date. set to 2000-01-01 00:00:00
+
+; STM
+;;;;;;;;;;;;;;;;;
+
+; Software Transactional Memory é o mecanismo que Clojure usa para gerenciar
+; estado persistente. Tem algumas construções em Clojure que o utilizam.
+
+; O atom é o mais simples. Passe pra ele um valor inicial
+(def my-atom (atom {}))
+
+; Atualize o atom com um swap!.
+; swap! pega uma funçnao and chama ela com o valor atual do atom
+; como primeiro argumento, e qualquer argumento restante como o segundo
+(swap! my-atom assoc :a 1) ; Coloca o valor do átomo my-atom como o resultado de (assoc {} :a 1)
+(swap! my-atom assoc :b 2) ; Coloca o valor do átomo my-atom como o resultado de (assoc {:a 1} :b 2)
+
+; Use '@' para desreferenciar um atom e acessar seu valor
+my-atom ;=> Atom<#...> (Retorna o objeto do Atom)
+@my-atom ; => {:a 1 :b 2}
+
+; Abaixo um contador simples usando um atom
+(def counter (atom 0))
+(defn inc-counter []
+ (swap! counter inc))
+
+(inc-counter)
+(inc-counter)
+(inc-counter)
+(inc-counter)
+(inc-counter)
+
+@counter ; => 5
+
+; Outras construção STM são refs e agents.
+; Refs: http://clojure.org/refs
+; Agents: http://clojure.org/agents
+```
+
+### Leitura adicional
+
+Esse tutorial está longe de ser exaustivo, mas deve ser suficiente para que você possa começar.
+
+Clojure.org tem vários artigos:
+[http://clojure.org/](http://clojure.org/)
+
+Clojuredocs.org tem documentação com exemplos para quase todas as funções principais (pertecentes ao core):
+[http://clojuredocs.org/quickref/Clojure%20Core](http://clojuredocs.org/quickref/Clojure%20Core)
+
+4Clojure é um grande jeito de aperfeiçoar suas habilidades em Clojure/Programação Funcional:
+[http://www.4clojure.com/](http://www.4clojure.com/)
+
+Clojure-doc.org tem um bom número de artigos para iniciantes:
+[http://clojure-doc.org/](http://clojure-doc.org/)
diff --git a/pt-br/groovy-pt.html.markdown b/pt-br/groovy-pt.html.markdown
new file mode 100644
index 00000000..885d5b27
--- /dev/null
+++ b/pt-br/groovy-pt.html.markdown
@@ -0,0 +1,435 @@
+---
+language: Groovy
+category: language
+filename: learngroovy.groovy
+contributors:
+ - ["Roberto Pérez Alcolea", "http://github.com/rpalcolea"]
+translators:
+ - ["João Farias", "https://github.com/JoaoGFarias"]
+lang: pt-br
+---
+
+Groovy - Uma linguagem dinâmica para a plataforma Java. [Leia mais aqui.](http://groovy.codehaus.org)
+
+```groovy
+
+/*
+ Prepara-se:
+
+ 1) Instale a máquina virtual de Groovy - http://gvmtool.net/
+ 2) Intalse o Groovy: gvm install groovy
+ 3) Inicie o console groovy digitando: groovyConsole
+
+*/
+
+// Comentário de uma linha inicia-se com duas barras
+/*
+Comentário de múltiplas linhas são assim.
+*/
+
+// Olá Mundo!
+println "Olá mundo!"
+
+/*
+ Variáveis:
+
+ Você pode atribuir valores a variáveis para uso posterior
+*/
+
+def x = 1
+println x
+
+x = new java.util.Date()
+println x
+
+x = -3.1499392
+println x
+
+x = false
+println x
+
+x = "Groovy!"
+println x
+
+/*
+ Coleções e mapeamentos
+*/
+
+//Criando uma lista vazia
+def tecnologias = []
+
+/*** Adicionando elementos à lista ***/
+
+// Assim como Java
+tecnologias.add("Grails")
+
+// Shift para esquerda adiciona e retorna a lista
+tecnologias << "Groovy"
+
+// Adição de múltiplos elementos
+tecnologias.addAll(["Gradle","Griffon"])
+
+/*** Removendo elementos da lista ***/
+
+// Assim como Java
+tecnologias.remove("Griffon")
+
+// Subtração também funciona
+tecnologias = technologies - 'Grails'
+
+/*** Iterando sobre listas ***/
+
+// Itera sobre os elementos da lista
+tecnologias.each { println "Tecnologias: $it"}
+tecnologias.eachWithIndex { it, i -> println "$i: $it"}
+
+/*** Checando os elementos da lista ***/
+
+//Avalia se a lista contém o elemento 'Groovy'
+contem = tecnologias.contains( 'Groovy' )
+
+// Ou
+contem = 'Groovy' in tecnologias
+
+// Checagem por múltiplos elementos
+tecnologias.containsAll(['Groovy','Grails'])
+
+/*** Ordenando listas ***/
+
+// Ordena a lista (altera a lista in-place)
+tecnologias.sort()
+
+// Para ordenar a lista sem alterar a original
+tecnologiasOrdenadas = tecnologias.sort( false )
+
+/*** Manipulando listas ***/
+
+//Substitue todos os elementos da lista
+Collections.replaceAll(tecnologias, 'Gradle', 'gradle')
+
+//Desorganiza a lista
+Collections.shuffle(tecnologias, new Random())
+
+//Limpa a lista
+technologies.clear()
+
+//Criando um mapeamento vazio
+def devMap = [:]
+
+//Adicionando valores
+devMap = ['nome':'Roberto', 'framework':'Grails', 'linguagem':'Groovy']
+devMap.put('ultimoNome','Perez')
+
+//Iterando sobre os elementos do mapeamento
+devMap.each { println "$it.key: $it.value" }
+devMap.eachWithIndex { it, i -> println "$i: $it"}
+
+//Avalia se um mapeamento contém uma chave
+assert devMap.containsKey('nome')
+
+//Avalia se um mapeamento contém um valor
+assert devMap.containsValue('Roberto')
+
+//Pega as chaves de um mapeamento
+println devMap.keySet()
+
+//Pega os valores de um mapeamento
+println devMap.values()
+
+/*
+ Groovy Beans
+
+ GroovyBeans são JavaBeans com uma sintaxe muito mais simples.
+
+ Quando Groovy é compilado para bytecode, as seguintes regras são usadas:
+
+ * Se o nome é declarado com um modificador de acesso(public, private or
+ protected) então um atributo é gerado.
+
+ * Um nome declarado sem modificador de acesso gera um campo privado com
+ getter e setter públicos (ou seja, uma propriedade).
+
+ * Se uma propriedade é declarada como final, um campo private final é criado
+ e o setter não é gerado.
+
+ * Você pode declarar uma propriedade e também declarar seus próprios getters
+ e setters.
+
+ * Você pode declarar uma propriedade e um campo com o mesmo nome, a propriedade
+ usará este campo.
+
+ * Se você quer uma propriedade private ou protected, você deve prover seus
+ próprios getters e setter, que devem ser declarados como private ou protected.
+
+ * Se você acessar uma propriedade dentro da classe e esta propriedade é definida
+ em tempo de compilação com 'this', implícito ou explícito (por exemplo,
+ this.foo, ou simplesmente foo), Groovy acessará este campo diretamente, sem
+ passar pelo getter ou setter.
+
+ * Se você acessar uma propriedade que não existe usando foo, explicitamente ou
+ implicitamente, então Groovy irá acessar esta propriedade através da meta
+ classe, o que pode falhar em tempo de execução.
+
+*/
+
+class Foo {
+ // propriedade de leitura, apenas
+ final String nome = "Roberto"
+
+ // propriedade de leitura, apenas, com getter e setter públicos
+ String linguagem
+ protected void setLinguagem(String linguagem) { this.linguagem = linguagem }
+
+ // propriedade tipada dinamicamente
+ def ultimoNome
+}
+
+/*
+ Condicionais e loops
+*/
+
+//Groovy suporta a sintaxe if-else
+def x = 3
+
+if(x==1) {
+ println "Um"
+} else if(x==2) {
+ println "Dois"
+} else {
+ println "X é maior que Dois"
+}
+
+//Groovy também suporta o operador ternário
+def y = 10
+def x = (y > 1) ? "functionou" : "falhou"
+assert x == "functionou"
+
+//Loop 'for'
+//Itera sobre um intervalo (range)
+def x = 0
+for (i in 0 .. 30) {
+ x += i
+}
+
+//Itera sobre uma lista
+x = 0
+for( i in [5,3,2,1] ) {
+ x += i
+}
+
+//Itera sobre um array
+array = (0..20).toArray()
+x = 0
+for (i in array) {
+ x += i
+}
+
+//Itera sobre um mapa
+def map = ['name':'Roberto', 'framework':'Grails', 'language':'Groovy']
+x = 0
+for ( e in map ) {
+ x += e.value
+}
+
+/*
+ Operadores
+
+ Sobrecarregamento de Operadores para uma lsita dos operadores comuns que
+ Grooby suporta:
+ http://groovy.codehaus.org/Operator+Overloading
+
+ Operadores Groovy úteis
+*/
+//Operador de espalhamento: invoca uma ação sobre todos os itens de um
+//objeto agregador.
+def tecnologias = ['Groovy','Grails','Gradle']
+tecnologias*.toUpperCase() // = to tecnologias.collect { it?.toUpperCase() }
+
+//Operador de navegação segura: usado para evitar NullPointerException.
+def usuario = User.get(1)
+def nomeUsuario = usuario?.nomeUsuario
+
+
+/*
+ Closures
+ Um closure, em Grooby, é como um "bloco de código" ou um ponteiro para método.
+ É um pedação de código que é definido e executado em um momento posterior.
+
+ Mais informação em: http://groovy.codehaus.org/Closures+-+Formal+Definition
+*/
+//Exemplo:
+def clos = { println "Hello World!" }
+
+println "Executando o closure:"
+clos()
+
+//Passando parêmetros para um closure
+def soma = { a, b -> println a+b }
+soma(2,4)
+
+//Closdures por referir-se a variáveis que não estão listadas em sua
+//lista de parêmetros.
+def x = 5
+def multiplicarPor = { num -> num * x }
+println multiplicarPor(10)
+
+// Se você tiver um closure que tem apenas um argumento, você pode omitir
+// o parâmetro na definição do closure
+def clos = { print it }
+clos( "oi" )
+
+/*
+ Groovy pode memorizar resultados de closures [1][2][3]
+*/
+def cl = {a, b ->
+ sleep(3000) // simula processamento
+ a + b
+}
+
+mem = cl.memoize()
+
+def chamaClosure(a, b) {
+ def inicio = System.currentTimeMillis()
+ mem(a, b)
+ println "Os inputs(a = $a, b = $b) - tomam ${System.currentTimeMillis() - inicio} msecs."
+}
+
+chamaClosure(1, 2)
+chamaClosure(1, 2)
+chamaClosure(2, 3)
+chamaClosure(2, 3)
+chamaClosure(3, 4)
+chamaClosure(3, 4)
+chamaClosure(1, 2)
+chamaClosure(2, 3)
+chamaClosure(3, 4)
+
+/*
+ Expando
+
+ A classe Expando é um bean dinâmico que permite adicionar propriedade e
+ closures como métodos a uma instância desta classe
+
+ http://mrhaki.blogspot.mx/2009/10/groovy-goodness-expando-as-dynamic-bean.html
+*/
+ def usuario = new Expando(nome:"Roberto")
+ assert 'Roberto' == nome.name
+
+ nome.lastName = 'Pérez'
+ assert 'Pérez' == nome.lastName
+
+ nome.showInfo = { out ->
+ out << "Name: $name"
+ out << ", Last name: $lastName"
+ }
+
+ def sw = new StringWriter()
+ println nome.showInfo(sw)
+
+
+/*
+ Metaprogramação (MOP)
+*/
+
+//Usando a ExpandoMetaClasse para adicionar comportamento
+String.metaClass.testAdd = {
+ println "adicionamos isto"
+}
+
+String x = "teste"
+x?.testAdd()
+
+//Interceptando chamadas a métodos
+class Test implements GroovyInterceptable {
+ def soma(Integer x, Integer y) { x + y }
+
+ def invocaMetodo(String name, args) {
+ System.out.println "Invoca método $name com argumentos: $args"
+ }
+}
+
+def teste = new Test()
+teste?.soma(2,3)
+teste?.multiplica(2,3)
+
+//Groovy suporta propertyMissing para lidar com tentativas de resolução de
+//propriedades.
+class Foo {
+ def propertyMissing(String nome) { nome }
+}
+def f = new Foo()
+
+assertEquals "boo", f.boo
+
+/*
+ TypeChecked e CompileStatic
+ Groovy, por natureza, é e sempre será uma linguagem dinâmica, mas ela também
+ suporta typecheked e compilestatic
+
+ Mais informações: http://www.infoq.com/articles/new-groovy-20
+*/
+//TypeChecked
+import groovy.transform.TypeChecked
+
+void testeMethod() {}
+
+@TypeChecked
+void test() {
+ testeMethod()
+
+ def nome = "Roberto"
+
+ println noomee
+
+}
+
+//Outro exemplo:
+import groovy.transform.TypeChecked
+
+@TypeChecked
+Integer test() {
+ Integer num = "1"
+
+ Integer[] numeros = [1,2,3,4]
+
+ Date dia = numeros[1]
+
+ return "Teste"
+
+}
+
+//Exemplo de CompileStatic :
+import groovy.transform.CompileStatic
+
+@CompileStatic
+int soma(int x, int y) {
+ x + y
+}
+
+assert soma(2,5) == 7
+
+
+```
+
+## Referências
+
+[Groovy documentation](http://groovy.codehaus.org/Documentation)
+
+[Groovy web console](http://groovyconsole.appspot.com/)
+
+Junte-se a um [grupo de usuários Groovy](http://groovy.codehaus.org/User+Groups)
+
+## Livro
+
+* [Groovy Goodness] (https://leanpub.com/groovy-goodness-notebook)
+
+* [Groovy in Action] (http://manning.com/koenig2/)
+
+* [Programming Groovy 2: Dynamic Productivity for the Java Developer] (http://shop.oreilly.com/product/9781937785307.do)
+
+[1] http://roshandawrani.wordpress.com/2010/10/18/groovy-new-feature-closures-can-now-memorize-their-results/
+[2] http://www.solutionsiq.com/resources/agileiq-blog/bid/72880/Programming-with-Groovy-Trampoline-and-Memoize
+[3] http://mrhaki.blogspot.mx/2011/05/groovy-goodness-cache-closure-results.html
+
+
+
diff --git a/pt-br/haskell-pt.html.markdown b/pt-br/haskell-pt.html.markdown
index 55f90bd6..788dc1d2 100644
--- a/pt-br/haskell-pt.html.markdown
+++ b/pt-br/haskell-pt.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
translators:
diff --git a/pt-br/markdown-pt.html.markdown b/pt-br/markdown-pt.html.markdown
index cac4a13e..4030ce3c 100644
--- a/pt-br/markdown-pt.html.markdown
+++ b/pt-br/markdown-pt.html.markdown
@@ -14,7 +14,7 @@ escrever sintaxe que converte facilmente em HTML (hoje, suporta outros formatos
Dê-me feedback tanto quanto você quiser! / Sinta-se livre para a garfar (fork) e
puxar o projeto (pull request)
-```
+```markdown
<!-- Markdown é um superconjunto do HTML, de modo que qualquer arvquivo HTML é
um arquivo Markdown válido, isso significa que nós podemos usar elementos HTML
em Markdown, como o elemento de comentário, e eles não serão afetados pelo analisador
diff --git a/pt-br/php-pt.html.markdown b/pt-br/php-pt.html.markdown
index 344df43a..0e710742 100644
--- a/pt-br/php-pt.html.markdown
+++ b/pt-br/php-pt.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/pt-br/ruby-pt.html.markdown b/pt-br/ruby-pt.html.markdown
index 4a8a1b5c..89a051d4 100644
--- a/pt-br/ruby-pt.html.markdown
+++ b/pt-br/ruby-pt.html.markdown
@@ -33,7 +33,7 @@ Você não deve usar também
10 * 2 #=> 20
35 / 5 #=> 7
-# Aritimética é apenas açúcar sintático
+# Aritmética é apenas açúcar sintático
# para chamar um método de um objeto
1.+(3) #=> 4
10.* 5 #=> 50
@@ -129,7 +129,7 @@ array = [1, "Oi", false] #=> => [1, "Oi", false]
array[0] #=> 1
array[12] #=> nil
-# Como aritimética, o acesso via [var]
+# Como aritmética, o acesso via [var]
# é apenas açúcar sintático
# para chamar o método [] de um objeto
array.[] 0 #=> 1
@@ -171,7 +171,7 @@ end
# Desde o Ruby 1.9, temos uma sintaxe especial quando usamos símbolos como chaves (keys)
-novo_hash = { defcon: 3, acao: true}
+novo_hash = {defcon: 3, acao: true}
novo_hash.keys #=> [:defcon, :acao]
@@ -183,9 +183,9 @@ novo_hash.keys #=> [:defcon, :acao]
if true
"Se verdadeiro"
elsif false
- "else if, opicional"
+ "else if, opcional"
else
- "else, também é opicional"
+ "else, também é opcional"
end
for contador in 1..5
@@ -259,7 +259,7 @@ end
# Argumentos de métodos são separados por uma vírgula
somar 3, 4 #=> 7
-somar somar(3,4), 5 #=> 12
+somar(3,4), 5 #=> 12
# yield
# Todos os métodos possuem implicitamente um paramêntro opcional que é um bloco
diff --git a/pt-br/swift-pt.html.markdown b/pt-br/swift-pt.html.markdown
new file mode 100644
index 00000000..a29490b0
--- /dev/null
+++ b/pt-br/swift-pt.html.markdown
@@ -0,0 +1,500 @@
+---
+language: swift
+contributors:
+ - ["Grant Timmerman", "http://github.com/grant"],
+ - ["Christopher Bess", "http://github.com/cbess"]
+translators:
+ - ["Mariane Siqueira Machado", "https://twitter.com/mariane_sm"]
+lang: pt-br
+filename: learnswift.swift
+---
+
+Swift é uma linguagem de programação para desenvolvimento de aplicações no iOS e OS X criada pela Apple. Criada para
+coexistir com Objective-C e para ser mais resiliente a código com erros, Swift foi apresentada em 2014 na Apple's
+developer conference WWDC. Foi construída com o compilador LLVM já incluído no Xcode 6 beta.
+
+O livro oficial [Swift Programming Language] (https://itunes.apple.com/us/book/swift-programming-language/id881256329) da
+Apple já está disponível via IBooks (apenas em inglês).
+
+Confira também o tutorial completo de Swift da Apple [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html), também disponível apenas em inglês.
+
+```swift
+// importa um módulo
+import UIKit
+
+//
+// MARK: Noções básicas
+//
+
+// Xcode supporta anotações para seu código e lista elas na barra de atalhos
+// MARK: Marca uma sessão
+// TODO: Faça algo logo
+// FIXME: Conserte esse código
+
+println("Hello, world")
+
+// Valores em variáveis (var) podem ter seu valor alterado depois de declarados.
+// Valores em constantes (let) NÃO podem ser alterados depois de declarados.
+
+var myVariable = 42
+let øπΩ = "value" // nomes de variáveis em unicode
+let π = 3.1415926
+let convenience = "keyword" // nome de variável contextual
+let weak = "keyword"; let override = "another keyword" // comandos podem ser separados por uma ponto e vírgula
+let `class` = "keyword" // Crases permitem que palavras-chave seja usadas como nome de variáveis
+let explicitDouble: Double = 70
+let intValue = 0007 // 7
+let largeIntValue = 77_000 // 77000
+let label = "some text " + String(myVariable) // Coerção
+let piText = "Pi = \(π), Pi 2 = \(π * 2)" // Interpolação de strings
+
+// Constrói valores específicos
+// Utiliza configuração de build -D
+#if false
+ println("Not printed")
+ let buildValue = 3
+#else
+ let buildValue = 7
+#endif
+println("Build value: \(buildValue)") // Build value: 7
+
+/*
+ Optionals fazem parte da linguagem e permitem que você armazene um
+ valor `Some` (algo) ou `None` (nada).
+
+ Como Swift requer que todas as propriedades tenham valores, até mesmo nil deve
+ ser explicitamente armazenado como um valor Optional.
+
+ Optional<T> é uma enum.
+*/
+var someOptionalString: String? = "optional" // Pode ser nil
+// o mesmo acima, mas ? é um operador pós-fixado (açúcar sintático)
+var someOptionalString2: Optional<String> = "optional"
+
+if someOptionalString != nil {
+ // Eu não sou nil
+ if someOptionalString!.hasPrefix("opt") {
+ println("has the prefix")
+ }
+
+ let empty = someOptionalString?.isEmpty
+}
+someOptionalString = nil
+
+// Optional implicitamente desempacotado (unwrapped)
+var unwrappedString: String! = "Valor é esperado."
+// o mesmo acima, mas ? é um operador pósfixado (açúcar sintático)
+var unwrappedString2: ImplicitlyUnwrappedOptional<String> = "Valor é esperado."
+
+if let someOptionalStringConstant = someOptionalString {
+ // Tem `Some` (algum) valor, não nil
+ if !someOptionalStringConstant.hasPrefix("ok") {
+ // não possui o prefixo
+ }
+}
+
+// Swift tem suporte para armazenar um valor de qualquer tipo.
+// AnyObject == id
+// Ao contrário de Objective-C `id`, AnyObject funciona com qualquer valor (Class, Int, struct, etc)
+var anyObjectVar: AnyObject = 7
+anyObjectVar = "Mudou o valor para string, não é uma boa prática, mas é possível."
+
+/*
+Comentário aqui
+ /*
+ Comentários aninhados também são suportados
+ */
+*/
+
+//
+// MARK: Coleções
+//
+
+/*
+ Tipos Array e Dicionário são structs. Portanto `let` e `var`
+ também indicam se são mutáveis (var) ou imutáveis (let) quando declarados
+ com esses tipos.
+*/
+
+// Array
+var shoppingList = ["catfish", "water", "lemons"]
+shoppingList[1] = "bottle of water"
+let emptyArray = [String]() // imutável
+var emptyMutableArray = [String]() // mutável
+
+
+// Dicionário
+var occupations = [
+ "Malcolm": "Captain",
+ "kaylee": "Mechanic"
+]
+occupations["Jayne"] = "Public Relations"
+let emptyDictionary = [String: Float]() // imutável
+var emptyMutableDictionary = [String: Float]() // mutável
+
+
+//
+// MARK: Controle de fluxo
+//
+
+// laço for (array)
+let myArray = [1, 1, 2, 3, 5]
+for value in myArray {
+ if value == 1 {
+ println("One!")
+ } else {
+ println("Not one!")
+ }
+}
+
+// laço for (dicionário)
+var dict = ["one": 1, "two": 2]
+for (key, value) in dict {
+ println("\(key): \(value)")
+}
+
+// laço for (alcance)
+for i in -1...shoppingList.count {
+ println(i)
+}
+shoppingList[1...2] = ["steak", "peacons"]
+// use ..< para excluir o último número
+
+// laço while (enquanto)
+var i = 1
+while i < 1000 {
+ i *= 2
+}
+
+// laço do-while
+do {
+ println("hello")
+} while 1 == 2
+
+// Switch
+let vegetable = "red pepper"
+switch vegetable {
+case "celery":
+ let vegetableComment = "Add some raisins and make ants on a log."
+case "cucumber", "watercress":
+ let vegetableComment = "That would make a good tea sandwich."
+case let x where x.hasSuffix("pepper"):
+ let vegetableComment = "Is it a spicy \(x)?"
+default: // required (in order to cover all possible input)
+ let vegetableComment = "Everything tastes good in soup."
+}
+
+
+//
+// MARK: Funções
+//
+
+// Funções são tipos de primeira classe, o que significa que eles podem ser aninhados
+// em funções e podem ser passados como parâmetros
+
+// Funções Swift com cabeçalhos doc (formato como reStructedText)
+/**
+Uma operação de saudação
+
+- Um bullet em documentos
+- Outro bullet
+
+:param: nome A nome
+:param: dia A dia
+:returns: Uma string contendo o nome e o dia.
+*/
+func greet(name: String, day: String) -> String {
+ return "Hello \(name), today is \(day)."
+}
+greet("Bob", "Tuesday")
+
+// Função que retorna múltiplos items em uma tupla
+func getGasPrices() -> (Double, Double, Double) {
+ return (3.59, 3.69, 3.79)
+}
+let pricesTuple = getGasPrices()
+let price = pricesTuple.2 // 3.79
+// Ignore valores de Tuplas (ou outros valores) usando _ (underscore)
+let (_, price1, _) = pricesTuple // price1 == 3.69
+println(price1 == pricesTuple.1) // true
+println("Gas price: \(price)")
+
+// Número variável de argumentos
+func setup(numbers: Int...) {
+ // its an array
+ let number = numbers[0]
+ let argCount = numbers.count
+}
+
+// Passando e retornando funções
+func makeIncrementer() -> (Int -> Int) {
+ func addOne(number: Int) -> Int {
+ return 1 + number
+ }
+ return addOne
+}
+var increment = makeIncrementer()
+increment(7)
+
+// passagem por referência
+func swapTwoInts(inout a: Int, inout b: Int) {
+ let tempA = a
+ a = b
+ b = tempA
+}
+var someIntA = 7
+var someIntB = 3
+swapTwoInts(&someIntA, &someIntB)
+println(someIntB) // 7
+
+
+//
+// MARK: Closures
+//
+var numbers = [1, 2, 6]
+
+// Funções são casos especiais de closures ({})
+
+// Exemplo de closure.
+// `->` separa argumentos e tipo de retorno
+// `in` separa o cabeçalho do closure do seu corpo
+numbers.map({
+ (number: Int) -> Int in
+ let result = 3 * number
+ return result
+})
+
+// Quando o tipo é conhecido, como abaixo, nós podemos fazer o seguinte
+numbers = numbers.map({ number in 3 * number })
+// Ou até mesmo isso
+//numbers = numbers.map({ $0 * 3 })
+
+print(numbers) // [3, 6, 18]
+
+// Closure restante
+numbers = sorted(numbers) { $0 > $1 }
+
+print(numbers) // [18, 6, 3]
+
+// Super atalho, já que o operador < infere os tipos
+
+numbers = sorted(numbers, < )
+
+print(numbers) // [3, 6, 18]
+
+//
+// MARK: Estruturas
+//
+
+// Estruturas e classes tem funcionalidades muito similares
+struct NamesTable {
+ let names: [String]
+
+ // Custom subscript
+ subscript(index: Int) -> String {
+ return names[index]
+ }
+}
+
+// Estruturas possuem um inicializador auto-gerado automático (implícito)
+let namesTable = NamesTable(names: ["Me", "Them"])
+//let name = namesTable[2]
+//println("Name is \(name)") // Name is Them
+
+//
+// MARK: Classes
+//
+
+// Classes, Estruturas e seus membros possuem três níveis de modificadores de acesso
+// Eles são: internal (default), public, private
+
+public class Shape {
+ public func getArea() -> Int {
+ return 0;
+ }
+}
+
+// Todos os métodos e propriedades de uma classe são públicos.
+// Se você só precisa armazenar dados em um objeto estruturado, use `struct`
+
+internal class Rect: Shape {
+ var sideLength: Int = 1
+
+ // Getter e setter personalizado
+ private var perimeter: Int {
+ get {
+ return 4 * sideLength
+ }
+ set {
+ // `newValue` é uma variável implicita disponível para os setters
+ sideLength = newValue / 4
+ }
+ }
+
+ // Carregue uma propriedade sob demanda (lazy)
+ // subShape permanece nil (não inicializado) até seu getter ser chamado
+ lazy var subShape = Rect(sideLength: 4)
+
+ // Se você não precisa de um getter e setter personalizado,
+ // mas ainda quer roda código antes e depois de configurar
+ // uma propriedade, você pode usar `willSet` e `didSet`
+ var identifier: String = "defaultID" {
+ // o argumento `willSet` será o nome da variável para o novo valor
+ willSet(someIdentifier) {
+ print(someIdentifier)
+ }
+ }
+
+ init(sideLength: Int) {
+ self.sideLength = sideLength
+ // sempre chame super.init por último quand inicializar propriedades personalizadas (custom)
+ super.init()
+ }
+
+ func shrink() {
+ if sideLength > 0 {
+ --sideLength
+ }
+ }
+
+ override func getArea() -> Int {
+ return sideLength * sideLength
+ }
+}
+
+// Uma classe básica `Square` que estende `Rect`
+class Square: Rect {
+ convenience init() {
+ self.init(sideLength: 5)
+ }
+}
+
+var mySquare = Square()
+print(mySquare.getArea()) // 25
+mySquare.shrink()
+print(mySquare.sideLength) // 4
+
+// Compara instâncias, não é o mesmo que == o qual compara objetos
+if mySquare === mySquare {
+ println("Yep, it's mySquare")
+}
+
+
+//
+// MARK: Enums
+//
+
+// Enums podem opcionalmente ser de um tipo específico ou não.
+// Podem conter métodos do mesmo jeito que classes.
+
+enum Suit {
+ case Spades, Hearts, Diamonds, Clubs
+ func getIcon() -> String {
+ switch self {
+ case .Spades: return "♤"
+ case .Hearts: return "♡"
+ case .Diamonds: return "♢"
+ case .Clubs: return "♧"
+ }
+ }
+}
+
+
+//
+// MARK: Protocolos
+//
+
+// `protocol` pode requerer que os tipos que se adequam tenham
+// propriedades de instância, métodos, operadores e subscripts.
+protocol ShapeGenerator {
+ var enabled: Bool { get set }
+ func buildShape() -> Shape
+}
+
+// Protocolos declarados com @objc permitem funções opcionais,
+// que permitem verificar a confomidade
+@objc protocol TransformShape {
+ optional func reshaped()
+ optional func canReshape() -> Bool
+}
+
+class MyShape: Rect {
+ var delegate: TransformShape?
+
+ func grow() {
+ sideLength += 2
+
+ if let allow = self.delegate?.canReshape?() {
+ // test for delegate then for method
+ // testa por delegação e então por método
+ self.delegate?.reshaped?()
+ }
+ }
+}
+
+
+//
+// MARK: Outros
+//
+
+// `extension`s: Adicionam uma funcionalidade extra para um tipo já existente.
+
+// Square agora "segue" o protocolo `Printable`
+extension Square: Printable {
+ var description: String {
+ return "Area: \(self.getArea()) - ID: \(self.identifier)"
+ }
+}
+
+println("Square: \(mySquare)")
+
+// Você pode também estender tipos embutidos (built-in)
+extension Int {
+ var customProperty: String {
+ return "This is \(self)"
+ }
+
+ func multiplyBy(num: Int) -> Int {
+ return num * self
+ }
+}
+
+println(7.customProperty) // "This is 7"
+println(14.multiplyBy(2)) // 42
+
+// Generics: Similar com Java e C#. Use a palavra-chave `where` para
+// especificar os requisitos do generics.
+
+func findIndex<T: Equatable>(array: [T], valueToFind: T) -> Int? {
+ for (index, value) in enumerate(array) {
+ if value == valueToFind {
+ return index
+ }
+ }
+ return nil
+}
+let foundAtIndex = findIndex([1, 2, 3, 4], 3)
+println(foundAtIndex == 2) // true
+
+// Operadores:
+// Operadores personalizados (custom) podem começar com os seguintes caracteres:
+// / = - + * % < > ! & | ^ . ~
+// ou
+// Unicode math, símbolo, seta, e caracteres tipográficos ou de desenho.
+prefix operator !!! {}
+
+// Um operador de prefixo que triplica o comprimento do lado do quadrado
+// quando usado
+prefix func !!! (inout shape: Square) -> Square {
+ shape.sideLength *= 3
+ return shape
+}
+
+// valor atual
+println(mySquare.sideLength) // 4
+
+// Troca o comprimento do lado usando um operador personalizado !!!, aumenta o lado por 3
+!!!mySquare
+println(mySquare.sideLength) // 12
+
+```
diff --git a/python.html.markdown b/python.html.markdown
index 9057dde2..53381f32 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -3,24 +3,25 @@ language: python
contributors:
- ["Louie Dinh", "http://ldinh.ca"]
- ["Amin Bandali", "http://aminbandali.com"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
filename: learnpython.py
---
-Python was created by Guido Van Rossum in the early 90's. It is now one of the most popular
+Python was created by Guido Van Rossum in the early 90s. 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 2.7 specifically, but should be applicable
-to Python 2.x. Look for another tour of Python 3 soon!
+to Python 2.x. For Python 3.x, take a look at the Python 3 tutorial.
```python
# Single line comments start with a number symbol.
""" Multiline strings can be written
- using three "'s, and are often used
+ using three "s, and are often used
as comments
"""
@@ -54,12 +55,23 @@ to Python 2.x. Look for another tour of Python 3 soon!
# Modulo operation
7 % 3 # => 1
+# Exponentiation (x to the yth power)
+2**4 # => 16
+
# Enforce precedence with parentheses
(1 + 3) * 2 # => 8
-# Boolean values are primitives
-True
-False
+# Boolean Operators
+# Note "and" and "or" are case-sensitive
+True and False #=> False
+False or True #=> True
+
+# Note using Bool operators with ints
+0 and 2 #=> 0
+-5 or 0 #=> -5
+0 == False #=> True
+2 == True #=> False
+1 == True #=> True
# negate with not
not True # => False
@@ -90,6 +102,9 @@ not False # => True
# Strings can be added too!
"Hello " + "world!" # => "Hello world!"
+# ... or multiplied
+"Hello" * 3 # => "HelloHelloHello"
+
# A string can be treated like a list of characters
"This is a string"[0] # => 'T'
@@ -124,11 +139,12 @@ bool("") # => False
## 2. Variables and Collections
####################################################
-# Python has a print function, available in versions 2.7 and 3...
-print("I'm Python. Nice to meet you!")
-# and an older print statement, in all 2.x versions but removed from 3.
-print "I'm also Python!"
-
+# Python has a print statement, in all 2.x versions but removed from 3.
+print "I'm Python. Nice to meet you!"
+# Python also has a print function, available in versions 2.7 and 3...
+# but for 2.7 you need to add the import (uncommented):
+# from __future__ import print_function
+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
@@ -158,6 +174,10 @@ li.append(3) # li is now [1, 2, 4, 3] again.
# Access a list like you would any array
li[0] # => 1
+# Assign new values to indexes that have already been initialized with =
+li[0] = 42
+li[0] # => 42
+li[0] = 1 # Note: setting it back to the original value
# Look at the last element
li[-1] # => 3
@@ -182,7 +202,8 @@ li[::-1] # => [3, 4, 2, 1]
del li[2] # li is now [1, 2, 3]
# You can add lists
-li + other_li # => [1, 2, 3, 4, 5, 6] - Note: values for li and for other_li are not modified.
+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]
@@ -243,17 +264,25 @@ 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
+# note that filled_dict.get("four") is still => 4
+# (get doesn't set the value in the dictionary)
+
+# set the value of a key with a syntax similar to lists
+filled_dict["four"] = 4 # now, filled_dict["four"] => 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
-# Sets store ... well sets
+# Sets store ... well sets (which are like lists but can contain no duplicates)
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])
+# order is not guaranteed, even though it may sometimes look sorted
+another_set = set([4, 3, 2, 2, 1]) # another_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}
@@ -359,7 +388,7 @@ add(y=6, x=5) # Keyword arguments can arrive in any order.
# You can define functions that take a variable number of
-# positional arguments
+# positional args, which will be interpreted as a tuple if you do not use the *
def varargs(*args):
return args
@@ -367,7 +396,7 @@ varargs(1, 2, 3) # => (1, 2, 3)
# You can define functions that take a variable number of
-# keyword arguments, as well
+# keyword args, as well, which will be interpreted as a map if you do not use **
def keyword_args(**kwargs):
return kwargs
@@ -386,26 +415,33 @@ all_the_args(1, 2, a=3, b=4) prints:
"""
# When calling functions, you can do the opposite of args/kwargs!
-# Use * to expand tuples and use ** to expand kwargs.
+# Use * to expand positional args and use ** to expand keyword args.
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)
+# you can pass args and kwargs along to other functions that take args/kwargs
+# by expanding them with * and ** respectively
+def pass_all_the_args(*args, **kwargs):
+ all_the_args(*args, **kwargs)
+ print varargs(*args)
+ print keyword_args(**kwargs)
+
# Function Scope
x = 5
def setX(num):
# Local var x not the same as global variable x
x = num # => 43
- print (x) # => 43
+ print x # => 43
def setGlobalX(num):
global x
- print (x) # => 5
+ print x # => 5
x = num # global var x is now set to 6
- print (x) # => 6
+ print x # => 6
setX(43)
setGlobalX(6)
@@ -430,11 +466,11 @@ filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
+
####################################################
## 5. Classes
####################################################
-
# We subclass from object to get a class.
class Human(object):
@@ -504,6 +540,9 @@ from math import *
# You can shorten module names
import math as m
math.sqrt(16) == m.sqrt(16) # => True
+# you can also test that the functions are equivalent
+from math import sqrt
+math.sqrt == m.sqrt == sqrt # => True
# Python modules are just ordinary python files. You
# can write your own, and import them. The name of the
@@ -530,8 +569,9 @@ def double_numbers(iterable):
# double_numbers.
# Note xrange is a generator that does the same thing range does.
# Creating a list 1-900000000 would take lot of time and space to be made.
-# xrange creates an xrange generator object instead of creating the entire list like range does.
-# We use a trailing underscore in variable names when we want to use a name that
+# xrange creates an xrange generator object instead of creating the entire list
+# like range does.
+# We use a trailing underscore in variable names when we want to use a name that
# would normally collide with a python keyword
xrange_ = xrange(1, 900000000)
diff --git a/python3.html.markdown b/python3.html.markdown
index 8bcc85d1..6b1d3156 100644
--- a/python3.html.markdown
+++ b/python3.html.markdown
@@ -3,10 +3,11 @@ language: python3
contributors:
- ["Louie Dinh", "http://pythonpracticeprojects.com"]
- ["Steven Basart", "http://github.com/xksteven"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
filename: learnpython3.py
---
-Python was created by Guido Van Rossum in the early 90's. It is now one of the most popular
+Python was created by Guido Van Rossum in the early 90s. 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.
@@ -19,7 +20,7 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
# Single line comments start with a number symbol.
""" Multiline strings can be written
- using three "'s, and are often used
+ using three "s, and are often used
as comments
"""
@@ -50,6 +51,9 @@ Note: This article applies to Python 3 specifically. Check out the other tutoria
# Modulo operation
7 % 3 # => 1
+# Exponentiation (x to the yth power)
+2**4 # => 16
+
# Enforce precedence with parentheses
(1 + 3) * 2 # => 8
@@ -61,6 +65,18 @@ False
not True # => False
not False # => True
+# Boolean Operators
+# Note "and" and "or" are case-sensitive
+True and False #=> False
+False or True #=> True
+
+# Note using Bool operators with ints
+0 and 2 #=> 0
+-5 or 0 #=> -5
+0 == False #=> True
+2 == True #=> False
+1 == True #=> True
+
# Equality is ==
1 == 1 # => True
2 == 1 # => False
@@ -127,7 +143,8 @@ bool({}) #=> False
# 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
+# No need to declare variables before assigning to them.
+# Convention is to use lower_case_with_underscores
some_var = 5
some_var # => 5
@@ -176,7 +193,8 @@ li[::-1] # => [3, 4, 2, 1]
del li[2] # li is now [1, 2, 3]
# You can add lists
-li + other_li # => [1, 2, 3, 4, 5, 6] - Note: values for li and for other_li are not modified.
+# Note: values for li and for other_li are not modified.
+li + other_li # => [1, 2, 3, 4, 5, 6]
# Concatenate lists with "extend()"
li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6]
@@ -215,14 +233,17 @@ 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"]
+# Get all keys as a list with "keys()".
+# We need to wrap the call in list() because we are getting back an iterable. We'll talk about those later.
# Note - Dictionary key ordering is not guaranteed.
# Your results might not match this exactly.
+list(filled_dict.keys()) # => ["three", "two", "one"]
+
# Get all values as a list with "values()". Once again we need to wrap it in list() to get it out of the iterable.
-list(filled_dict.values()) # => [3, 2, 1]
# Note - Same as above regarding key ordering.
+list(filled_dict.values()) # => [3, 2, 1]
+
# Check for existence of keys in a dictionary with "in"
"one" in filled_dict # => True
@@ -242,6 +263,10 @@ filled_dict.get("four", 4) # => 4
filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5
filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5
+# Adding to a dictionary
+filled_dict.update({"four":4}) #=> {"one": 1, "two": 2, "three": 3, "four": 4}
+#filled_dict["four"] = 4 #another way to add to dict
+
# Remove keys from a dictionary with del
del filled_dict["one"] # Removes the key "one" from filled dict
@@ -458,6 +483,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
+# List comprehension stores the output as a list which can itself be a nested list
[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
diff --git a/r.html.markdown b/r.html.markdown
index b59fc29c..c555d748 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -8,7 +8,7 @@ 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.
-```python
+```r
# Comments start with number symbols.
@@ -179,7 +179,7 @@ c(3,3,3,2,2,1) # 3 3 3 2 2 1
# You can also have infinitely large or small numbers
class(Inf) # "numeric"
class(-Inf) # "numeric"
-# You might use "Inf", for example, in integrate( dnorm(x), 3, Inf);
+# You might use "Inf", for example, in integrate(dnorm, 3, Inf);
# this obviates Z-score tables.
# BASIC ARITHMETIC
@@ -236,11 +236,12 @@ c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE
# FACTORS
# The factor class is for categorical data
# 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
+factor(c("female", "female", "male", NA, "female"))
+# female female male <NA> female
+# Levels: female male
# The "levels" are the values the categorical data can take
-levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male" "NA"
+# Note that missing data does not enter the levels
+levels(factor(c("male", "male", "female", NA, "female"))) # "female" "male"
# If a factor vector has length 1, its levels will have length 1, too
length(factor("male")) # 1
length(levels(factor("male"))) # 1
diff --git a/ru-ru/coffeescript-ru.html.markdown b/ru-ru/coffeescript-ru.html.markdown
new file mode 100644
index 00000000..f8416f38
--- /dev/null
+++ b/ru-ru/coffeescript-ru.html.markdown
@@ -0,0 +1,104 @@
+---
+language: coffeescript
+contributors:
+ - ["Tenor Biel", "http://github.com/L8D"]
+ - ["Xavier Yao", "http://github.com/xavieryao"]
+translators:
+ - ["asaskevich", "http://github.com/asaskevich"]
+filename: learncoffee-ru.coffee
+lang: ru-ru
+---
+
+CoffeeScript - это небольшой язык, который компилируется один-в-один в эквивалентный код на языке JavaScript, а потому он не интерпретируется во время исполнения JavaScript кода.
+Ключевой особенностью CoffeeScript является то, что он пытается создать читабельный, качественно оформленный и плавный JavaScript код, прекрасно работающий в любой среде JavaScript.
+
+Также загляните на официальный сайт [языка](http://coffeescript.org/), где можно найти весьма полное учебное пособие по CoffeeScript.
+
+```coffeescript
+# CoffeeScript - язык хипстеров.
+# Язык использует самое модное из множества современных языков.
+# Эти комментарии по стилю похожи на комментарии Ruby или Python, они используют "решетку" в качестве знака комментария.
+
+###
+Блоки комментариев выделяются тремя символами "решетки", в результирующем JavaScript коде они будут преобразованы в '/ * и '* /'.
+
+Перед тем, как идти далее, Вам нужно понимать семантику JavaScript.
+###
+
+# Присвоение:
+number = 42 #=> var number = 42;
+opposite = true #=> var opposite = true;
+
+# Условия:
+number = -42 if opposite #=> if(opposite) { number = -42; }
+
+# Функции:
+square = (x) -> x * x #=> var square = function(x) { return x * x; }
+
+fill = (container, liquid = "coffee") ->
+ "Заполняем #{container} жидкостью #{liquid}..."
+#=>var fill;
+#
+#fill = function(container, liquid) {
+# if (liquid == null) {
+# liquid = "coffee";
+# }
+# return "Заполняем " + container + " жидкостью " + liquid + "...";
+#};
+
+# Списки и диапазоны:
+list = [1..5] #=> var list = [1, 2, 3, 4, 5];
+
+# Объекты:
+math =
+ root: Math.sqrt
+ square: square
+ cube: (x) -> x * square x
+#=> var math = {
+# "root": Math.sqrt,
+# "square": square,
+# "cube": function(x) { return x * square(x); }
+#}
+
+# Многоточия:
+race = (winner, runners...) ->
+ print winner, runners
+#=>race = function() {
+# var runners, winner;
+# winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
+# return print(winner, runners);
+#};
+
+# Проверка на существование объекта:
+alert "Так и знал!" if elvis?
+#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("Так и знал!"); }
+
+# Итерации по массивам:
+cubes = (math.cube num for num in list)
+#=>cubes = (function() {
+# var _i, _len, _results;
+# _results = [];
+# for (_i = 0, _len = list.length; _i < _len; _i++) {
+# num = list[_i];
+# _results.push(math.cube(num));
+# }
+# return _results;
+# })();
+
+foods = ['broccoli', 'spinach', 'chocolate']
+eat food for food in foods when food isnt 'chocolate'
+#=>foods = ['broccoli', 'spinach', 'chocolate'];
+#
+#for (_k = 0, _len2 = foods.length; _k < _len2; _k++) {
+# food = foods[_k];
+# if (food !== 'chocolate') {
+# eat(food);
+# }
+#}
+```
+
+## На почитать
+
+- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/)
+- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read)
+- [CoffeeScript на русском](http://cidocs.ru/coffeescript/)
diff --git a/ru-ru/go-ru.html.markdown b/ru-ru/go-ru.html.markdown
index 5b9d8ebf..e06ae9bd 100644
--- a/ru-ru/go-ru.html.markdown
+++ b/ru-ru/go-ru.html.markdown
@@ -13,11 +13,11 @@ lang: ru-ru
---
Go - это язык общего назначения, целью которого является удобство, простота,
-конкуррентность. Это не тренд в компьютерных науках, а новейший и быстрый
+конкурентность. Это не тренд в компьютерных науках, а новейший и быстрый
способ решать насущные проблемы.
Концепции Go схожи с другими императивными статически типизированными языками.
-Быстро компилируется и быстро исполняется, имеет легкие в понимании конструкции
+Быстро компилируется и быстро исполняется, имеет лёгкие в понимании конструкции
для создания масштабируемых и многопоточных программ.
Может похвастаться отличной стандартной библиотекой и большим комьюнити, полным
@@ -57,7 +57,7 @@ func main() {
func beyondHello() {
var x int // Переменные должны быть объявлены до их использования.
x = 3 // Присвоение значения переменной.
- // Краткое определение := позволяет объявить перменную с автоматической
+ // Краткое определение := позволяет объявить переменную с автоматической
// подстановкой типа из значения.
y := 4
sum, prod := learnMultiple(x, y) // Функция возвращает два значения.
@@ -65,12 +65,12 @@ func beyondHello() {
learnTypes() // < y minutes, learn more!
}
-// Функция имеющая входные параметры и возврат нескольких значений.
+// Функция, имеющая входные параметры и возвращающая несколько значений.
func learnMultiple(x, y int) (sum, prod int) {
return x + y, x * y // Возврат двух значений.
}
-// Некотрые встроенные типы и литералы.
+// Некоторые встроенные типы и литералы.
func learnTypes() {
// Краткое определение переменной говорит само за себя.
s := "Learn Go!" // Тип string.
@@ -97,7 +97,7 @@ func learnTypes() {
// Слайсы (slices) имеют динамическую длину. И массивы, и слайсы имеют свои
// преимущества, но слайсы используются гораздо чаще.
- s3 := []int{4, 5, 9} // Сравните с a3. Тут нет троеточия.
+ s3 := []int{4, 5, 9} // Сравните с a3, тут нет троеточия.
s4 := make([]int, 4) // Выделение памяти для слайса из 4-х int (нули).
var d2 [][]float64 // Только объявление, память не выделяется.
bs := []byte("a slice") // Синтаксис приведения типов.
@@ -113,7 +113,7 @@ func learnTypes() {
delete(m, "three") // Встроенная функция, удаляет элемент из map-а.
// Неиспользуемые переменные в Go являются ошибкой.
- // Нижнее подчеркивание позволяет игнорировать такие переменные.
+ // Нижнее подчёркивание позволяет игнорировать такие переменные.
_, _, _, _, _, _, _, _, _ = s2, g, f, u, pi, n, a3, s4, bs
// Вывод считается использованием переменной.
fmt.Println(s, c, a4, s3, d2, m)
@@ -121,16 +121,16 @@ func learnTypes() {
learnFlowControl() // Идем дальше.
}
-// У Go есть полноценный сборщик мусора. В нем есть указатели но нет арифметики
+// У Go есть полноценный сборщик мусора. В нем есть указатели, но нет арифметики
// указателей. Вы можете допустить ошибку с указателем на nil, но не с
// инкрементацией указателя.
func learnMemory() (p, q *int) {
// Именованные возвращаемые значения p и q являются указателями на int.
p = new(int) // Встроенная функция new выделяет память.
- // Выделенный int проинициализирован нулем, p больше не содержит nil.
+ // Выделенный int проинициализирован нулём, p больше не содержит nil.
s := make([]int, 20) // Выделение единого блока памяти под 20 int-ов.
s[3] = 7 // Присвоить значение одному из них.
- r := -2 // Определить еще одну локальную переменную.
+ r := -2 // Определить ещё одну локальную переменную.
return &s[3], &r // Амперсанд(&) обозначает получение адреса переменной.
}
@@ -139,7 +139,7 @@ func expensiveComputation() float64 {
}
func learnFlowControl() {
- // If-ы всегда требуют наличине фигурных скобок, но не круглых.
+ // If-ы всегда требуют наличие фигурных скобок, но не круглых.
if true {
fmt.Println("told ya")
}
@@ -178,7 +178,7 @@ func learnFlowControl() {
}
// Функции являются замыканиями.
xBig := func() bool {
- return x > 10000 // Ссылается на x, объявленый выше switch.
+ return x > 10000 // Ссылается на x, объявленный выше switch.
}
fmt.Println("xBig:", xBig()) // true (т.к. мы присвоили x = e^10).
x = 1.3e3 // Тут х == 1300
@@ -189,7 +189,7 @@ func learnFlowControl() {
love:
learnDefer() // Быстрый обзор важного ключевого слова.
- learnInterfaces() // О! Интерфейсы, идем далее.
+ learnInterfaces() // О! Интерфейсы, идём далее.
}
func learnDefer() (ok bool) {
@@ -214,7 +214,7 @@ type pair struct {
// Объявление метода для типа pair. Теперь pair реализует интерфейс Stringer.
func (p pair) String() string { // p в данном случае называют receiver-ом.
- // Sprintf – еще одна функция из пакета fmt.
+ // Sprintf – ещё одна функция из пакета fmt.
// Обращение к полям p через точку.
return fmt.Sprintf("(%d, %d)", p.x, p.y)
}
@@ -234,7 +234,7 @@ func learnInterfaces() {
fmt.Println(p) // Вывод такой же, что и выше. Println вызывает метод String.
fmt.Println(i) // Вывод такой же, что и выше.
- learnVariadicParams("Учиться", "учиться", "и еще раз учиться!")
+ learnVariadicParams("Учиться", "учиться", "и ещё раз учиться!")
}
// Функции могут иметь варьируемое количество параметров.
@@ -263,22 +263,22 @@ func learnErrorHandling() {
// выведет "strconv.ParseInt: parsing "non-int": invalid syntax"
fmt.Println(err)
}
- // Мы еще обратимся к интерфейсам чуть позже, а пока...
+ // Мы ещё обратимся к интерфейсам чуть позже, а пока...
learnConcurrency()
}
-// c – это тип данных channel (канал), объект для конкуррентного взаимодействия.
+// c – это тип данных channel (канал), объект для конкурентного взаимодействия.
func inc(i int, c chan int) {
c <- i + 1 // когда channel слева, <- являтся оператором "отправки".
}
-// Будем использовать функцию inc для конкуррентной инкрементации чисел.
+// Будем использовать функцию inc для конкурентной инкрементации чисел.
func learnConcurrency() {
// Тот же make, что и в случае со slice. Он предназначен для выделения
// памяти и инициализации типов slice, map и channel.
c := make(chan int)
- // Старт трех конкуррентных goroutine. Числа будут инкрементированы
- // конкуррентно и, может быть параллельно, если машина правильно
+ // Старт трех конкурентных goroutine. Числа будут инкрементированы
+ // конкурентно и, может быть параллельно, если машина правильно
// сконфигурирована и позволяет это делать. Все они будут отправлены в один
// и тот же канал.
go inc(0, c) // go начинает новую горутину.
@@ -291,7 +291,7 @@ func learnConcurrency() {
cs := make(chan string) // другой канал, содержит строки.
cc := make(chan chan string) // канал каналов со строками.
go func() { c <- 84 }() // пуск новой горутины для отправки значения
- go func() { cs <- "wordy" }() // еще раз, теперь для cs
+ go func() { cs <- "wordy" }() // ещё раз, теперь для cs
// Select тоже что и switch, но работает с каналами. Он случайно выбирает
// готовый для взаимодействия канал.
select {
@@ -327,7 +327,7 @@ func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Основа всех основ в Go это [официальный веб сайт](http://golang.org/).
Там можно пройти туториал, поиграться с интерактивной средой Go и почитать
-объемную документацию.
+объёмную документацию.
Для живого ознакомления рекомендуется почитать исходные коды [стандартной
библиотеки Go](http://golang.org/src/pkg/). Отлично задокументированная, она
diff --git a/ru-ru/haskell-ru.html.markdown b/ru-ru/haskell-ru.html.markdown
index 03e66d05..e15fe6b7 100644
--- a/ru-ru/haskell-ru.html.markdown
+++ b/ru-ru/haskell-ru.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
contributors:
- ["Adit Bhargava", "http://adit.io"]
translators:
diff --git a/ru-ru/java-ru.html.markdown b/ru-ru/java-ru.html.markdown
new file mode 100644
index 00000000..005495cc
--- /dev/null
+++ b/ru-ru/java-ru.html.markdown
@@ -0,0 +1,506 @@
+---
+language: java
+contributors:
+ - ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Madison Dickson", "http://github.com/mix3d"]
+translators:
+ - ["Sergey Gaykov", "https://github.com/gaykov"]
+filename: LearnJavaRu.java
+lang: ru-ru
+---
+
+Java - это объектно ориентированный язык программирования общего назначения,
+основанный на классах и поддерживающий параллельное программирование.
+[Подробнее читайте здесь.](http://docs.oracle.com/javase/tutorial/java/index.html)
+
+```java
+// Однострочные комментарии начинаются с //.
+/*
+Многострочные комментарии
+выглядят так.
+*/
+/**
+JavaDoc-комментарии выглядят так. Они используются для описания класса
+и его членов.
+*/
+
+// Импорт класса ArrayList из пакета java.util.
+import java.util.ArrayList;
+// Импорт всех классов из пакета java.security.
+import java.security.*;
+
+// Каждый .java файл содержит один публичный класс, имя которого совпадает с
+// именем файла.
+public class LearnJavaRu {
+
+ // Программа должна содержать метод main, который является точкой входа.
+ public static void main (String[] args) {
+
+ // System.out.println используется для печати строк.
+ System.out.println("Hello World!");
+ System.out.println(
+ "Integer: " + 10 +
+ " Double: " + 3.14 +
+ " Boolean: " + true);
+
+ // Чтобы напечатать что-либо не заканчивая переводом строки
+ // используется System.out.print.
+ System.out.print("Hello ");
+ System.out.print("World");
+
+
+ ///////////////////////////////////////
+ // Типы и Переменные
+ ///////////////////////////////////////
+
+ // Переменные объявляются с использованием <тип> <имя>
+ // Byte - 8-битное целое число.
+ // (-128 <= byte <= 127)
+ byte fooByte = 100;
+
+ // Short - 16-битное целое число.
+ // (-32,768 <= short <= 32,767)
+ short fooShort = 10000;
+
+ // Integer - 32-битное целое число.
+ // (-2,147,483,648 <= int <= 2,147,483,647)
+ int fooInt = 1;
+
+ // Long - 64-битное целое число.
+ // (-9,223,372,036,854,775,808 <= long <= 9,223,372,036,854,775,807)
+ long fooLong = 100000L;
+ // L используется для указания на то, что переменная имеет тип long;
+ // По умолчанию, числа без L являются integer.
+
+ // Замечание: в Java нет беззнаковых типов.
+
+ // Float - 32-битное IEEE 754 число с плавающей запятой с одинарной степенью точности.
+ float fooFloat = 234.5f;
+ // f используется для указания на то, что переменная имеет тип float;
+ // иначе, число являлось бы double.
+
+ // Double - 64-битное IEEE 754 число с плавающей запятой с двойной степенью точности.
+ double fooDouble = 123.4;
+
+ // Boolean - true или false
+ boolean fooBoolean = true;
+ boolean barBoolean = false;
+
+ // Char - Простой 16-битный символ Unicode.
+ char fooChar = 'A';
+
+ // Переменным final не может быть присвоен другой объект.
+ final int HOURS_I_WORK_PER_WEEK = 9001;
+
+ // Строки.
+ String fooString = "My String Is Here!";
+
+ // \n - это экранированный символ, который означает начало новой строки.
+ String barString = "Printing on a new line?\nNo Problem!";
+ // \t - это экранированный символ, который добавляет символ табуляции.
+ String bazString = "Do you want to add a tab?\tNo Problem!";
+ System.out.println(fooString);
+ System.out.println(barString);
+ System.out.println(bazString);
+
+ // Массивы
+ // Размер массива должен быть указан при объявлении.
+ // Объявлять массив можно в следующих форматах:
+ //<тип данных> [] <имя> = new <тип данных>[<размер массива>];
+ //<тип данных> <имя>[] = new <тип данных>[<размер массива>];
+ int [] intArray = new int[10];
+ String [] stringArray = new String[1];
+ boolean boolArray [] = new boolean[100];
+
+ // Другой способ объявления и инициализации массива:
+ int [] y = {9000, 1000, 1337};
+ String names [] = {"Bob", "John", "Fred", "Juan Pedro"};
+ boolean bools[] = new boolean[] {true, false, false};
+
+ // Индексация массива - доступ к элементу.
+ System.out.println("intArray @ 0: " + intArray[0]);
+
+ // Массивы изменяемы и индекс в них начинается с 0.
+ intArray[1] = 1;
+ System.out.println("intArray @ 1: " + intArray[1]); // => 1
+
+ // Дополнительно.
+ // ArrayLists - похож на массив, но предлагает больше возможностей,
+ // его размер изменяемый.
+ // LinkedLists - реализация двусвязного списка. Все операции
+ // выполняются так, как ожидается от двусвязного
+ // списка.
+ // Maps - набор объектов, в которых присутствует связь
+ // ключ-значение. В Map ключ не может дублироваться.
+ // Каждый ключ связан только с одним значением.
+ // HashMaps - этот класс использует хэш-таблицу для реализации
+ // интерфейса Map. Это позволяет сохранить постоянной
+ // скорость выполнения базовых операций, таких как
+ // добавление и удаление элементов, вне зависимости
+ // от размера множества.
+
+ ///////////////////////////////////////
+ // Операторы
+ ///////////////////////////////////////
+ System.out.println("\n->Операторы");
+
+ int i1 = 1, i2 = 2; // Сокращение для множественного объявления.
+
+ // Арифметика в Java проста.
+ 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 (0.5 округлено)
+
+ // Остаток от деления
+ System.out.println("11%3 = "+(11 % 3)); // => 2
+
+ // Операторы сравнения.
+ System.out.println("3 == 2? " + (3 == 2)); // => false
+ System.out.println("3 != 2? " + (3 != 2)); // => true
+ System.out.println("3 > 2? " + (3 > 2)); // => true
+ System.out.println("3 < 2? " + (3 < 2)); // => false
+ System.out.println("2 <= 2? " + (2 <= 2)); // => true
+ System.out.println("2 >= 2? " + (2 >= 2)); // => true
+
+ // Побитовые операторы!
+ /*
+ ~ Унарное побитовое дополнение.
+ << Знаковый сдвиг влево.
+ >> Знаковый сдвиг вправо.
+ >>> Беззнаковый сдвиг вправо.
+ & Побитовое И.
+ ^ Побитовое исключающее ИЛИ.
+ | Побитовое ИЛИ.
+ */
+
+ // Операторы инкремента.
+ int i = 0;
+ System.out.println("\n->Inc/Dec-rementation");
+ // Операторы ++ и -- увеличивают и уменьшают значение на 1 соответственно.
+ // Если они находятся перед переменной, сначала происходит
+ // увеличение/уменьшение, затем операция, если после,
+ // то сначала выполняется операция, затем увеличение/уменьшение.
+ System.out.println(i++); //i = 1, напечатает 0 (пост-инкремент)
+ System.out.println(++i); //i = 2, напечатает 2 (пре-инкремент)
+ System.out.println(i--); //i = 1, напечатает 2 (пост-декремент)
+ System.out.println(--i); //i = 0, напечатает 0 (пре-декремент)
+
+ ///////////////////////////////////////
+ // Контролирующие операторы.
+ ///////////////////////////////////////
+ System.out.println("\n->Контролирующие операторы");
+
+ // Оператор if такой же, как и в С.
+ int j = 10;
+ if (j == 10){
+ System.out.println("Я напечатаюсь!");
+ } else if (j > 10) {
+ System.out.println("Я нет.");
+ } else {
+ System.out.println("И я тоже нет.");
+ }
+
+ // Цикл while.
+ int fooWhile = 0;
+ while(fooWhile < 100)
+ {
+ // System.out.println(fooWhile);
+ // Увеличить счетчик.
+ // Будет пройдено 100 итераций, fooWhile 0,1,2...99
+ fooWhile++;
+ }
+ System.out.println("Значение fooWhile: " + fooWhile);
+
+ // Цикл Do While.
+ int fooDoWhile = 0;
+ do
+ {
+ // System.out.println(fooDoWhile);
+ // Увеличить счетчик.
+ // Будет пройдено 100 итераций, fooDoWhile 0->99
+ fooDoWhile++;
+ } while(fooDoWhile < 100);
+ System.out.println("Значение fooDoWhile: " + fooDoWhile);
+
+ // Цикл for.
+ int fooFor;
+ // Структура цикла for => for(<начальное_состояние>; <условие>; <шаг>)
+ for(fooFor=0; fooFor<10; fooFor++){
+ // System.out.println(fooFor);
+ // Пройдет 10 итераций., fooFor 0->9
+ }
+ System.out.println("Значение fooFor: " + fooFor);
+
+ // Цикл For Each
+ // Автоматический проход через массив или список объектов.
+ int[] fooList = {1,2,3,4,5,6,7,8,9};
+ // Структура цикла for each => for(<объект> : <объект_массив>)
+ // читается как: для каждого объекта в массиве
+ // заметка: тип объекта должен совпадать с типом массива.
+
+ for( int bar : fooList ){
+ System.out.println(bar);
+ //Пройдет 9 итераций и напечатает 1-9 на новых строках.
+ }
+
+ // Switch Case
+ // switch работает с типами byte, short, char и int.
+ // Также он работает с перечислениями,
+ // классом String и с некоторыми классами-обертками над
+ // примитивными типами: Character, Byte, Short и Integer.
+ int month = 3;
+ String monthString;
+ switch (month){
+ case 1:
+ monthString = "Январь";
+ break;
+ case 2:
+ monthString = "Февраль";
+ break;
+ case 3:
+ monthString = "Март";
+ break;
+ default:
+ monthString = "Другой месяц";
+ break;
+ }
+ System.out.println("Результат Switch Case: " + monthString);
+
+ // Сокращенный синтаксис условного оператора.
+ // Вы можете использовать этот синтаксис для быстрого присвоения
+ // или логических переходов.
+ // Читается так: "Если (условие) истинно, использовать <значение 1>,
+ // в ином случае, использовать <значение 2>"
+ int foo = 5;
+ String bar = (foo < 10) ? "A" : "B";
+ System.out.println(bar); // Напечатает А, потому что условие истинно
+
+
+ ///////////////////////////////////////
+ // Преобразование и приведение типов данных.
+ ///////////////////////////////////////
+
+ // Преобразование данных.
+
+ // Преобразование строки в число.
+ Integer.parseInt("123"); // Вернет числовое представление "123".
+
+ // Преобразование числа в строку
+ Integer.toString(123); // Вернет строковое представление 123.
+
+ // Для других преобразований смотрите следующие классы:
+ // Double
+ // Long
+ // String
+
+ // Приведение типов
+ // Вы так же можете приводить типы в Java.
+ // Подробнее об этом можно узнать по ссылке:
+ // http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html
+
+
+ ///////////////////////////////////////
+ // Классы и Функции
+ ///////////////////////////////////////
+
+ System.out.println("\n->Классы и Функции");
+
+ // (Класс Bicycle определен ниже)
+
+ // Для создания экземпляра класса используется new.
+ Bicycle trek = new Bicycle();
+
+ // Вызов методов объекта.
+ trek.speedUp(3); // Вы должны всегда использовать сеттеры и геттеры.
+ trek.setCadence(100);
+
+ // toString возвращает строковое представление объекта.
+ System.out.println("trek info: " + trek.toString());
+
+ } // Конец метода main.
+} // Конец класса LearnJava.
+
+
+// Вы можете включать другие, не публичные классы в .java файл.
+
+
+// Синтаксис объявления класса:
+// <public/private/protected> class <имя класса>{
+// // Поля с данными, конструкторы, функции, все внутри.
+// // Функции называют методами в Java.
+// }
+
+class Bicycle {
+
+ // Поля/Переменные класса Bicycle.
+ public int cadence;// Публичные(public): Доступны из любого места.
+ private int speed; // Приватные(private): Доступны только внутри класса.
+ protected int gear;// Защищенные(protected): Доступ из класса и наследников.
+ String name; // по умолчанию: Доступны только внутри пакета.
+
+ // Конструкторы - способ создания класса.
+ // Это конструктор:
+ public Bicycle() {
+ gear = 1;
+ cadence = 50;
+ speed = 5;
+ name = "Bontrager";
+ }
+
+ // Это конструктор, который принимает аргументы:
+ public Bicycle(int startCadence, int startSpeed, int startGear, String name) {
+ this.gear = startGear;
+ this.cadence = startCadence;
+ this.speed = startSpeed;
+ this.name = name;
+ }
+
+ // Синтаксис функций:
+ // <public/private/protected> <тип возвращаемого значения> <имя>(<аргументы>)
+
+ // Классы в Java часто реализуют сеттеры и геттеры для своих полей.
+
+ // Синтаксис определения метода:
+ // <модификатор> <тип возвращаемого значения> <имя>(<аргументы>)
+ public int getCadence() {
+ return cadence;
+ }
+
+ // void-методы не возвращают значений.
+ public void setCadence(int newValue) {
+ cadence = newValue;
+ }
+
+ public void setGear(int newValue) {
+ gear = newValue;
+ }
+
+ public void speedUp(int increment) {
+ speed += increment;
+ }
+
+ public void slowDown(int decrement) {
+ speed -= decrement;
+ }
+
+ public void setName(String newName) {
+ name = newName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ //Метод для отображения значений атрибутов объекта.
+ @Override
+ public String toString() {
+ return "gear: " + gear +
+ " cadence: " + cadence +
+ " speed: " + speed +
+ " name: " + name;
+ }
+} // конец класса Bicycle.
+
+// PennyFarthing - это класс, наследованный от Bicycle
+class PennyFarthing extends Bicycle {
+ // (Penny Farthings - это такие велосипеды с большим передним колесом,
+ // у них нет передач.)
+
+ public PennyFarthing(int startCadence, int startSpeed){
+ // Вызов конструктора родительского класса.
+ super(startCadence, startSpeed, 0, "PennyFarthing");
+ }
+
+ // Вы должны пометить метод, который переопределяете, при помощи @аннотации
+ // Чтобы узнать о том, что такое аннотации и зачем они нужны, почитайте:
+ // http://docs.oracle.com/javase/tutorial/java/annotations/
+ @Override
+ public void setGear(int gear) {
+ gear = 0;
+ }
+
+}
+
+// Интерфейсы
+// Синтаксис определения интерфейса:
+// <модификатор доступа> interface <имя> extends <базовый интерфейс> {
+// // Константы
+// // Определение методов.
+//}
+
+// Пример - Еда:
+public interface Edible {
+ // Любой класс, реализующий этот интерфейс, должен реализовать этот метод.
+ public void eat();
+}
+
+public interface Digestible {
+ public void digest();
+}
+
+
+// Сейчас мы можем создать класс, реализующий оба эти интерфейса.
+public class Fruit implements Edible, Digestible {
+ public void eat() {
+ //...
+ }
+
+ public void digest() {
+ //...
+ }
+}
+
+// В Java Вы можете наследоватьтолько один класс, однако можете реализовывать
+// несколько интерфейсов. Например:
+public class ExampleClass extends ExampleClassParent implements InterfaceOne, InterfaceTwo {
+ public void InterfaceOneMethod() {
+
+ }
+
+ public void InterfaceTwoMethod() {
+
+ }
+}
+
+```
+
+## Почитать еще
+
+Здесь приведены ссылки только для того, чтобы получить общее представление о Java. Гуглите, чтобы найти какие-либо конкретные примеры.
+
+**Официальные руководства Oracle**:
+
+* [Java Tutorial Trail from Sun / Oracle](http://docs.oracle.com/javase/tutorial/index.html)
+
+* [Модификаторы доступа в Java](http://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html)
+
+* [Концепции объектно-ориентированного программирования](http://docs.oracle.com/javase/tutorial/java/concepts/index.html):
+ * [Наследование](http://docs.oracle.com/javase/tutorial/java/IandI/subclasses.html)
+ * [Полиморфизм](http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html)
+ * [Абстракция](http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html)
+
+* [Исключения](http://docs.oracle.com/javase/tutorial/essential/exceptions/index.html)
+
+* [Интерфейсы](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)
+
+**Уроки онлайн**
+
+* [Learneroo.com - Изучение Java](http://www.learneroo.com)
+
+* [Codingbat.com](http://codingbat.com/java)
+
+
+**Книги**:
+
+* [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)
+
+
diff --git a/ru-ru/julia-ru.html.markdown b/ru-ru/julia-ru.html.markdown
index cd55e116..29392604 100644
--- a/ru-ru/julia-ru.html.markdown
+++ b/ru-ru/julia-ru.html.markdown
@@ -1,5 +1,5 @@
---
-language: julia
+language: Julia
contributors:
- ["Leah Hanson", "http://leahhanson.us"]
translators:
diff --git a/ru-ru/lua-ru.html.markdown b/ru-ru/lua-ru.html.markdown
new file mode 100644
index 00000000..6f515975
--- /dev/null
+++ b/ru-ru/lua-ru.html.markdown
@@ -0,0 +1,425 @@
+---
+language: lua
+filename: learnlua-ru.lua
+contributors:
+ - ["Tyler Neylon", "http://tylerneylon.com/"]
+translators:
+ - ["Max Solomonov", "https://vk.com/solomonovmaksim"]
+ - ["Max Truhonin", "https://vk.com/maximmax42"]
+ - ["Konstantin Gromyko", "https://vk.com/id0x1765d79"]
+ - ["Stanislav Gromov", "https://vk.com/id156354391"]
+lang: ru-ru
+---
+
+```lua
+-- Два дефиса начинают однострочный комментарий.
+
+--[[
+ Добавление двух квадратных скобок
+ делает комментарий многострочным.
+--]]
+--------------------------------------------------------------------------------
+-- 1. Переменные, циклы и условия.
+--------------------------------------------------------------------------------
+
+num = 42 -- Все числа имеют тип double.
+-- Не волнуйтесь, в 64-битных double 52 бита
+-- отведено под хранение целой части числа;
+-- точность не является проблемой для
+-- целочисленных значений, занимающих меньше 52 бит.
+
+s = 'walternate' -- Неизменные строки, как в Python.
+t = "Двойные кавычки также приветствуются"
+u = [[ Двойные квадратные скобки
+ начинают и заканчивают
+ многострочные значения.]]
+t = nil -- Удаляет определение переменной t; в Lua есть сборка мусора.
+
+-- Блоки обозначаются ключевыми словами, такими как do/end:
+while num < 50 do
+ num = num + 1 -- Операторов ++ и += нет.
+end
+
+-- Ветвление "если":
+if num > 40 then
+ print('больше 40')
+elseif s ~= 'walternate' then -- ~= обозначает "не равно".
+ -- Проверка равенства это ==, как в Python; работает для строк.
+ io.write('не больше 40\n') -- По умолчанию вывод в stdout.
+else
+ -- По умолчанию переменные являются глобальными.
+ thisIsGlobal = 5 -- Стиль CamelСase является общим.
+
+ -- Как сделать переменную локальной:
+ local line = io.read() -- Считывает введённую строку.
+
+ -- Для конкатенации строк используется оператор .. :
+ print('Зима пришла, ' .. line)
+end
+
+-- Неопределённые переменные возвращают nil.
+-- Этот пример не является ошибочным:
+foo = anUnknownVariable -- Теперь foo = nil.
+
+aBoolValue = false
+
+-- Только значения nil и false являются ложными; 0 и '' являются истинными!
+if not aBoolValue then print('это значение ложно') end
+
+-- Для 'or' и 'and' действует принцип "какой оператор дальше,
+-- тот и применяется". Это действует аналогично оператору a?b:c в C/js:
+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
+
+-- В основном, диапазон устроен так: начало, конец[, шаг].
+
+-- Другая конструкция цикла:
+repeat
+ print('путь будущего')
+ num = num - 1
+until num == 0
+
+--------------------------------------------------------------------------------
+-- 2. Функции.
+--------------------------------------------------------------------------------
+
+function fib(n)
+ if n < 2 then return n end
+ return fib(n - 2) + fib(n - 1)
+end
+
+-- Вложенные и анонимные функции являются нормой:
+function adder(x)
+ -- Возращаемая функция создаётся, когда вызывается функция adder,
+ -- и запоминает значение переменной x:
+ return function (y) return x + y end
+end
+a1 = adder(9)
+a2 = adder(36)
+print(a1(16)) --> 25
+print(a2(64)) --> 100
+
+-- Возвраты, вызовы функций и присвоения работают со списками,
+-- которые могут иметь разную длину.
+-- Лишние получатели принимают значение nil, а лишние значения игнорируются.
+
+x, y, z = 1, 2, 3, 4
+-- Теперь x = 1, y = 2, z = 3, а 4 просто отбрасывается.
+
+function bar(a, b, c)
+ print(a, b, c)
+ return 4, 8, 15, 16, 23, 42
+end
+
+x, y = bar('zaphod') --> выводит "zaphod nil nil"
+-- Теперь x = 4, y = 8, а значения 15..42 отбрасываются.
+
+-- Функции могут быть локальными и глобальными. Эти строки делают одно и то же:
+function f(x) return x * x end
+f = function (x) return x * x end
+
+-- Эти тоже:
+local function g(x) return math.sin(x) end
+local g = function(x) return math.sin(x) end
+-- Эквивалентно для local function g(x)..., однако ссылки на g
+-- в теле функции не будут работать, как ожидалось.
+local g; g = function (x) return math.sin(x) end
+-- 'local g' будет прототипом функции.
+
+-- Кстати, тригонометрические функции работают с радианами.
+
+-- Вызов функции с одним строковым параметром не требует круглых скобок:
+print 'hello' -- Работает без ошибок.
+
+-- Вызов функции с одним табличным параметром также
+-- не требует круглых скобок (про таблицы в след. части):
+print {} -- Тоже сработает.
+
+--------------------------------------------------------------------------------
+-- 3. Таблицы.
+--------------------------------------------------------------------------------
+
+-- Таблица = единственная составная структура данных в Lua;
+-- представляет собой ассоциативный массив.
+-- Подобно массивам в PHP или объектам в JS, они представляют собой
+-- хеш-таблицы, которые также можно использовать в качестве списков.
+
+
+-- Использование словарей:
+
+-- Литералы имеют ключ по умолчанию:
+t = {key1 = 'value1', key2 = false}
+
+-- Строковые ключи используются, как в точечной нотации в JS:
+print(t.key1) -- Печатает 'value1'.
+t.newKey = {} -- Добавляет новую пару ключ/значение.
+t.key2 = nil -- Удаляет key2 из таблицы.
+
+-- Литеральная нотация для любого значения ключа (кроме nil):
+u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'}
+print(u[6.28]) -- пишет "tau"
+
+-- Ключ соответствует значению для чисел и строк, но при
+-- использовании таблицы в качестве ключа берётся её экземпляр.
+a = u['@!#'] -- Теперь a = 'qbert'.
+b = u[{}] -- Вы могли ожидать 1729, но получится nil:
+-- b = nil, т.к. ключ не будет найден.
+-- Это произойдёт потому, что за ключ мы использовали не тот же самый объект,
+-- который был использован для сохранения оригинального значения.
+-- Поэтому строки и числа удобнее использовать в качестве ключей.
+
+-- Вызов функции с одной таблицей в качестве аргумента
+-- не требует круглых скобок:
+function h(x) print(x.key1) end
+h{key1 = 'Sonmi~451'} -- Печатает 'Sonmi~451'.
+
+for key, val in pairs(u) do -- Цикл по таблице.
+ print(key, val)
+end
+
+-- _G - это таблица со всеми глобалями.
+print(_G['_G'] == _G) -- Печатает 'true'.
+
+-- Использование таблиц, как списков / массивов:
+
+-- Список значений с неявно заданными целочисленными ключами:
+v = {'value1', 'value2', 1.21, 'gigawatts'}
+for i = 1, #v do -- #v - размер списка v.
+ print(v[i]) -- Нумерация начинается с 1 !!
+end
+
+-- Список не является отдельным типом. v - всего лишь таблица
+-- с последовательными целочисленными ключами, воспринимаемая как список.
+
+--------------------------------------------------------------------------------
+-- 3.1 Метатаблицы и метаметоды.
+--------------------------------------------------------------------------------
+
+-- Таблицу можно связать с метатаблицей, задав ей поведение, как при
+-- перегрузке операторов. Позже мы увидим, что метатаблицы поддерживают
+-- поведение, как в js-прототипах.
+f1 = {a = 1, b = 2} -- Представляет дробь a/b.
+f2 = {a = 2, b = 3}
+
+-- Это не сработает:
+-- s = f1 + f2
+
+metafraction = {}
+function metafraction.__add(f1, f2)
+ local 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 -- вызвать __add(f1, f2) на метатаблице от f1
+
+-- f1, f2 не имеют ключа для своих метатаблиц в отличии от прототипов в js,
+-- нужно получить его через getmetatable(f1). Метатаблица - обычная таблица
+-- поэтому с ключами, известными для Lua (например, __add).
+
+-- Но следущая строка будет ошибочной т.к в s нет метатаблицы:
+-- t = s + s
+-- Похожий на классы подход, приведенный ниже, поможет это исправить.
+
+-- __index перегружает в метатаблице просмотр через точку:
+defaultFavs = {animal = 'gru', food = 'donuts'}
+myFavs = {food = 'pizza'}
+setmetatable(myFavs, {__index = defaultFavs})
+eatenBy = myFavs.animal -- работает! спасибо, мета-таблица.
+
+--------------------------------------------------------------------------------
+-- При неудаче прямой табличный поиск попытается использовать
+-- значение __index в метатаблице, причём это рекурсивно.
+
+-- Значение __index также может быть функцией
+-- function(tbl, key) для настраиваемого поиска.
+
+-- Значения типа __index, __add, ... называются метаметодами.
+-- Ниже приведён полный список метаметодов.
+
+-- __add(a, b) для a + b
+-- __sub(a, b) для a - b
+-- __mul(a, b) для a * b
+-- __div(a, b) для a / b
+-- __mod(a, b) для a % b
+-- __pow(a, b) для a ^ b
+-- __unm(a) для -a
+-- __concat(a, b) для a .. b
+-- __len(a) для #a
+-- __eq(a, b) для a == b
+-- __lt(a, b) для a < b
+-- __le(a, b) для a <= b
+-- __index(a, b) <функция или таблица> для a.b
+-- __newindex(a, b, c) для a.b = c
+-- __call(a, ...) для a(...)
+
+--------------------------------------------------------------------------------
+-- 3.2 Классоподобные таблицы и наследование.
+--------------------------------------------------------------------------------
+
+-- В Lua нет поддержки классов на уровне языка,
+-- однако существуют разные способы их создания с помощью
+-- таблиц и метатаблиц.
+
+-- Ниже приведён один из таких способов.
+
+Dog = {} -- 1.
+
+function Dog:new() -- 2.
+ local newObj = {sound = 'woof'} -- 3.
+ self.__index = self -- 4.
+ return setmetatable(newObj, self) -- 5.
+end
+
+function Dog:makeSound() -- 6.
+ print('I say ' .. self.sound)
+end
+
+mrDog = Dog:new() -- 7.
+mrDog:makeSound() -- 'I say woof' -- 8.
+
+-- 1. Dog похоже на класс, но на самом деле это таблица.
+-- 2. "function tablename:fn(...)" - то же самое, что и
+-- "function tablename.fn(self, ...)", просто : добавляет первый аргумент
+-- перед собой. См. пункты 7 и 8, чтобы понять, как self получает значение.
+-- 3. newObj - это экземпляр класса Dog.
+-- 4. "self" - экземпляр класса. Зачастую self = Dog, но с помощью наследования
+-- это можно изменить. newObj получит свои функции, когда мы установим
+-- метатаблицу для newObj и __index для self на саму себя.
+-- 5. Напоминание: setmetatable возвращает первый аргумент.
+-- 6. : работает, как в пункте 2, но в этот раз мы ожидаем,
+-- что self будет экземпляром, а не классом.
+-- 7. То же самое, что и Dog.new(Dog), поэтому self = Dog в new().
+-- 8. То же самое, что mrDog.makeSound(mrDog); self = mrDog.
+--------------------------------------------------------------------------------
+
+-- Пример наследования:
+
+LoudDog = Dog:new() -- 1.
+
+function LoudDog:makeSound()
+ local s = self.sound .. ' ' -- 2.
+ print(s .. s .. s)
+end
+
+seymour = LoudDog:new() -- 3.
+seymour:makeSound() -- 'woof woof woof' -- 4.
+
+--------------------------------------------------------------------------------
+-- 1. LoudDog получит методы и переменные класса Dog.
+-- 2. В self будет ключ 'sound' из new(), см. пункт 3.
+-- 3. То же самое, что и "LoudDog.new(LoudDog)", конвертированное
+-- в "Dog.new(LoudDog)", поскольку в LoudDog нет ключа 'new',
+-- но в его метатаблице есть "__index = Dog".
+-- Результат: Метатаблицей для seymour стала LoudDog,
+-- а "LoudDog.__index = Dog". Поэтому seymour.key будет равно
+-- seymour.key, LoudDog.key, Dog.key, в зависимости от того,
+-- какая таблица будет первой с заданным ключом.
+-- 4. Ключ 'makeSound' находится в LoudDog;
+-- то же самое, что и "LoudDog.makeSound(seymour)".
+
+-- При необходимости функция new() в подклассе
+-- может быть похожа на аналог в базовом классе.
+function LoudDog:new()
+ local newObj = {}
+ -- установить newObj
+ self.__index = self
+ return setmetatable(newObj, self)
+end
+
+--------------------------------------------------------------------------------
+-- 4. Модули.
+--------------------------------------------------------------------------------
+
+
+--[[ Я закомментировал этот раздел, чтобы остальная часть скрипта осталась
+-- работоспособной.
+```
+
+```lua
+-- Предположим, файл mod.lua будет выглядеть так:
+local M = {}
+
+local function sayMyName()
+ print('Hrunkner')
+end
+
+function M.sayHello()
+ print('Привет, ')
+ sayMyName()
+end
+
+return M
+
+-- Другой файл может использовать функционал mod.lua:
+local mod = require('mod') -- Запустим файл mod.lua.
+
+-- require - стандартный способ подключения модулей.
+-- require ведёт себя так: (если не кэшировано, см. ниже)
+local mod = (function ()
+ <содержимое mod.lua>
+end)()
+-- Файл mod.lua воспринимается, как тело функции, поэтому
+-- все локальные переменные и функции внутри него не видны за его пределами.
+
+-- Это работает, так как здесь mod = M в mod.lua:
+mod.sayHello() -- Выведет "Привет, Hrunkner".
+
+-- Это будет ошибочным; sayMyName доступна только в mod.lua:
+mod.sayMyName() -- ошибка
+
+-- Значения, возвращаемые require, кэшируются,
+-- поэтому содержимое файла выполняется только 1 раз,
+-- даже если он подключается с помощью require много раз.
+
+-- Предположим, mod2.lua содержит "print('Hi!')".
+local a = require('mod2') -- Выведет "Hi!"
+local b = require('mod2') -- Ничего не выведет; a=b.
+
+-- dofile, в отличии от require, работает без кэширования:
+dofile('mod2') --> Hi!
+dofile('mod2') --> Hi! (запустится снова)
+
+-- loadfile загружает файл, но не запускает его.
+f = loadfile('mod2') -- Вызов f() запустит содержимое mod2.lua.
+
+-- loadstring - это loadfile для строк.
+g = loadstring('print(343)') -- Вернет функцию.
+g() -- Напишет 343.
+
+--]]
+
+```
+## Примечание (от автора)
+
+Мне было интересно изучить Lua, чтобы делать игры при помощи <a href="http://love2d.org/">игрового движка LÖVE</a>.
+
+Я начинал с <a href="http://nova-fusion.com/2012/08/27/lua-for-programmers-part-1/">BlackBulletIV's Lua for programmers</a>.
+Затем я прочитал официальную <a href="http://www.lua.org/pil/contents.html">Документацию по Lua</a>.
+
+Также может быть полезной <a href="http://lua-users.org/files/wiki_insecure/users/thomasl/luarefv51.pdf">Краткая справка по Lua</a> на lua-users.org.
+
+Ещё из основных тем не охвачены стандартные библиотеки:
+
+* <a href="http://lua-users.org/wiki/StringLibraryTutorial">библиотека string</a>
+* <a href="http://lua-users.org/wiki/TableLibraryTutorial">библиотека table</a>
+* <a href="http://lua-users.org/wiki/MathLibraryTutorial">библиотека math</a>
+* <a href="http://lua-users.org/wiki/IoLibraryTutorial">библиотека io</a>
+* <a href="http://lua-users.org/wiki/OsLibraryTutorial">библиотека os</a>
+
+Кстати, весь файл написан на Lua; сохраните его как learn.lua и запустите при помощи "lua learn.lua" !
+
+Изначально эта статья была написана для tylerneylon.com.
+Также она доступна как <a href="https://gist.github.com/tylerneylon/5853042">github gist</a>. Удачи с Lua!
diff --git a/ru-ru/markdown-ru.html.markdown b/ru-ru/markdown-ru.html.markdown
new file mode 100644
index 00000000..eb8e4881
--- /dev/null
+++ b/ru-ru/markdown-ru.html.markdown
@@ -0,0 +1,279 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+ - ["Pirogov Alexey", "http://twitter.com/alex_pir"]
+filename: markdown-ru.md
+lang: ru-ru
+---
+
+Язык разметки Markdown создан Джоном Грубером (англ. John Gruber)
+и Аароном Шварцем (англ. Aaron H. Swartz) в 2004 году.
+Авторы задавались целью создать максимально удобочитаемый
+и удобный в публикации облегчённый язык разметки,
+пригодный для последующего преобразования в HTML
+(а также и в другие форматы).
+
+ ```markdown
+<!-- Markdown является надмножеством HTML, поэтому любой HTML-файл является
+валидным документом Markdown, что позволяет использовать напрямую
+любые элементы HTML-разметки, такие, например, как этот комментарий.
+ Встроенные в документ HTML-элементы не затрагиваются парсером Markdown
+и попадают в итоговый HTML без изменений. Однако, следует понимать,
+что эта же особенность не позволяет использовать разметку Markdown внутри
+HTML-элементов -->
+
+<!-- Ещё одна особенность формата Markdown состоит в том, что поддерживаемые
+возможности разметки зависят от конкретной реализации парсера. В данном
+руководстве возможности, поддерживаемые лишь определёнными парсерами,
+сопровождаются соответствующими примечаниями. -->
+
+<!-- Заголовки -->
+
+<!-- HTML-элементы от <h1> до <h6> размечаются очень просто:
+текст, который должен стать заголовком, предваряется
+соответствующим количеством символов "#": -->
+# Это заголовок h1
+## Это заголовок h2
+### Это заголовок h3
+#### Это заголовок h4
+##### Это заголовок h5
+###### Это заголовок h6
+
+<!-- Markdown позволяет размечать заголовки <h1> и <h2> ещё одним способом: -->
+Это заголовок h1
+================
+
+А это заголовок h2
+------------------
+
+<!-- Простейшая стилизация текста -->
+
+<!-- Текст легко сделать полужирным и/или курсивным: -->
+
+*Этот текст будет выведен курсивом.*
+_Так же, как этот._
+
+**А этот текст будет полужирным.**
+__И этот тоже.__
+
+***Полужирный курсив.***
+**_И тут!_**
+*__И даже здесь!__*
+
+<!-- В Github Flavored Markdown (версии Markdown, использующейся в Github,
+для рендеринга Markdown-документов) текст можно сделать зачёркнутым: -->
+
+~~Зачёркнутый текст.~~
+
+<!-- Абзацами являются любые строки, следующие друг за другом.
+Разделяются же абзацы одной или несколькими пустыми строками: -->
+
+Это абзац. Всё предельно просто.
+
+А тут уже параграф №2.
+Эта строка всё ещё относится к параграфу №2!
+
+
+О, а вот это уже параграф №3!
+
+<!-- Для вставки принудительных переносов можно использовать HTML-тэг <br/>: -->
+
+Принудительный <br/> перенос!
+
+<!-- Цитаты размечаются с помощью символа ">": -->
+
+> Это цитата. В цитатах можно
+> принудительно переносить строки, вставляя ">" в начало каждой следующей строки. А можно просто оставлять достаточно длинными, и такие длинные строки будут перенесены автоматически.
+> Разницы между этими двумя подходами к переносу строк нет, коль скоро
+> каждая строка начинается с символа ">"
+
+> А ещё цитаты могут быть многоуровневыми:
+>> как здесь
+>>> и здесь :)
+> Неплохо?
+
+<!-- Списки -->
+<!-- Маркированные списки размечаются вставкой в начало каждого элемента
+одного из символов "*", "+" или "-":
+(символ должен быть одним и тем же для всех элементов) -->
+
+* Список,
+* Размеченный
+* Звёздочками
+
+либо
+
++ Список,
++ Размеченный
++ Плюсами
+
+либо
+
+- Список,
+- Размеченный
+- Дефисами
+
+<!-- В нумерованных списках каждая строка начинается
+с числа и точки вслед за ним: -->
+
+1. Первый элемент
+2. Второй элемент
+3. Третий элемент
+
+<!-- Заметьте, нумеровать элементы корректно необязательно. Достаточно указать
+любое число в начале каждого элемента и рендер пронумерует элементы сам!
+Правда, злоупотреблять этим не стоит :) -->
+
+1. Первый элемент
+1. Второй элемент
+1. Третий элемент
+<!-- (Этот список будет отрендерен так же, как и предыдущий!) -->
+
+<!-- Списки могут быть вложенными: -->
+
+1. Введение
+2. Начало работы
+3. Примеры использования
+ * Простые
+ * Сложные
+4. Заключение
+
+<!-- Блоки с исходным кодом -->
+<!-- Фрагменты исходного кода выделяются очень просто - каждая строка блока должна иметь отступ в четыре пробела либо в один символ табуляции -->
+
+ Это код,
+ причём - многострочный
+
+<!-- Дополнительные отступы в коде следует делать с помощью четырёх пробелов: -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- Иногда бывает нужно вставить фрагмент кода прямо в строку текста,
+не выделяя код в блок. Для этого фрагменты кода нужно обрамлять
+символами "`": -->
+
+Например, можно выделить имя функции `go_to()` прямо посреди текста.
+
+<!-- Github Flavored Markdown позволяет указать для блока кода синтаксис оного.
+В этом случае синтаксис внутри блока будет подсвечен. Пример: -->
+
+\`\`\`ruby <!-- Только нужно будет убрать символы "\", оставив лишь "```ruby" -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- И здесь тоже backslashes нужно убрать, т.е. оставить "```" -->
+
+<-- Обратите внимание: фрагмент, указанный выше, не предваряется отступами,
+поскольку Github сам в состоянии определить границы блока - по строкам "```" -->
+
+<!-- Горизонтальный разделитель (<hr />) -->
+<!-- Разделители добавляются вставкой строки из трёх и более
+(одинаковых) символов "*" или "-": -->
+
+***
+---
+- - - <!-- между символами допустимы пробелы -->
+****************
+
+<!-- Ссылки -->
+<!-- Одной из сильных сторон Markdown можно смело считать то,
+как просто размечаются гиперссылки. Для создания ссылки укажите
+текст ссылки, заключив его в квадратные скобки,
+и сразу после - url, заключенный в "круглые" -->
+
+[Ссылка!](http://test.com/)
+
+<!-- Также для ссылки можно указать всплывающую подсказку: -->
+
+[Ссылка!](http://test.com/ "Ссылка на Test.com")
+
+<!-- В url можно использовать относительные пути: -->
+
+[Перейти к музыке](/music/).
+
+<!-- Markdown позволяет размечать ссылку в виде сноски: -->
+
+[Здесь][link1] высможете узнать больше!
+А можно кликнуть [сюда][foobar], если очень хочется.
+
+<!-- где-нибудь внизу -->
+[link1]: http://test.com/ "Круто!"
+[foobar]: http://foobar.biz/ "Тоже хорошо!"
+
+<!-- Примечания:
+- Подсказка может быть заключена в одинарные кавычки вместо двойных,
+ а также в круглые скобки.
+- Сноска может находиться в любом месте документа и может иметь
+идентификатор (далее ID) произвольной длины,
+лишь бы это ID был уникальным. -->
+
+<!-- Также при разметке ссылок-сносок можно опустить ID,
+если текст ссылки уникален в пределах документа: -->
+
+Ссылка на [Google][].
+
+[google]: http://google.com/
+
+<!-- Правда, эта возможность не очень распространена. -->
+
+<!-- Изображения -->
+<!-- Разметка изображений очень похожа на разметку ссылок.
+Нужно всего лишь добавить "!" перед ссылкой! -->
+
+![Альтернативный текст для изображения](http://imgur.com/myimage.jpg "Подсказка")
+
+<!-- Изображения тоже могут быть оформлены, как сноски: -->
+
+![Альтернативный текст][myimage]
+
+![То же изображение ещё раз][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "подсказка"
+
+<!-- Ещё немного ссылок: -->
+<!-- Автоссылки -->
+
+Ссылка вида <http://testwebsite.com/> эквивалентна
+[http://testwebsite.com/](http://testwebsite.com/)
+
+<!-- Автоссылки для адресов электронной почты -->
+
+<foo@bar.com>
+
+<!-- Экранирование символов -->
+
+<!-- Может потребоваться вставить спецсимвол в текст "как есть",
+т.е. защитить его от обработки парсером.
+Такой символ должен быть "экранирован" с помощью обратной косой черты
+(символа "\"): -->
+
+\*текст, заключённый в звёздочки!\*
+
+<!-- Таблицы -->
+<!-- Таблицы официально поддерживаются только в Github Flavored Markdown,
+да и синтаксис имеют не слишком удобный.
+Но если очень нужно, размечайте таблицы так: -->
+
+| Столбец 1 | Столбец 2 | Столбец 3 |
+| :----------- | :----------: | -----------: |
+| Выравнивание | Выравнивание | Выравнивание |
+| влево | по центру | вправо |
+
+<!-- Или более компактно -->
+
+Колонка 1|Колонка 2|Колонка 3
+:--|:-:|--:
+Выглядит|это|страшновато...
+
+<!-- Ну вот и всё! -->
+
+```
+
+За более подробной информацией обращайтесь к [статье](http://daringfireball.net/projects/markdown/syntax) Джона Грубера о синтаксисе Markdown.
+
+Также часто бывает полезной отличная ["шпаргалка"](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) по Markdown от Adam Pritchard.
+
+Если вдруг встретите ошибки в переводе или же захотите его дополнить, делайте pull requests - авторы всегда рады обратной связи!
diff --git a/ru-ru/objective-c-ru.html.markdown b/ru-ru/objective-c-ru.html.markdown
index 72e3b9e0..3246de82 100644
--- a/ru-ru/objective-c-ru.html.markdown
+++ b/ru-ru/objective-c-ru.html.markdown
@@ -13,7 +13,7 @@ Objective-C — компилируемый объектно-ориентиров
построенный на основе языка Си и парадигм Smalltalk.
В частности, объектная модель построена в стиле Smalltalk — то есть объектам посылаются сообщения.
-```cpp
+```objective_c
// Однострочный комментарий
/*
diff --git a/ru-ru/php-ru.html.markdown b/ru-ru/php-ru.html.markdown
index edcac4dd..53b2f916 100644
--- a/ru-ru/php-ru.html.markdown
+++ b/ru-ru/php-ru.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/ru-ru/python-ru.html.markdown b/ru-ru/python-ru.html.markdown
index 204eb357..d59d3e21 100644
--- a/ru-ru/python-ru.html.markdown
+++ b/ru-ru/python-ru.html.markdown
@@ -5,25 +5,29 @@ contributors:
- ["Louie Dinh", "http://ldinh.ca"]
translators:
- ["Yury Timofeev", "http://twitter.com/gagar1n"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
filename: learnpython-ru.py
---
-Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из самых популярных
-языков. Я люблю его за его понятный и доходчивый синтаксис - это почти что исполняемый псевдокод.
+Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из
+самых популярных языков. Я люблю его за понятный и доходчивый синтаксис — это
+почти что исполняемый псевдокод.
-С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh) или louiedinh [at] [google's email service]
+С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh)
+или louiedinh [at] [почтовый сервис Google]
-Замечание: Эта статья относится к Python 2.7, но должно работать и в Python 2.x. Скоро будет версия и для Python 3!
+Замечание: Эта статья относится к Python 2.7, но должно работать и в Python 2.x.
+Скоро будет версия и для Python 3!
```python
-# Однострочные комментарии начинаются с hash-символа.
+# Однострочные комментарии начинаются с символа решётки.
""" Многострочный текст может быть
записан, используя 3 знака " и обычно используется
в качестве комментария
"""
####################################################
-## 1. Примитивные типы данных и операторов
+## 1. Примитивные типы данных и операторы
####################################################
# У вас есть числа
@@ -36,17 +40,31 @@ filename: learnpython-ru.py
35 / 5 #=> 7
# А вот деление немного сложнее. В этом случае происходит деление
-# целых чисел и результат автоматически округляется в меньшую сторону.
+# целых чисел, и результат автоматически округляется в меньшую сторону.
5 / 2 #=> 2
-# Чтобы научиться делить, сначала нужно немного узнать о дробных числах.
-2.0 # Это дробное число
+# Чтобы научиться делить, сначала нужно немного узнать о числах
+# с плавающей запятой.
+2.0 # Это число с плавающей запятой
11.0 / 4.0 #=> 2.75 Вооот... Так гораздо лучше
+# Результат целочисленного деления округляется в меньшую сторону
+# как для положительных, так и для отрицательных чисел.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # работает и для чисел с плавающей запятой
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# Остаток от деления
+7 % 3 # => 1
+
+# Возведение в степень
+2 ** 4 # => 16
+
# Приоритет операций указывается скобками
(1 + 3) * 2 #=> 8
-# Логические значения являются примитивами
+# Логические (булевы) значения являются примитивами
True
False
@@ -54,15 +72,15 @@ False
not True #=> False
not False #=> True
-# Равенство это ==
+# Равенство — это ==
1 == 1 #=> True
2 == 1 #=> False
-# Неравенство это !=
+# Неравенство — это !=
1 != 1 #=> False
2 != 1 #=> True
-# Еще немного сравнений
+# Ещё немного сравнений
1 < 10 #=> True
1 > 10 #=> False
2 <= 2 #=> True
@@ -85,9 +103,10 @@ not False #=> True
# Символ % используется для форматирования строк, например:
"%s могут быть %s" % ("строки", "интерполированы")
-# Новый метод форматирования строк - использование метода format.
+# Новый способ форматирования строк — использование метода format.
# Это предпочитаемый способ.
"{0} могут быть {1}".format("строки", "форматированы")
+
# Если вы не хотите считать, можете использовать ключевые слова.
"{name} хочет есть {food}".format(name="Боб", food="лазанью")
@@ -95,7 +114,7 @@ not False #=> True
None #=> None
# Не используйте оператор равенства '=='' для сравнения
-# объектов с None. Используйте для этого 'is'
+# объектов с None. Используйте для этого «is»
"etc" is None #=> False
None is None #=> True
@@ -113,17 +132,18 @@ None is None #=> True
## 2. Переменные и коллекции
####################################################
-# Печатать довольно просто
-print "Я Python. Приятно познакомиться!"
-
+# У Python есть функция Print, доступная в версиях 2.7 и 3,
+print("Я Python. Приятно познакомиться!")
+# ...и старый оператор print, доступный в версиях 2.x, но удалённый в версии 3.
+print "И я тоже Python!"
# Необязательно объявлять переменные перед их инициализацией.
-some_var = 5 # По соглашению используется нижний_регистр_с_подчеркиваниями
+some_var = 5 # По соглашению используется нижний_регистр_с_подчёркиваниями
some_var #=> 5
-# При попытке доступа к неинициализированной переменной,
+# При попытке доступа к неинициализированной переменной
# выбрасывается исключение.
-# См. раздел "Поток управления" для информации об исключениях.
+# См. раздел «Поток управления» для информации об исключениях.
some_other_var # Выбрасывает ошибку именования
# if может быть использован как выражение
@@ -149,24 +169,30 @@ li[0] #=> 1
# Обратимся к последнему элементу
li[-1] #=> 3
-# Попытка выйти за границы массива приведет к IndexError
-li[4] # Выдает IndexError
+# Попытка выйти за границы массива приведёт к ошибке индекса
+li[4] # Выдаёт IndexError
# Можно обращаться к диапазону, используя "кусочный синтаксис" (slice syntax)
-# (Для тех, кто любит математику, это называется замкнуто/открытый интервал.)
+# (Для тех, кто любит математику, это называется замкнуто-открытый интервал).
li[1:3] #=> [2, 4]
# Опускаем начало
li[2:] #=> [4, 3]
# Опускаем конец
li[:3] #=> [1, 2, 4]
+# Выбираем каждый второй элемент
+li[::2] # =>[1, 4]
+# Переворачиваем список
+li[::-1] # => [3, 4, 2, 1]
+# Используйте сочетания всего вышеназванного для выделения более сложных кусков
+# li[начало:конец:шаг]
# Удаляем произвольные элементы из списка оператором del
del li[2] # [1, 2, 3]
# Вы можете складывать списки
-li + other_li #=> [1, 2, 3, 4, 5, 6] - Замечание: li и other_li остаются нетронутыми
+li + other_li #=> [1, 2, 3, 4, 5, 6] — Замечание: li и other_li не изменяются
-# Конкатенировать списки можно методом extend
+# Объединять списки можно методом extend
li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
# Проверить элемент на вхождение в список можно оператором in
@@ -176,12 +202,12 @@ li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
len(li) #=> 6
-# Кортежи - это такие списки, только неизменяемые
+# Кортежи — это такие списки, только неизменяемые
tup = (1, 2, 3)
tup[0] #=> 1
-tup[0] = 3 # Выдает TypeError
+tup[0] = 3 # Выдаёт TypeError
-# Все то же самое можно делать и с кортежами
+# Всё то же самое можно делать и с кортежами
len(tup) #=> 3
tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
tup[:2] #=> (1, 2)
@@ -203,33 +229,33 @@ filled_dict = {"one": 1, "two": 2, "three": 3}
# Значения ищутся по ключу с помощью оператора []
filled_dict["one"] #=> 1
-# Можно получить все ключи в виде списка
+# Можно получить все ключи в виде списка с помощью метода keys
filled_dict.keys() #=> ["three", "two", "one"]
-# Замечание - сохранение порядка ключей в словаре не гарантируется
+# Замечание: сохранение порядка ключей в словаре не гарантируется
# Ваши результаты могут не совпадать с этими.
-# Можно получить и все значения в виде списка
+# Можно получить и все значения в виде списка, используйте метод values
filled_dict.values() #=> [3, 2, 1]
-# То же самое замечание насчет порядка ключей справедливо и здесь
+# То же самое замечание насчёт порядка ключей справедливо и здесь
# При помощи оператора in можно проверять ключи на вхождение в словарь
"one" in filled_dict #=> True
1 in filled_dict #=> False
-# Попытка получить значение по несуществующему ключу выбросит KeyError
+# Попытка получить значение по несуществующему ключу выбросит ошибку ключа
filled_dict["four"] # KeyError
# Чтобы избежать этого, используйте метод get
filled_dict.get("one") #=> 1
filled_dict.get("four") #=> None
-# Метод get также принимает аргумент default, значение которого будет
+# Метод get также принимает аргумент по умолчанию, значение которого будет
# возвращено при отсутствии указанного ключа
filled_dict.get("one", 4) #=> 1
filled_dict.get("four", 4) #=> 4
-# Метод setdefault - это безопасный способ добавить новую пару ключ-значение в словарь
+# Метод setdefault вставляет пару ключ-значение, только если такого ключа нет
filled_dict.setdefault("five", 5) #filled_dict["five"] возвращает 5
-filled_dict.setdefault("five", 6) #filled_dict["five"] по прежнему возвращает 5
+filled_dict.setdefault("five", 6) #filled_dict["five"] по-прежнему возвращает 5
# Множества содержат... ну, в общем, множества
@@ -237,8 +263,8 @@ empty_set = set()
# Инициализация множества набором значений
some_set = set([1,2,2,3,4]) # some_set теперь равно set([1, 2, 3, 4])
-# Начиная с Python 2.7, вы можете использовать {} чтобы обьявить множество
-filled_set = {1, 2, 2, 3, 4} # => {1 2 3 4}
+# Начиная с Python 2.7, вы можете использовать {}, чтобы объявить множество
+filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
# Добавление новых элементов в множество
filled_set.add(5) # filled_set равно {1, 2, 3, 4, 5}
@@ -262,33 +288,33 @@ filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
## 3. Поток управления
####################################################
-# Для начала заведем переменную
+# Для начала заведём переменную
some_var = 5
# Так выглядит выражение if. Отступы в python очень важны!
-# результат: "some_var меньше, чем 10"
+# результат: «some_var меньше, чем 10»
if some_var > 10:
- print "some_var намного больше, чем 10."
+ print("some_var намного больше, чем 10.")
elif some_var < 10: # Выражение elif необязательно.
- print "some_var меньше, чем 10."
+ print("some_var меньше, чем 10.")
else: # Это тоже необязательно.
- print "some_var равно 10."
+ print("some_var равно 10.")
"""
Циклы For проходят по спискам
Результат:
- собака это млекопитающее
- кошка это млекопитающее
- мышь это млекопитающее
+ собака — это млекопитающее
+ кошка — это млекопитающее
+ мышь — это млекопитающее
"""
for animal in ["собака", "кошка", "мышь"]:
# Можете использовать оператор % для интерполяции форматированных строк
- print "%s это млекопитающее" % animal
+ print("%s — это млекопитающее" % animal)
"""
-`range(number)` возвращает список чисел
+«range(число)» возвращает список чисел
от нуля до заданного числа
Результат:
0
@@ -297,7 +323,7 @@ for animal in ["собака", "кошка", "мышь"]:
3
"""
for i in range(4):
- print i
+ print(i)
"""
Циклы while продолжаются до тех пор, пока указанное условие не станет ложным.
@@ -309,19 +335,24 @@ for i in range(4):
"""
x = 0
while x < 4:
- print x
- x += 1 # То же самое, что x = x + 1
+ print(x)
+ x += 1 # Краткая запись для x = x + 1
-# Обрабывайте исключения блоками try/except
+# Обрабатывайте исключения блоками try/except
# Работает в Python 2.6 и выше:
try:
- # Для выбора ошибки используется raise
- raise IndexError("Это IndexError")
+ # Чтобы выбросить ошибку, используется raise
+ raise IndexError("Это ошибка индекса")
except IndexError as e:
# pass это просто отсутствие оператора. Обычно здесь происходит
- # восстановление от ошибки.
+ # восстановление после ошибки.
pass
+except (TypeError, NameError):
+ pass # Несколько исключений можно обработать вместе, если нужно.
+else: # Необязательное выражение. Должно следовать за последним блоком except
+ print("Всё хорошо!") # Выполнится, только если не было никаких исключений
+
####################################################
@@ -330,23 +361,23 @@ except IndexError as e:
# Используйте def для создания новых функций
def add(x, y):
- print "x равен %s, а y равен %s" % (x, y)
+ print("x равен %s, а y равен %s" % (x, y))
return x + y # Возвращайте результат выражением return
# Вызов функции с аргументами
-add(5, 6) #=> prints out "x равен 5, а y равен 6" и возвращает 11
+add(5, 6) #=> выводит «x равен 5, а y равен 6» и возвращает 11
-# Другой способ вызова функции с аргументами
+# Другой способ вызова функции — вызов с именованными аргументами
add(y=6, x=5) # Именованные аргументы можно указывать в любом порядке.
-# Вы можете определить функцию, принимающую неизвестное количество аргументов
+# Вы можете определить функцию, принимающую изменяемое число аргументов
def varargs(*args):
return args
varargs(1, 2, 3) #=> (1,2,3)
-# А также можете определить функцию, принимающую изменяющееся количество
+# А также можете определить функцию, принимающую изменяемое число
# именованных аргументов
def keyword_args(**kwargs):
return kwargs
@@ -356,8 +387,8 @@ keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
# Если хотите, можете использовать оба способа одновременно
def all_the_args(*args, **kwargs):
- print args
- print kwargs
+ print(args)
+ print(kwargs)
"""
all_the_args(1, 2, a=3, b=4) выводит:
(1, 2)
@@ -368,11 +399,28 @@ all_the_args(1, 2, a=3, b=4) выводит:
# Используйте символ * для передачи кортежей и ** для передачи словарей
args = (1, 2, 3, 4)
kwargs = {"a": 3, "b": 4}
-all_the_args(*args) # эквивалент foo(1, 2, 3, 4)
-all_the_args(**kwargs) # эквивалент foo(a=3, b=4)
-all_the_args(*args, **kwargs) # эквивалент foo(1, 2, 3, 4, a=3, b=4)
+all_the_args(*args) # эквивалентно foo(1, 2, 3, 4)
+all_the_args(**kwargs) # эквивалентно foo(a=3, b=4)
+all_the_args(*args, **kwargs) # эквивалентно foo(1, 2, 3, 4, a=3, b=4)
-# Python имеет функции первого класса
+# Область определения функций
+x = 5
+
+def setX(num):
+ # Локальная переменная x — это не то же самое, что глобальная переменная x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # Глобальная переменная x теперь равна 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+# В Python есть функции первого класса
def create_adder(x):
def adder(y):
return x + y
@@ -388,7 +436,7 @@ add_10(3) #=> 13
map(add_10, [1,2,3]) #=> [11, 12, 13]
filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
-# Мы можем использовать списки для удобного отображения и фильтрации
+# Для удобного отображения и фильтрации можно использовать списочные включения
[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
@@ -402,7 +450,11 @@ class Human(object):
# Атрибут класса. Он разделяется всеми экземплярами этого класса
species = "H. sapiens"
- # Обычный конструктор
+ # Обычный конструктор, вызывается при инициализации экземпляра класса
+ # Обратите внимание, что двойное подчёркивание в начале и в конце имени
+ # означает объекты и атрибуты, которые используются Python, но находятся
+ # в пространствах имён, управляемых пользователем.
+ # Не придумывайте им имена самостоятельно.
def __init__(self, name):
# Присваивание значения аргумента атрибуту класса name
self.name = name
@@ -423,17 +475,17 @@ class Human(object):
return "*grunt*"
-# Инстанцирование класса
+# Инициализация экземпляра класса
i = Human(name="Иван")
-print i.say("привет") # "Иван: привет"
+print(i.say("привет")) # Выводит: «Иван: привет»
-j = Human("Петр")
-print j.say("Привет") # "Петр: привет"
+j = Human("Пётр")
+print(j.say("Привет")) # Выводит: «Пётр: привет»
# Вызов метода класса
i.get_species() #=> "H. sapiens"
-# Присвоение разделяемому атрибуту
+# Изменение разделяемого атрибута
Human.species = "H. neanderthalensis"
i.get_species() #=> "H. neanderthalensis"
j.get_species() #=> "H. neanderthalensis"
@@ -448,12 +500,12 @@ Human.grunt() #=> "*grunt*"
# Вы можете импортировать модули
import math
-print math.sqrt(16) #=> 4
+print(math.sqrt(16)) #=> 4
# Вы можете импортировать отдельные функции модуля
from math import ceil, floor
-print ceil(3.7) #=> 4.0
-print floor(3.7) #=> 3.0
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7)) #=> 3.0
# Можете импортировать все функции модуля.
# (Хотя это и не рекомендуется)
@@ -463,7 +515,7 @@ from math import *
import math as m
math.sqrt(16) == m.sqrt(16) #=> True
-# Модули в Python это обычные файлы с кодом python. Вы
+# Модули в Python — это обычные Python-файлы. Вы
# можете писать свои модули и импортировать их. Название
# модуля совпадает с названием файла.
@@ -472,18 +524,72 @@ math.sqrt(16) == m.sqrt(16) #=> True
import math
dir(math)
+####################################################
+## 7. Дополнительно
+####################################################
+
+# Генераторы помогут выполнить ленивые вычисления
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# Генератор создаёт значения на лету.
+# Он не возвращает все значения разом, а создаёт каждое из них при каждой
+# итерации. Это значит, что значения больше 15 в double_numbers
+# обработаны не будут.
+# Обратите внимание: xrange — это генератор, который делает то же, что и range.
+# Создание списка чисел от 1 до 900000000 требует много места и времени.
+# xrange создаёт объект генератора, а не список сразу, как это делает range.
+# Если нам нужно имя переменной, совпадающее с ключевым словом Python,
+# мы используем подчёркивание в конце
+xrange_ = xrange(1, 900000000)
+
+# Будет удваивать все числа, пока результат не будет >= 30
+for i in double_numbers(xrange_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Декораторы
+# В этом примере beg оборачивает say
+# Метод beg вызовет say. Если say_please равно True,
+# он изменит возвращаемое сообщение
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, " Пожалуйста! У меня нет денег :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Вы не купите мне пива?"
+ return msg, say_please
+
+
+print(say()) # Вы не купите мне пива?
+print(say(say_please=True)) # Вы не купите мне пива? Пожалуйста! У меня нет денег :(
```
-## Хотите еще?
+## Хотите ещё?
### Бесплатные онлайн-материалы
* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
* [Dive Into Python](http://www.diveintopython.net/)
-* [The Official Docs](http://docs.python.org/2.6/)
+* [Официальная документация](http://docs.python.org/2.6/)
* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
* [Python Module of the Week](http://pymotw.com/2/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
### Платные
diff --git a/ru-ru/python3-ru.html.markdown b/ru-ru/python3-ru.html.markdown
new file mode 100644
index 00000000..637c0157
--- /dev/null
+++ b/ru-ru/python3-ru.html.markdown
@@ -0,0 +1,630 @@
+---
+language: python3
+lang: ru-ru
+contributors:
+ - ["Louie Dinh", "http://ldinh.ca"]
+ - ["Steven Basart", "http://github.com/xksteven"]
+translators:
+ - ["Andre Polykanine", "https://github.com/Oire"]
+filename: learnpython3-ru.py
+---
+
+Язык Python был создан Гвидо ван Россумом в начале 90-х. Сейчас это один из
+самых популярных языков. Я люблю его за понятный и доходчивый синтаксис — это
+почти что исполняемый псевдокод.
+
+С благодарностью жду ваших отзывов: [@louiedinh](http://twitter.com/louiedinh)
+или louiedinh [at] [почтовый сервис Google]
+
+Замечание: Эта статья относится только к Python 3.
+Если вы хотите изучить Python 2.7, обратитесь к другой статье.
+
+```python
+# Однострочные комментарии начинаются с символа решётки.
+""" Многострочный текст может быть
+ записан, используя 3 знака " и обычно используется
+ в качестве встроенной документации
+"""
+
+####################################################
+## 1. Примитивные типы данных и операторы
+####################################################
+
+# У вас есть числа
+3 #=> 3
+
+# Математика работает вполне ожидаемо
+1 + 1 #=> 2
+8 - 1 #=> 7
+10 * 2 #=> 20
+
+# Кроме деления, которое по умолчанию возвращает число с плавающей запятой
+35 / 5 # => 7.0
+
+# Результат целочисленного деления округляется в меньшую сторону
+# как для положительных, так и для отрицательных чисел.
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # работает и для чисел с плавающей запятой
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# Когда вы используете числа с плавающей запятой,
+# результатом будет также число с плавающей запятой
+3 * 2.0 # => 6.0
+
+# Остаток от деления
+7 % 3 # => 1
+
+# Возведение в степень
+2 ** 4 # => 16
+
+# Приоритет операций указывается скобками
+(1 + 3) * 2 #=> 8
+
+# Для логических (булевых) значений существует отдельный примитивный тип
+True
+False
+
+# Для отрицания используется ключевое слово not
+not True #=> False
+not False #=> True
+
+# Равенство — это ==
+1 == 1 #=> True
+2 == 1 #=> False
+
+# Неравенство — это !=
+1 != 1 #=> False
+2 != 1 #=> True
+
+# Ещё немного сравнений
+1 < 10 #=> True
+1 > 10 #=> False
+2 <= 2 #=> True
+2 >= 2 #=> True
+
+# Сравнения могут быть записаны цепочкой:
+1 < 2 < 3 #=> True
+2 < 3 < 2 #=> False
+
+# Строки определяются символом " или '
+"Это строка."
+'Это тоже строка.'
+
+# И строки тоже могут складываться! Хотя лучше этого не делайте.
+"Привет " + "мир!" #=> "Привет мир!"
+
+# Со строкой можно работать, как со списком символов
+"Это строка"[0] #=> 'Э'
+
+# Метод format используется для форматирования строк:
+"{0} могут быть {1}".format("строки", "форматированы")
+
+# Вы можете повторять аргументы форматирования, чтобы меньше печатать.
+"Ехал {0} через реку, видит {0} - в реке {1}! Сунул {0} руку в реку, {1} за руку греку цап!".format("грека", "рак")
+#=> "Ехал грека через реку, видит грека - в реке рак! Сунул грека руку в реку, рак за руку греку цап!"
+# Если вы не хотите считать, можете использовать ключевые слова.
+"{name} хочет есть {food}".format(name="Боб", food="лазанью")
+
+# Если ваш код на Python 3 нужно запускать также и под Python 2.5 и ниже,
+# вы также можете использовать старый способ форматирования:
+"%s можно %s %s способом" % ("строки", "интерполировать", "старым")
+
+# None является объектом
+None #=> None
+
+# Не используйте оператор равенства '==' для сравнения
+# объектов с None. Используйте для этого 'is'
+"etc" is None #=> False
+None is None #=> True
+
+# Оператор «is» проверяет идентичность объектов. Он не
+# очень полезен при работе с примитивными типами, но
+# зато просто незаменим при работе с объектами.
+
+# None, 0 и пустые строки/списки/словари приводятся к False.
+# Все остальные значения равны True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. Переменные и коллекции
+####################################################
+
+# У Python есть функция Print
+print("Я Python. Приятно познакомиться!")
+
+# Необязательно объявлять переменные перед их инициализацией.
+# По соглашению используется нижний_регистр_с_подчёркиваниями
+some_var = 5
+some_var #=> 5
+
+# При попытке доступа к неинициализированной переменной
+# выбрасывается исключение.
+# Об исключениях см. раздел «Поток управления и итерируемые объекты».
+some_unknown_var # Выбрасывает ошибку именования
+
+# Списки хранят последовательности
+li = []
+# Можно сразу начать с заполненным списком
+other_li = [4, 5, 6]
+
+# Объекты добавляются в конец списка методом append
+li.append(1) # [1]
+li.append(2) # [1, 2]
+li.append(4) # [1, 2, 4]
+li.append(3) # [1, 2, 4, 3]
+# И удаляются с конца методом pop
+li.pop() #=> возвращает 3 и li становится равен [1, 2, 4]
+# Положим элемент обратно
+li.append(3) # [1, 2, 4, 3].
+
+# Обращайтесь со списком, как с обычным массивом
+li[0] #=> 1
+# Обратимся к последнему элементу
+li[-1] #=> 3
+
+# Попытка выйти за границы массива приведёт к ошибке индекса
+li[4] # Выдаёт IndexError
+
+# Можно обращаться к диапазону, используя "кусочный синтаксис" (slice syntax)
+# (Для тех, кто любит математику, это называется замкнуто-открытый интервал).
+li[1:3] #=> [2, 4]
+# Опускаем начало
+li[2:] #=> [4, 3]
+# Опускаем конец
+li[:3] #=> [1, 2, 4]
+# Выбираем каждый второй элемент
+li[::2] # =>[1, 4]
+# Переворачиваем список
+li[::-1] # => [3, 4, 2, 1]
+# Используйте сочетания всего вышеназванного для выделения более сложных кусков
+# li[начало:конец:шаг]
+
+# Удаляем произвольные элементы из списка оператором del
+del li[2] # [1, 2, 3]
+
+# Вы можете складывать списки
+li + other_li #=> [1, 2, 3, 4, 5, 6] — Замечание: li и other_li не изменяются
+
+# Объединять списки можно методом extend
+li.extend(other_li) # Теперь li содержит [1, 2, 3, 4, 5, 6]
+
+# Проверить элемент на вхождение в список можно оператором in
+1 in li #=> True
+
+# Длина списка вычисляется функцией len
+len(li) #=> 6
+
+
+# Кортежи — это такие списки, только неизменяемые
+tup = (1, 2, 3)
+tup[0] #=> 1
+tup[0] = 3 # Выдаёт TypeError
+
+# Всё то же самое можно делать и с кортежами
+len(tup) #=> 3
+tup + (4, 5, 6) #=> (1, 2, 3, 4, 5, 6)
+tup[:2] #=> (1, 2)
+2 in tup #=> True
+
+# Вы можете распаковывать кортежи (или списки) в переменные
+a, b, c = (1, 2, 3) # a == 1, b == 2 и c == 3
+# Кортежи создаются по умолчанию, если опущены скобки
+d, e, f = 4, 5, 6
+# Обратите внимание, как легко поменять местами значения двух переменных
+e, d = d, e # теперь d == 5, а e == 4
+
+
+# Словари содержат ассоциативные массивы
+empty_dict = {}
+# Вот так описывается предзаполненный словарь
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# Значения ищутся по ключу с помощью оператора []
+filled_dict["one"] #=> 1
+
+# Все значения в виде списка получаются с помощью метода keys().
+# Его вызов нужно обернуть в list(), так как обратно мы получаем
+# итерируемый объект, о которых поговорим позднее.
+list(filled_dict.keys()) # => ["three", "two", "one"]
+# Замечание: сохранение порядка ключей в словаре не гарантируется
+# Ваши результаты могут не совпадать с этими.
+
+# Все значения в виде списка можно получить с помощью values().
+# И снова нам нужно обернуть вызов в list(), чтобы превратить
+# итерируемый объект в список.
+list(filled_dict.values()) # => [3, 2, 1]
+# То же самое замечание насчёт порядка ключей справедливо и здесь
+
+# При помощи оператора in можно проверять ключи на вхождение в словарь
+"one" in filled_dict #=> True
+1 in filled_dict #=> False
+
+# Попытка получить значение по несуществующему ключу выбросит ошибку ключа
+filled_dict["four"] # KeyError
+
+# Чтобы избежать этого, используйте метод get
+filled_dict.get("one") #=> 1
+filled_dict.get("four") #=> None
+# Метод get также принимает аргумент по умолчанию, значение которого будет
+# возвращено при отсутствии указанного ключа
+filled_dict.get("one", 4) #=> 1
+filled_dict.get("four", 4) #=> 4
+
+# Метод setdefault вставляет пару ключ-значение, только если такого ключа нет
+filled_dict.setdefault("five", 5) #filled_dict["five"] возвращает 5
+filled_dict.setdefault("five", 6) #filled_dict["five"] по-прежнему возвращает 5
+
+# Удаляйте ключи из словаря с помощью оператора del
+del filled_dict["one"] # Удаляет ключ «one» из словаря
+
+
+# Множества содержат... ну, в общем, множества
+empty_set = set()
+# Инициализация множества набором значений.
+# Да, оно выглядит примерно как словарь… ну извините, так уж вышло.
+filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4}
+
+# Множеству можно назначать новую переменную
+filled_set = some_set
+
+# Добавление новых элементов в множество
+filled_set.add(5) # filled_set равно {1, 2, 3, 4, 5}
+
+# Пересечение множеств: &
+other_set = {3, 4, 5, 6}
+filled_set & other_set #=> {3, 4, 5}
+
+# Объединение множеств: |
+filled_set | other_set #=> {1, 2, 3, 4, 5, 6}
+
+# Разность множеств: -
+{1,2,3,4} - {2,3,5} #=> {1, 4}
+
+# Проверка на вхождение во множество: in
+2 in filled_set #=> True
+10 in filled_set #=> False
+
+
+####################################################
+## 3. Поток управления и итерируемые объекты
+####################################################
+
+# Для начала заведём переменную
+some_var = 5
+
+# Так выглядит выражение if. Отступы в python очень важны!
+# результат: «some_var меньше, чем 10»
+if some_var > 10:
+ print("some_var намного больше, чем 10.")
+elif some_var < 10: # Выражение elif необязательно.
+ print("some_var меньше, чем 10.")
+else: # Это тоже необязательно.
+ print("some_var равно 10.")
+
+
+# Циклы For проходят по спискам. Результат:
+ # собака — это млекопитающее
+ # кошка — это млекопитающее
+ # мышь — это млекопитающее
+for animal in ["собака", "кошка", "мышь"]:
+ # Можете использовать format() для интерполяции форматированных строк
+ print("{} — это млекопитающее".format(animal))
+
+"""
+«range(число)» возвращает список чисел
+от нуля до заданного числа
+Результат:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+Циклы while продолжаются до тех пор, пока указанное условие не станет ложным.
+Результат:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # Краткая запись для x = x + 1
+
+# Обрабатывайте исключения блоками try/except
+try:
+ # Чтобы выбросить ошибку, используется raise
+ raise IndexError("Это ошибка индекса")
+except IndexError as e:
+ # pass это просто отсутствие оператора. Обычно здесь происходит
+ # восстановление после ошибки.
+ pass
+except (TypeError, NameError):
+ pass # Несколько исключений можно обработать вместе, если нужно.
+else: # Необязательное выражение. Должно следовать за последним блоком except
+ print("Всё хорошо!") # Выполнится, только если не было никаких исключений
+
+# Python предоставляет фундаментальную абстракцию,
+# которая называется итерируемым объектом (an iterable).
+# Итерируемый объект — это объект, который воспринимается как последовательность.
+# Объект, который возвратила функция range(), итерируемый.
+filled_dict = {"one": 1, "two": 2, "three": 3}
+our_iterable = filled_dict.keys()
+print(our_iterable) #=> range(1,10). Это объект, реализующий интерфейс iterable
+
+# Мы можем проходить по нему циклом.
+for i in our_iterable:
+ print(i) # Выводит one, two, three
+
+# Но мы не можем обращаться к элементу по индексу.
+our_iterable[1] # Выбрасывает ошибку типа
+
+# Итерируемый объект знает, как создавать итератор.
+our_iterator = iter(our_iterable)
+
+# Итератор может запоминать состояние при проходе по объекту.
+# Мы получаем следующий объект, вызывая функцию __next__.
+our_iterator.__next__() #=> "one"
+
+# Он сохраняет состояние при вызове __next__.
+our_iterator.__next__() #=> "two"
+our_iterator.__next__() #=> "three"
+
+# Возвратив все данные, итератор выбрасывает исключение StopIterator
+our_iterator.__next__() # Выбрасывает исключение остановки итератора
+
+# Вы можете получить сразу все элементы итератора, вызвав на нём функцию list().
+list(filled_dict.keys()) #=> Возвращает ["one", "two", "three"]
+
+
+####################################################
+## 4. Функции
+####################################################
+
+# Используйте def для создания новых функций
+def add(x, y):
+ print("x равен %s, а y равен %s" % (x, y))
+ return x + y # Возвращайте результат выражением return
+
+# Вызов функции с аргументами
+add(5, 6) #=> выводит «x равен 5, а y равен 6» и возвращает 11
+
+# Другой способ вызова функции — вызов с именованными аргументами
+add(y=6, x=5) # Именованные аргументы можно указывать в любом порядке.
+
+# Вы можете определить функцию, принимающую изменяемое число аргументов
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) #=> (1,2,3)
+
+
+# А также можете определить функцию, принимающую изменяемое число
+# именованных аргументов
+def keyword_args(**kwargs):
+ return kwargs
+
+# Вызовем эту функцию и посмотрим, что из этого получится
+keyword_args(big="foot", loch="ness") #=> {"big": "foot", "loch": "ness"}
+
+# Если хотите, можете использовать оба способа одновременно
+def all_the_args(*args, **kwargs):
+ print(args)
+ print(kwargs)
+"""
+all_the_args(1, 2, a=3, b=4) выводит:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# Вызывая функции, можете сделать наоборот!
+# Используйте символ * для передачи кортежей и ** для передачи словарей
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # эквивалентно foo(1, 2, 3, 4)
+all_the_args(**kwargs) # эквивалентно foo(a=3, b=4)
+all_the_args(*args, **kwargs) # эквивалентно foo(1, 2, 3, 4, a=3, b=4)
+
+# Область определения функций
+x = 5
+
+def setX(num):
+ # Локальная переменная x — это не то же самое, что глобальная переменная x
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # Глобальная переменная x теперь равна 6
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+# В Python функции — «объекты первого класса». Это означает, что их можно использовать наравне с любыми другими значениями
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) #=> 13
+
+# Также есть и анонимные функции
+(lambda x: x > 2)(3) #=> True
+
+# Есть встроенные функции высшего порядка
+map(add_10, [1,2,3]) #=> [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) #=> [6, 7]
+
+# Для удобного отображения и фильтрации можно использовать списочные включения
+[add_10(i) for i in [1, 2, 3]] #=> [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] #=> [6, 7]
+
+####################################################
+## 5. Классы
+####################################################
+
+# Чтобы получить класс, мы наследуемся от object.
+class Human(object):
+
+ # Атрибут класса. Он разделяется всеми экземплярами этого класса
+ species = "H. sapiens"
+
+ # Обычный конструктор, вызывается при инициализации экземпляра класса
+ # Обратите внимание, что двойное подчёркивание в начале и в конце имени
+ # означает объекты и атрибуты, которые используются Python, но находятся
+ # в пространствах имён, управляемых пользователем.
+ # Не придумывайте им имена самостоятельно.
+ def __init__(self, name):
+ # Присваивание значения аргумента атрибуту класса name
+ self.name = name
+
+ # Метод экземпляра. Все методы принимают self в качестве первого аргумента
+ def say(self, msg):
+ return "{name}: {message}".format(name=self.name, message=msg)
+
+ # Метод класса разделяется между всеми экземплярами
+ # Они вызываются с указыванием вызывающего класса в качестве первого аргумента
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # Статический метод вызывается без ссылки на класс или экземпляр
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# Инициализация экземпляра класса
+i = Human(name="Иван")
+print(i.say("привет")) # Выводит: «Иван: привет»
+
+j = Human("Пётр")
+print(j.say("Привет")) # Выводит: «Пётр: привет»
+
+# Вызов метода класса
+i.get_species() #=> "H. sapiens"
+
+# Изменение разделяемого атрибута
+Human.species = "H. neanderthalensis"
+i.get_species() #=> "H. neanderthalensis"
+j.get_species() #=> "H. neanderthalensis"
+
+# Вызов статического метода
+Human.grunt() #=> "*grunt*"
+
+
+####################################################
+## 6. Модули
+####################################################
+
+# Вы можете импортировать модули
+import math
+print(math.sqrt(16)) #=> 4
+
+# Вы можете импортировать отдельные функции модуля
+from math import ceil, floor
+print(ceil(3.7)) #=> 4.0
+print(floor(3.7)) #=> 3.0
+
+# Можете импортировать все функции модуля.
+# (Хотя это и не рекомендуется)
+from math import *
+
+# Можете сокращать имена модулей
+import math as m
+math.sqrt(16) == m.sqrt(16) #=> True
+
+# Модули в Python — это обычные Python-файлы. Вы
+# можете писать свои модули и импортировать их. Название
+# модуля совпадает с названием файла.
+
+# Вы можете узнать, какие функции и атрибуты определены
+# в модуле
+import math
+dir(math)
+
+####################################################
+## 7. Дополнительно
+####################################################
+
+# Генераторы помогут выполнить ленивые вычисления
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# Генератор создаёт значения на лету.
+# Он не возвращает все значения разом, а создаёт каждое из них при каждой
+# итерации. Это значит, что значения больше 15 в double_numbers
+# обработаны не будут.
+# Обратите внимание: range — это тоже генератор.
+# Создание списка чисел от 1 до 900000000 требует много места и времени.
+# Если нам нужно имя переменной, совпадающее с ключевым словом Python,
+# мы используем подчёркивание в конце
+range_ = range(1, 900000000)
+
+# Будет удваивать все числа, пока результат не превысит 30
+for i in double_numbers(xrange_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# Декораторы
+# В этом примере beg оборачивает say
+# Метод beg вызовет say. Если say_please равно True,
+# он изменит возвращаемое сообщение
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, " Пожалуйста! У меня нет денег :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Вы не купите мне пива?"
+ return msg, say_please
+
+
+print(say()) # Вы не купите мне пива?
+print(say(say_please=True)) # Вы не купите мне пива? Пожалуйста! У меня нет денег :(
+
+```
+
+## Хотите ещё?
+
+### Бесплатные онлайн-материалы
+
+* [Learn Python The Hard Way](http://learnpythonthehardway.org/book/)
+* [Dive Into Python](http://www.diveintopython.net/)
+* [Ideas for Python Projects](http://pythonpracticeprojects.com)
+* [Официальная документация](http://docs.python.org/3/)
+* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/)
+* [Python Module of the Week](http://pymotw.com/3/)
+* [A Crash Course in Python for Scientists](http://nbviewer.ipython.org/5920182)
+
+### Платные
+
+* [Programming Python](http://www.amazon.com/gp/product/0596158106/ref=as_li_qf_sp_asin_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0596158106&linkCode=as2&tag=homebits04-20)
+* [Dive Into Python](http://www.amazon.com/gp/product/1441413022/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1441413022&linkCode=as2&tag=homebits04-20)
+* [Python Essential Reference](http://www.amazon.com/gp/product/0672329786/ref=as_li_tf_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=0672329786&linkCode=as2&tag=homebits04-20)
+
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 962853a2..7cf5bdc7 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -9,6 +9,8 @@ contributors:
- ["Nick LaMuro", "https://github.com/NickLaMuro"]
- ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"]
- ["Ariel Krakowski", "http://www.learneroo.com"]
+ - ["Dzianis Dashkevich", "https://github.com/dskecse"]
+ - ["Levi Bostian", "https://github.com/levibostian"]
---
@@ -35,7 +37,7 @@ You shouldn't either
8 - 1 #=> 7
10 * 2 #=> 20
35 / 5 #=> 7
-2 ** 5 #=> 32
+2**5 #=> 32
# Arithmetic is just syntactic sugar
# for calling a method on an object
@@ -78,14 +80,17 @@ false.class #=> FalseClass
'I am a string'.class #=> String
"I am a string too".class #=> String
-placeholder = "use string interpolation"
+placeholder = 'use string interpolation'
"I can #{placeholder} when using double quoted strings"
#=> "I can use string interpolation when using double quoted strings"
+# Prefer single quoted strings to double quoted ones where possible
+# Double quoted strings perform additional inner calculations
+
# Combine strings, but not with numbers
-"hello " + "world" #=> "hello world"
-"hello " + 3 #=> TypeError: can't convert Fixnum into String
-"hello " + 3.to_s #=> "hello 3"
+'hello ' + 'world' #=> "hello world"
+'hello ' + 3 #=> TypeError: can't convert Fixnum into String
+'hello ' + 3.to_s #=> "hello 3"
# print to the output
puts "I'm printing!"
@@ -130,7 +135,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]
# Arrays can contain different types of items
-[1, "hello", false] #=> [1, "hello", false]
+[1, 'hello', false] #=> [1, "hello", false]
# Arrays can be indexed
# From the front
@@ -157,7 +162,7 @@ array << 6 #=> [1, 2, 3, 4, 5, 6]
# Hashes are Ruby's primary dictionary with keys/value pairs.
# Hashes are denoted with curly braces:
-hash = {'color' => 'green', 'number' => 5}
+hash = { 'color' => 'green', 'number' => 5 }
hash.keys #=> ['color', 'number']
@@ -170,7 +175,7 @@ hash['nothing here'] #=> nil
# Since Ruby 1.9, there's a special syntax when using symbols as keys:
-new_hash = { defcon: 3, action: true}
+new_hash = { defcon: 3, action: true }
new_hash.keys #=> [:defcon, :action]
@@ -180,11 +185,11 @@ new_hash.keys #=> [:defcon, :action]
# Control structures
if true
- "if statement"
+ 'if statement'
elsif false
- "else if, optional"
+ 'else if, optional'
else
- "else, also optional"
+ 'else, also optional'
end
for counter in 1..5
@@ -216,7 +221,7 @@ end
#=> iteration 5
# You can also surround blocks in curly brackets:
-(1..5).each {|counter| puts "iteration #{counter}"}
+(1..5).each { |counter| puts "iteration #{counter}" }
# The contents of data structures can also be iterated using each.
array.each do |element|
@@ -241,34 +246,45 @@ grade = 'B'
case grade
when 'A'
- puts "Way to go kiddo"
+ puts 'Way to go kiddo'
when 'B'
- puts "Better luck next time"
+ puts 'Better luck next time'
when 'C'
- puts "You can do better"
+ puts 'You can do better'
when 'D'
- puts "Scraping through"
+ puts 'Scraping through'
when 'F'
- puts "You failed!"
+ puts 'You failed!'
else
- puts "Alternative grading system, eh?"
+ puts 'Alternative grading system, eh?'
end
-
#=> "Better luck next time"
# cases can also use ranges
grade = 82
case grade
- when 90..100
- puts "Hooray!"
- when 80...90
- puts "OK job"
- else
- puts "You failed!"
+when 90..100
+ puts 'Hooray!'
+when 80...90
+ puts 'OK job'
+else
+ puts 'You failed!'
end
-
#=> "OK job"
+# exception handling:
+begin
+ # code here that might raise an exception
+ raise NoMemoryError, 'You ran out of memory.'
+rescue NoMemoryError => exception_variable
+ puts 'NoMemoryError was raised', exception_variable
+rescue RuntimeError => other_exception_variable
+ puts 'RuntimeError was raised now'
+else
+ puts 'This runs if no exceptions were thrown at all'
+ensure
+ puts 'This code always runs no matter what'
+end
# Functions
@@ -284,23 +300,23 @@ double 3 #=> 6
double double 3 #=> 12
-def sum(x,y)
+def sum(x, y)
x + y
end
# Method arguments are separated by a comma
sum 3, 4 #=> 7
-sum sum(3,4), 5 #=> 12
+sum sum(3, 4), 5 #=> 12
# yield
# All methods have an implicit, optional block parameter
# it can be called with the 'yield' keyword
def surround
- puts "{"
+ puts '{'
yield
- puts "}"
+ puts '}'
end
surround { puts 'hello world' }
@@ -311,25 +327,25 @@ surround { puts 'hello world' }
# You can pass a block to a function
-# "&" marks a reference to a passed block
+# "&" marks a reference to a passed block
def guests(&block)
- block.call "some_argument"
+ block.call 'some_argument'
end
-
+
# You can pass a list of arguments, which will be converted into an array
-# That's what splat operator ("*") is for
+# That's what splat operator ("*") is for
def guests(*array)
- array.each { |guest| puts "#{guest}" }
+ array.each { |guest| puts guest }
end
# Define a class with the class keyword
class Human
# A class variable. It is shared by all instances of this class.
- @@species = "H. sapiens"
+ @@species = 'H. sapiens'
# Basic initializer
- def initialize(name, age=0)
+ def initialize(name, age = 0)
# Assign the argument to the "name" instance variable for the instance
@name = name
# If no age given, we will fall back to the default in the arguments list.
@@ -356,20 +372,19 @@ class Human
# A class method uses self to distinguish from instance methods.
# It can only be called on the class, not an instance.
def self.say(msg)
- puts "#{msg}"
+ puts msg
end
def species
@@species
end
-
end
# Instantiate a class
-jim = Human.new("Jim Halpert")
+jim = Human.new('Jim Halpert')
-dwight = Human.new("Dwight K. Schrute")
+dwight = Human.new('Dwight K. Schrute')
# Let's call a couple of methods
jim.species #=> "H. sapiens"
@@ -380,7 +395,7 @@ dwight.species #=> "H. sapiens"
dwight.name #=> "Dwight K. Schrute"
# Call the class method
-Human.say("Hi") #=> "Hi"
+Human.say('Hi') #=> "Hi"
# Variable's scopes are defined by the way we name them.
# Variables that start with $ have global scope
@@ -399,7 +414,7 @@ defined? @@var #=> "class variable"
Var = "I'm a constant"
defined? Var #=> "constant"
-# Class also is object in ruby. So class can have instance variables.
+# Class is also an object in ruby. So class can have instance variables.
# Class variable is shared among the class and all of its descendants.
# base class
@@ -415,7 +430,7 @@ class Human
end
end
-# derived class
+# derived class
class Worker < Human
end
@@ -451,8 +466,8 @@ module ModuleExample
end
end
-# Including modules binds the methods to the object instance
-# Extending modules binds the methods to the class instance
+# Including modules binds their methods to the class instances
+# Extending modules binds their methods to the class itself
class Person
include ModuleExample
@@ -467,7 +482,7 @@ Person.new.foo # => 'foo'
Book.foo # => 'foo'
Book.new.foo # => NoMethodError: undefined method `foo'
-# Callbacks when including and extending a module are executed
+# Callbacks are executed when including and extending a module
module ConcernExample
def self.included(base)
@@ -500,9 +515,8 @@ Something.new.qux # => 'qux'
## Additional resources
-- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
+- [Learn Ruby by Example with Challenges](http://www.learneroo.com/modules/61/nodes/338) - A variant of this reference with in-browser challenges.
- [Official Documentation](http://www.ruby-doc.org/core-2.1.1/)
- [Ruby from other languages](https://www.ruby-lang.org/en/documentation/ruby-from-other-languages/)
-- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free addition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
-
-
+- [Programming Ruby](http://www.amazon.com/Programming-Ruby-1-9-2-0-Programmers/dp/1937785491/) - An older [free edition](http://ruby-doc.com/docs/ProgrammingRuby/) is available online.
+- [Ruby Style Guide](https://github.com/bbatsov/ruby-style-guide) - A community-driven Ruby coding style guide.
diff --git a/rust.html.markdown b/rust.html.markdown
index 0b9a5e58..3717a7d9 100644
--- a/rust.html.markdown
+++ b/rust.html.markdown
@@ -255,8 +255,8 @@ fn main() {
## Further reading
There’s a lot more to Rust—this is just the basics of Rust so you can
-understand the most important things. To learn more about Rust, read the
-[Rust tutorial](http://doc.rust-lang.org/tutorial.html) and check out the
+understand the most important things. To learn more about Rust, read [The Rust
+Guide](http://doc.rust-lang.org/guide.html) and check out the
[/r/rust](http://reddit.com/r/rust) subreddit. The folks on the #rust channel
on irc.mozilla.org are also always keen to help newcomers.
diff --git a/scala.html.markdown b/scala.html.markdown
index 379c092c..544abd5b 100644
--- a/scala.html.markdown
+++ b/scala.html.markdown
@@ -4,12 +4,13 @@ filename: learnscala.scala
contributors:
- ["George Petrov", "http://github.com/petrovg"]
- ["Dominic Bou-Samra", "http://dbousamra.github.com"]
+ - ["Geoff Liu", "http://geoffliu.me"]
filename: learn.scala
---
Scala - the scalable language
-```cpp
+```scala
/*
Set yourself up:
@@ -20,34 +21,50 @@ Scala - the scalable language
scala>
- This is the so called REPL. You can run commands in the REPL. Let's do just
- that:
+ This is the so called REPL (Read-Eval-Print Loop). You may type any valid
+ Scala expression into it, and the result will be printed. We will explain what
+ Scala files look like further into this tutorial, but for now, let's start
+ with some basics.
*/
-println(10) // prints the integer 10
-println("Boo!") // printlns the string Boo!
+/////////////////////////////////////////////////
+// 1. Basics
+/////////////////////////////////////////////////
+// Single line comments start with two forward slashes
-// Some basics
+/*
+ Multi line comments, as you can already see from above, look like this.
+*/
// Printing, and forcing a new line on the next print
println("Hello world!")
+println(10)
+
// Printing, without forcing a new line on next print
print("Hello world")
-// Declaring values is done using either var or val
-// val declarations are immutable, whereas var's are mutable. Immutability is
+// Declaring values is done using either var or val.
+// val declarations are immutable, whereas var's are mutable. Immutability is
// a good thing.
val x = 10 // x is now 10
x = 20 // error: reassignment to val
-var x = 10
-x = 20 // x is now 20
+var y = 10
+y = 20 // y is now 20
-// Single line comments start with two forward slashes
-/*
-Multi line comments look like this.
+/*
+ Scala is a statically typed language, yet note that in the above declarations,
+ we did not specify a type. This is due to a language feature called type
+ inference. In most cases, Scala compiler can guess what the type of a variable
+ is, so you don't have to type it every time. We can explicitly declare the
+ type of a variable like so:
*/
+val z: Int = 10
+val a: Double = 1.0
+
+// Notice automatic conversion from Int to Double, result is 10.0, not 10
+val b: Double = 10
// Boolean values
true
@@ -64,9 +81,11 @@ true == false // false
2 - 1 // 1
5 * 3 // 15
6 / 2 // 3
+6 / 4 // 1
+6.0 / 4 // 1.5
-// Evaluating a command in the REPL gives you the type and value of the result
+// Evaluating an expression in the REPL gives you the type and value of the result
1 + 7
@@ -78,153 +97,128 @@ true == false // false
This means the result of evaluating 1 + 7 is an object of type Int with a
value of 8
- 1+7 will give you the same result
-*/
-
-
-// Everything is an object, including a function. Type these in the REPL:
-
-7 // results in res30: Int = 7 (res30 is just a generated var name for the result)
-
-// The next line gives you a function that takes an Int and returns it squared
-(x:Int) => x * x
-
-// You can assign this function to an identifier, like this:
-val sq = (x:Int) => x * x
-
-/* The above says this
-
- sq: Int => Int = <function1>
-
- Which means that this time we gave an explicit name to the value - sq is a
- function that take an Int and returns Int.
-
- sq can be executed as follows:
+ Note that "res29" is a sequentially generated variable name to store the
+ results of the expressions you typed, your output may differ.
*/
-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.
-
-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:
-List(1, 2, 3) map (x => x + 10)
-
-// And the underscore symbol, can be used if there is just one argument to the
-// anonymous function. It gets bound as the variable
-List(1, 2, 3) map (_ + 10)
-
-// If the anonymous block AND the function you are applying both take one
-// argument, you can even omit the underscore
-List("Dom", "Bob", "Natalia") foreach println
-
-
-
-// Data structures
-
-val a = Array(1, 2, 3, 5, 8, 13)
-a(0)
-a(3)
-a(21) // Throws an exception
-
-val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo")
-m("fork")
-m("spoon")
-m("bottle") // Throws an exception
-
-val safeM = m.withDefaultValue("no lo se")
-safeM("bottle")
-
-val s = Set(1, 3, 7)
-s(0)
-s(1)
-
-/* Look up the documentation of map here -
- * http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map
- * and make sure you can read it
- */
-
-
-// Tuples
-
-(1, 2)
-
-(4, 3, 2)
-
-(1, 2, "three")
-
-(a, 2, "three")
-
-// Why have this?
-val divideInts = (x:Int, y:Int) => (x / y, x % y)
-
-divideInts(10,3) // The function divideInts gives you the result and the remainder
-
-// To access the elements of a tuple, use _._n where n is the 1-based index of
-// the element
-val d = divideInts(10,3)
+"Scala strings are surrounded by double quotes"
+'a' // A Scala Char
+// 'Single quote strings don't exist' <= This causes an error
-d._1
+// Strings have the usual Java methods defined on them
+"hello world".length
+"hello world".substring(2, 6)
+"hello world".replace("C", "3")
-d._2
+// They also have some extra Scala methods. See also: scala.collection.immutable.StringOps
+"hello world".take(5)
+"hello world".drop(5)
+// String interpolation: notice the prefix "s"
+val n = 45
+s"We have $n apples" // => "We have 45 apples"
+// Expressions inside interpolated strings are also possible
+val a = Array(11, 9, 6)
+s"My second daughter is ${a(0) - a(2)} years old." // => "My second daughter is 5 years old."
+s"We have double the amount of ${n / 2.0} in apples." // => "We have double the amount of 22.5 in apples."
+s"Power of 2: ${math.pow(2, 2)}" // => "Power of 2: 4"
-// Combinators
+// Formatting with interpolated strings with the prefix "f"
+f"Power of 5: ${math.pow(5, 2)}%1.0f" // "Power of 5: 25"
+f"Square root of 122: ${math.sqrt(122)}%1.4f" // "Square root of 122: 11.0454"
-s.map(sq)
+// Raw strings, ignoring special characters.
+raw"New line feed: \n. Carriage return: \r." // => "New line feed: \n. Carriage return: \r."
-val sSquared = s. map(sq)
+// Some characters need to be "escaped", e.g. a double quote inside a string:
+"They stood outside the \"Rose and Crown\"" // => "They stood outside the "Rose and Crown""
-sSquared.filter(_ < 10)
+// Triple double-quotes let strings span multiple rows and contain quotes
+val html = """<form id="daform">
+ <p>Press belo', Joe</p>
+ <input type="submit">
+ </form>"""
-sSquared.reduce (_+_)
-// The filter function takes a predicate (a function from A -> Boolean) and
-// selects all elements which satisfy the predicate
-List(1, 2, 3) filter (_ > 2) // List(3)
-List(
- Person(name = "Dom", age = 23),
- Person(name = "Bob", age = 30)
-).filter(_.age > 25) // List(Person("Bob", 30))
+/////////////////////////////////////////////////
+// 2. Functions
+/////////////////////////////////////////////////
+
+// Functions are defined like so:
+//
+// def functionName(args...): ReturnType = { body... }
+//
+// If you come from more traditional languages, notice the omission of the
+// return keyword. In Scala, the last expression in the function block is the
+// return value.
+def sumOfSquares(x: Int, y: Int): Int = {
+ val x2 = x * x
+ val y2 = y * y
+ x2 + y2
+}
+// The { } can be omitted if the function body is a single expression:
+def sumOfSquaresShort(x: Int, y: Int): Int = x * x + y * y
-// Scala a foreach method defined on certain collections that takes a type
-// returning Unit (a void method)
-aListOfNumbers foreach (x => println(x))
-aListOfNumbers foreach println
+// Syntax for calling functions is familiar:
+sumOfSquares(3, 4) // => 25
+// In most cases (with recursive functions the most notable exception), function
+// return type can be omitted, and the same type inference we saw with variables
+// will work with function return values:
+def sq(x: Int) = x * x // Compiler can guess return type is Int
+// Functions can have default parameters:
+def addWithDefault(x: Int, y: Int = 5) = x + y
+addWithDefault(1, 2) // => 3
+addWithDefault(1) // => 6
-// For comprehensions
+// Anonymous functions look like this:
+(x:Int) => x * x
-for { n <- s } yield sq(n)
+// Unlike defs, even the input type of anonymous functions can be omitted if the
+// context makes it clear. Notice the type "Int => Int" which means a function
+// that takes Int and returns Int.
+val sq: Int => Int = x => x * x
-val nSquared2 = for { n <- s } yield sq(n)
+// Anonymous functions can be called as usual:
+sq(10) // => 100
-for { n <- nSquared2 if n < 10 } yield n
+// If your anonymous function has one or two arguments, and each argument is
+// used only once, Scala gives you an even shorter way to define them. These
+// anonymous functions turn out to be extremely common, as will be obvious in
+// the data structure section.
+val addOne: Int => Int = _ + 1
+val weirdSum: (Int, Int) => Int = (_ * 2 + _ * 3)
-for { n <- s; nSquared = n * n if nSquared < 10} yield nSquared
+addOne(5) // => 6
+weirdSum(2, 4) // => 16
-/* NB Those were not for loops. The semantics of a for loop is 'repeat', whereas
- a for-comprehension defines a relationship between two sets of data. */
+// The return keyword exists in Scala, but it only returns from the inner-most
+// def that surrounds it. It has no effect on anonymous functions. For example:
+def foo(x: Int) = {
+ val anonFunc: Int => Int = { z =>
+ if (z > 5)
+ return z // This line makes z the return value of foo!
+ else
+ z + 2 // This line is the return value of anonFunc
+ }
+ anonFunc(x) // This line is the return value of foo
+}
-// Loops and iteration
+/////////////////////////////////////////////////
+// 3. Flow Control
+/////////////////////////////////////////////////
1 to 5
val r = 1 to 5
r.foreach( println )
-r foreach println
+r foreach println
// NB: Scala is quite lenient when it comes to dots and brackets - study the
// rules separately. This helps write DSLs and APIs that read like English
@@ -238,12 +232,12 @@ while (i < 10) { println("i " + i); i+=1 } // Yes, again. What happened? Why
i // Show the value of i. Note that while is a loop in the classical sense -
// it executes sequentially while changing the loop variable. while is very
- // fast, faster that Java // loops, but using the combinators and
+ // fast, faster that Java loops, but using the combinators and
// comprehensions above is easier to understand and parallelize
// A do while loop
do {
- println("x is still less than 10");
+ println("x is still less than 10");
x += 1
} while (x < 10)
@@ -255,7 +249,7 @@ def showNumbersInRange(a:Int, b:Int):Unit = {
if (a < b)
showNumbersInRange(a + 1, b)
}
-
+showNumbersInRange(1,14)
// Conditionals
@@ -270,36 +264,146 @@ if (x == 11) println ("yeah") else println("nay")
println(if (x == 10) "yeah" else "nope")
val text = if (x == 10) "yeah" else "nope"
-var i = 0
-while (i < 10) { println("i " + i); i+=1 }
+/////////////////////////////////////////////////
+// 4. Data Structures
+/////////////////////////////////////////////////
+val a = Array(1, 2, 3, 5, 8, 13)
+a(0)
+a(3)
+a(21) // Throws an exception
+
+val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo")
+m("fork")
+m("spoon")
+m("bottle") // Throws an exception
-// Object oriented features
+val safeM = m.withDefaultValue("no lo se")
+safeM("bottle")
-// Classname is Dog
-class Dog {
- //A method called bark, returning a String
- def bark: String = {
- // the body of the method
- "Woof, woof!"
- }
+val s = Set(1, 3, 7)
+s(0)
+s(1)
+
+/* Look up the documentation of map here -
+ * http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map
+ * and make sure you can read it
+ */
+
+
+// Tuples
+
+(1, 2)
+
+(4, 3, 2)
+
+(1, 2, "three")
+
+(a, 2, "three")
+
+// Why have this?
+val divideInts = (x:Int, y:Int) => (x / y, x % y)
+
+divideInts(10,3) // The function divideInts gives you the result and the remainder
+
+// To access the elements of a tuple, use _._n where n is the 1-based index of
+// the element
+val d = divideInts(10,3)
+
+d._1
+
+d._2
+
+
+/////////////////////////////////////////////////
+// 5. Object Oriented Programming
+/////////////////////////////////////////////////
+
+/*
+ Aside: Everything we've done so far in this tutorial has been simple
+ expressions (values, functions, etc). These expressions are fine to type into
+ the command-line interpreter for quick tests, but they cannot exist by
+ themselves in a Scala file. For example, you cannot have just "val x = 5" in
+ a Scala file. Instead, the only top-level constructs allowed in Scala are:
+
+ - objects
+ - classes
+ - case classes
+ - traits
+
+ And now we will explain what these are.
+*/
+
+// classes are similar to classes in other languages. Constructor arguments are
+// declared after the class name, and initialization is done in the class body.
+class Dog(br: String) {
+ // Constructor code here
+ var breed: String = br
+
+ // Define a method called bark, returning a String
+ def bark = "Woof, woof!"
+
+ // Values and methods are assumed public. "protected" and "private" keywords
+ // are also available.
+ private def sleep(hours: Int) =
+ println(s"I'm sleeping for $hours hours")
+
+ // Abstract methods are simply methods with no body. If we uncomment the next
+ // line, class Dog would need to be declared abstract
+ // abstract class Dog(...) { ... }
+ // def chaseAfter(what: String): String
}
-// Classes can contain nearly any other construct, including other classes,
-// functions, methods, objects, case classes, traits etc.
+val mydog = new Dog("greyhound")
+println(mydog.breed) // => "greyhound"
+println(mydog.bark) // => "Woof, woof!"
+
+
+// The "object" keyword creates a type AND a singleton instance of it. It is
+// common for Scala classes to have a "companion object", where the per-instance
+// behavior is captured in the classes themselves, but behavior related to all
+// instance of that class go in objects. The difference is similar to class
+// methods vs static methods in other languages. Note that objects and classes
+// can have the same name.
+object Dog {
+ def allKnownBreeds = List("pitbull", "shepherd", "retriever")
+ def createDog(breed: String) = new Dog(breed)
+}
+
+
+// Case classes are classes that have extra functionality built in. A common
+// question for Scala beginners is when to use classes and when to use case
+// classes. The line is quite fuzzy, but in general, classes tend to focus on
+// encapsulation, polymorphism, and behavior. The values in these classes tend
+// to be private, and only methods are exposed. The primary purpose of case
+// classes is to hold immutable data. They often have few methods, and the
+// methods rarely have side-effects.
+case class Person(name: String, phoneNumber: String)
+// Create a new instance. Note cases classes don't need "new"
+val george = Person("George", "1234")
+val kate = Person("Kate", "4567")
+// With case classes, you get a few perks for free, like getters:
+george.phoneNumber // => "1234"
-// Case classes
+// Per field equality (no need to override .equals)
+Person("George", "1234") == Person("Kate", "1236") // => false
-case class Person(name:String, phoneNumber:String)
+// Easy way to copy
+// otherGeorge == Person("george", "9876")
+val otherGeorge = george.copy(phoneNumber = "9876")
-Person("George", "1234") == Person("Kate", "1236")
+// And many others. Case classes also get pattern matching for free, see below.
+// Traits coming soon!
-// Pattern matching
+
+/////////////////////////////////////////////////
+// 6. Pattern Matching
+/////////////////////////////////////////////////
val me = Person("George", "1234")
@@ -338,49 +442,130 @@ matcher("52917") // => "No match on '52917'"
matcher("52752-16432-22178-47917") // => "Serial key: 52752, 16432, 22178, 47917"
-// Strings
+/////////////////////////////////////////////////
+// 7. Functional Programming
+/////////////////////////////////////////////////
-"Scala strings are surrounded by double quotes" //
-'a' // A Scala Char
-'Single quote strings don't exist' // Error
-"Strings have the usual Java methods defined on them".length
-"They also have some extra Scala methods.".reverse
+// Scala allows methods and functions to return, or take as parameters, other
+// functions or methods.
-// Seealso: scala.collection.immutable.StringOps
+List(1, 2, 3) map add10 // List(11, 12, 13) - add10 is applied to each element
-println("ABCDEF".length)
-println("ABCDEF".substring(2, 6))
-println("ABCDEF".replace("C", "3"))
+// Anonymous functions can be used instead of named functions:
+List(1, 2, 3) map (x => x + 10)
-// String interpolation
-val n = 45
-println(s"We have $n apples") // => "We have 45 apples"
+// And the underscore symbol, can be used if there is just one argument to the
+// anonymous function. It gets bound as the variable
+List(1, 2, 3) map (_ + 10)
-// Expressions inside interpolated strings are also possible
-val a = Array(11, 9, 6)
-println(s"My second daughter is ${a(0) - a(2)} years old.") // => "My second daughter is 5 years old."
-println(s"We have double the amount of ${n / 2.0} in apples.") // => "We have double the amount of 22.5 in apples."
-println(s"Power of 2: ${math.pow(2, 2)}") // => "Power of 2: 4"
+// If the anonymous block AND the function you are applying both take one
+// argument, you can even omit the underscore
+List("Dom", "Bob", "Natalia") foreach println
-// Formatting with interpolated strings (note the prefixed f)
-println(f"Power of 5: ${math.pow(5, 2)}%1.0f") // "Power of 5: 25"
-println(f"Square root of 122: ${math.sqrt(122)}%1.4f") // "Square root of 122"
-// Ignoring special characters.
-println(raw"New line feed: \n. Carriage return: \r.") // => "New line feed: \n. Carriage return: \r."
+// Combinators
-// Some characters need to be 'escaped', e.g. a double quote inside a string:
-val a = "They stood outside the \"Rose and Crown\"" // => "They stood outside the "Rose and Crown""
+s.map(sq)
-// Triple double-quotes let strings span multiple rows and contain quotes
-val html = """<form id="daform">
- <p>Press belo', Joe</p>
- | <input type="submit">
- </form>"""
+val sSquared = s. map(sq)
+sSquared.filter(_ < 10)
+sSquared.reduce (_+_)
+
+// The filter function takes a predicate (a function from A -> Boolean) and
+// selects all elements which satisfy the predicate
+List(1, 2, 3) filter (_ > 2) // List(3)
+case class Person(name:String, age:Int)
+List(
+ Person(name = "Dom", age = 23),
+ Person(name = "Bob", age = 30)
+).filter(_.age > 25) // List(Person("Bob", 30))
+
+
+// Scala a foreach method defined on certain collections that takes a type
+// returning Unit (a void method)
+val aListOfNumbers = List(1, 2, 3, 4, 10, 20, 100)
+aListOfNumbers foreach (x => println(x))
+aListOfNumbers foreach println
+
+// For comprehensions
+
+for { n <- s } yield sq(n)
+
+val nSquared2 = for { n <- s } yield sq(n)
+
+for { n <- nSquared2 if n < 10 } yield n
+
+for { n <- s; nSquared = n * n if nSquared < 10} yield nSquared
+
+/* NB Those were not for loops. The semantics of a for loop is 'repeat', whereas
+ a for-comprehension defines a relationship between two sets of data. */
+
+
+/////////////////////////////////////////////////
+// 8. Implicits
+/////////////////////////////////////////////////
+
+/* WARNING WARNING: Implicits are a set of powerful features of Scala, and
+ * therefore it is easy to abuse them. Beginners to Scala should resist the
+ * temptation to use them until they understand not only how they work, but also
+ * best practices around them. We only include this section in the tutorial
+ * because they are so commonplace in Scala libraries that it is impossible to
+ * do anything meaningful without using a library that has implicits. This is
+ * meant for you to understand and work with implicts, not declare your own.
+ */
-// Application structure and organization
+// Any value (vals, functions, objects, etc) can be declared to be implicit by
+// using the, you guessed it, "implicit" keyword. Note we are using the Dog
+// class from section 5 in these examples.
+implicit val myImplicitInt = 100
+implicit def myImplicitFunction(breed: String) = new Dog("Golden " + breed)
+
+// By itself, implicit keyword doesn't change the behavior of the value, so
+// above values can be used as usual.
+myImplicitInt + 2 // => 102
+myImplicitFunction("Pitbull").breed // => "Golden Pitbull"
+
+// The difference is that these values are now eligible to be used when another
+// piece of code "needs" an implicit value. One such situation is implicit
+// function arguments:
+def sendGreetings(toWhom: String)(implicit howMany: Int) =
+ s"Hello $toWhom, $howMany blessings to you and yours!"
+
+// If we supply a value for "howMany", the function behaves as usual
+sendGreetings("John")(1000) // => "Hello John, 1000 blessings to you and yours!"
+
+// But if we omit the implicit parameter, an implicit value of the same type is
+// used, in this case, "myImplicitInt":
+sendGreetings("Jane") // => "Hello Jane, 100 blessings to you and yours!"
+
+// Implicit function parameters enable us to simulate type classes in other
+// functional languages. It is so often used that it gets its own shorthand. The
+// following two lines mean the same thing:
+def foo[T](implicit c: C[T]) = ...
+def foo[T : C] = ...
+
+
+// Another situation in which the compiler looks for an implicit is if you have
+// obj.method(...)
+// but "obj" doesn't have "method" as a method. In this case, if there is an
+// implicit conversion of type A => B, where A is the type of obj, and B has a
+// method called "method", that conversion is applied. So having
+// myImplicitFunction above in scope, we can say:
+"Retriever".breed // => "Golden Retriever"
+"Sheperd".bark // => "Woof, woof!"
+
+// Here the String is first converted to Dog using our function above, and then
+// the appropriate method is called. This is an extremely powerful feature, but
+// again, it is not to be used lightly. In fact, when you defined the implicit
+// function above, your compiler should have given you a warning, that you
+// shouldn't do this unless you really know what you're doing.
+
+
+/////////////////////////////////////////////////
+// 9. Misc
+/////////////////////////////////////////////////
// Importing things
import scala.collection.immutable.List
diff --git a/self.html.markdown b/self.html.markdown
new file mode 100644
index 00000000..69524a84
--- /dev/null
+++ b/self.html.markdown
@@ -0,0 +1,161 @@
+---
+language: self
+contributors:
+ - ["Russell Allen", "http://github.com/russellallen"]
+filename: learnself.self
+---
+
+Self is a fast prototype based OO language which runs in its own JIT vm. Most development is done through interacting with live objects through a visual development environment called *morphic* with integrated browsers and debugger.
+
+Everything in Self is an object. All computation is done by sending messages to objects. Objects in Self can be understood as sets of key-value slots.
+
+# Constructing objects
+
+The inbuild Self parser can construct objects, including method objects.
+
+```
+"This is a comment"
+
+"A string:"
+'This is a string with \'escaped\' characters.\n'
+
+"A 30 bit integer"
+23
+
+"A 30 bit float"
+3.2
+
+"-20"
+-14r16
+
+"An object which only understands one message, 'x' which returns 20"
+(|
+ x = 20.
+|)
+
+"An object which also understands 'x:' which sets the x slot"
+(|
+ x <- 20.
+|)
+
+"An object which understands the method 'doubleX' which
+doubles the value of x and then returns the object"
+(|
+ x <- 20.
+ doubleX = (x: x * 2. self)
+|)
+
+"An object which understands all the messages
+that 'traits point' understands". The parser
+looks up 'traits point' by sending the messages
+'traits' then 'point' to a known object called
+the 'lobby'. It looks up the 'true' object by
+also sending the message 'true' to the lobby."
+(| parent* = traits point.
+ x = 7.
+ y <- 5.
+ isNice = true.
+|)
+```
+
+# Sending messages to objects
+
+Messages can either be unary, binary or keyword. Precedence is in that order. Unlike Smalltalk, the precedence of binary messages must be specified, and all keywords after the first must start with a capital letter. Messages are separeated from their destination by whitespace.
+
+```
+"unary message, sends 'printLine' to the object '23'
+which prints the string '23' to stdout and returns the receiving object (ie 23)"
+23 printLine
+
+"sends the message '+' with '7' to '23', then the message '*' with '8' to the result"
+(23 + 7) * 8
+
+"sends 'power:' to '2' with '8' returns 256"
+2 power: 8
+
+"sends 'keyOf:IfAbsent:' to 'hello' with arguments 'e' and '-1'.
+Returns 1, the index of 'e' in 'hello'."
+'hello' keyOf: 'e' IfAbsent: -1
+```
+
+# Blocks
+
+Self defines flow control like Smalltalk and Ruby by way of blocks. Blocks are delayed computations of the form:
+
+```
+[|:x. localVar| x doSomething with: localVar]
+```
+
+Examples of the use of a block:
+
+```
+"returns 'HELLO'"
+'hello' copyMutable mapBy: [|:c| c capitalize]
+
+"returns 'Nah'"
+'hello' size > 5 ifTrue: ['Yay'] False: ['Nah']
+
+"returns 'HaLLO'"
+'hello' copyMutable mapBy: [|:c|
+ c = 'e' ifTrue: [c capitalize]
+ False: ['a']]
+```
+
+Multiple expressions are separated by a period. ^ returns immediately.
+
+```
+"returns An 'E'! How icky!"
+'hello' copyMutable mapBy: [|:c. tmp <- ''|
+ tmp: c capitalize.
+ tmp = 'E' ifTrue: [^ 'An \'E\'! How icky!'].
+ c capitalize
+ ]
+```
+
+Blocks are performed by sending them the message 'value' and inherit (delegate to) their contexts:
+```
+"returns 0"
+[|x|
+ x: 15.
+ "Repeatedly sends 'value' to the first block while the result of sending 'value' to the
+ second block is the 'true' object"
+ [x > 0] whileTrue: [x: x - 1].
+ x
+] value
+```
+
+# Methods
+
+Methods are like blocks but they are not within a context but instead are stored as values of slots. Unlike Smalltalk, methods by default return their final value not 'self'.
+
+```
+"Here is an object with one assignable slot 'x' and a method 'reduceXTo: y'.
+Sending the message 'reduceXTo: 10' to this object will put
+the object '10' in the 'x' slot and return the original object"
+(|
+ x <- 50.
+ reduceXTo: y = (
+ [x > y] whileTrue: [x: x - 1].
+ self)
+|)
+.
+```
+
+# Prototypes
+
+Self has no classes. The way to get an object is to find a prototype and copy it.
+
+```
+| d |
+d: dictionary copy.
+d at: 'hello' Put: 23 + 8.
+d at: 'goodbye' Put: 'No!.
+"Prints No!"
+( d at: 'goodbye' IfAbsent: 'Yes! ) printLine.
+"Prints 31"
+( d at: 'hello' IfAbsent: -1 ) printLine.
+```
+
+# Further information
+
+The [Self handbook](http://handbook.selflanguage.org) has much more information, and nothing beats hand-on experience with Self by downloading it from the [homepage](http://www.selflanguage.org).
diff --git a/swift.html.markdown b/swift.html.markdown
index 6d98b067..0d1d2df4 100644
--- a/swift.html.markdown
+++ b/swift.html.markdown
@@ -2,130 +2,259 @@
language: swift
contributors:
- ["Grant Timmerman", "http://github.com/grant"]
+ - ["Christopher Bess", "http://github.com/cbess"]
filename: learnswift.swift
---
-Swift is a programming language for iOS and OS X development created by Apple. Designed to coexist with Objective-C and to be more resilient against erroneous code, Swift was introduced in 2014 at Apple's developer conference WWDC. It is built with the LLVM compiler included in Xcode 6 beta.
+Swift is a programming language for iOS and OS X development created by Apple. Designed to coexist with Objective-C and to be more resilient against erroneous code, Swift was introduced in 2014 at Apple's developer conference WWDC. It is built with the LLVM compiler included in Xcode 6+.
+
+The official [Swift Programming Language](https://itunes.apple.com/us/book/swift-programming-language/id881256329) book from Apple is now available via iBooks.
See also Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html), which has a complete tutorial on Swift.
-```js
+```swift
+// import a module
+import UIKit
+
//
-// Basics
+// MARK: Basics
//
+// Xcode supports landmarks to annotate your code and lists them in the jump bar
+// MARK: Section mark
+// TODO: Do something soon
+// FIXME: Fix this code
+
println("Hello, world")
+
+// variables (var) value can change after being set
+// constants (let) value can NOT be changed after being set
+
var myVariable = 42
-let myConstant = 3.1415926
+let øπΩ = "value" // unicode variable names
+let π = 3.1415926
+let convenience = "keyword" // contextual variable name
+let weak = "keyword"; let override = "another keyword" // statements can be separated by a semi-colon
+let `class` = "keyword" // backticks allow keywords to be used as variable names
let explicitDouble: Double = 70
-let label = "some text " + String(myVariable) // Casting
-let piText = "Pi = \(myConstant)" // String interpolation
-var optionalString: String? = "optional" // Can be nil
-optionalString = nil
+let intValue = 0007 // 7
+let largeIntValue = 77_000 // 77000
+let label = "some text " + String(myVariable) // Casting
+let piText = "Pi = \(π), Pi 2 = \(π * 2)" // String interpolation
+
+// Build Specific values
+// uses -D build configuration
+#if false
+ println("Not printed")
+ let buildValue = 3
+#else
+ let buildValue = 7
+#endif
+println("Build value: \(buildValue)") // Build value: 7
+
+/*
+ Optionals are a Swift language feature that allows you to store a `Some` or
+ `None` value.
+
+ Because Swift requires every property to have a value, even nil must be
+ explicitly stored as an Optional value.
+
+ Optional<T> is an enum.
+*/
+var someOptionalString: String? = "optional" // Can be nil
+// same as above, but ? is a postfix operator (syntax candy)
+var someOptionalString2: Optional<String> = "optional"
+
+if someOptionalString != nil {
+ // I am not nil
+ if someOptionalString!.hasPrefix("opt") {
+ println("has the prefix")
+ }
+
+ let empty = someOptionalString?.isEmpty
+}
+someOptionalString = nil
+
+// implicitly unwrapped optional
+var unwrappedString: String! = "Value is expected."
+// same as above, but ! is a postfix operator (more syntax candy)
+var unwrappedString2: ImplicitlyUnwrappedOptional<String> = "Value is expected."
+
+if let someOptionalStringConstant = someOptionalString {
+ // has `Some` value, non-nil
+ if !someOptionalStringConstant.hasPrefix("ok") {
+ // does not have the prefix
+ }
+}
+// Swift has support for storing a value of any type.
+// AnyObject == id
+// Unlike Objective-C `id`, AnyObject works with any value (Class, Int, struct, etc)
+var anyObjectVar: AnyObject = 7
+anyObjectVar = "Changed value to a string, not good practice, but possible."
+
+/*
+ Comment here
+
+ /*
+ Nested comments are also supported
+ */
+*/
//
-// Arrays and Dictionaries
+// MARK: Collections
//
+/*
+ Array and Dictionary types are structs. So `let` and `var` also indicate
+ that they are mutable (var) or immutable (let) when declaring these types.
+*/
+
// Array
var shoppingList = ["catfish", "water", "lemons"]
shoppingList[1] = "bottle of water"
-let emptyArray = [String]()
+let emptyArray = [String]() // let == immutable
+let emptyArray2 = Array<String>() // same as above
+var emptyMutableArray = [String]() // var == mutable
+
// Dictionary
var occupations = [
- "Malcolm": "Captain",
- "kaylee": "Mechanic"
+ "Malcolm": "Captain",
+ "kaylee": "Mechanic"
]
occupations["Jayne"] = "Public Relations"
-let emptyDictionary = [String: Float]()
+let emptyDictionary = [String: Float]() // let == immutable
+let emptyDictionary2 = Dictionary<String, Float>() // same as above
+var emptyMutableDictionary = [String: Float]() // var == mutable
//
-// Control Flow
+// MARK: Control Flow
//
// for loop (array)
let myArray = [1, 1, 2, 3, 5]
for value in myArray {
- if value == 1 {
- println("One!")
- } else {
- println("Not one!")
- }
+ if value == 1 {
+ println("One!")
+ } else {
+ println("Not one!")
+ }
}
// for loop (dictionary)
+var dict = ["one": 1, "two": 2]
for (key, value) in dict {
- println("\(key): \(value)")
+ println("\(key): \(value)")
}
// for loop (range)
-for i in -1...1 { // [-1, 0, 1]
- println(i)
+for i in -1...shoppingList.count {
+ println(i)
}
+shoppingList[1...2] = ["steak", "peacons"]
// use ..< to exclude the last number
// while loop
var i = 1
while i < 1000 {
- i *= 2
+ i *= 2
}
// do-while loop
do {
- println("hello")
+ println("hello")
} while 1 == 2
// Switch
+// Very powerful, think `if` statements with syntax candy
+// They support String, object instances, and primitives (Int, Double, etc)
let vegetable = "red pepper"
switch vegetable {
case "celery":
- let vegetableComment = "Add some raisins and make ants on a log."
+ let vegetableComment = "Add some raisins and make ants on a log."
case "cucumber", "watercress":
- let vegetableComment = "That would make a good tea sandwich."
-case let x where x.hasSuffix("pepper"):
- let vegetableComment = "Is it a spicy \(x)?"
+ let vegetableComment = "That would make a good tea sandwich."
+case let localScopeValue where localScopeValue.hasSuffix("pepper"):
+ let vegetableComment = "Is it a spicy \(localScopeValue)?"
default: // required (in order to cover all possible input)
- let vegetableComment = "Everything tastes good in soup."
+ let vegetableComment = "Everything tastes good in soup."
}
//
-// Functions
+// MARK: Functions
//
// Functions are a first-class type, meaning they can be nested
// in functions and can be passed around
-// Function
+// Function with Swift header docs (format as reStructedText)
+
+/**
+ A greet operation
+
+ - A bullet in docs
+ - Another bullet in the docs
+
+ :param: name A name
+ :param: day A day
+ :returns: A string containing the name and day value.
+*/
func greet(name: String, day: String) -> String {
- return "Hello \(name), today is \(day)."
+ return "Hello \(name), today is \(day)."
}
greet("Bob", "Tuesday")
+// similar to above except for the function parameter behaviors
+func greet2(#requiredName: String, externalParamName localParamName: String) -> String {
+ return "Hello \(requiredName), the day is \(localParamName)"
+}
+greet2(requiredName:"John", externalParamName: "Sunday")
+
// Function that returns multiple items in a tuple
func getGasPrices() -> (Double, Double, Double) {
- return (3.59, 3.69, 3.79)
+ return (3.59, 3.69, 3.79)
+}
+let pricesTuple = getGasPrices()
+let price = pricesTuple.2 // 3.79
+// Ignore Tuple (or other) values by using _ (underscore)
+let (_, price1, _) = pricesTuple // price1 == 3.69
+println(price1 == pricesTuple.1) // true
+println("Gas price: \(price)")
+
+// Variadic Args
+func setup(numbers: Int...) {
+ // its an array
+ let number = numbers[0]
+ let argCount = numbers.count
}
-
-// Args
-func setup(numbers: Int...) {}
// Passing and returning functions
func makeIncrementer() -> (Int -> Int) {
- func addOne(number: Int) -> Int {
- return 1 + number
- }
- return addOne
+ func addOne(number: Int) -> Int {
+ return 1 + number
+ }
+ return addOne
}
var increment = makeIncrementer()
increment(7)
+// pass by ref
+func swapTwoInts(inout a: Int, inout b: Int) {
+ let tempA = a
+ a = b
+ b = tempA
+}
+var someIntA = 7
+var someIntB = 3
+swapTwoInts(&someIntA, &someIntB)
+println(someIntB) // 7
+
//
-// Closures
+// MARK: Closures
//
var numbers = [1, 2, 6]
@@ -135,93 +264,256 @@ var numbers = [1, 2, 6]
// `->` separates the arguments and return type
// `in` separates the closure header from the closure body
numbers.map({
- (number: Int) -> Int in
- let result = 3 * number
- return result
- })
+ (number: Int) -> Int in
+ let result = 3 * number
+ return result
+})
// When the type is known, like above, we can do this
numbers = numbers.map({ number in 3 * number })
-//Or even this
+// Or even this
//numbers = numbers.map({ $0 * 3 })
print(numbers) // [3, 6, 18]
+// Trailing closure
+numbers = sorted(numbers) { $0 > $1 }
+
+print(numbers) // [18, 6, 3]
+
+// Super shorthand, since the < operator infers the types
+
+numbers = sorted(numbers, < )
+
+print(numbers) // [3, 6, 18]
+
+//
+// MARK: Structures
+//
+
+// Structures and classes have very similar capabilites
+struct NamesTable {
+ let names = [String]()
+
+ // Custom subscript
+ subscript(index: Int) -> String {
+ return names[index]
+ }
+}
+
+// Structures have an auto-generated (implicit) designated initializer
+let namesTable = NamesTable(names: ["Me", "Them"])
+let name = namesTable[1]
+println("Name is \(name)") // Name is Them
//
-// Classes
+// MARK: Classes
//
+// Classes, structures and its members have three levels of access control
+// They are: internal (default), public, private
+
+public class Shape {
+ public func getArea() -> Int {
+ return 0;
+ }
+}
+
// All methods and properties of a class are public.
// If you just need to store data in a
// structured object, you should use a `struct`
-// A simple class `Square` extends `Shape`
-class Square: Shape {
- var sideLength: Int = 1
-
- // Custom getter and setter property
- var perimeter: Int {
- get {
- return 4 * sideLength
+internal class Rect: Shape {
+ var sideLength: Int = 1
+
+ // Custom getter and setter property
+ private var perimeter: Int {
+ get {
+ return 4 * sideLength
+ }
+ set {
+ // `newValue` is an implicit variable available to setters
+ sideLength = newValue / 4
+ }
}
- set {
- sideLength = newValue / 4
+
+ // Lazily load a property
+ // subShape remains nil (uninitialized) until getter called
+ lazy var subShape = Rect(sideLength: 4)
+
+ // If you don't need a custom getter and setter,
+ // but still want to run code before and after getting or setting
+ // a property, you can use `willSet` and `didSet`
+ var identifier: String = "defaultID" {
+ // the `willSet` arg will be the variable name for the new value
+ willSet(someIdentifier) {
+ print(someIdentifier)
+ }
}
- }
-
- init(sideLength: Int) {
- super.init()
- self.sideLength = sideLength
- }
-
- func shrink() {
- if sideLength > 0 {
- --sideLength
+
+ init(sideLength: Int) {
+ self.sideLength = sideLength
+ // always super.init last when init custom properties
+ super.init()
+ }
+
+ func shrink() {
+ if sideLength > 0 {
+ --sideLength
+ }
+ }
+
+ override func getArea() -> Int {
+ return sideLength * sideLength
}
- }
+}
- override func getArea() -> Int {
- return sideLength * sideLength
- }
+// A simple class `Square` extends `Rect`
+class Square: Rect {
+ convenience init() {
+ self.init(sideLength: 5)
+ }
}
-var mySquare = new Square(sideLength: 5)
+
+var mySquare = Square()
print(mySquare.getArea()) // 25
mySquare.shrink()
print(mySquare.sideLength) // 4
-// If you don't need a custom getter and setter,
-// but still want to run code before and after getting or setting
-// a property, you can use `willSet` and `didSet`
+// cast instance
+let aShape = mySquare as Shape
+
+// compare instances, not the same as == which compares objects (equal to)
+if mySquare === mySquare {
+ println("Yep, it's mySquare")
+}
//
-// Enums
+// MARK: Enums
//
// Enums can optionally be of a specific type or on their own.
// They can contain methods like classes.
enum Suit {
- case Spades, Hearts, Diamonds, Clubs
- func getIcon() -> String {
- switch self {
- case .Spades: return "♤"
- case .Hearts: return "♡"
- case .Diamonds: return "♢"
- case .Clubs: return "♧"
+ case Spades, Hearts, Diamonds, Clubs
+ func getIcon() -> String {
+ switch self {
+ case .Spades: return "♤"
+ case .Hearts: return "♡"
+ case .Diamonds: return "♢"
+ case .Clubs: return "♧"
+ }
+ }
+}
+
+// Enum values allow short hand syntax, no need to type the enum type
+// when the variable is explicitly declared
+var suitValue: Suit = .Hearts
+
+// Non-Integer enums require direct raw value assignments
+enum BookName: String {
+ case John = "John"
+ case Luke = "Luke"
+}
+println("Name: \(BookName.John.rawValue)")
+
+
+//
+// MARK: Protocols
+//
+
+// `protocol`s can require that conforming types have specific
+// instance properties, instance methods, type methods,
+// operators, and subscripts.
+
+protocol ShapeGenerator {
+ var enabled: Bool { get set }
+ func buildShape() -> Shape
+}
+
+// Protocols declared with @objc allow optional functions,
+// which allow you to check for conformance
+@objc protocol TransformShape {
+ optional func reshaped()
+ optional func canReshape() -> Bool
+}
+
+class MyShape: Rect {
+ var delegate: TransformShape?
+
+ func grow() {
+ sideLength += 2
+
+ if let allow = self.delegate?.canReshape?() {
+ // test for delegate then for method
+ self.delegate?.reshaped?()
+ }
}
- }
}
//
-// Other
+// MARK: Other
//
-// `protocol`: Similar to Java interfaces.
-// `extension`s: Add extra functionality to an already created type
-// Generics: Similar to Java. Use the `where` keyword to specify the
+// `extension`s: Add extra functionality to an already existing type
+
+// Square now "conforms" to the `Printable` protocol
+extension Square: Printable {
+ var description: String {
+ return "Area: \(self.getArea()) - ID: \(self.identifier)"
+ }
+}
+
+println("Square: \(mySquare)")
+
+// You can also extend built-in types
+extension Int {
+ var customProperty: String {
+ return "This is \(self)"
+ }
+
+ func multiplyBy(num: Int) -> Int {
+ return num * self
+ }
+}
+
+println(7.customProperty) // "This is 7"
+println(14.multiplyBy(2)) // 42
+
+// Generics: Similar to Java and C#. Use the `where` keyword to specify the
// requirements of the generics.
+func findIndex<T: Equatable>(array: [T], valueToFind: T) -> Int? {
+ for (index, value) in enumerate(array) {
+ if value == valueToFind {
+ return index
+ }
+ }
+ return nil
+}
+let foundAtIndex = findIndex([1, 2, 3, 4], 3)
+println(foundAtIndex == 2) // true
+
+// Operators:
+// Custom operators can start with the characters:
+// / = - + * % < > ! & | ^ . ~
+// or
+// Unicode math, symbol, arrow, dingbat, and line/box drawing characters.
+prefix operator !!! {}
+
+// A prefix operator that triples the side length when used
+prefix func !!! (inout shape: Square) -> Square {
+ shape.sideLength *= 3
+ return shape
+}
+
+// current value
+println(mySquare.sideLength) // 4
+
+// change side length using custom !!! operator, increases size by 3
+!!!mySquare
+println(mySquare.sideLength) // 12
```
diff --git a/tmux.html.markdown b/tmux.html.markdown
new file mode 100644
index 00000000..9eb96303
--- /dev/null
+++ b/tmux.html.markdown
@@ -0,0 +1,243 @@
+---
+category: tool
+tool: tmux
+contributors:
+ - ["wzsk", "https://github.com/wzsk"]
+filename: LearnTmux.txt
+---
+
+
+<a href="http://tmux.sourceforge.net/">
+tmux</a> is a terminal multiplexer: it enables a number of terminals
+to be created, accessed, and controlled from a single screen. tmux
+may be detached from a screen and continue running in the background
+then later reattached.
+
+
+```
+
+ tmux [command] # Run a command
+ # 'tmux' with no commands will create a new session
+
+ new # Create a new session
+ -s "Session" # Create named session
+ -n "Window" # Create named Window
+ -c "/dir" # Start in target directory
+
+ attach # Attach last/available session
+ -t "#" # Attach target session
+ -d # Detach the session from other instances
+
+ ls # List open sessions
+ -a # List all open sessions
+
+ lsw # List windows
+ -a # List all windows
+ -s # List all windows in session
+
+ lsp # List panes
+ -a # List all panes
+ -s # List all panes in session
+ -t # List app panes in target
+
+ kill-window # Kill current window
+ -t "#" # Kill target window
+ -a # Kill all windows
+ -a -t "#" # Kill all windows but the target
+
+ kill-session # Kill current session
+ -t "#" # Kill target session
+ -a # Kill all sessions
+ -a -t "#" # Kill all sessions but the target
+
+
+
+## Key Bindings
+
+# The method of controlling an attached tmux session is via key
+# combinations called 'Prefix' keys.
+
+----------------------------------------------------------------------
+ (C-b) = Ctrl + b # 'Prefix' combination required to use keybinds
+
+ (M-1) = Meta + 1 -or- Alt + 1
+----------------------------------------------------------------------
+
+ ? # List all key bindings
+ : # Enter the tmux command prompt
+ r # Force redraw of the attached client
+ c # Create a new window
+
+ ! # Break the current pane out of the window.
+ % # Split the current pane into two, left and right
+ " # Split the current pane into two, top and bottom
+
+ n # Change to the next window
+ p # Change to the previous window
+ { # Swap the current pane with the previous pane
+ } # Swap the current pane with the next pane
+
+ s # Select a new session for the attached client
+ interactively
+ w # Choose the current window interactively
+ 0 to 9 # Select windows 0 to 9
+
+ d # Detach the current client
+ D # Choose a client to detach
+
+ & # Kill the current window
+ x # Kill the current pane
+
+ Up, Down # Change to the pane above, below, left, or right
+ Left, Right
+
+ M-1 to M-5 # Arrange panes:
+ # 1) even-horizontal
+ # 2) even-vertical
+ # 3) main-horizontal
+ # 4) main-vertical
+ # 5) tiled
+
+ C-Up, C-Down # Resize the current pane in steps of one cell
+ C-Left, C-Right
+
+ M-Up, M-Down # Resize the current pane in steps of five cells
+ M-Left, M-Right
+
+```
+
+
+### Configuring ~/.tmux.conf
+
+ tmux.conf can be used to set options automatically on start up, much
+like how .vimrc or init.el are used.
+
+
+```
+# Example tmux.conf
+# 2014.10
+
+
+### General
+###########################################################################
+
+# Enable UTF-8
+setw -g utf8 on
+set-option -g status-utf8 on
+
+# Scrollback/History limit
+set -g history-limit 2048
+
+# Index Start
+set -g base-index 1
+
+# Mouse
+set-option -g mouse-select-pane on
+
+# Force reload of config file
+unbind r
+bind r source-file ~/.tmux.conf
+
+
+### Keybinds
+###########################################################################
+
+# Unbind C-b as the default prefix
+unbind C-b
+
+# Set new default prefix
+set-option -g prefix `
+
+# Return to previous window when prefix is pressed twice
+bind C-a last-window
+bind ` last-window
+
+# Allow swapping C-a and ` using F11/F12
+bind F11 set-option -g prefix C-a
+bind F12 set-option -g prefix `
+
+# Keybind preference
+setw -g mode-keys vi
+set-option -g status-keys vi
+
+# Moving between panes with vim movement keys
+bind h select-pane -L
+bind j select-pane -D
+bind k select-pane -U
+bind l select-pane -R
+
+# Window Cycle/Swap
+bind e previous-window
+bind f next-window
+bind E swap-window -t -1
+bind F swap-window -t +1
+
+# Easy split pane commands
+bind = split-window -h
+bind - split-window -v
+unbind '"'
+unbind %
+
+# Activate inner-most session (when nesting tmux) to send commands
+bind a send-prefix
+
+
+### Theme
+###########################################################################
+
+# Statusbar Color Palatte
+set-option -g status-justify left
+set-option -g status-bg black
+set-option -g status-fg white
+set-option -g status-left-length 40
+set-option -g status-right-length 80
+
+# Pane Border Color Palette
+set-option -g pane-active-border-fg green
+set-option -g pane-active-border-bg black
+set-option -g pane-border-fg white
+set-option -g pane-border-bg black
+
+# Message Color Palette
+set-option -g message-fg black
+set-option -g message-bg green
+
+# Window Status Color Palette
+setw -g window-status-bg black
+setw -g window-status-current-fg green
+setw -g window-status-bell-attr default
+setw -g window-status-bell-fg red
+setw -g window-status-content-attr default
+setw -g window-status-content-fg yellow
+setw -g window-status-activity-attr default
+setw -g window-status-activity-fg yellow
+
+
+### UI
+###########################################################################
+
+# Notification
+setw -g monitor-activity on
+set -g visual-activity on
+set-option -g bell-action any
+set-option -g visual-bell off
+
+# Automatically set window titles
+set-option -g set-titles on
+set-option -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name,active (or not)
+
+# Statusbar Adjustments
+set -g status-left "#[fg=red] #H#[fg=green]:#[fg=white]#S#[fg=green] |#[default]"
+
+# Show performance counters in statusbar
+# Requires https://github.com/thewtex/tmux-mem-cpu-load/
+set -g status-interval 4
+set -g status-right "#[fg=green] | #[fg=white]#(tmux-mem-cpu-load)#[fg=green] | #[fg=cyan]%H:%M #[default]"
+
+```
+
+<a href="http://tmux.sourceforge.net/">Tmux | Home</a><br>
+<a href="http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux">Tmux Manual page</a><br>
+<a href="http://wiki.gentoo.org/wiki/Tmux">Gentoo Wiki</a><br>
+<a href="https://wiki.archlinux.org/index.php/Tmux">Archlinux Wiki</a><br>
+<a href="https://stackoverflow.com/questions/11558907/is-there-a-better-way-to-display-cpu-usage-in-tmux">Display CPU/MEM % in statusbar</a><br>
diff --git a/tr-tr/objective-c-tr.html.markdown b/tr-tr/objective-c-tr.html.markdown
index 854d70f6..f27cbf08 100644
--- a/tr-tr/objective-c-tr.html.markdown
+++ b/tr-tr/objective-c-tr.html.markdown
@@ -14,7 +14,7 @@ kendi çatıları olan Cocoa ve Cocoa Touch için kullanılan bir programlama di
Genel açamlı, object-oriented bir yapıya sahip programlama dilidir. C
programlama diline Smalltalk stilinde mesajlaşma ekler.
-```cpp
+```objective_c
// Tek satır yorum // işaretleri ile başlar
/*
diff --git a/tr-tr/php-tr.html.markdown b/tr-tr/php-tr.html.markdown
index 3db437cf..5258d785 100644
--- a/tr-tr/php-tr.html.markdown
+++ b/tr-tr/php-tr.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
filename: learnphp-tr.php
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
diff --git a/typescript.html.markdown b/typescript.html.markdown
index 8173aac8..9f04169a 100644
--- a/typescript.html.markdown
+++ b/typescript.html.markdown
@@ -13,7 +13,7 @@ This article will focus only on TypeScript extra syntax, as oposed to [JavaScrip
To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript.
-```ts
+```js
//There are 3 basic types in TypeScript
var isDone: boolean = false;
var lines: number = 42;
diff --git a/vi-vn/git-vi.html.markdown b/vi-vn/git-vi.html.markdown
index bdb88204..1bcc94a0 100644
--- a/vi-vn/git-vi.html.markdown
+++ b/vi-vn/git-vi.html.markdown
@@ -2,14 +2,15 @@
category: tool
tool: git
contributors:
- - ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Vinh Nguyen", "https://twitter.com/vinhnx"]
filename: LearnGit-vi.txt
lang: vi-vn
---
Git là một hệ quản lý mã nguồn và phiên bản phân tán (distributed version control and source code management system).
-Nó làm được điều này là do một loạt các snapshot từ đề án của bạn, and nó hoạt động
+Nó làm được điều này là do một loạt các snapshot từ đề án của bạn, và nó hoạt động
với các snapshot đó để cung cấp cho bạn với chức năng đến phiên bản và
quản lý mã nguồn của bạn.
@@ -19,7 +20,7 @@ quản lý mã nguồn của bạn.
Version Control là một hệ thống ghi lại những thay đổi ở một tập tin, hay một nhóm các tập tin, theo thời gian.
-### Centralized Versioning VS Distributed Versioning
+### So sánh giữa Centralized Versioning và Distributed Versioning
* Quản lý phiên bản tập trung (Centralized Versioning) tập trung vào việc đồng bộ hóa, theo dõi, và lưu trữ tập tin.
* Quản lý phiên bản phân tán (Distributed Versioning) tập trung vào việc chia sẻ các thay đổi. Mỗi sự thay đổi có một mã định dạng (id) duy nhất.
@@ -75,7 +76,7 @@ con trỏ này sẽ cập nhật tự động và trỏ đến commit mới nh
### HEAD và head (thành phần của thư mục .git)
-HEAD là một con trỏ đến nhánh hiện tại. Một repo chỉ có một HEAD *đang hoạt động*.
+HEAD là một con trỏ đến branch hiện tại. Một repo chỉ có một HEAD *đang hoạt động*.
head là một con trỏ đến bất kỳ commit nào. Một repo có thể có nhiều head.
### Các Tài Nguyên Mang Tính Khái Niệm
@@ -165,29 +166,29 @@ $ git add ./*.java
### branch
-Quản lý nhánh. Bạn có thể xem, sửa, tạo, xóa các nhánh bằng cách dùng lệnh này.
+Quản lý nhánh (branch). Bạn có thể xem, sửa, tạo, xóa các nhánh bằng cách dùng lệnh này.
```bash
-# liệt kê các nhanh đang có và ở remote
+# liệt kê các branch đang có và ở remote
$ git branch -a
-# tạo nhánh mới
+# tạo branch mới
$ git branch myNewBranch
-# xóa một nhánh
+# xóa một branch
$ git branch -d myBranch
-# đặt tên lại một nhánh
+# đặt tên lại một branch
# git branch -m <oldname> <newname>
$ git branch -m myBranchName myNewBranchName
-# chỉnh sủa diễn giải của một nhánh
+# chỉnh sửa diễn giải của một branch
$ git branch myBranchName --edit-description
```
### checkout
-Cập nhật tất cả các file torng tree hiện tại để cho trùng khớp với phiên bản của index, hoặc tree cụ thể.
+Cập nhật tất cả các file trong tree hiện tại để cho trùng khớp với phiên bản của index, hoặc tree cụ thể.
```bash
# Checkout (chuyển) một repo - mặc định là nhánh master
@@ -201,8 +202,8 @@ $ git checkout -b newBranch
### clone
Nhân bản, hoặc sao chép, một repo hiện có thành một thư mục mới. Nó cũng thêm
-các nhánh có remote-tracking cho mỗi nhánh trong một repo được nhân bản, mà
-cho phép bạn push đến một nhánh remote.
+các branch có remote-tracking cho mỗi branch trong một repo được nhân bản, mà
+cho phép bạn push đến một remote branch.
```bash
# Nhân bản learnxinyminutes-docs
@@ -211,7 +212,7 @@ $ git clone https://github.com/adambard/learnxinyminutes-docs.git
### commit
-Lưu trữ nội dung hiện tại của index trong một "commit" mới. Điều này cho phép tạo ra thay đổi và một lời nhắn (ghi chú) tạo ra bởi người dùng.
+Lưu trữ nội dung hiện tại của index trong một "commit" mới. Điều này cho phép tạo ra thay đổi và một ghi chú tạo ra bởi người dùng.
```bash
# commit với một ghi chú
@@ -279,7 +280,7 @@ $ git log --merges
"Trộn" các thay đổi từ commit bên ngoài vào trong nhánh hiện tại.
```bash
-# Merge nhánh cụ thể vào nhánh hiện tại.
+# Merge branch cụ thể vào branch hiện tại.
$ git merge branchName
# Luôn khởi tạo một merge commit khi trộn (merge)
@@ -304,30 +305,35 @@ $ git mv -f myFile existingFile
### pull
-Kéo (tải) về từ một repo và merge nó vào nhánh khác.
+Pull về từ một repo và merge nó vào branch khác.
```bash
-# Cập nhật repo cục bộ của bạn, bằng cách merge các thay đổi mới
+# Cập nhật repo local của bạn, bằng cách merge các thay đổi mới
# từ remote "origin" và nhánh "master".
# git pull <remote> <branch>
# git pull => hoàn toàn mặc định như => git pull origin master
$ git pull origin master
-# Merge các thay đổi từ nhánh remote và rebase
-# các commit nhánh lên trên thư mục cục bộ, như: "git pull <remote> <branch>, git rebase <branch>"
+# Merge các thay đổi từ remote branch và rebase
+# các commit trong branch lên trên local repo, như sau: "git pull <remote> <branch>, git rebase <branch>"
$ git pull origin master --rebase
```
### push
-Đẩy và trộn (mege) các tay đổi từ một nhánh đế một remote & nhánh.
-
-```bash
-# Push và merge các thay đổi từ repo cục bộ đến một
-# remote tên là "origin" và nhánh "master".
-# git push <remote> <branch>
-# git push => hoàn toàn defaults to => git push origin master
-$ git push origin master
+push và merge các thay đổi từ một branch đến một remote & branch.
+
+```bash
+# Push và merge các thay đổi từ một repo local đến một
+# remote có tên là "origin" và nhánh "master".
+# git push <remote> <branch>
+# git push => mặc định ẩn đến => git push origin master
+$ git push origin master
+
+# Để liên kết đến một branch local với một branch remote, thêm vào cờ -u:
+$ git push -u origin master
+# Từ lúc này, bất cứ khi nào bạn muốn push từ cùng một nhánh local đó, sử dụng lối tắt:
+$ git push
```
### rebase (thận trọng)
@@ -390,4 +396,8 @@ $ git rm /pather/to/the/file/HelloWorld.c
* [SalesForce Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)
-* [GitGuys](http://www.gitguys.com/)
+* [GitGuys](http://www.gitguys.com/)
+
+* [Git - the simple guide](http://rogerdudler.github.io/git-guide/index.html)
+
+
diff --git a/vi-vn/objective-c-vi.html.markdown b/vi-vn/objective-c-vi.html.markdown
index 6d19ca02..c97bb560 100644
--- a/vi-vn/objective-c-vi.html.markdown
+++ b/vi-vn/objective-c-vi.html.markdown
@@ -12,7 +12,7 @@ filename: LearnObjectiveC-vi.m
Objective-C là ngôn ngữ lập trình chính được sử dụng bởi Apple cho các hệ điều hành OS X, iOS và các framework tương ứng của họ, Cocoa và Cocoa Touch.
Nó là một ngôn ngữ lập trình mục đích tổng quát, hướng đối tượng có bổ sung thêm kiểu truyền thông điệp giống Smalltalk vào ngôn ngữ lập trình C.
-```cpp
+```objective_c
// Chú thích dòng đơn bắt đầu với //
/*
diff --git a/zh-cn/c-cn.html.markdown b/zh-cn/c-cn.html.markdown
index 223f6e35..1e10416e 100644
--- a/zh-cn/c-cn.html.markdown
+++ b/zh-cn/c-cn.html.markdown
@@ -566,7 +566,7 @@ typedef void (*my_fnp_type)(char *);
'\'' // 单引号
'\"' // 双引号
'\xhh' // 十六进制数字. 例子: '\xb' = vertical tab
-'\ooo' // 十进制数字. 例子: '\013' = vertical tab
+'\ooo' // 八进制数字. 例子: '\013' = vertical tab
// 打印格式:
"%d" // 整数
@@ -579,7 +579,7 @@ typedef void (*my_fnp_type)(char *);
"%c" // 字母
"%p" // 指针
"%x" // 十六进制
-"%o" // 十进制
+"%o" // 八进制
"%%" // 打印 %
///////////////////////////////////////
diff --git a/zh-cn/common-lisp-cn.html.markdown b/zh-cn/common-lisp-cn.html.markdown
index c4dc3274..b82829a9 100644
--- a/zh-cn/common-lisp-cn.html.markdown
+++ b/zh-cn/common-lisp-cn.html.markdown
@@ -17,7 +17,7 @@ ANSI Common Lisp 是一个广泛通用于各个工业领域的、支持多种范
另外还有一本热门的近期出版的
[Land of Lisp](http://landoflisp.com/).
-```scheme
+```common-lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 0. 语法
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/zh-cn/haskell-cn.html.markdown b/zh-cn/haskell-cn.html.markdown
index 8d51f144..cb7ccdee 100644
--- a/zh-cn/haskell-cn.html.markdown
+++ b/zh-cn/haskell-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: haskell
+language: Haskell
filename: learn-haskell-zh.hs
contributors:
- ["Adit Bhargava", "http://adit.io"]
diff --git a/zh-cn/julia-cn.html.markdown b/zh-cn/julia-cn.html.markdown
index 7afc9043..1f91d52c 100644
--- a/zh-cn/julia-cn.html.markdown
+++ b/zh-cn/julia-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: julia
+language: Julia
filename: learn-julia-zh.jl
contributors:
- ["Jichao Ouyang", "http://oyanglul.us"]
diff --git a/zh-cn/livescript-cn.html.markdown b/zh-cn/livescript-cn.html.markdown
new file mode 100644
index 00000000..fea00bc1
--- /dev/null
+++ b/zh-cn/livescript-cn.html.markdown
@@ -0,0 +1,322 @@
+---
+language: LiveScript
+filename: learnLivescript.ls
+contributors:
+ - ["Christina Whyte", "http://github.com/kurisuwhyte/"]
+translators:
+ - ["ShengDa Lyu", "http://github.com/SDLyu/"]
+lang: zh-cn
+---
+
+LiveScript 是一种具有函数式特性且编译成 JavaScript 的语言,能对应 JavaScript 的基本语法。
+还有些额外的特性如:柯里化,组合函数,模式匹配,还有借镜于 Haskell,F# 和 Scala 的许多特点。
+
+LiveScript 诞生于 [Coco][],而 Coco 诞生于 [CoffeeScript][]。
+LiveScript 目前已释出稳定版本,开发中的新版本将会加入更多特性。
+
+[Coco]: http://satyr.github.io/coco/
+[CoffeeScript]: http://coffeescript.org/
+
+非常期待您的反馈,你可以通过
+[@kurisuwhyte](https://twitter.com/kurisuwhyte) 与我连系 :)
+
+
+```coffeescript
+# 与 CoffeeScript 一样,LiveScript 使用 # 单行注解。
+
+/*
+ 多行注解与 C 相同。使用注解可以避免被当成 JavaScript 输出。
+*/
+```
+```coffeescript
+# 语法的部份,LiveScript 使用缩进取代 {} 来定义区块,
+# 使用空白取代 () 来执行函数。
+
+
+########################################################################
+## 1. 值类型
+########################################################################
+
+# `void` 取代 `undefined` 表示未定义的值
+void # 与 `undefined` 等价但更安全(不会被覆写)
+
+# 空值则表示成 Null。
+null
+
+
+# 最基本的值类型数据是罗辑类型:
+true
+false
+
+# 罗辑类型的一些别名,等价于前者:
+on; off
+yes; no
+
+
+# 数字与 JS 一样,使用倍精度浮点数表示。
+10
+0.4 # 开头的 0 是必要的
+
+
+# 可以使用底线及单位后缀提高可读性,编译器会自动略过底线及单位后缀。
+12_344km
+
+
+# 字串与 JS 一样,是一种不可变的字元序列:
+"Christina" # 单引号也可以!
+"""Multi-line
+ strings
+ are
+ okay
+ too."""
+
+# 在前面加上 \ 符号也可以表示字串:
+\keyword # => 'keyword'
+
+
+# 数组是值的有序集合。
+fruits =
+ * \apple
+ * \orange
+ * \pear
+
+# 可以用 [] 简洁地表示数组:
+fruits = [ \apple, \orange, \pear ]
+
+
+# 你可以更方便地建立字串数组,并使用空白区隔元素。
+fruits = <[ apple orange pear ]>
+
+# 以 0 为起始值的数组下标获取元素:
+fruits[0] # => "apple"
+
+
+# 对象是无序键值对集合(更多给节将在下面章节讨论)。
+person =
+ name: "Christina"
+ likes:
+ * "kittens"
+ * "and other cute stuff"
+
+# 你也可以用更简洁的方式表示对象:
+person = {name: "Christina", likes: ["kittens", "and other cute stuff"]}
+
+# 可以通过键值获取值:
+person.name # => "Christina"
+person["name"] # => "Christina"
+
+
+# 正则表达式的使用跟 JavaScript 一样:
+trailing-space = /\s$/ # dashed-words 变成 dashedWords
+
+# 你也可以用多行描述表达式!(注解和空白会被忽略)
+funRE = //
+ function\s+(.+) # name
+ \s* \((.*)\) \s* # arguments
+ { (.*) } # body
+ //
+
+
+########################################################################
+## 2. 基本运算
+########################################################################
+
+# 数值操作符与 JavaScript 一样:
+1 + 2 # => 3
+2 - 1 # => 1
+2 * 3 # => 6
+4 / 2 # => 2
+3 % 2 # => 1
+
+
+# 比较操作符大部份也一样,除了 `==` 等价于 JS 中的 `===`,
+# JS 中的 `==` 在 LiveScript 里等价于 `~=`,
+# `===` 能进行对象、数组和严格比较。
+2 == 2 # => true
+2 == "2" # => false
+2 ~= "2" # => true
+2 === "2" # => false
+
+[1,2,3] == [1,2,3] # => false
+[1,2,3] === [1,2,3] # => true
+
++0 == -0 # => true
++0 === -0 # => false
+
+# 其它关系操作符包括 <、<=、> 和 >=
+
+# 罗辑值可以通过 `or`、`and` 和 `not` 结合:
+true and false # => false
+false or true # => true
+not false # => true
+
+
+# 集合也有一些便利的操作符
+[1, 2] ++ [3, 4] # => [1, 2, 3, 4]
+'a' in <[ a b c ]> # => true
+'name' of { name: 'Chris' } # => true
+
+
+########################################################################
+## 3. 函数
+########################################################################
+
+# 因为 LiveScript 是函数式特性的语言,你可以期待函数在语言里被高规格的对待。
+add = (left, right) -> left + right
+add 1, 2 # => 3
+
+# 加上 ! 防止函数执行后的返回值
+two = -> 2
+two!
+
+# LiveScript 与 JavaScript 一样使用函式作用域,且一样拥有闭包的特性。
+# 与 JavaScript 不同的地方在于,`=` 变量赋值时,左边的对象永远不用变量宣告。
+
+# `:=` 操作符允许*重新賦值*父作用域里的变量。
+
+
+# 你可以解构函数的参数,从不定长度的参数结构里获取感兴趣的值。
+tail = ([head, ...rest]) -> rest
+tail [1, 2, 3] # => [2, 3]
+
+# 你也可以使用一元或二元操作符转换参数。当然也可以预设传入的参数值。
+foo = (a = 1, b = 2) -> a + b
+foo! # => 3
+
+# 你可以以拷贝的方式传入参数来避免副作用,例如:
+copy = (^^target, source) ->
+ for k,v of source => target[k] = v
+ target
+a = { a: 1 }
+copy a, { b: 2 } # => { a: 1, b: 2 }
+a # => { a: 1 }
+
+
+# 使用长箭号取代短箭号来柯里化一个函数:
+add = (left, right) --> left + right
+add1 = add 1
+add1 2 # => 3
+
+# 函式里有一个隐式的 `it` 变量,意谓着你不用宣告它。
+identity = -> it
+identity 1 # => 1
+
+# 操作符在 LiveScript 里不是一個函数,但你可以简单地将它们转换成函数!
+# Enter the operator sectioning:
+divide-by-2 = (/ 2)
+[2, 4, 8, 16].map(divide-by-2) .reduce (+)
+
+
+# LiveScript 里不只有应用函数,如同其它良好的函数式语言,你可以合并函数获得更多发挥:
+double-minus-one = (- 1) . (* 2)
+
+# 除了普通的数学公式合并 `f . g` 之外,还有 `>>` 和 `<<` 操作符定义函数的合并顺序。
+double-minus-one = (* 2) >> (- 1)
+double-minus-one = (- 1) << (* 2)
+
+
+# 说到合并函数的参数, LiveScript 使用 `|>` 和 `<|` 操作符将参数传入:
+map = (f, xs) --> xs.map f
+[1 2 3] |> map (* 2) # => [2 4 6]
+
+# 你也可以选择填入值的位置,只需要使用底线 _ 标记:
+reduce = (f, xs, initial) --> xs.reduce f, initial
+[1 2 3] |> reduce (+), _, 0 # => 6
+
+
+# 你也能使 _ 让任何函数变成偏函数应用:
+div = (left, right) -> left / right
+div-by-2 = div _, 2
+div-by-2 4 # => 2
+
+
+# 最后,也很重要的,LiveScript 拥有後呼叫特性, 可以是基於回调的代码
+# (你可以试试其它函数式特性的解法,比如 Promises):
+readFile = (name, f) -> f name
+a <- readFile 'foo'
+b <- readFile 'bar'
+console.log a + b
+
+# 等同於:
+readFile 'foo', (a) -> readFile 'bar', (b) -> console.log a + b
+
+
+########################################################################
+## 4. 模式、判断和流程控制
+########################################################################
+
+# 流程控制可以使用 `if...else` 表达式:
+x = if n > 0 then \positive else \negative
+
+# 除了 `then` 你也可以使用 `=>`
+x = if n > 0 => \positive
+ else \negative
+
+# 过於复杂的流程可以用 `switch` 表达式代替:
+y = {}
+x = switch
+ | (typeof y) is \number => \number
+ | (typeof y) is \string => \string
+ | 'length' of y => \array
+ | otherwise => \object # `otherwise` 和 `_` 是等价的。
+
+# 函数主体、宣告式和赋值式可以表式成 `switch`,这可以省去一些代码:
+take = (n, [x, ...xs]) -->
+ | n == 0 => []
+ | _ => [x] ++ take (n - 1), xs
+
+
+########################################################################
+## 5. 推导式
+########################################################################
+
+# 在 JavaScript 的标准函式库里有一些辅助函数能帮助处理列表及对象
+#(LiveScript 则带有一个 prelude.ls ,作为标准函式库的补充 ),
+# 推导式能让你使用优雅的语法且快速地处理这些事:
+oneToTwenty = [1 to 20]
+evens = [x for x in oneToTwenty when x % 2 == 0]
+
+# 在推导式里 `when` 和 `unless` 可以当成过滤器使用。
+
+# 对象推导式在使用上也是同样的方式,差别在于你使用的是对象而不是数组:
+copy = { [k, v] for k, v of source }
+
+
+########################################################################
+## 6. OOP
+########################################################################
+
+# 虽然 LiveScript 是一门函数式语言,但具有一些命令式及面向对象的特性。
+# 像是 class 语法和一些借镜於 CoffeeScript 的类别继承语法糖:
+class Animal
+ (@name, kind) ->
+ @kind = kind
+ action: (what) -> "*#{@name} (a #{@kind}) #{what}*"
+
+class Cat extends Animal
+ (@name) -> super @name, 'cat'
+ purr: -> @action 'purrs'
+
+kitten = new Cat 'Mei'
+kitten.purr! # => "*Mei (a cat) purrs*"
+
+# 除了类别的单一继承模式之外,还提供了像混入 (Mixins) 这种特性。
+# Mixins 在语言里被当成普通对象:
+Huggable =
+ hug: -> @action 'is hugged'
+
+class SnugglyCat extends Cat implements Huggable
+
+kitten = new SnugglyCat 'Purr'
+kitten.hug! # => "*Mei (a cat) is hugged*"
+```
+
+## 延伸阅读
+
+LiveScript 还有许多强大之处,但这些应该足够启发你写些小型函数式程式了。
+[LiveScript](http://livescript.net/)有更多关于 LiveScript 的资讯
+和线上编译器等着你来试!
+
+你也可以参考
+[prelude.ls](http://gkz.github.io/prelude-ls/),和一些 `#livescript`
+的网络聊天室频道。
diff --git a/zh-cn/lua-cn.html.markdown b/zh-cn/lua-cn.html.markdown
index 95a94c76..098d0ab5 100644
--- a/zh-cn/lua-cn.html.markdown
+++ b/zh-cn/lua-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: lua
+language: Lua
lang: zh-cn
contributors:
- ["Tyler Neylon", "http://tylerneylon.com/"]
@@ -9,6 +9,7 @@ contributors:
- ["Amr Tamimi", "https://amrtamimi.com"]
translators:
- ["Jakukyo Friel", "http://weakish.github.io"]
+filename: lua-cn.lua
---
```lua
@@ -62,8 +63,8 @@ foo = anUnknownVariable -- 现在 foo = nil.
aBoolValue = false
---只有nil和false为假; 0和 ''都均为真!
-if not aBoolValue then print('twas false') end
+--只有nil和false为假; 0和 ''均为真!
+if not aBoolValue then print('false') end
-- 'or'和 'and'短路
-- 类似于C/js里的 a?b:c 操作符:
@@ -148,7 +149,7 @@ print {} -- 一样可以工作。
-- Table = Lua唯一的组合数据结构;
-- 它们是关联数组。
-- 类似于PHP的数组或者js的对象,
--- 它们是哈希表或者字典,也可以当初列表使用。
+-- 它们是哈希表或者字典,也可以当列表使用。
-- 按字典/map的方式使用Table:
diff --git a/zh-cn/markdown-cn.html.markdown b/zh-cn/markdown-cn.html.markdown
new file mode 100644
index 00000000..1c577efb
--- /dev/null
+++ b/zh-cn/markdown-cn.html.markdown
@@ -0,0 +1,240 @@
+---
+language: markdown
+contributors:
+ - ["Dan Turkel", "http://danturkel.com/"]
+translators:
+ - ["Fangzhou Chen","https://github.com/FZSS"]
+filename: learnmarkdown-cn.md
+lang: zh-cn
+---
+
+Markdown 由 John Gruber 于 2004年创立. 它旨在成为一门容易读写的语法结构,并可以便利地转换成 HTML(以及其他很多)格式。
+
+欢迎您多多反馈以及分支和请求合并。
+
+
+```markdown
+<!-- Markdown 是 HTML 的父集,所以任何 HTML 文件都是有效的 Markdown。
+这意味着我们可以在 Markdown 里使用任何 HTML 元素,比如注释元素,
+且不会被 Markdown 解析器所影响。不过如果你在 Markdown 文件内创建了 HTML 元素,
+你将无法在 HTML 元素的内容中使用 Markdown 语法。-->
+
+<!-- 在不同的解析器中,Markdown 的实现方法有所不同。
+此教程会指出当某功能是否通用及是否只对某一解析器有效。 -->
+
+<!-- 标头 -->
+<!-- 通过在文本前加上不同数量的hash(#), 你可以创建相对应的 <h1>
+到 <h6> HTML元素。-->
+
+# 这是一个 <h1>
+## 这是一个 <h2>
+### 这是一个 <h3>
+#### 这是一个 <h4>
+##### 这是一个 <h5>
+###### 这是一个 <h6>
+
+<!-- 对于 <h1> 和 <h2> 元素,Markdown 额外提供了两种添加方式。 -->
+这是一个 h1
+=============
+
+这是一个 h2
+-------------
+
+<!-- 简易文本样式 -->
+<!-- 文本的斜体,粗体,和删除线在 Markdown 中可以轻易地被实现。-->
+
+*此文本为斜体。*
+_此文本也是。_
+
+**此文本为粗体。**
+__此文本也是__
+
+***此文本是斜体加粗体。***
+**_或者这样。_**
+*__这个也是!__*
+
+<!-- 在 Github 采用的 Markdown 中 -->
+
+~~此文本为删除线效果。~~
+
+<!-- 单个段落由一句或多句邻近的句子组成,这些句子由一个或多个空格分隔。-->
+
+这是第一段落. 这句话在同一个段落里,好玩么?
+
+现在我是第二段落。
+这句话也在第二段落!
+
+这句话在第三段落!
+
+<!-- 如果你插入一个 HTML中的<br />标签,你可以在段末加入两个以上的空格,
+然后另起一段。-->
+
+此段落结尾有两个空格(选中以显示)。
+
+上文有一个 <br /> !
+
+<!-- 段落引用可由 > 字符轻松实现。-->
+
+> 这是一个段落引用. 你可以
+> 手动断开你的句子,然后在每句句子前面添加 “>” 字符。或者让你的句子变得很长,以至于他们自动得断开。
+> 只要你的文字以“>” 字符开头,两种方式无异。
+
+> 你也对文本进行
+>> 多层引用
+> 这多机智啊!
+
+<!-- 序列 -->
+<!-- 无序序列可由星号,加号或者减号来建立 -->
+
+* 项目
+* 项目
+* 另一个项目
+
+或者
+
++ 项目
++ 项目
++ 另一个项目
+
+或者
+
+- 项目
+- 项目
+- 最后一个项目
+
+<!-- 有序序列可由数字加点来实现 -->
+
+1. 项目一
+2. 项目二
+3. 项目三
+
+<!-- 即使你的标签数字有误,Markdown 依旧会呈现出正确的序号,
+不过这并不是一个好主意-->
+
+1. 项目一
+1. 项目二
+1. 项目三
+<!-- (此段与前例一模一样) -->
+
+<!-- 你也可以使用子序列 -->
+
+1. 项目一
+2. 项目二
+3. 项目三
+ * 子项目
+ * 子项目
+4. 项目四
+
+<!-- 代码段落 -->
+<!-- 代码段落(HTML中 <code>标签)可以由缩进四格(spaces)
+或者一个标签页(tab)实现-->
+
+ This is code
+ So is this
+
+<!-- 在你的代码中,你仍然使用tab可以进行缩进操作 -->
+
+ my_array.each do |item|
+ puts item
+ end
+
+<!-- 内联代码可由反引号 ` 实现 -->
+
+John 甚至不知道 `go_to()` 方程是干嘛的!
+
+<!-- 在Github的 Markdown中,对于代码你可以使用特殊的语法 -->
+
+\`\`\`ruby <!-- 插入时记得移除反斜线, 仅留```ruby ! -->
+def foobar
+ puts "Hello world!"
+end
+\`\`\` <!-- 这里也是,移除反斜线,仅留 ``` -->
+
+<!-- 以上代码不需要缩进,而且 Github 会根据```后表明的语言来进行语法高亮 -->
+
+<!-- 水平线 (<hr />) -->
+<!-- 水平线可由三个或以上的星号或者减号创建,可带可不带空格。 -->
+
+***
+---
+- - -
+****************
+
+<!-- 链接 -->
+<!-- Markdown 最棒的地方就是简易的链接制作。链接文字放在中括号[]内,
+在随后的括弧()内加入url。-->
+
+[点我点我!](http://test.com/)
+
+<!-- 你也可以为链接加入一个标题:在括弧内使用引号 -->
+
+[点我点我!](http://test.com/ "连接到Test.com")
+
+<!-- 相对路径也可以有 -->
+
+[去 music](/music/).
+
+<!-- Markdown同样支持引用样式的链接 -->
+
+[点此链接][link1]以获取更多信息!
+[看一看这个链接][foobar] 如果你愿意的话.
+
+[link1]: http://test.com/ "Cool!"
+[foobar]: http://foobar.biz/ "Alright!"
+
+<!-- 链接的标题可以处于单引号中,括弧中或是被忽略。引用名可以在文档的任意何处,
+并且可以随意命名,只要名称不重复。-->
+
+<!-- “隐含式命名” 的功能可以让链接文字作为引用名 -->
+
+[This][] is a link.
+
+[this]: http://thisisalink.com/
+
+<!-- 但这并不常用 -->
+
+<!-- 图像 -->
+<!-- 图像与链接相似,只需在前添加一个感叹号 -->
+
+![这是我图像的悬停文本(alt text)](http://imgur.com/myimage.jpg "可选命名")
+
+<!-- 引用样式也同样起作用 -->
+
+![这是我的悬停文本.][myimage]
+
+[myimage]: relative/urls/cool/image.jpg "在此输入标题"
+
+<!-- 杂项 -->
+<!-- 自动链接 -->
+
+<http://testwebsite.com/> 与
+[http://testwebsite.com/](http://testwebsite.com/) 等同
+
+<!-- 电子邮件的自动链接 -->
+
+<foo@bar.com>
+
+<!-- 转义字符 -->
+
+我希望 *将这段文字置于星号之间* 但是我不希望它被
+斜体化, 所以我就: \*这段置文字于星号之间\*。
+
+<!-- 表格 -->
+<!-- 表格只被 Github 的 Markdown 支持,并且有一点笨重,但如果你真的要用的话: -->
+
+| 第一列 | 第二列 | 第三列 |
+| :---------- | :------: | ----------: |
+| 左对齐 | 居个中 | 右对齐 |
+| 某某某 | 某某某 | 某某某 |
+
+<!-- 或者, 同样的 -->
+
+第一列 | 第二列 | 第三列
+:-- | :-: | --:
+这太丑了 | 药不能 | 停
+
+<!-- 结束! -->
+
+```
+
+更多信息, 请于[此处](http://daringfireball.net/projects/Markdown/syntax)参见 John Gruber 关于语法的官方帖子,及于[此处](https://github.com/adam-p/Markdown-here/wiki/Markdown-Cheatsheet) 参见 Adam Pritchard 的摘要笔记。
diff --git a/zh-cn/php-cn.html.markdown b/zh-cn/php-cn.html.markdown
index 24939681..2def7f1c 100644
--- a/zh-cn/php-cn.html.markdown
+++ b/zh-cn/php-cn.html.markdown
@@ -1,5 +1,5 @@
---
-language: php
+language: PHP
contributors:
- ["Malcolm Fell", "http://emarref.net/"]
- ["Trismegiste", "https://github.com/Trismegiste"]
diff --git a/zh-cn/python3-cn.html.markdown b/zh-cn/python3-cn.html.markdown
new file mode 100644
index 00000000..c223297c
--- /dev/null
+++ b/zh-cn/python3-cn.html.markdown
@@ -0,0 +1,629 @@
+---
+language: python3
+contributors:
+ - ["Louie Dinh", "http://pythonpracticeprojects.com"]
+ - ["Steven Basart", "http://github.com/xksteven"]
+ - ["Andre Polykanine", "https://github.com/Oire"]
+translators:
+ - ["Geoff Liu", "http://geoffliu.me"]
+filename: learnpython3-cn.py
+lang: zh-cn
+---
+
+Python是由吉多·范罗苏姆(Guido Van Rossum)在90年代早期设计。它是如今最常用的编程
+语言之一。它的语法简洁且优美,几乎就是可执行的伪代码。
+
+欢迎大家斧正。英文版原作Louie Dinh [@louiedinh](http://twitter.com/louiedinh)
+或着Email louiedinh [at] [谷歌的信箱服务]。中文翻译Geoff Liu。
+
+注意:这篇教程是特别为Python3写的。如果你想学旧版Python2,我们特别有另一篇教程。
+
+```python
+
+# 用井字符开头的是单行注释
+
+""" 多行字符串用三个引号
+ 包裹,也常被用来做多
+ 行注释
+"""
+
+####################################################
+## 1. 原始数据类型和运算符
+####################################################
+
+# 整数
+3 # => 3
+
+# 算术没有什么出乎意料的
+1 + 1 # => 2
+8 - 1 # => 7
+10 * 2 # => 20
+
+# 但是除法例外,会自动转换成浮点数
+35 / 5 # => 7.0
+5 / 3 # => 1.6666666666666667
+
+# 整数除法的结果都是向下取整
+5 // 3 # => 1
+5.0 // 3.0 # => 1.0 # 浮点数也可以
+-5 // 3 # => -2
+-5.0 // 3.0 # => -2.0
+
+# 浮点数的运算结果也是浮点数
+3 * 2.0 # => 6.0
+
+# 模除
+7 % 3 # => 1
+
+# x的y次方
+2**4 # => 16
+
+# 用括号决定优先级
+(1 + 3) * 2 # => 8
+
+# 布尔值
+True
+False
+
+# 用not取非
+not True # => False
+not False # => True
+
+# 逻辑运算符,注意and和or都是小写
+True and False #=> False
+False or True #=> True
+
+# 整数也可以当作布尔值
+0 and 2 #=> 0
+-5 or 0 #=> -5
+0 == False #=> True
+2 == True #=> False
+1 == True #=> 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
+
+# 字符串用单引双引都可以
+"这是个字符串"
+'这也是个字符串'
+
+# 用加号连接字符串
+"Hello " + "world!" # => "Hello world!"
+
+# 字符串可以被当作字符列表
+"This is a string"[0] # => 'T'
+
+# 用.format来格式化字符串
+"{} can be {}".format("strings", "interpolated")
+
+# 可以重复参数以节省时间
+"{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"
+
+# 如果不想数参数,可以用关键字
+"{name} wants to eat {food}".format(name="Bob", food="lasagna") #=> "Bob wants to eat lasagna"
+
+# 如果你的Python3程序也要在Python2.5以下环境运行,也可以用老式的格式化语法
+"%s can be %s the %s way" % ("strings", "interpolated", "old")
+
+# None是一个对象
+None # => None
+
+# 当与None进行比较时不要用 ==,要用is。is是用来比较两个变量是否指向同一个对象。
+"etc" is None # => False
+None is None # => True
+
+# None,0,空字符串,空列表,空字典都算是False
+# 所有其他值都是True
+bool(0) # => False
+bool("") # => False
+bool([]) #=> False
+bool({}) #=> False
+
+
+####################################################
+## 2. 变量和集合
+####################################################
+
+# print是内置的打印函数
+print("I'm Python. Nice to meet you!")
+
+# 在给变量赋值前不用提前声明
+# 传统的变量命名是小写,用下划线分隔单词
+some_var = 5
+some_var # => 5
+
+# 访问未赋值的变量会抛出异常
+# 参考流程控制一段来学习异常处理
+some_unknown_var # 抛出NameError
+
+# 用列表(list)储存序列
+li = []
+# 创建列表时也可以同时赋给元素
+other_li = [4, 5, 6]
+
+# 用append在列表最后追加元素
+li.append(1) # li现在是[1]
+li.append(2) # li现在是[1, 2]
+li.append(4) # li现在是[1, 2, 4]
+li.append(3) # li现在是[1, 2, 4, 3]
+# 用pop从列表尾部删除
+li.pop() # => 3 且li现在是[1, 2, 4]
+# 把3再放回去
+li.append(3) # li变回[1, 2, 4, 3]
+
+# 列表存取跟数组一样
+li[0] # => 1
+# 取出最后一个元素
+li[-1] # => 3
+
+# 越界存取会造成IndexError
+li[4] # 抛出IndexError
+
+# 列表有切割语法
+li[1:3] # => [2, 4]
+# 取尾
+li[2:] # => [4, 3]
+# 取头
+li[:3] # => [1, 2, 4]
+# 隔一个取一个
+li[::2] # =>[1, 4]
+# 倒排列表
+li[::-1] # => [3, 4, 2, 1]
+# 可以用三个参数的任何组合来构建切割
+# li[始:终:步伐]
+
+# 用del删除任何一个元素
+del li[2] # li is now [1, 2, 3]
+
+# 列表可以相加
+# 注意:li和other_li的值都不变
+li + other_li # => [1, 2, 3, 4, 5, 6]
+
+# 用extend拼接列表
+li.extend(other_li) # li现在是[1, 2, 3, 4, 5, 6]
+
+# 用in测试列表是否包含值
+1 in li # => True
+
+# 用len取列表长度
+len(li) # => 6
+
+
+# 元组是不可改变的序列
+tup = (1, 2, 3)
+tup[0] # => 1
+tup[0] = 3 # 抛出TypeError
+
+# 列表允许的操作元组大都可以
+len(tup) # => 3
+tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6)
+tup[:2] # => (1, 2)
+2 in tup # => True
+
+# 可以把元组合列表解包,赋值给变量
+a, b, c = (1, 2, 3) # 现在a是1,b是2,c是3
+# 元组周围的括号是可以省略的
+d, e, f = 4, 5, 6
+# 交换两个变量的值就这么简单
+e, d = d, e # 现在d是5,e是4
+
+
+# 用字典表达映射关系
+empty_dict = {}
+# 初始化的字典
+filled_dict = {"one": 1, "two": 2, "three": 3}
+
+# 用[]取值
+filled_dict["one"] # => 1
+
+
+# 用keys获得所有的键。因为keys返回一个可迭代对象,所以在这里把结果包在list里。我们下面会详细介绍可迭代。
+# 注意:字典键的顺序是不定的,你得到的结果可能和以下不同。
+list(filled_dict.keys()) # => ["three", "two", "one"]
+
+
+# 用values获得所有的值。跟keys一样,要用list包起来,顺序也可能不同。
+list(filled_dict.values()) # => [3, 2, 1]
+
+
+# 用in测试一个字典是否包含一个键
+"one" in filled_dict # => True
+1 in filled_dict # => False
+
+# 访问不存在的键会导致KeyError
+filled_dict["four"] # KeyError
+
+# 用get来避免KeyError
+filled_dict.get("one") # => 1
+filled_dict.get("four") # => None
+# 当键不存在的时候get方法可以返回默认值
+filled_dict.get("one", 4) # => 1
+filled_dict.get("four", 4) # => 4
+
+# setdefault方法只有当键不存在的时候插入新值
+filled_dict.setdefault("five", 5) # filled_dict["five"]设为5
+filled_dict.setdefault("five", 6) # filled_dict["five"]还是5
+
+# 字典赋值
+filled_dict.update({"four":4}) #=> {"one": 1, "two": 2, "three": 3, "four": 4}
+filled_dict["four"] = 4 # 另一种赋值方法
+
+# 用del删除
+del filled_dict["one"] # 从filled_dict中把one删除
+
+
+# 用set表达集合
+empty_set = set()
+# 初始化一个集合,语法跟字典相似。
+some_set = {1, 1, 2, 2, 3, 4} # some_set现在是{1, 2, 3, 4}
+
+# 可以把集合赋值于变量
+filled_set = some_set
+
+# 为集合添加元素
+filled_set.add(5) # filled_set现在是{1, 2, 3, 4, 5}
+
+# & 取交集
+other_set = {3, 4, 5, 6}
+filled_set & other_set # => {3, 4, 5}
+
+# | 取并集
+filled_set | other_set # => {1, 2, 3, 4, 5, 6}
+
+# - 取补集
+{1, 2, 3, 4} - {2, 3, 5} # => {1, 4}
+
+# in 测试集合是否包含元素
+2 in filled_set # => True
+10 in filled_set # => False
+
+
+####################################################
+## 3. 流程控制和迭代器
+####################################################
+
+# 先随便定义一个变量
+some_var = 5
+
+# 这是个if语句。注意缩进在Python里是有意义的
+# 印出"some_var比10小"
+if some_var > 10:
+ print("some_var比10大")
+elif some_var < 10: # elif句是可选的
+ print("some_var比10小")
+else: # else也是可选的
+ print("some_var就是10")
+
+
+"""
+用for循环语句遍历列表
+打印:
+ dog is a mammal
+ cat is a mammal
+ mouse is a mammal
+"""
+for animal in ["dog", "cat", "mouse"]:
+ print("{} is a mammal".format(animal))
+
+"""
+"range(number)"返回数字列表从0到给的数字
+打印:
+ 0
+ 1
+ 2
+ 3
+"""
+for i in range(4):
+ print(i)
+
+"""
+while循环直到条件不满足
+打印:
+ 0
+ 1
+ 2
+ 3
+"""
+x = 0
+while x < 4:
+ print(x)
+ x += 1 # x = x + 1 的简写
+
+# 用try/except块处理异常状况
+try:
+ # 用raise抛出异常
+ raise IndexError("This is an index error")
+except IndexError as e:
+ pass # pass是无操作,但是应该在这里处理错误
+except (TypeError, NameError):
+ pass # 可以同时处理不同类的错误
+else: # else语句是可选的,必须在所有的except之后
+ print("All good!") # 只有当try运行完没有错误的时候这句才会运行
+
+
+# Python提供一个叫做可迭代(iterable)的基本抽象。一个可迭代对象是可以被当作序列
+# 的对象。比如说上面range返回的对象就是可迭代的。
+
+filled_dict = {"one": 1, "two": 2, "three": 3}
+our_iterable = filled_dict.keys()
+print(our_iterable) # => range(1,10) 是一个实现可迭代接口的对象
+
+# 可迭代对象可以遍历
+for i in our_iterable:
+ print(i) # 打印 one, two, three
+
+# 但是不可以随机访问
+our_iterable[1] # 抛出TypeError
+
+# 可迭代对象知道怎么生成迭代器
+our_iterator = iter(our_iterable)
+
+# 迭代器是一个可以记住遍历的位置的对象
+# 用__next__可以取得下一个元素
+our_iterator.__next__() #=> "one"
+
+# 再一次调取__next__时会记得位置
+our_iterator.__next__() #=> "two"
+our_iterator.__next__() #=> "three"
+
+# 当迭代器所有元素都取出后,会抛出StopIteration
+our_iterator.__next__() # 抛出StopIteration
+
+# 可以用list一次取出迭代器所有的元素
+list(filled_dict.keys()) #=> Returns ["one", "two", "three"]
+
+
+
+####################################################
+## 4. 函数
+####################################################
+
+# 用def定义新函数
+def add(x, y):
+ print("x is {} and y is {}".format(x, y))
+ return x + y # 用return语句返回
+
+# 调用函数
+add(5, 6) # => 印出"x is 5 and y is 6"并且返回11
+
+# 也可以用关键字参数来调用函数
+add(y=6, x=5) # 关键字参数可以用任何顺序
+
+
+# 我们可以定义一个可变参数函数
+def varargs(*args):
+ return args
+
+varargs(1, 2, 3) # => (1, 2, 3)
+
+
+# 我们也可以定义一个关键字可变参数函数
+def keyword_args(**kwargs):
+ return kwargs
+
+# 我们来看看结果是什么:
+keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"}
+
+
+# 这两种可变参数可以混着用
+def all_the_args(*args, **kwargs):
+ print(args)
+ print(kwargs)
+"""
+all_the_args(1, 2, a=3, b=4) prints:
+ (1, 2)
+ {"a": 3, "b": 4}
+"""
+
+# 调用可变参数函数时可以做跟上面相反的,用*展开序列,用**展开字典。
+args = (1, 2, 3, 4)
+kwargs = {"a": 3, "b": 4}
+all_the_args(*args) # 相当于 foo(1, 2, 3, 4)
+all_the_args(**kwargs) # 相当于 foo(a=3, b=4)
+all_the_args(*args, **kwargs) # 相当于 foo(1, 2, 3, 4, a=3, b=4)
+
+
+# 函数作用域
+x = 5
+
+def setX(num):
+ # 局部作用域的x和全局域的x是不同的
+ x = num # => 43
+ print (x) # => 43
+
+def setGlobalX(num):
+ global x
+ print (x) # => 5
+ x = num # 现在全局域的x被赋值
+ print (x) # => 6
+
+setX(43)
+setGlobalX(6)
+
+
+# 函数在Python是一等公民
+def create_adder(x):
+ def adder(y):
+ return x + y
+ return adder
+
+add_10 = create_adder(10)
+add_10(3) # => 13
+
+# 也有匿名函数
+(lambda x: x > 2)(3) # => True
+
+# 内置的高阶函数
+map(add_10, [1, 2, 3]) # => [11, 12, 13]
+filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7]
+
+# 用列表推导式可以简化映射和过滤。列表推导式的返回值是另一个列表。
+[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13]
+[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7]
+
+####################################################
+## 5. 类
+####################################################
+
+
+# 定义一个继承object的类
+class Human(object):
+
+ # 类属性,被所有此类的实例共用。
+ species = "H. sapiens"
+
+ # 构造方法,当实例被初始化时被调用。注意名字前后的双下划线,这是表明这个属
+ # 性或方法对Python有特殊意义,但是允许用户自行定义。你自己取名时不应该用这
+ # 种格式。
+ def __init__(self, name):
+ # Assign the argument to the instance's name attribute
+ self.name = name
+
+ # 实例方法,第一个参数总是self,就是这个实例对象
+ def say(self, msg):
+ return "{name}: {message}".format(name=self.name, message=msg)
+
+ # 类方法,被所有此类的实例共用。第一个参数是这个类对象。
+ @classmethod
+ def get_species(cls):
+ return cls.species
+
+ # 静态方法。调用时没有实例或类的绑定。
+ @staticmethod
+ def grunt():
+ return "*grunt*"
+
+
+# 构造一个实例
+i = Human(name="Ian")
+print(i.say("hi")) # 印出 "Ian: hi"
+
+j = Human("Joel")
+print(j.say("hello")) # 印出 "Joel: hello"
+
+# 调用一个类方法
+i.get_species() # => "H. sapiens"
+
+# 改一个共用的类属性
+Human.species = "H. neanderthalensis"
+i.get_species() # => "H. neanderthalensis"
+j.get_species() # => "H. neanderthalensis"
+
+# 调用静态方法
+Human.grunt() # => "*grunt*"
+
+
+####################################################
+## 6. 模块
+####################################################
+
+# 用import导入模块
+import math
+print(math.sqrt(16)) # => 4
+
+# 也可以从模块中导入个别值
+from math import ceil, floor
+print(ceil(3.7)) # => 4.0
+print(floor(3.7)) # => 3.0
+
+# 可以导入一个模块中所有值
+# 警告:不建议这么做
+from math import *
+
+# 如此缩写模块名字
+import math as m
+math.sqrt(16) == m.sqrt(16) # => True
+
+# Python模块其实就是普通的Python文件。你可以自己写,然后导入,
+# 模块的名字就是文件的名字。
+
+# 你可以这样列出一个模块里所有的值
+import math
+dir(math)
+
+
+####################################################
+## 7. 高级用法
+####################################################
+
+# 用生成器(generators)方便地写惰性运算
+def double_numbers(iterable):
+ for i in iterable:
+ yield i + i
+
+# 生成器只有在需要时才计算下一个值。它们每一次循环只生成一个值,而不是把所有的
+# 值全部算好。这意味着double_numbers不会生成大于15的数字。
+#
+# range的返回值也是一个生成器,不然一个1到900000000的列表会花很多时间和内存。
+#
+# 如果你想用一个Python的关键字当作变量名,可以加一个下划线来区分。
+range_ = range(1, 900000000)
+# 当找到一个 >=30 的结果就会停
+for i in double_numbers(range_):
+ print(i)
+ if i >= 30:
+ break
+
+
+# 装饰器(decorators)
+# 这个例子中,beg装饰say
+# beg会先调用say。如果返回的say_please为真,beg会改变返回的字符串。
+from functools import wraps
+
+
+def beg(target_function):
+ @wraps(target_function)
+ def wrapper(*args, **kwargs):
+ msg, say_please = target_function(*args, **kwargs)
+ if say_please:
+ return "{} {}".format(msg, "Please! I am poor :(")
+ return msg
+
+ return wrapper
+
+
+@beg
+def say(say_please=False):
+ msg = "Can you buy me a beer?"
+ return msg, say_please
+
+
+print(say()) # Can you buy me a beer?
+print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(
+```
+
+## 想继续学吗?
+
+### 线上免费材料(英文)
+
+* [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)
+
+### 书籍(也是英文)
+
+* [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/zh-cn/r-cn.html.markdown b/zh-cn/r-cn.html.markdown
index 19c5f25d..0c46bc22 100644
--- a/zh-cn/r-cn.html.markdown
+++ b/zh-cn/r-cn.html.markdown
@@ -13,7 +13,7 @@ lang: zh-cn
R 是一门统计语言。它有很多数据分析和挖掘程序包。可以用来统计、分析和制图。
你也可以在 LaTeX 文档中运行 `R` 命令。
-```python
+```r
# 评论以 # 开始
# R 语言原生不支持 多行注释
diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown
index 3c47f3f9..99250b43 100644
--- a/zh-cn/ruby-cn.html.markdown
+++ b/zh-cn/ruby-cn.html.markdown
@@ -40,7 +40,7 @@ translators:
1.+(3) #=> 4
10.* 5 #=> 50
-# 特殊的只也是对象
+# 特殊的值也是对象
nil # 空
true # 真
false # 假
diff --git a/zh-cn/scala-cn.html.markdown b/zh-cn/scala-cn.html.markdown
index 28af8ddc..58f5cd47 100644
--- a/zh-cn/scala-cn.html.markdown
+++ b/zh-cn/scala-cn.html.markdown
@@ -11,7 +11,7 @@ lang: zh-cn
Scala - 一门可拓展性的语言
-```cpp
+```scala
/*
自行设置:
diff --git a/zh-cn/swift-cn.html.markdown b/zh-cn/swift-cn.html.markdown
index c87f9d10..b9696c72 100644
--- a/zh-cn/swift-cn.html.markdown
+++ b/zh-cn/swift-cn.html.markdown
@@ -12,7 +12,7 @@ Swift 是Apple 开发的用于iOS 和OS X 开发的编程语言。Swift 于2014
参阅:Apple's [getting started guide](https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/LandingPage/index.html) ——一个完整的Swift 教程
-```js
+```swift
//
// 基础
//