diff options
33 files changed, 661 insertions, 128 deletions
| diff --git a/c.html.markdown b/c.html.markdown index 3d632eab..7c2386ef 100644 --- a/c.html.markdown +++ b/c.html.markdown @@ -148,15 +148,10 @@ int main (int argc, char** argv)    printf("Enter the array size: "); // ask the user for an array size    int size;    fscanf(stdin, "%d", &size); -  char buf[size]; -  fgets(buf, sizeof buf, stdin); - -  // strtoul parses a string to an unsigned integer -  size_t size2 = strtoul(buf, NULL, 10); -  int var_length_array[size2]; // declare the VLA +  int var_length_array[size]; // declare the VLA    printf("sizeof array = %zu\n", sizeof var_length_array); -  // A possible outcome of this program may be: +  // Example:    // > Enter the array size: 10    // > sizeof array = 40 diff --git a/chapel.html.markdown b/chapel.html.markdown index 7252a3e4..866e92d2 100644 --- a/chapel.html.markdown +++ b/chapel.html.markdown @@ -629,7 +629,7 @@ for (i, j) in zip( toThisArray.domain, -100..#5 ){  }  writeln( toThisArray ); -// This is all very important in undestanding why the statement +// This is all very important in understanding why the statement  // var iterArray : [1..10] int = [ i in 1..10 ] if ( i % 2 == 1 ) then j;  // exhibits a runtime error.  // Even though the domain of the array and the loop-expression are @@ -914,7 +914,7 @@ proc main(){    [ val in myBigArray ] val = 1 / val; // Parallel operation    // Atomic variables, common to many languages, are ones whose operations -  // occur uninterupted. Multiple threads can both modify atomic variables +  // occur uninterrupted. Multiple threads can both modify atomic variables    // and can know that their values are safe.    // Chapel atomic variables can be of type bool, int, uint, and real.    var uranium: atomic int; diff --git a/de-de/bash-de.html.markdown b/de-de/bash-de.html.markdown index fb9cd9d4..541d28bb 100644 --- a/de-de/bash-de.html.markdown +++ b/de-de/bash-de.html.markdown @@ -28,18 +28,50 @@ echo Hello, world!  echo 'Dies ist die erste Zeile'; echo 'Dies die zweite Zeile'  # Variablen deklariert man so: -VARIABLE="irgendein String" +Variable="irgendein String"  # Aber nicht so: -VARIABLE = "irgendein String" -# Bash wird VARIABLE für einen Befehl halten, den es ausführen soll. Es wird einen Fehler ausgeben,  +Variable = "irgendein String" +# Bash wird 'Variable' für einen Befehl halten, den es ausführen soll. Es wird einen Fehler ausgeben,   # weil es den Befehl nicht findet.  +# Und so auch nicht: +Variable= 'Some string' +# Bash wird 'Variable' wieder für einen Befehl halten, den es ausführen soll. Es wird einen Fehler ausgeben,  +# Hier wird der Teil 'Variable=' als nur für diesen einen Befehl gültige Zuweisung an die Variable gesehen. +  # Eine Variable wird so benutzt: -echo $VARIABLE -echo "$VARIABLE" -# Wenn du eine Variable selbst benutzt – ihr Werte zuweist, sie exportierst oder irgendetwas anders –,  +echo $Variable +echo "$Variable" +echo ${Variable} +# aber +echo '$Variable' +# Wenn du eine Variable selbst benutzt – ihr Werte zuweist, sie exportierst oder irgendetwas anderes –,   # dann über ihren Namen ohne $. Aber wenn du ihren zugewiesenen Wert willst, dann musst du $ voranstellen. +# Beachte: ' (Hochkomma) verhindert das Interpretieren der Variablen + +# Ersetzen von Zeichenketten in Variablen +echo ${Variable/irgendein/neuer} +# Ersetzt das erste Vorkommen von "irgendein" durch "neuer" + +# Teil einer Zeichenkette +Laenge=7 +echo ${Variable:0:Laenge} +# Gibt nur die ersten 7 Zeichen zurück + +# Standardwert verwenden +echo ${Foo:-"ErsatzWennLeerOderUngesetzt"} +# Das funktioniert mit nicht gesetzten Variablen (Foo=) und leeren Zeichenketten (Foo="") +# Die Zahl 0 (Foo=0) liefert 0. +# Beachte: der wert der Variablen wird nicht geändert + +# Eingebaute Variable (BUILTINS): +# Einige nützliche Beispiele +echo "Rückgabewert des letzten Befehls: $?" +echo "Die PID des skripts: $$" +echo "Anzahl der Argumente beim Aufruf: $#" +echo "Alle Argumente beim Aufruf: $@" +echo "Die Argumente in einzelnen Variablen: $1 $2..."  # Einen Wert aus der Eingabe lesen:  echo "Wie heisst du?" @@ -47,14 +79,30 @@ read NAME # Wir mussten nicht mal eine neue Variable deklarieren  echo Hello, $NAME!  # Wir haben die übliche if-Struktur: -if true +# 'man test' liefert weitere Informationen zu Bedingungen +if [ "$NAME" -ne $USER ]  then -    echo "Wie erwartet" +    echo "Dein Name ist nicht dein Login-Name"  else -    echo "Und dies nicht" +    echo "Dein Name ist dein Login-Name" +fi + +# Es gibt auch bedingte Ausführung +echo "immer ausgeführt" || echo "Nur ausgeführt wenn der erste Befehl fehlschlägt" +echo "immer ausgeführt" && echo "Nur ausgeführt wenn der erste Befehl Erfolg hat" + +# Um && und || mit if statements zu verwenden, braucht man mehrfache Paare eckiger Klammern: +if [ $NAME == "Steve" ] && [ $Alter -eq 15 ] +then +    echo "Wird ausgeführt wenn $NAME gleich 'Steve' UND $Alter gleich 15." +fi + +if [ $Name == "Daniya" ] || [ $Name == "Zach" ] +then +    echo "Wird ausgeführt wenn $NAME gleich 'Daniya' ODER $NAME gleich 'Zach'."  fi -# Ausdrücke werden im folgenden Format festgehalten: +# Ausdrücke haben folgendes Format:  echo $(( 10 + 5 ))  # Anders als andere Programmiersprachen ist Bash eine Shell – es arbeitet also im Kontext von Verzeichnissen. @@ -69,13 +117,60 @@ ls -l # Liste alle Dateien und Unterverzeichnisse auf einer eigenen Zeile auf  # txt-Dateien im aktuellen Verzeichnis auflisten:  ls -l | grep "\.txt" -# Befehle können innerhalb anderer Befehle mit $( ) erstetzt werden: +# Ein- und Ausgabe können umgeleitet werden (stdin, stdout, and stderr). +# Von stdin lesen bis "EOF" allein in einer Zeile auftaucht +# und die Datei hello.py mit den Zeilen zwischen den beiden "EOF" +# überschreiben: +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 + +# Führe hello.py mit verschiedenen Umleitungen von +# stdin, stdout und stderr aus: +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 +# Die Fehlerausgabe würde die Datei "error.err" überschreiben (falls sie existiert)  +# verwende ">>" um stattdessen anzuhängen: +python hello.py >> "output.out" 2>> "error.err" + +# Überschreibe output.out, hänge an error.err an und zähle die Zeilen beider Dateien: +info bash 'Basic Shell Features' 'Redirections' > output.out 2>> error.err +wc -l output.out error.err + +# Führe einen Befehl aus und gib dessen "file descriptor" (zB /dev/fd/123) aus +# siehe: man fd +echo <(echo "#helloworld") + +# Mehrere Arten, um output.out mit "#helloworld" zu überschreiben: +cat > output.out <(echo "#helloworld") +echo "#helloworld" > output.out +echo "#helloworld" | cat > output.out +echo "#helloworld" | tee output.out >/dev/null + +# Löschen der Hilfsdateien von oberhalb, mit Anzeige der Dateinamen +# (mit '-i' für "interactive" erfolgt für jede Date eine Rückfrage) +rm -v output.out error.err output-and-error.log + +# Die Ausgabe von Befehlen kann mit Hilfe von $( ) in anderen Befehlen verwendet weden:  # Der folgende Befehl zeigt die Anzahl aller Dateien und Unterverzeichnisse  # im aktuellen Verzeichnis an.  echo "Dieser Ordner beinhaltet $(ls | wc -l) Dateien und Verzeichnisse." +# Dasselbe kann man mit "backticks" `` erreichen, aber diese können +# nicht verschachtelt werden. $() ist die empfohlene Methode. +echo "Dieser Ordner beinhaltet `ls | wc -l` Dateien und Verzeichnisse." +  # Bash nutzt einen case-Ausdruck, der sich ähnlich wie switch in Java oder C++ verhält. -case "$VARIABLE" +case "$Variable"  in      # Liste der Fälle, die unterschieden werden sollen      0) echo "Hier ist eine Null." @@ -83,10 +178,106 @@ in      *) echo "Das ist nicht Null."  esac -# loops iterieren über die angegebene Zahl von Argumenten: -# Der Inhalt von $VARIABLE wird dreimal ausgedruckt. -for $VARIABLE in x y z +# 'for' Schleifen iterieren über die angegebene Zahl von Argumenten: +# Der Inhalt von $Variable wird dreimal ausgedruckt. +for $Variable in {1..3}  do -    echo "$VARIABLE" +    echo "$Variable"  done + +# Oder verwende die "traditionelle 'for'-Schleife": +for ((a=1; a <= 3; a++)) +do +    echo $a +done + +# Schleifen können auch mit Dateien arbeiten: +# 'cat' zeigt zuerst file1 an und dann file2 +for Variable in file1 file2 +do +    cat "$Variable" +done + +# .. oder mit der Ausgabe eines Befehls: +# Ausgabe des Inhalts jeder Datei, die von 'ls' aufgezählt wird +for Output in $(ls) +do +    cat "$Output" +done + +# while Schleife: +while [ true ] +do +    echo "Schleifenkörper..." +    break +done + +# Funktionen definieren +# Definition: +function foo () +{ +    echo "Argumente funktionieren wie bei skripts: $@" +    echo Und: $1 $2..." +    echo "Dies ist eine Funktion" +    return 0 +} + +# oder einfacher +bar () +{ +    echo "Auch so kann man Funktionen deklarieren!" +    return 0 +} + +# Aufruf der Funktion: +foo "My name is" $Name + +# Was du noch lernen könntest: +# Ausgabe der letzten 10 Zeilen von file.txt +tail -n 10 file.txt +# Ausgabe der ersten 10 Zeilen von file.txt +head -n 10 file.txt +# sortierte Ausgabe von file.txt +sort file.txt +# Mehrfachzeilen in sortierten Dateien unterdrücken +# oder (mit -d) nur diese ausgeben +uniq -d file.txt +# Ausgabe nur der ersten Spalte (vor dem ersten ',') +cut -d ',' -f 1 file.txt +# ersetze in file.txt jedes vorkommende 'gut' durch 'super' (versteht regex) +sed -i 's/gut/super/g' file.txt +# Ausgabe nach stdout aller Zeilen von file.txt, die auf eine regex passen +# Im Beispiel: Zeilen, die mit "foo" beginnen und mit "bar" enden +grep "^foo.*bar$" file.txt +# Mit der Option "-c" wird stattdessen die Anzahl der gefundenen Zeilen ausgegeben +grep -c "^foo.*bar$" file.txt +# verwende 'fgrep' oder 'grep -F' wenn du buchstäblich nach den Zeichen +# suchen willst, ohne sie als regex zu interpretieren +fgrep "^foo.*bar$" file.txt + +# Dokumentation über die in bash eingebauten Befehle +# bekommst du mit dem eingebauten Befehl 'help' +help +help help +help for +help return +help source +help . + +# Das bash-Handbuch liest du mit 'man' +apropos bash +man 1 bash +man bash + +# Dann gibt es noch das 'info' System (drücke ? um Hilfe angezeigt zu bekommen) +apropos info | grep '^info.*(' +man info +info info +info 5 info + +# info Dokumentation über bash: +info bash +info bash 'Bash Features' +info bash 6 +info --apropos bash  ``` diff --git a/de-de/git-de.html.markdown b/de-de/git-de.html.markdown index 43939129..dea329d5 100644 --- a/de-de/git-de.html.markdown +++ b/de-de/git-de.html.markdown @@ -18,12 +18,12 @@ Anmerkung des Übersetzers: Einige englische Begriffe wie *Repository*, *Commit*  ### Was ist Versionsverwaltung? -Eine Versionskontrolle erfasst die Änderungen einer Datei oder eines Verzeichnisses im Verlauf der Zeit. +Eine Versionsverwaltung erfasst die Änderungen einer Datei oder eines Verzeichnisses im Verlauf der Zeit.  ### Zentrale im Vergleich mit verteilter Versionverwaltung -* Zentrale Versionskontrolle konzentriert sich auf das Synchronisieren, Verfolgen und Sichern von Dateien. -* Verteilte Versionskontrolle konzentriert sich auf das Teilen der Änderungen. Jede Änderung hat eine eindeutige ID. +* Zentrale Versionsverwaltung konzentriert sich auf das Synchronisieren, Verfolgen und Sichern von Dateien. +* Verteilte Versionsverwaltung konzentriert sich auf das Teilen der Änderungen. Jede Änderung hat eine eindeutige ID.  * Verteilte Systeme haben keine vorbestimmte Struktur. Ein SVN-ähnliches, zentrales System wäre mit Git ebenso umsetzbar.  [Weiterführende Informationen](http://git-scm.com/book/en/Getting-Started-About-Version-Control) @@ -61,7 +61,7 @@ Der Index ist die die Staging-Area von Git. Es ist im Grunde eine Ebene, die Arb  ### Commit -Ein Commit ist ein Schnappschuss von Uderungen in deinem Arbeitsverzeichnis. Wenn du zum Beispiel 5 Dateien hinzugefügt und 2 andere entfernt hast, werden diese Änderungen im Commit (Schnappschuss) enthalten sein. Dieser Commit kann dann in andere Repositorys gepusht werden. Oder nicht! +Ein Commit ist ein Schnappschuss von Änderungen in deinem Arbeitsverzeichnis. Wenn du zum Beispiel 5 Dateien hinzugefügt und 2 andere entfernt hast, werden diese Änderungen im Commit (Schnappschuss) enthalten sein. Dieser Commit kann dann in andere Repositories gepusht werden. Oder nicht!  ### Branch @@ -69,7 +69,9 @@ Ein Branch, ein Ast oder Zweig, ist im Kern ein Pointer auf den letzten Commit,  ### HEAD und head (Teil des .git-Verzeichnisses) -HEAD ist ein Pointer auf den aktuellen Branch. Ein Repository hat nur einen *aktiven* HEAD. Ein head ist ein Pointer, der auf ein beliebige Zahl von heads zeigt. +HEAD ist ein Pointer auf den aktuellen Branch. Ein Repository hat nur einen *aktiven* HEAD.  + +Ein *head* ist ein Pointer, der auf einen beliebigen Commit zeigt.  Ein Repository kann eine beliebige Zahl von *heads* enthalten.  ### Konzeptionelle Hintergründe @@ -127,7 +129,7 @@ Zeigt die Unterschiede zwischen Index (im Grunde dein Arbeitsverzeichnis/-reposi  ```bash -# Zeigt den Branch, nicht-verfolgte Dateien, Uderungen und andere Unterschiede an +# Zeigt den Branch, nicht-verfolgte Dateien, Änderungen und andere Unterschiede an  $ git status  # Anderes Wissenswertes über git status anzeigen @@ -151,7 +153,7 @@ $ git add ./*.java  ### branch -Verwalte alle Branches. Du kannst sie mit diesem Befehl ansehen, bearbeiten, neue erschaffen oder löschen. +Verwalte alle Branches. Du kannst sie mit diesem Befehl ansehen, bearbeiten, neue erzeugen oder löschen.  ```bash  # Liste alle bestehenden Branches und Remotes auf @@ -186,7 +188,7 @@ $ git checkout -b newBranch  ### clone -Ein bestehendes Repository in ein neues Verzeichnis klonen oder kopieren. Es fügt außerdem für hedes geklonte Repo remote-tracking Branches hinzu. Du kannst auf diese Remote-Branches pushen. +Ein bestehendes Repository in ein neues Verzeichnis klonen oder kopieren. Es fügt außerdem für jedes geklonte Repository remote-tracking Branches hinzu. Du kannst auf diese Remote-Branches pushen.  ```bash  # Klone learnxinyminutes-docs @@ -288,16 +290,16 @@ $ git mv -f myFile existingFile  ### pull -Führe einen Pull, zieht alle Daten, eines Repositorys und f?? einen Merge mit einem anderen Branch durch. +Führe einen Pull (zieht alle Daten eines Repositories) aus und führt einen Merge mit einem anderen Branch durch.  ```bash -# Update deines lokalen Repos, indem ein Merge der neuen Uderungen -# von den remote-liegenden "origin"- und "master"-Branches durchgef?? wird. +# Update deines lokalen Repos, indem ein Merge der neuen Änderungen +# von den remote-liegenden "origin"- und "master"-Branches durchgeführt wird.  # git pull <remote> <branch>  # git pull => impliziter Verweis auf origin und master  $ git pull origin master -# F?? einen Merge von Uderungen eines remote-Branch und ein Rebase +# Führt einen Merge von Änderungen eines remote-Branch und ein Rebase  # des Branch-Commits im lokalen Repo durch. Wie: pull <remote> <branch>, git rebase <branch>"  $ git pull origin master --rebase  ``` @@ -337,8 +339,8 @@ $ git reset  # Setze die Staging-Area zurück, um dem letzten Commit zu entsprechen und überschreibe das Arbeitsverzeichnis  $ git reset --hard -# Bewegt die Spitze des Branches zu dem angegebenen Commit (das Verzeichnis bleibt unber??) -# Alle Uderungen bleiben im Verzeichnis erhalten +# Bewegt die Spitze des Branches zu dem angegebenen Commit (das Verzeichnis bleibt unberührt) +# Alle Änderungen bleiben im Verzeichnis erhalten  $ git reset 31f2bb1  # Bewegt die Spitze des Branches zurück zu dem angegebenen Commit diff --git a/de-de/go-de.html.markdown b/de-de/go-de.html.markdown index 7e61bf81..d3a192fe 100644 --- a/de-de/go-de.html.markdown +++ b/de-de/go-de.html.markdown @@ -25,7 +25,7 @@ aktive Community.     zeiliger Kommentar */  // Eine jede Quelldatei beginnt mit einer Paket-Klausel. -// "main" ist ein besonderer Pkaetname, da er ein ausführbares Programm +// "main" ist ein besonderer Paketname, da er ein ausführbares Programm  // einleitet, im Gegensatz zu jedem anderen Namen, der eine Bibliothek  // deklariert.  package main @@ -38,7 +38,7 @@ import (      "strconv"  // Zeichenkettenmanipulation  ) -// Es folgt die Definition einer Funktions, in diesem Fall von "main". Auch hier +// Es folgt die Definition einer Funktion, in diesem Fall von "main". Auch hier  // ist der Name wieder besonders. "main" markiert den Eintrittspunkt des  // Programms. Vergessen Sie nicht die geschweiften Klammern!  func main() { @@ -56,7 +56,7 @@ func beyondHello() {      var x int // Deklaration einer Variable, muss vor Gebrauch geschehen.      x = 3     // Zuweisung eines Werts.      // Kurze Deklaration: Benutzen Sie ":=", um die Typisierung automatisch zu -    // folgern, die Variable zu deklarieren und ihr einen Wert zu zuweisen. +    // folgern, die Variable zu deklarieren und ihr einen Wert zuzuweisen.      y := 4      // Eine Funktion mit mehreren Rückgabewerten. @@ -147,7 +147,7 @@ func learnFlowControl() {      if false {          // nicht hier      } else { -        // sonder hier! spielt die Musik +        // sondern hier! spielt die Musik      }      // Benutzen Sie ein "switch" Statement anstatt eine Anreihung von if-s @@ -166,7 +166,7 @@ func learnFlowControl() {      // Ab hier gilt wieder: x == 1      // For ist die einzige Schleifenform in Go, sie hat aber mehrere Formen: -    for { // Endloschleife +    for { // Endlosschleife          break    // nur ein Spaß          continue // wird nie ausgeführt      } @@ -263,10 +263,10 @@ func learnConcurrency() {      // Auslesen und dann Ausgeben der drei berechneten Werte.      // Man kann nicht im voraus feststellen in welcher Reihenfolge die Werte      // ankommen. -    fmt.Println(<-c, <-c, <-c) // mit dem Kannal rechts ist <- der Empfangs-Operator +    fmt.Println(<-c, <-c, <-c) // mit dem Kanal rechts ist <- der Empfangs-Operator -    cs := make(chan string)       // ein weiterer Kannal, diesmal für strings -    cc := make(chan chan string)  // ein Kannal für string Kannäle +    cs := make(chan string)       // ein weiterer Kanal, diesmal für strings +    cc := make(chan chan string)  // ein Kanal für string Kanäle      // Start einer neuen Goroutine, nur um einen Wert zu senden      go func() { c <- 84 }() @@ -283,7 +283,7 @@ func learnConcurrency() {          fmt.Println("wird nicht passieren.")      }      // Hier wird eine der beiden Goroutines fertig sein, die andere nicht. -    // Sie wird warten bis der Wert den sie sendet von dem Kannal gelesen wird. +    // Sie wird warten bis der Wert den sie sendet von dem Kanal gelesen wird.      learnWebProgramming() // Go kann es und Sie hoffentlich auch bald.  } @@ -301,7 +301,7 @@ func learnWebProgramming() {  // Methode implementieren: ServeHTTP  func (p pair) ServeHTTP(w http.ResponseWriter, r *http.Request) {      // Senden von Daten mit einer Methode des http.ResponseWriter -    w.Write([]byte("Sie habe Go in Y Minuten gelernt!")) +    w.Write([]byte("Sie haben Go in Y Minuten gelernt!"))  }  ``` diff --git a/edn.html.markdown b/edn.html.markdown new file mode 100644 index 00000000..655c20f1 --- /dev/null +++ b/edn.html.markdown @@ -0,0 +1,108 @@ +--- +language: edn +filename: learnedn.edn +contributors: +  - ["Jason Yeo", "https://github.com/jsyeo"] +--- + +Extensible Data Notation or EDN for short is a format for serializing data. + +The notation is used internally by Clojure to represent programs and it also +used as a data transfer format like JSON. Though it is more commonly used in +Clojure land, there are implementations of EDN for many other languages. + +The main benefit of EDN over JSON and YAML is that it is extensible, which we +will see how it is extended later on. + +```Clojure +; Comments start with a semicolon. +; Anythng after the semicolon is ignored. + +;;;;;;;;;;;;;;;;;;; +;;; Basic Types ;;; +;;;;;;;;;;;;;;;;;;; + +nil         ; also known in other languages as null + +; Booleans +true +false + +; Strings are enclosed in double quotes +"hungarian breakfast" +"farmer's cheesy omelette" + +; Characters are preceeded by backslashes +\g \r \a \c \e + +; Keywords start with a colon. They behave like enums. Kind of +; like symbols in Ruby. +:eggs +:cheese +:olives + +; Symbols are used to represent identifiers. They start with #. +; You can namespace symbols by using /. Whatever preceeds / is +; the namespace of the name. +#spoon +#kitchen/spoon ; not the same as #spoon +#kitchen/fork +#github/fork   ; you can't eat with this + +; Integers and floats +42 +3.14159 + +; Lists are sequences of values +(:bun :beef-patty 9 "yum!") + +; Vectors allow random access +[:gelato 1 2 -2] + +; Maps are associative data structures that associates the key with its value +{:eggs        2 + :lemon-juice 3.5 + :butter      1} + +; You're not restricted to using keywords as keys +{[1 2 3 4] "tell the people what she wore", + [5 6 7 8] "the more you see the more you hate"} + +; You may use commas for readability. They are treated as whitespaces. + +; Sets are collections that contain unique elements. +#{:a :b 88 "huat"} + +;;;;;;;;;;;;;;;;;;;;;;; +;;; Tagged Elements ;;; +;;;;;;;;;;;;;;;;;;;;;;; + +; EDN can be extended by tagging elements with # symbols. + +#MyYelpClone/MenuItem {:name "eggs-benedict" :rating 10} + +; Let me explain this with a clojure example. Suppose I want to transform that +; piece of edn into a MenuItem record. + +(defrecord MenuItem [name rating]) + +; To transform edn to clojure values, I will need to use the built in EDN +; reader, edn/read-string + +(edn/read-string "{:eggs 2 :butter 1 :flour 5}") +; -> {:eggs 2 :butter 1 :flour 5} + +; To transform tagged elements, define the reader function and pass a map +; that maps tags to reader functions to edn/read-string like so + +(edn/read-string {:readers {'MyYelpClone/MenuItem map->menu-item}} +                 "#MyYelpClone/MenuItem {:name \"eggs-benedict\" :rating 10}") +; -> #user.MenuItem{:name "eggs-benedict", :rating 10} + +``` + +# References + +- [EDN spec](https://github.com/edn-format/edn) +- [Implementations](https://github.com/edn-format/edn/wiki/Implementations) +- [Tagged Elements](http://www.compoundtheory.com/clojure-edn-walkthrough/) diff --git a/es-es/markdown-es.html.markdown b/es-es/markdown-es.html.markdown index d90e3eb5..bc481df7 100644 --- a/es-es/markdown-es.html.markdown +++ b/es-es/markdown-es.html.markdown @@ -11,7 +11,7 @@ lang: es-es  Markdown fue creado por John Gruber en 2004. Su propósito es ser una sintaxis fácil de leer y escribir que se convierta  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! +¡Denme toda la retroalimentación que quieran! / ¡Sientanse en la libertad de hacer forks o pull requests!  ```markdown @@ -44,7 +44,7 @@ Esto es un h2  -------------  <!-- Estilos para texto plano --> -<!-- El texto puede ser fácilmente estilizaedo con italicas, negritas o tachado  +<!-- El texto puede ser fácilmente estilizado con italicas, negritas o tachado   usando markdown -->  *Este texto está en itálicas.* @@ -62,7 +62,7 @@ Markdown en Github, también tenemos: -->  ~~Este texto está tachado.~~ -<!-- Los párrafos son una o múltuples líneas de texto adyacentes separadas por  +<!-- Los párrafos son una o múltiples líneas de texto adyacentes separadas por   una o múltiples líneas en blanco-->  Este es un párrafo. Estoy escribiendo un párrafo, ¿No es divertido? diff --git a/fa-ir/brainfuck.html.markdown b/fa-ir/brainfuck-fa.html.markdown index ef2bcba3..ef2bcba3 100644 --- a/fa-ir/brainfuck.html.markdown +++ b/fa-ir/brainfuck-fa.html.markdown diff --git a/fa-ir/javascript.html.markdown b/fa-ir/javascript-fa.html.markdown index fe3555af..fe3555af 100644 --- a/fa-ir/javascript.html.markdown +++ b/fa-ir/javascript-fa.html.markdown diff --git a/fr-fr/livescript-fr.html.markdown b/fr-fr/livescript-fr.html.markdown index 9c3b8003..13bbffe5 100644 --- a/fr-fr/livescript-fr.html.markdown +++ b/fr-fr/livescript-fr.html.markdown @@ -4,7 +4,7 @@ filename: learnLivescript-fr.ls  contributors:      - ["Christina Whyte", "http://github.com/kurisuwhyte/"]  translators: -    - ["Morgan Bohn", "https://github.com/morganbohn"] +    - ["Morgan Bohn", "https://github.com/dotmobo"]  lang: fr-fr  --- diff --git a/fr-fr/python-fr.html.markdown b/fr-fr/python-fr.html.markdown index 3f6dcabb..d78291be 100644 --- a/fr-fr/python-fr.html.markdown +++ b/fr-fr/python-fr.html.markdown @@ -14,8 +14,7 @@ Je suis tombé amoureux de Python de par la clarté de sa syntaxe. C'est pratiqu  Vos retours sont grandement appréciés. Vous pouvez me contacter sur Twitter [@louiedinh](http://twitter.com/louiedinh) ou par e-mail: louiedinh [at] [google's email service] -NB: Cet artice s'applique spécifiquement à Python 2.7, mais devrait s'appliquer pour toute version Python 2.x -Vous pourrez bientôt trouver un article pour Python 3 en Français. Pour le moment vous pouvez jettez un coup d'oeil à l'article [Python 3 en Anglais](http://learnxinyminutes.com/docs/python3/). +N.B. : Cet article s'applique spécifiquement à Python 2.7, mais devrait s'appliquer pour toute version Python 2.x. Python 2.7 est en fin de vie et ne sera plus maintenu à partir de 2020, il est donc recommandé d'apprendre Python avec Python 3. Pour Python 3.x, il existe un autre [tutoriel pour Python 3](http://learnxinyminutes.com/docs/fr-fr/python3-fr/).  ```python  # Une ligne simple de commentaire commence par un dièse diff --git a/fsharp.html.markdown b/fsharp.html.markdown index 76318d7d..b5c47ed7 100644 --- a/fsharp.html.markdown +++ b/fsharp.html.markdown @@ -248,7 +248,7 @@ module SequenceExamples =      // sequences can use yield and      // can contain subsequences      let strange = seq { -        // "yield! adds one element +        // "yield" adds one element          yield 1; yield 2;          // "yield!" adds a whole subsequence @@ -297,7 +297,7 @@ module DataTypeExamples =      let person1 = {First="John"; Last="Doe"}      // Pattern match to unpack -    let {First=first} = person1    //sets first="john" +    let {First=first} = person1    //sets first="John"      // ------------------------------------      // Union types (aka variants) have a set of choices @@ -426,7 +426,7 @@ module ActivePatternExamples =      // -----------------------------------      // You can create partial matching patterns as well -    // Just use undercore in the defintion, and return Some if matched. +    // Just use underscore in the defintion, and return Some if matched.      let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None      let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None diff --git a/go.html.markdown b/go.html.markdown index a857a76c..dc684227 100644 --- a/go.html.markdown +++ b/go.html.markdown @@ -108,12 +108,13 @@ can include line breaks.` // Same string type.  	bs := []byte("a slice") // Type conversion syntax.  	// Because they are dynamic, slices can be appended to on-demand. -	// To append elements to a slice, built-in append() function is used. +	// To append elements to a slice, the built-in append() function is used.  	// First argument is a slice to which we are appending. Commonly,  	// the array variable is updated in place, as in example below.  	s := []int{1, 2, 3}		// Result is a slice of length 3.  	s = append(s, 4, 5, 6)	// Added 3 elements. Slice now has length of 6.  	fmt.Println(s) // Updated slice is now [1 2 3 4 5 6] +  	// To append another slice, instead of list of atomic elements we can  	// pass a reference to a slice or a slice literal like this, with a  	// trailing ellipsis, meaning take a slice and unpack its elements, diff --git a/haskell.html.markdown b/haskell.html.markdown index 369b1b20..08611e63 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -195,11 +195,11 @@ foo 5 -- 15  -- function composition  -- the (.) function chains functions together.  -- For example, here foo is a function that takes a value. It adds 10 to it, --- multiplies the result of that by 5, and then returns the final value. -foo = (*5) . (+10) +-- multiplies the result of that by 4, and then returns the final value. +foo = (*4) . (+10) --- (5 + 10) * 5 = 75 -foo 5 -- 75 +-- (5 + 10) * 4 = 60 +foo 5 -- 60  -- fixing precedence  -- Haskell has another operator called `$`. This operator applies a function  diff --git a/hu-hu/go.html.markdown b/hu-hu/go-hu.html.markdown index 638c9489..638c9489 100644 --- a/hu-hu/go.html.markdown +++ b/hu-hu/go-hu.html.markdown diff --git a/hu-hu/ruby.html.markdown b/hu-hu/ruby-hu.html.markdown index 169f2b8e..169f2b8e 100644 --- a/hu-hu/ruby.html.markdown +++ b/hu-hu/ruby-hu.html.markdown diff --git a/id-id/xml-id.html.markdown b/id-id/xml-id.html.markdown index c1e985aa..8b8d72ae 100644 --- a/id-id/xml-id.html.markdown +++ b/id-id/xml-id.html.markdown @@ -1,6 +1,6 @@  ---  language: xml -filename: learnxml.xml +filename: learnxml-id.xml  contributors:    - ["João Farias", "https://github.com/JoaoGFarias"]  translators: diff --git a/java.html.markdown b/java.html.markdown index 38c9e490..4f5cde38 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -186,9 +186,9 @@ public class LearnJava {          //               operations perform as could be expected for a          //               doubly-linked list.          // Maps - A set of objects that map keys to values. Map is -	//        an interface and therefore cannot be instantiated. -	//        The type of keys and values contained in a Map must -	//        be specified upon instantiation of the implementing +        //        an interface and therefore cannot be instantiated. +        //        The type of keys and values contained in a Map must +        //        be specified upon instantiation of the implementing          //        class. Each key may map to only one corresponding value,          //        and each key may appear only once (no duplicates).          // HashMaps - This class uses a hashtable to implement the Map @@ -450,6 +450,17 @@ class Bicycle {      protected int gear; // Protected: Accessible from the class and subclasses      String name; // default: Only accessible from within this package +    static String className; // Static class variable + +    // Static block  +    // Java has no implementation of static constructors, but +    // has a static block that can be used to initialize class variables  +    // (static variables).  +    // This block will be called when the class is loaded. +    static { +        className = "Bicycle"; +    } +      // Constructors are a way of creating classes      // This is a constructor      public Bicycle() { @@ -709,7 +720,7 @@ The links provided here below are just to get an understanding of the topic, fee  * [Generics](http://docs.oracle.com/javase/tutorial/java/generics/index.html) -* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html) +* [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconvtoc-136057.html)  **Online Practice and Tutorials** diff --git a/javascript.html.markdown b/javascript.html.markdown index a119be88..e285ca4e 100644 --- a/javascript.html.markdown +++ b/javascript.html.markdown @@ -16,13 +16,14 @@ JavaScript isn't just limited to web browsers, though: Node.js, a project that  provides a standalone runtime for Google Chrome's V8 JavaScript engine, is  becoming more and more popular. -Feedback would be highly appreciated! You can reach me at -[@adambrenecki](https://twitter.com/adambrenecki), or -[adam@brenecki.id.au](mailto:adam@brenecki.id.au). +JavaScript has a C-like syntax, so if you've used languages like C or Java, +a lot of the basic syntax will already be familiar. Despite this, and despite +the similarity in name, JavaScript's object model is significantly different to +Java's.  ```js -// Comments are like C. Single-line comments start with two slashes, -/* and multiline comments start with slash-star +// Single-line comments start with two slashes. +/* Multiline comments start with slash-star,     and end with star-slash */  // Statements can be terminated by ; @@ -40,7 +41,7 @@ doStuff()  // JavaScript has one number type (which is a 64-bit IEEE 754 double).  // Doubles have a 52-bit mantissa, which is enough to store integers -//    up to about 9✕10¹⁵ precisely. +// up to about 9✕10¹⁵ precisely.  3; // = 3  1.5; // = 1.5 @@ -100,6 +101,10 @@ false;  // Strings are concatenated with +  "Hello " + "world!"; // = "Hello world!" +// ... which works with more than just strings +"1, 2, " + 3; // = "1, 2, 3" +"Hello " + ["world", "!"] // = "Hello world,!" +  // and are compared with < and >  "a" < "b"; // = true @@ -140,7 +145,7 @@ undefined; // used to indicate a value is not currently present (although  // character.  var someVar = 5; -// if you leave the var keyword off, you won't get an error... +// If you leave the var keyword off, you won't get an error...  someOtherVar = 10;  // ...but your variable will be created in the global scope, not in the scope @@ -149,7 +154,7 @@ someOtherVar = 10;  // Variables declared without being assigned to are set to undefined.  var someThirdVar; // = undefined -// if you wan't to declare a couple of variables, then you could use a comma  +// If you want to declare a couple of variables, then you could use a comma  // separator  var someFourthVar = 2, someFifthVar = 4; @@ -198,8 +203,6 @@ myObj.myFourthKey; // = undefined  ///////////////////////////////////  // 3. Logic and Control Structures -// The syntax for this section is almost identical to Java's. -  // The `if` structure works as you'd expect.  var count = 1;  if (count == 3){ @@ -227,15 +230,15 @@ for (var i = 0; i < 5; i++){      // will run 5 times  } -//The For/In statement loops iterates over every property across the entire prototype chain +// The for/in statement iterates over every property across the entire prototype chain.  var description = "";  var person = {fname:"Paul", lname:"Ken", age:18};  for (var x in person){      description += person[x] + " ";  } -//If only want to consider properties attached to the object itself, -//and not its prototypes use hasOwnProperty() check +// To only consider properties attached to the object itself +// and not its prototypes, use the `hasOwnProperty()` check.  var description = "";  var person = {fname:"Paul", lname:"Ken", age:18};  for (var x in person){ @@ -244,8 +247,9 @@ for (var x in person){      }  } -//for/in should not be used to iterate over an Array where the index order is important. -//There is no guarantee that for/in will return the indexes in any particular order +// For/in should not be used to iterate over an Array where the index order +// is important, as there is no guarantee that for/in will return the indexes +// in any particular order.  // && is logical and, || is logical or  if (house.size == "big" && house.colour == "blue"){ @@ -260,7 +264,7 @@ var name = otherName || "default";  // The `switch` statement checks for equality with `===`. -// use 'break' after each case +// Use 'break' after each case  // or the cases after the correct one will be executed too.  grade = 'B';  switch (grade) { @@ -507,6 +511,10 @@ myNumber === myNumberObj; // = false  if (0){      // This code won't execute, because 0 is falsy.  } +if (new Number(0)){ +   // This code will execute, because wrapped numbers are objects, and objects +   // are always truthy. +}  // However, the wrapper objects and the regular builtins share a prototype, so  // you can actually add functionality to a string, for instance. @@ -534,28 +542,39 @@ if (Object.create === undefined){ // don't overwrite it if it exists  ## Further Reading -The [Mozilla Developer -Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) provides -excellent documentation for JavaScript as it's used in browsers. Plus, it's a -wiki, so as you learn more you can help others out by sharing your own -knowledge. +The [Mozilla Developer Network][1] provides excellent documentation for +JavaScript as it's used in browsers. Plus, it's a wiki, so as you learn more you +can help others out by sharing your own knowledge. + +MDN's [A re-introduction to JavaScript][2] covers much of the concepts covered +here in more detail. This guide has quite deliberately only covered the +JavaScript language itself; if you want to learn more about how to use +JavaScript in web pages, start by learning about the [Document Object Model][3]. + +[Learn Javascript by Example and with Challenges][4] is a variant of this +reference with built-in challenges. + +[JavaScript Garden][5] is an in-depth guide of all the counter-intuitive parts +of the language. + +[JavaScript: The Definitive Guide][6] is a classic guide and reference book. + +[Eloquent Javascript][8] by Marijn Haverbeke is an excellent JS book/ebook with attached terminal -MDN's [A re-introduction to -JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) -covers much of the concepts covered here in more detail. This guide has quite -deliberately only covered the JavaScript language itself; if you want to learn -more about how to use JavaScript in web pages, start by learning about the -[Document Object -Model](https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core) +[Javascript: The Right Way][9] is a guide intended to introduce new developers to JavaScript and help experienced developers learn more about its best practices. -[Learn Javascript by Example and with Challenges](http://www.learneroo.com/modules/64/nodes/350) is a variant of this reference with built-in challenges. -[JavaScript Garden](http://bonsaiden.github.io/JavaScript-Garden/) is an in-depth -guide of all the counter-intuitive parts of the language. +In addition to direct contributors to this article, some content is adapted from +Louie Dinh's Python tutorial on this site, and the [JS Tutorial][7] on the +Mozilla Developer Network. -[JavaScript: The Definitive Guide](http://www.amazon.com/gp/product/0596805527/) is a classic guide / reference book. -In addition to direct contributors to this article, some content is adapted -from Louie Dinh's Python tutorial on this site, and the [JS -Tutorial](https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript) -on the Mozilla Developer Network. +[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript +[2]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript +[3]: https://developer.mozilla.org/en-US/docs/Using_the_W3C_DOM_Level_1_Core +[4]: http://www.learneroo.com/modules/64/nodes/350 +[5]: http://bonsaiden.github.io/JavaScript-Garden/ +[6]: http://www.amazon.com/gp/product/0596805527/ +[7]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript +[8]: http://eloquentjavascript.net/ +[9]: http://jstherightway.org/ diff --git a/latex.html.markdown b/latex.html.markdown index 9b7b4feb..31231a70 100644 --- a/latex.html.markdown +++ b/latex.html.markdown @@ -106,6 +106,9 @@ Here's how you state all y that belong to X, $\forall$ x $\in$ X. \\  % However, the math symbols only exist in math-mode.   % We can enter math-mode from text mode with the $ signs.  % The opposite also holds true. Variable can also be rendered in math-mode. +% We can also enter math mode with \[\] + +\[a^2 + b^2 = c^2 \]  My favorite Greek letter is $\xi$. I also like $\beta$, $\gamma$ and $\sigma$.  I haven't found a Greek letter that yet that LaTeX doesn't know about! diff --git a/lua.html.markdown b/lua.html.markdown index 0809215f..3d95c146 100644 --- a/lua.html.markdown +++ b/lua.html.markdown @@ -190,7 +190,7 @@ end  --------------------------------------------------------------------------------  -- A table can have a metatable that gives the table operator-overloadish --- behavior. Later we'll see how metatables support js-prototypey behavior. +-- behavior. Later we'll see how metatables support js-prototypey behaviour.  f1 = {a = 1, b = 2}  -- Represents the fraction a/b.  f2 = {a = 2, b = 3} diff --git a/matlab.html.markdown b/matlab.html.markdown index 4d97834c..ad42d9a9 100644 --- a/matlab.html.markdown +++ b/matlab.html.markdown @@ -262,7 +262,7 @@ pcolor(A) % Heat-map of matrix: plot as grid of rectangles, coloured by value  contour(A) % Contour plot of matrix  mesh(A) % Plot as a mesh surface -h = figure	% Create new figure object, with handle h +h = figure % Create new figure object, with handle h  figure(h) % Makes the figure corresponding to handle h the current figure  close(h) % close figure with handle h  close all % close all open figure windows @@ -460,7 +460,7 @@ length  % length of a vector  sort    % sort in ascending order  sum     % sum of elements  prod    % product of elements -mode	% modal value +mode    % modal value  median  % median value  mean    % mean value  std     % standard deviation diff --git a/ms-my/coffeescript-my.html.markdown b/ms-my/coffeescript-my.html.markdown new file mode 100644 index 00000000..9820a561 --- /dev/null +++ b/ms-my/coffeescript-my.html.markdown @@ -0,0 +1,105 @@ +--- +language: coffeescript +contributors: +  - ["Tenor Biel", "http://github.com/L8D"] +  - ["Xavier Yao", "http://github.com/xavieryao"] +filename: coffeescript-ms.coffee +translators: +    - ["hack1m", "https://github.com/hack1m"] +lang: ms-my +--- + +CoffeeScript adalah bahasa kecil yang menyusun/kompil satu-per-satu menjadi setara JavaScript, dan tidak ada interpretasi di runtime. +Sebagai salah satu pengganti kepada JavaScript, CoffeeScript mencuba yang terbaik untuk output kod JavaScript yang mudah dibaca, cantik-dicetak dan berfungsi lancar, yang mana berfungsi baik pada setiap runtime JavaScript. + +Lihat juga [Laman sesawang CoffeeScript](http://coffeescript.org/), yang mana ada tutorial lengkap untuk CoffeeScript. + +```coffeescript +# CoffeeScript adalah bahasa hipster. +# Ia beredar mengikut trend kebanyakkan bahasa moden. +# Jadi komen sama seperti Ruby dan Python, ia menggunakan simbol nombor. + +### +Blok komen seperti ini, dan ia terjemah terus ke '/ *'s dan '* /'s +untuk keputusan kod JavaScript. + +Sebelum meneruskan anda perlu faham kebanyakkan daripada +JavaScript adalah semantik. +### + +# Menetapkan: +number   = 42 #=> var number = 42; +opposite = true #=> var opposite = true; + +# Bersyarat: +number = -42 if opposite #=> if(opposite) { number = -42; } + +# Fungsi: +square = (x) -> x * x #=> var square = function(x) { return x * x; } + +fill = (container, liquid = "coffee") -> +  "Filling the #{container} with #{liquid}..." +#=>var fill; +# +#fill = function(container, liquid) { +#  if (liquid == null) { +#    liquid = "coffee"; +#  } +#  return "Filling the " + container + " with " + liquid + "..."; +#}; + +# Julat: +list = [1..5] #=> var list = [1, 2, 3, 4, 5]; + +# Objek: +math = +  root:   Math.sqrt +  square: square +  cube:   (x) -> x * square x +#=> var math = { +#    "root": Math.sqrt, +#    "square": square, +#    "cube": function(x) { return x * square(x); } +#   }; + +# Splats: +race = (winner, runners...) -> +  print winner, runners +#=>race = function() { +#    var runners, winner; +#    winner = arguments[0], runners = 2 <= arguments.length ? __slice.call(arguments, 1) : []; +#    return print(winner, runners); +#  }; + +# Kewujudan: +alert "I knew it!" if elvis? +#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); } + +# Pemahaman array: +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); +#  } +#} +``` + +## Sumber tambahan + +- [Smooth CoffeeScript](http://autotelicum.github.io/Smooth-CoffeeScript/) +- [CoffeeScript Ristretto](https://leanpub.com/coffeescript-ristretto/read) diff --git a/php.html.markdown b/php.html.markdown index cf9544b3..0504ced2 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -733,7 +733,7 @@ $cls = new SomeOtherNamespace\MyClass();  /**********************  * Late Static Binding  * -* / +*/  class ParentClass {      public static function who() { diff --git a/python.html.markdown b/python.html.markdown index ff4471e9..541bd36d 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -15,8 +15,8 @@ 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. Python 2.7 is reachong end of life and will stop beeign maintained in 2020, -it is though recommended to start learnign Python with Python 3. +to Python 2.x. Python 2.7 is reaching end of life and will stop being maintained in 2020, +it is though recommended to start learning Python with Python 3.  For Python 3.x, take a look at the [Python 3 tutorial](http://learnxinyminutes.com/docs/python3/).  It is also possible to write Python code which is compatible with Python 2.7 and 3.x at the same time, diff --git a/r.html.markdown b/r.html.markdown index 8896c5b0..8539b10e 100644 --- a/r.html.markdown +++ b/r.html.markdown @@ -3,6 +3,7 @@ language: R  contributors:      - ["e99n09", "http://github.com/e99n09"]      - ["isomorphismes", "http://twitter.com/isomorphisms"] +    - ["kalinn", "http://github.com/kalinn"]  filename: learnr.r  --- @@ -197,6 +198,14 @@ class(NaN) # "numeric"  # You can do arithmetic on two vectors with length greater than 1,  # so long as the larger vector's length is an integer multiple of the smaller  c(1,2,3) + c(1,2,3) # 2 4 6 +# Since a single number is a vector of length one, scalars are applied  +# elementwise to vectors +(4 * c(1,2,3) - 2) / 2 # 1 3 5 +# Except for scalars, use caution when performing arithmetic on vectors with  +# different lengths. Although it can be done,  +c(1,2,3,1,2,3) * c(1,2) # 1 4 3 2 2 6 +# Matching lengths is better practice and easier to read +c(1,2,3,1,2,3) * c(1,2,1,2,1,2)   # CHARACTERS  # There's no difference between strings and characters in R @@ -235,6 +244,9 @@ class(NA)	# "logical"  TRUE | FALSE	# TRUE  # AND  TRUE & FALSE	# FALSE +# Applying | and & to vectors returns elementwise logic operations +c(TRUE,FALSE,FALSE) | c(FALSE,TRUE,FALSE) # TRUE TRUE FALSE +c(TRUE,FALSE,TRUE) & c(FALSE,TRUE,TRUE) # FALSE FALSE TRUE  # You can test if x is TRUE  isTRUE(TRUE)	# TRUE  # Here we get a logical vector with many elements: @@ -665,15 +677,101 @@ write.csv(pets, "pets2.csv") # to make a new .csv file  ######################### +# Statistical Analysis +######################### + +# Linear regression! +linearModel <- lm(price  ~ time, data = list1) +linearModel # outputs result of regression +# => +# Call: +# lm(formula = price ~ time, data = list1) +#  +# Coefficients: +# (Intercept)         time   +#      0.1453       0.4943   +summary(linearModel) # more verbose output from the regression +# => +# Call: +# lm(formula = price ~ time, data = list1) +# +# Residuals: +#     Min      1Q  Median      3Q     Max  +# -8.3134 -3.0131 -0.3606  2.8016 10.3992  +# +# Coefficients: +#             Estimate Std. Error t value Pr(>|t|)     +# (Intercept)  0.14527    1.50084   0.097    0.923     +# time         0.49435    0.06379   7.749 2.44e-09 *** +# --- +# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 +# +# Residual standard error: 4.657 on 38 degrees of freedom +# Multiple R-squared:  0.6124,	Adjusted R-squared:  0.6022  +# F-statistic: 60.05 on 1 and 38 DF,  p-value: 2.44e-09 +coef(linearModel) # extract estimated parameters +# => +# (Intercept)        time  +#   0.1452662   0.4943490  +summary(linearModel)$coefficients # another way to extract results +# => +#              Estimate Std. Error    t value     Pr(>|t|) +# (Intercept) 0.1452662 1.50084246 0.09678975 9.234021e-01 +# time        0.4943490 0.06379348 7.74920901 2.440008e-09 +summary(linearModel)$coefficients[,4] # the p-values  +# => +#  (Intercept)         time  +# 9.234021e-01 2.440008e-09  + +# GENERAL LINEAR MODELS +# Logistic regression +set.seed(1) +list1$success = rbinom(length(list1$time), 1, .5) # random binary +glModel <- glm(success  ~ time, data = list1,  +	family=binomial(link="logit")) +glModel # outputs result of logistic regression +# => +# Call:  glm(formula = success ~ time,  +#	family = binomial(link = "logit"), data = list1) +# +# Coefficients: +# (Intercept)         time   +#     0.17018     -0.01321   +#  +# Degrees of Freedom: 39 Total (i.e. Null);  38 Residual +# Null Deviance:	    55.35  +# Residual Deviance: 55.12 	 AIC: 59.12 +summary(glModel) # more verbose output from the regression +# => +# Call: +# glm(formula = success ~ time,  +#	family = binomial(link = "logit"), data = list1) + +# Deviance Residuals:  +#    Min      1Q  Median      3Q     Max   +# -1.245  -1.118  -1.035   1.202   1.327   +#  +# Coefficients: +#             Estimate Std. Error z value Pr(>|z|) +# (Intercept)  0.17018    0.64621   0.263    0.792 +# time        -0.01321    0.02757  -0.479    0.632 +#  +# (Dispersion parameter for binomial family taken to be 1) +# +#     Null deviance: 55.352  on 39  degrees of freedom +# Residual deviance: 55.121  on 38  degrees of freedom +# AIC: 59.121 +#  +# Number of Fisher Scoring iterations: 3 + + +#########################  # Plots  #########################  # BUILT-IN PLOTTING FUNCTIONS  # Scatterplots!  plot(list1$time, list1$price, main = "fake data") -# Regressions! -linearModel <- lm(price  ~ time, data = list1) -linearModel # outputs result of regression  # Plot regression line on existing plot  abline(linearModel, col = "red")  # Get a variety of nice diagnostics diff --git a/scala.html.markdown b/scala.html.markdown index 7f545196..192e03d7 100644 --- a/scala.html.markdown +++ b/scala.html.markdown @@ -278,21 +278,21 @@ val text = if (x == 10) "yeah" else "nope"  /////////////////////////////////////////////////  val a = Array(1, 2, 3, 5, 8, 13) -a(0) -a(3) +a(0)     // Int = 1 +a(3)     // Int = 5  a(21)    // Throws an exception  val m = Map("fork" -> "tenedor", "spoon" -> "cuchara", "knife" -> "cuchillo") -m("fork") -m("spoon") +m("fork")         // java.lang.String = tenedor +m("spoon")        // java.lang.String = cuchara  m("bottle")       // Throws an exception  val safeM = m.withDefaultValue("no lo se") -safeM("bottle") +safeM("bottle")   // java.lang.String = no lo se  val s = Set(1, 3, 7) -s(0) -s(1) +s(0)      // Boolean = false +s(1)      // Boolean = true  /* Look up the documentation of map here -   * http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map @@ -313,15 +313,16 @@ s(1)  // 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 +// The function divideInts gives you the result and the remainder +divideInts(10, 3)    // (Int, Int) = (3,1)  // To access the elements of a tuple, use _._n where n is the 1-based index of  // the element -val d = divideInts(10, 3) +val d = divideInts(10, 3)    // (Int, Int) = (3,1) -d._1 +d._1    // Int = 3 -d._2 +d._2    // Int = 1  ///////////////////////////////////////////////// diff --git a/ta_in/css.html.markdown b/ta_in/css-ta.html.markdown index 56f94ed0..56f94ed0 100644 --- a/ta_in/css.html.markdown +++ b/ta_in/css-ta.html.markdown diff --git a/ta_in/javascript.html.markdown b/ta_in/javascript-ta.html.markdown index f0b0a36a..f0b0a36a 100644 --- a/ta_in/javascript.html.markdown +++ b/ta_in/javascript-ta.html.markdown diff --git a/ta_in/json.html.markdown b/ta_in/json-ta.html.markdown index d85e0d82..d85e0d82 100644 --- a/ta_in/json.html.markdown +++ b/ta_in/json-ta.html.markdown diff --git a/ta_in/xml.html.markdown b/ta_in/xml-ta.html.markdown index a9bfa9cd..a9bfa9cd 100644 --- a/ta_in/xml.html.markdown +++ b/ta_in/xml-ta.html.markdown diff --git a/zh-cn/haskell-cn.html.markdown b/zh-cn/haskell-cn.html.markdown index 8904970f..b0b1183f 100644 --- a/zh-cn/haskell-cn.html.markdown +++ b/zh-cn/haskell-cn.html.markdown @@ -200,13 +200,13 @@ foo 5 -- 75  -- 你可以使用 `$` 来移除多余的括号。  -- 修改前 -(even (fib 7)) -- true +(even (fib 7)) -- False  -- 修改后 -even . fib $ 7 -- true +even . fib $ 7 -- False  -- 等价地 -even $ fib 7 -- true +even $ fib 7 -- False  ----------------------------------------------------  -- 5. 类型声明 diff --git a/zh-cn/java-cn.html.markdown b/zh-cn/java-cn.html.markdown index 12afa59a..a8fd2a4c 100644 --- a/zh-cn/java-cn.html.markdown +++ b/zh-cn/java-cn.html.markdown @@ -405,4 +405,4 @@ class PennyFarthing extends Bicycle {  * [泛型](http://docs.oracle.com/javase/tutorial/java/generics/index.html) -* [Java代码规范](http://www.oracle.com/technetwork/java/codeconv-138413.html) +* [Java代码规范](http://www.oracle.com/technetwork/java/codeconvtoc-136057.html) | 
