summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--c++.html.markdown7
-rw-r--r--c.html.markdown2
-rw-r--r--css.html.markdown91
-rw-r--r--de-de/css-de.html.markdown179
-rw-r--r--es-es/bash-es.html.markdown1
-rw-r--r--go.html.markdown4
-rw-r--r--json.html.markdown2
-rw-r--r--julia.html.markdown7
-rw-r--r--nim.html.markdown265
-rw-r--r--perl6.html.markdown119
-rw-r--r--zh-cn/livescript-cn.html.markdown322
11 files changed, 844 insertions, 155 deletions
diff --git a/c++.html.markdown b/c++.html.markdown
index 7609dd46..5bf7e2ea 100644
--- a/c++.html.markdown
+++ b/c++.html.markdown
@@ -132,7 +132,7 @@ namespace myFirstNameSpace
cos(int x)
{
printf("My inner soul was made to program.");
- }
+ }
}
}
@@ -266,10 +266,9 @@ int main () {
//C++ Class inheritance
-class German_Sheperd
+class German_Sheperd : public Doggie
{
- //This class now inherits everything public and protected from Doggie class
- Doggie d_dog;
+ //This class now inherits everything public and protected from Doggie class
//Good practice to put d_ in front of datatypes in classes
std::string d_type;
diff --git a/c.html.markdown b/c.html.markdown
index cbb6d289..10e6fa45 100644
--- a/c.html.markdown
+++ b/c.html.markdown
@@ -217,7 +217,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";
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/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/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/go.html.markdown b/go.html.markdown
index b4c6afff..17f10bd9 100644
--- a/go.html.markdown
+++ b/go.html.markdown
@@ -72,7 +72,7 @@ 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.
@@ -126,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)
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..feb38463 100644
--- a/julia.html.markdown
+++ b/julia.html.markdown
@@ -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/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/perl6.html.markdown b/perl6.html.markdown
index 4e7d8c6e..7afcc930 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 2 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
@@ -1303,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」
@@ -1317,16 +1395,26 @@ 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 probably used to is LTM.
+# 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.
@@ -1351,6 +1439,9 @@ so 'ayc' ~~ / a [ b | y ] c /; # `True`. Obviously enough ...
# 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
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`
+的网络聊天室频道。