diff options
| -rw-r--r-- | ansible.html.markdown | 2 | ||||
| -rw-r--r-- | de-de/c++-de.html.markdown | 1 | ||||
| -rw-r--r-- | es-es/kotlin-es.html.markdown | 68 | ||||
| -rw-r--r-- | it-it/rust-it.html.markdown | 2 | ||||
| -rw-r--r-- | prolog.html.markdown | 2 | ||||
| -rw-r--r-- | pt-br/clojure-pt.html.markdown | 2 | ||||
| -rw-r--r-- | pug.html.markdown | 204 | ||||
| -rw-r--r-- | python3.html.markdown | 2 | ||||
| -rw-r--r-- | rst.html.markdown | 16 | ||||
| -rw-r--r-- | th-th/pascal.th.html.markdown | 236 | ||||
| -rw-r--r-- | typescript.html.markdown | 24 | ||||
| -rw-r--r-- | zh-cn/ruby-cn.html.markdown | 160 | 
12 files changed, 641 insertions, 78 deletions
| diff --git a/ansible.html.markdown b/ansible.html.markdown index 2b61cc8e..41a8c9b5 100644 --- a/ansible.html.markdown +++ b/ansible.html.markdown @@ -49,7 +49,7 @@ environments, it may be noticable amount.  'on-demand' - there is no built-in mechanism that would warn you about some  change automatically (this can be achieved with reasonable effort)  * Official GUI - Ansible Tower - is great but expensive. -* There is no 'small enterprice' payment plan, however Ansible AWX is the free +* There is no 'small enterprise' payment plan, however Ansible AWX is the free  open source version we were all waiting for.  #### Neutral diff --git a/de-de/c++-de.html.markdown b/de-de/c++-de.html.markdown index 23cc26a8..eec11d61 100644 --- a/de-de/c++-de.html.markdown +++ b/de-de/c++-de.html.markdown @@ -9,6 +9,7 @@ contributors:      - ["Ankush Goyal", "http://github.com/ankushg07"]      - ["Jatin Dhankhar", "https://github.com/jatindhankhar"]      - ["Maximilian Sonnenburg", "https://github.com/LamdaLamdaLamda"] +lang: de-de  ---  C++ ist eine Systemprogrammiersprache die,  diff --git a/es-es/kotlin-es.html.markdown b/es-es/kotlin-es.html.markdown index 045f92d1..80d7a4bb 100644 --- a/es-es/kotlin-es.html.markdown +++ b/es-es/kotlin-es.html.markdown @@ -2,6 +2,7 @@  language: kotlin  contributors:  - ["S Webber", "https://github.com/s-webber"] +- ["Aitor Escolar", "https://github.com/aiescola"]  translators:  - ["Ivan Alburquerque", "https://github.com/AlburIvan"]  lang: es-es @@ -40,6 +41,12 @@ fun main(args: Array<String>) {      Podemos declarar explícitamente el tipo de una variable así:      */      val foo: Int = 7 +     +    /*  +    A diferencia de JavaScript, aunque el tipo se infiera, es tipado, por lo que no se puede cambiar el tipo a posteriori +    */ +    var fooInt = 14 // Se infiere tipo Int +    fooInt = "Cadena" // ERROR en tiempo de compilación: Type mismatch      /*      Las cadenas pueden ser representadas de la misma manera que Java. @@ -84,7 +91,6 @@ fun main(args: Array<String>) {      println(fooNullable?.length) // => null      println(fooNullable?.length ?: -1) // => -1 -      /*      Las funciones pueden ser declaras usando la palabra clave "fun".      Los argumentos de las funciones son especificados entre corchetes despues del nombre de la función. @@ -122,6 +128,40 @@ fun main(args: Array<String>) {      fun even(x: Int) = x % 2 == 0      println(even(6)) // => true      println(even(7)) // => false +     +    /*  +    Kotlin permite el uso de lambdas, o funciones anónimas +    */ +     +    // Sin lambda: +    interface MyListener { +        fun onClick(foo: Foo) +    } + +    fun listenSomething(listener: MyListener) { +        listener.onClick(Foo()) +    } +     +    listenSomething(object: MyListener { +        override fun onClick(foo: Foo) { +            //... +        } +    }) +     +    // Con lambda: +    fun listenSomethingLambda(listener: (Foo) -> Unit) { +        listener(Foo()) +    } +     +    listenSomethingLambda { +        //Se recibe foo +    } +     +    // el operador typealias permite, entre otras cosas, simplificar las expresiones con lambdas +    typealias MyLambdaListener = (Foo) -> Unit +    fun listenSomethingLambda(listener: MyLambdaListener) { +        listener(Foo()) +    }      // Las funciones pueden tomar funciones como argumentos y       // retornar funciones. @@ -219,6 +259,11 @@ fun main(args: Array<String>) {      val fooMap = mapOf("a" to 8, "b" to 7, "c" to 9)      // Se puede acceder a los valores del mapa por su llave.      println(fooMap["a"]) // => 8 +     +    // Tanto Map como cualquier colección iterable, tienen la función de extensión forEach +    fooMap.forEach { +        println("${it.key} ${it.value}") +    }      /*      Las secuencias representan colecciones evaluadas diferidamente. @@ -245,7 +290,7 @@ fun main(args: Array<String>) {      val y = fibonacciSequence().take(10).toList()      println(y) // => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] -    // Kotlin provee funciones de Orden-Mayor para trabajar con colecciones. +    // Kotlin provee funciones de orden superior para trabajar con colecciones.      val z = (1..9).map {it * 3}              .filter {it < 20}              .groupBy {it % 2 == 0} @@ -305,17 +350,11 @@ fun main(args: Array<String>) {      ese tipo sin convertido de forma explícita.       */      fun smartCastExample(x: Any) : Boolean { -        if (x is Boolean) { -            // x es automaticamente convertido a Boolean -            return x -        } else if (x is Int) { -            // x es automaticamente convertido a Int -            return x > 0 -        } else if (x is String) { -            // x  es automaticamente convertido a String -            return x.isNotEmpty() -        } else { -            return false +        return when (x) { +            is Boolean -> x // x es automaticamente convertido a Boolean +            is Int -> x > 0 // x es automaticamente convertido a Int +            is String -> x.isNotEmpty() // x  es automaticamente convertido a String +            else -> false          }      }      println(smartCastExample("Hola, mundo!")) // => true @@ -345,7 +384,8 @@ enum class EnumExample {  /*  La palabra clave "object" se puede utilizar para crear objetos únicos.  No podemos asignarlo a una variable, pero podemos hacer referencia a ella por su nombre. -Esto es similar a los objetos únicos de Scala +Esto es similar a los objetos únicos de Scala. +En la mayoría de ocasiones, los objetos únicos se usan como alternativa a los Singleton.  */  object ObjectExample {      fun hello() : String { diff --git a/it-it/rust-it.html.markdown b/it-it/rust-it.html.markdown index 76fbf008..e4b7c33f 100644 --- a/it-it/rust-it.html.markdown +++ b/it-it/rust-it.html.markdown @@ -130,7 +130,7 @@ fn main() {      /////////////      // Strutture -    struct Point { +    struct Punto {          x: i32,          y: i32,      } diff --git a/prolog.html.markdown b/prolog.html.markdown index f7b55ac6..d4c28cba 100644 --- a/prolog.html.markdown +++ b/prolog.html.markdown @@ -75,7 +75,7 @@ magicNumber(42).  ?- 2 = 3.                            % False - equality test  ?- X = 3.                            % X = 3 - assignment  ?- X = 2, X = Y.                     % X = Y = 2 - two assignments -                                     % Note Y is assigned to, even though it is +                                     % Note Y is assigned too, even though it is                                       % on the right hand side, because it is free  ?- X = 3, X = 2.                     % False                                       % First acts as assignment and binds X=3 diff --git a/pt-br/clojure-pt.html.markdown b/pt-br/clojure-pt.html.markdown index 7e8b3f7b..b88d4eec 100644 --- a/pt-br/clojure-pt.html.markdown +++ b/pt-br/clojure-pt.html.markdown @@ -340,7 +340,7 @@ keymap ; => {:a 1, :b 2, :c 3}  (def my-atom (atom {}))  ; Atualize o atom com um swap!. -; swap! pega uma funçnao and chama ela com o valor atual do atom +; swap! pega uma função e chama ela com o valor atual do atom  ; como primeiro argumento, e qualquer argumento restante como o segundo  (swap! my-atom assoc :a 1) ; Coloca o valor do átomo my-atom como o resultado de  (assoc {} :a 1)  (swap! my-atom assoc :b 2) ; Coloca o valor do átomo my-atom como o resultado de (assoc {:a 1} :b 2) diff --git a/pug.html.markdown b/pug.html.markdown new file mode 100644 index 00000000..0187f1e0 --- /dev/null +++ b/pug.html.markdown @@ -0,0 +1,204 @@ +--- +language: Pug +contributors: +  - ["Michael Warner", "https://github.com/MichaelJGW"] +filename: index.pug +--- + +## Getting Started with Pug + +Pug is a little language that compiles into the HTML. It has cleaner syntax  +with additional features like if statements and loops. It can also be used  +as a server side templating language for server languages like NodeJS. + +### The Language +```pug + +//- Single Line Comment + +//- Multi Line +    Comment + +//- ---TAGS--- +//- Basic +div +//- <div></div> +h1 +//- <h1></h1> +my-customTag +//- <my-customTag></my-customTag> + +//- Sibling +div +div +//- <div></div> +    <div></div> + +//- Child +div +  div +//- <div> +      <div></div> +    </div> + +//- Text +h1 Hello there +//- <h1>Hello there</h1> + +//- Multi Line Text +div. +  Hello +  There +//- <div> +      Hello +      There +    </div> + +//- ---ATTRIBUTES--- +div(class="my-class" id="my-id" my-custom-attrs="data" enabled) +//- <div class="my-class" id="my-id" my-custom-attrs="data" enabled></div> + +//- Short Hand +span.my-class +//- <span class="my-class"></span> +.my-class +//- <div class="my-class"></div> +div#my-id +//- <div id="my-id"></div> +div#my-id.my-class +//- <div class="my-class" id="my-id"></div> + + +//- ---JS--- +- const lang = "pug"; + +//- Multi Line JS +- +  const lang = "pug"; +  const awesome = true; + +//- JS Classes +- const myClass = ['class1', 'class2', 'class3'] +div(class=myClass) +//- <div class="class1 class2 class3"></div> + +//- JS Styles +- const myStyles = {'color':'white', 'background-color':'blue'} +div(styles=myStyles) +//- <div styles="{"color":"white","background-color":"blue"}"></div> + +//- JS Attributes +- const myAttributes = {"src": "photo.png", "alt": "My Photo"} +img&attributes(myAttributes) +//- <img src="photo.png" alt="My Photo"> +- let disabled = false +input(type="text" disabled=disabled) +//- <input type="text"> +- disabled = true +input(type="text" disabled=disabled) +//- <input type="text" disabled> + +//- JS Templating +- const name = "Bob"; +h1 Hi #{name} +h1= name +//- <h1>Hi Bob</h1> +//- <h1>Bob</h1> + +//- ---LOOPS--- + +//- 'each' and 'for' do the same thing we will use 'each' only. + +each value, i in [1,2,3] +  p=value +//- +  <p>1</p> +  <p>2</p> +  <p>3</p> + +each value, index in [1,2,3] +  p=value + '-' + index +//- +  <p>1-0</p> +  <p>2-1</p> +  <p>3-2</p> + +each value in [] +  p=value +//-  + +each value in [] +  p=value +else +  p No Values are here + +//- <p>No Values are here</p> + +//- ---CONDITIONALS--- + +- const number = 5 +if number < 5 +  p number is less then 5 +else if number > 5 +  p number is greater then 5 +else +  p number is 5 +//- <p>number is 5</p> + +- const orderStatus = "Pending"; +case orderStatus +  when "Pending" +    p.warn Your order is pending +  when "Completed" +    p.success Order is Completed. +  when -1 +    p.error Error Occurred +  default +    p No Order Record Found +//- <p class="warn">Your order is pending</p> + +//- --INCLUDE-- +//- File path -> "includes/nav.png" +h1 Company Name +nav +  a(href="index.html") Home +  a(href="about.html") About Us + +//- File path -> "index.png" +html +  body +    include includes/nav.pug +//- +  <html> +    <body> +      <h1>Company Name</h1> +      <nav><a href="index.html">Home</a><a href="about.html">About Us</a></nav> +    </body> +  </html> + +//- Importing JS and CSS +script +  include scripts/index.js +style +  include styles/theme.css + +//- ---MIXIN--- +mixin basic() +  div Hello ++basic("Bob") +//- <div>Hello</div> + +mixin comment(name, comment) +  div +    span.comment-name= name +    div.comment-text= comment ++comment("Bob", "This is Awesome") +//- <div>Hello</div> + +``` + + +### Additional Resources +- [The Site](https://pugjs.org/) +- [The Docs](https://pugjs.org/api/getting-started.html) +- [Github Repo](https://github.com/pugjs/pug) diff --git a/python3.html.markdown b/python3.html.markdown index c4f15867..ecdbd932 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -155,7 +155,7 @@ len("This is a string")  # => 16  name = "Reiko"  f"She said her name is {name}." # => "She said her name is Reiko"  # You can basically put any Python statement inside the braces and it will be output in the string. -f"{name} is {len(name)} characters long." +f"{name} is {len(name)} characters long." # => "Reiko is 5 characters long."  # None is an object diff --git a/rst.html.markdown b/rst.html.markdown index 01595fe4..2423622e 100644 --- a/rst.html.markdown +++ b/rst.html.markdown @@ -47,19 +47,27 @@ Title are underlined with equals signs too  Subtitles with dashes  --------------------- -You can  put text in *italic* or in **bold**, you can "mark" text as code with double backquote ``print()``. +You can put text in *italic* or in **bold**, you can "mark" text as code with double backquote ``print()``. -Lists are as simple as in Markdown: +Lists are similar to Markdown, but a little more involved. + +Remember to line up list symbols (like - or *) with the left edge of the previous text block, and remember to use blank lines to separate new lists from parent lists:      - First item  - Second item -    - Sub item + +  - Sub item +     +- Third item  or  * First item  * Second item -    * Sub item +     +  * Sub item + +* Third item  Tables are really easy to write: diff --git a/th-th/pascal.th.html.markdown b/th-th/pascal.th.html.markdown new file mode 100644 index 00000000..05e37a28 --- /dev/null +++ b/th-th/pascal.th.html.markdown @@ -0,0 +1,236 @@ +--- +language: Pascal +filename: learnpascal.pas +contributors: +    - ["Ganesha Danu", "http://github.com/blinfoldking"] +    - ["Keith Miyake", "https://github.com/kaymmm"] +translator: +    - ["Worajedt Sitthidumrong", "https://bitbucket.org/wrj"] +lang: th-th +--- + +> Pascal (ปาสกาล) เป็นภาษาโปรแกรมมิ่งทั้งแบบ imperative และ procedural ที่ออกแบบโดย Niklaus Wirth (นิเคล้า เวิร์ท) เมื่อปี 1968-69 และเผยแพร่ตอน 1970 โดยเน้นให้เป็นภาษาที่เล็ก มีประสิทธิภาพ เพื่อเสริมการเขียนโปรแกรมที่มีแนวปฏิบัติที่ดีด้วยการใช้โครงสร้างของตัวภาษา และโครงสร้างข้อมูลมากำกับ ชื่อของภาษานี้ตั้งเป็นเกียรติให้กับนักคณิตศาสตร์ชาวฝรั่งเศส, นักปรัชญา และนักฟิสิกส์ ชื่อ Blaise Pascal (เบลส ปาสกาล) ข้อมูลจาก : [วิกิพีเดีย][1] + +การคอมไพล์และรันโค้ดภาษาปาสกาลนี้ สามารถใช้ปาสกาลคอมไพลเลอร์ฟรีชื่อ Free Pascal ได้ โดย [ดาวน์โหลดที่นี่][2] + +ด้านล่างจะเป็นโครงสร้างภาษาหลัก ๆ ที่ต้องเข้าใจก่อน ปาสกาลจะเป็นภาษาที่เข้มงวดกับโครงสร้างโค้ดมาก + +```pascal +//โปรแกรมปาสกาล +//คอมเม้นต์เขียนแบบนี้ ใช้สแลชสองครั้ง +{ +    แต่ถ้าต้องการคอมเม้นหลาย ๆ บรรทัด +    ให้ใช้ วงเล็บปีกกา (curly brackets) +    เนื้อหาอยู่บรรทัดเดียวกันกับปีกกาได้ +} + +//อย่างแรก ต้องประกาศ ชื่อโปรแกรม +program learn_pascal; //<-- ห้ามลืม semicolon + +const +    { +        ประกาศค่าคงที่ (constant) ในบล็อคนี้ +    } +type +    { +        ประกาศชนิดข้อมูลของเราเองที่นี่ ไม่ว่าจะเป็น ชนิดข้อมูลทั่วไป +        หรือจะเป็นคลาส  +    } +var +    { +        ตัวแปร ในภาษาปาสกาล ไม่เหมือนกับภาษาอื่น ๆ  +        เพราะต้องประกาศในบล็อค var ก่อนใช้งานเสมอ +    } + +//มาถึงส่วนโปรแกรมหลัก หรือ main fucntion นั่นเอง +begin +    { +        โค้ดเราทำงานอะไร อย่างไร ก็เริ่มรันจากตรงนี้ +    } +end. // จบการทำงานของ _โปรแกรม_ เราจะจบด้วย จุลภาค "." +``` + +โค้ดต่อจากนี้ จะเป็นการอธิบายประกาศตัวแปรของปาสกาล + +```pascal +//การประกาศตัวแปร ทำได้แบบนี้ +//var ชื่อตัวแปร : ชนิด ; +var a:integer; +var b:integer; + +//หรือแบบที่นิยมมากกว่า คือเอามาเก็บในบล็อค var ทั้งหมด +var  +    a : integer; +    b : integer; + +//ถ้าจะเอาแบบสั้น ๆ บรรทัดเดียว ก็ทำได้ ทำได้พร้อมกันหลาย ๆ ตัวแปรด้วย +var a,b : integer; +``` + +โค้ดตัวอย่างนี้เป็นโปรแกรม Learn\_More ที่เป็นโครงสร้างโปรแกรมง่าย ๆ ที่จบสมบูรณ์หนึ่งโปรแกรม มีบล็อค program, const, type, main (Begin..End.) + +```pascal +program Learn_More; +// มาต่อเรื่อง ชนิดของข้อมูล (data types) และ ตัวดำเนินการ (operators) + +const +    PI = 3.141592654; +    GNU = 'GNU''s Not Unix'; +        // ค่าคงที่ ให้ตั้งชื่อเป็น ตัวพิมพ์ใหญ่ ทั้งหมด ใช้กับชนิดข้อมูลใดๆ ก็ได้ +        // ค่าคงที่ ก็ตามชื่อเลย กำหนดค่าแล้ว ไม่สามารถเปลี่ยนแปลงได้ขณะรัน + +// การประกาศชนิดข้อมูลของเราเอง +// "ชนิด" ของตัวแปรสองแบบนี้ จะนำไปใช้ด้านล่าง +type +    ch_array : array [0..255] of char; +        // อะเรย์ เป็นชนิดข้อมูลที่มี ความยาว/ช่องเก็บข้อมูล และ ชนิดข้อมูล +        // โค้ดด้านบน เป็นการประกาศอะเรย์ของตัวอักษา 255 ตัวอักษา +        // ซึ่งได้ ความยาว/ช่องเก็บข้อมูลในตัวแปรตัวนี้ 256 ช่องที่เป็นข้อความ  +    md_array : array of array of integer; +        // ด้านบนนี้ เป็นตัวอย่าง อะเรย์สองมิติของเลขจำนวนเต็ม +        // อะเรย์ ยังซ้อนกับอะเรย์ได้อีกด้วย ทำให้สร้าง อะเรย์หลายมิติได้ +        // เรายังสามารถสร้าง อะเรย์ที่มีความยาวช่องเท่ากับศูนย์ (0) ได้อีกด้วย +        // ซึ่งทำให้เกิด อะเรย์ที่จำนวนช่องยืดหยุ่นได้ (dymaically sized array) + +// การประกาศตัวแปร : ชื่อตัวแปรเหล่านี้จะนำไปใช้ด้านล่างต่อไป +var +    int, c, d  : integer; +           // ประกาศในบล็อค var มีตัวแปรสามตัวเป็นอินทีเจอร์  +           // ชนิดจำนวนเต็ม แบบ 16 bit มีช่วงข้อมูล [-32,768.. 32,767] +           // »int« ในที่นี้เป็น "ชื่อตัวแปร" ที่ต้นฉบับตั้งให้สอดคล้องกับชนิดข้อมูล +           // อย่าสับสนกับบางภาษาที่มีชนิด int ประกาศหน้าชื่อตัวแปร +    r    : real; +           // ตัวแปร r เป็นชนิดเรียล (real) หรือเลขทศนิยม  +           // real มีช่วงข้อมูล [3.4E-38..3.4E38] +    bool : boolean; +           // ข้อมูลชนิดบูเลียน (boolean) มีค่าได้สองแบบ คือ True/False +    ch   : char; +           // ตัวแปร ch เป็นชนิดตัวอักษร (ชาร์? คาร์?) หรือคาแรกเตอร์ +           // ตัวอักษรเป็นแบบ ASCII 8 bit ดังนั้นจะไม่ใช่ UTF, Unicode  +    str  : string; +           // ตัวแปรสตริงจะเก็บข้อความ หรือ char หลาย ๆ ตัว +           // ชนิดข้อมูลนี้ไม่เป็นมาตรฐานภาษาแต่คอมไพเลอร์ปาสกาลก็มักจะมีให้ +           // ทั่ว ๆ ไปแล้ว จะเป็นอะเรย์ของ char ความยาวตั้งต้น 255  +    s    : string[50]; +           // แบบนี้คือ กำหนดความยาว string เอง ให้เก็บ char 50 ตัว +           // แบบนี้ก็ทำให้ประหยัดหน่วยความจำมากขึ้นนั่นเอง +    my_str: ch_array; +           // ชนิดตัวแปร ใช้เป็นชนิดที่เรากำหนดเองก็ได้ อย่างตอนนี้ +           // ch_array เป็น "ชนิดข้อมูล" ที่เราสร้างขึ้นมาในบล็อค type +    my_2d : md_array; +           // ตัวแปรแบบอะเรย์ที่ไม่ประกาศขนาด (dynamically sized array) +           // ก่อนเอาไปใช้จริงต้องระบุขนาดก่อนใช้เสมอ + +    // ชนิดข้อมูลแบบ integer เพิ่มเติม +    b    : byte;     // มีช่วงข้อมูล [0..255] +    shi  : shortint; // มีช่วงข้อมูล [-128..127] +    smi  : smallint; // มีช่วงข้อมูล [-32,768..32,767] (standard Integer) +    w    : word;     // มีช่วงข้อมูล [0..65,535] +    li   : longint;  // มีช่วงข้อมูล [-2,147,483,648..2,147,483,647] +    lw   : longword; // มีช่วงข้อมูล [0..4,294,967,295] +    c    : cardinal; // ก็คือ longword +    i64  : int64;    // มีช่วงข้อมูล  +                     // [-9223372036854775808..9223372036854775807] +    qw   : qword;    // มีช่วงข้อมูล [0..18,446,744,073,709,551,615] + +    // ชนิดข้อมูลแบบ real เพิ่มเติม +    rr   : real;     // มีช่วงข้อมูลที่ขึ้นกับระบบปฏิบัติการ  +                     // (เช่นเป็นแบบ 8-bit, 16-bit, ฯลฯ) +    rs   : single;   // มีช่วงข้อมูล [1.5E-45..3.4E38] +    rd   : double;   // มีช่วงข้อมูล [5.0E-324 .. 1.7E308] +    re   : extended; // มีช่วงข้อมูล [1.9E-4932..1.1E4932] +    rc   : comp;     // มีช่วงข้อมูล [-2E64+1 .. 2E63-1] + +Begin +    // การกำหนดค่าตัวแปรให้ขณะประกาศ +    int  := 1; +    r    := 3.14; +    ch   := 'a';  // ใช้ single quote เหมือนกันทั้ง char และ string +    str  := 'apple';   +    bool := true; +    // ภาษาปาสกาล มอง "ชื่อเฉพาะ" แบบไม่สนพิมพ์ใหญ่พิมพ์เล็ก +    // (case-insensitive language) +    // ตัวดำเนินการแบบคณิตศาสตร์ (arithmethic operation) +    int := 1 + 1;   // int = 2 ซึ่งจะกำหนดทับค่าเดิมด้านบนที่เคยประกาศ +    int := int + 1; // int = 2 + 1 = 3 นำค่าตอนนี้ (2) มา +1 ได้ 3 +    int := 4 div 2; // int = 2 หารด้วย div จะได้ผลเป็น integer เสมอ +    int := 3 div 2; // int = 1 +    int := 1 div 2; // int = 0 + +    bool := true or false;  // bool = true +    bool := false and true; // bool = false +    bool := true xor true;  // bool = false + +    r := 3 / 2;  // หารด้วย / จะได้ผลเป็น real เสมอ +    r := int;    // เรากำหนดค่า integer ให้ตัวแปร real ได้ +                 // แต่ทำกลับกัน โดยกำหนด real ให้ integer ไม่ได้ + +    c := str[1]; // กำหนดค่าแรกใน array str ให้ตัวแปร c ที่เป็น char +    str := 'hello' + 'world'; // เรารวม string เข้าด้วยกันด้วย +  + +    my_str[0] := 'a'; // กำหนดค่าให้ string เฉพาะตำแหน่งแบบอะเรย์ทั่วไป + +    setlength(my_2d,10,10); // ปรับขนาดอะเรย์ 2 มิติให้เป็นขนาด 10x10 +                            // โดยตัวแปร my_2d นี้สร้างแล้วด้านบน +    for c := 0 to 9 do      // อะเรย์เริ่มจาก 0 และจบที่ ความยาว-1 +        for d := 0 to 9 do  // ตัวนับ (counter) จำเป็นต้องประกาศก่อนใช้ +        my_2d[c,d] := c * d; +          // กำหนดอะเรย์หลายมิติ ด้วยการใช้วงเล็บก้ามปู (square brackets) + +End. +// จบโปรแกรมบริบูรณ์ ด้วย "." +``` + +ด้านล่าง เป็นตัวอย่างการเขียนโปรแกรมปาสกาลชื่อ Functional\_Programming + +```pascal +program Functional_Programming; + +Var +    i, dummy : integer; + +function factorial_recursion(const a: integer) : integer; +{  ทำการคำนวณแฟคทอเรียลซ้ำ ๆ ของเลขจำนวนเต็ม โดยผ่านพารามิเตอร์ a +   ถ้าจะประกาศตัวแปรโลคอลในฟังก์ชั่น ก็ทำได้ โดยการใช้บล็อค var ภายในฟังก์ชั่น +   เช่น : +   var +      local_a : integer; +} +Begin +    If a >= 1 Then +    { ฟังก์ชั่นนี้คืนค่ากลับ โดยการกำหนดค่าที่ผ่านทางพารามิเตอร์ a +     นำมาคูณกับฟังก์ชั่นที่ผ่าน a-1 สุดท้ายก็กำหนดค่าลงไปให้กับฟังก์ชั่นตรงๆ } +        factorial_recursion := a * factorial_recursion(a-1) +    Else +        factorial_recursion := 1; +End; // จบ ฟังก์ชั่น ด้วย ";" หลัง End ไม่เหมือนกับจบ โปรแกรม ที่จะใช้ "." + +procedure get_integer(var i : integer; dummy : integer); +{ เรารับ input จากผู้ใช้มาเก็บใน parameter i ที่เป็น integer ที่ตั้งขึ้นใน +  พารามิเตอร์ โดยใช้ var ประกาศ ทำให้ค่าที่รับเข้ามาจะเปลี่ยนปรับได้จาก +  ภายนอกการประกาศพารามิเตอร์นี้ ส่วน dummy เป็นตัวแปรที่ปรับเปลี่ยนได้ +  "เฉพาะจากภายในฟังก์ชั่น,โพรซีเยอร์นั้น ๆ } +Begin +    write('Enter an integer: '); +    readln(i); +    dummy := 4; // dummy จะไม่ทำให้ค่าที่ได้รับมาครั้งแรกใน main block เปลี่ยน +End; + +//--------------------// +// main program block +//--------------------// +Begin  +    dummy := 3; +    get_integer(i, dummy); +    writeln(i, '! = ', factorial_recursion(i)); +    // พิมพ์ค่า i! +    writeln('dummy = ', dummy); // จะให้ค่าเป็น '3' เสมอ  +                                // เพราะจะไม่เปลี่ยนเนื่องด้วย +                                // การประกาศพารามิเตอร์ใน +                                // โพรซีเยอร์ get_integer ด้านบน +End. + +``` + +[1]:	https://en.wikipedia.org/wiki/Pascal_(programming_language) +[2]:	https://www.freepascal.org/ diff --git a/typescript.html.markdown b/typescript.html.markdown index ba4a9e71..55d8cefe 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -223,6 +223,30 @@ moreNumbers[5] = 5; // Error, elements are read-only  moreNumbers.push(5); // Error, no push method (because it mutates array)  moreNumbers.length = 3; // Error, length is read-only  numbers = moreNumbers; // Error, mutating methods are missing + +// Iterators and Generators + +// for..of statement +// iterate over the list of values on the object being iterated +let arrayOfAnyType = [1, "string", false]; +for (const val of arrayOfAnyType) { +    console.log(val); // 1, "string", false +} + +let list = [4, 5, 6]; +for (const i of list) { +   console.log(i); // "4", "5", "6" +} + +// for..in statement +// iterate over the list of keys on the object being iterated +for (const i in list) { +   console.log(i); // "0", "1", "2", +} + + + +  ```  ## Further Reading diff --git a/zh-cn/ruby-cn.html.markdown b/zh-cn/ruby-cn.html.markdown index 657a913d..9918c022 100644 --- a/zh-cn/ruby-cn.html.markdown +++ b/zh-cn/ruby-cn.html.markdown @@ -6,11 +6,25 @@ contributors:    - ["David Underwood", "http://theflyingdeveloper.com"]    - ["Joel Walden", "http://joelwalden.net"]    - ["Luke Holder", "http://twitter.com/lukeholder"] +  - ["Tristan Hume", "http://thume.ca/"] +  - ["Nick LaMuro", "https://github.com/NickLaMuro"] +  - ["Marcos Brizeno", "http://www.about.me/marcosbrizeno"] +  - ["Ariel Krakowski", "http://www.learneroo.com"] +  - ["Dzianis Dashkevich", "https://github.com/dskecse"] +  - ["Levi Bostian", "https://github.com/levibostian"] +  - ["Rahil Momin", "https://github.com/iamrahil"] +  - ["Gabriel Halley", "https://github.com/ghalley"] +  - ["Persa Zula", "http://persazula.com"] +  - ["Jake Faris", "https://github.com/farisj"] +  - ["Corey Ward", "https://github.com/coreyward"] +  - ["Jannik Siebert", "https://github.com/janniks"] +  - ["Keith Miyake", "https://github.com/kaymmm"]    - ["lidashuang", "https://github.com/lidashuang"]    - ["ftwbzhao", "https://github.com/ftwbzhao"]  translators:    - ["Lin Xiangyu", "https://github.com/oa414"]    - ["Jiang Haiyun", "https://github.com/haiiiiiyun"] +  - ["woclass", "https://github.com/inkydragon"]  ---  ```ruby @@ -18,26 +32,27 @@ translators:  =begin  这是多行注释 -没人用这个 -你也不该用  =end -# 首先,也是最重要的,所有东西都是对象 +# 在 Ruby 中,(几乎)所有东西都是对象  # 数字是对象 - -3.class #=> Fixnum - +3.class #=> Integer  3.to_s #=> "3" +# 字符串是对象 +"Hello".class #=> String + +# 甚至方法也是对象 +"Hello".method(:class).class #=> Method -# 一些基本的算术符号 -1 + 1 #=> 2 -8 - 1 #=> 7 -10 * 2 #=> 20 -35 / 5 #=> 7 -2**5 #=> 32 -5 % 3 #=> 2 +# 一些基本的算术操作 +1 + 1   #=> 2 +8 - 1   #=> 7 +10 * 2  #=> 20 +35 / 5  #=> 7 +2 ** 5  #=> 32 +5 % 3   #=> 2  # 位运算符  3 & 5 #=> 1 @@ -48,6 +63,7 @@ translators:  # 实际上是调用对象的方法  1.+(3) #=> 4  10.* 5 #=> 50  +100.methods.include?(:/) #=> true  # 特殊的值也是对象  nil # 相当于其它语言中的 null @@ -66,11 +82,11 @@ false.class #=> FalseClass  1 != 1 #=> false  2 != 1 #=> true -# 除了false自己,nil是唯一的另一个值为false的对象 - -!nil   #=> true -!false #=> true -!0     #=> false +# 除了 false 自己,nil 是唯一的另一个值为 false 的对象 +!!nil   #=> false +!!false #=> false +!!0     #=> true +!!""    #=> true  # 更多比较  1 < 10 #=> true @@ -90,11 +106,11 @@ true || false #=> true  !true #=> false  # 也有优先级更低的逻辑运算符 -# 它们用于控制流结构中,用来串接语句,直到返回true或false。 +# 它们用于控制流结构中,用来串接语句,直到返回 true 或 false。 -# `do_something_else` 只当 `do_something` 返回true时才会被调用 +# `do_something_else` 只当 `do_something` 返回 true 时才会被调用  do_something() and do_something_else() -# `log_error` 只当 `do_something` 返回false时才会被调用 +# `log_error` 只当 `do_something` 返回 false 时才会被调用  do_something() or log_error() @@ -114,6 +130,7 @@ placeholder = "use string interpolation"  'hello ' + 'world'  #=> "hello world"  'hello ' + 3 #=> TypeError: can't convert Fixnum into String  'hello ' + 3.to_s #=> "hello 3" +"hello #{3}" #=> "hello 3"  # 合并字符串及其运算符  'hello ' * 3 #=> "hello hello hello " @@ -141,7 +158,7 @@ x = y = 10 #=> 10  x #=> 10  y #=> 10 -# 按照惯例,使用类似snake_case风格的变量名 +# 按照惯例,使用类似 snake_case 风格的变量名  snake_case = true  # 使用有意义的变量名 @@ -174,6 +191,7 @@ array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5]  # 数组可以被索引  # 从前面开始  array[0] #=> 1 +array.first #=> 1  array[12] #=> nil  # 像运算符一样,[var] 形式的访问 @@ -189,13 +207,13 @@ array.last #=> 5  # 同时指定开始的位置和长度  array[2, 3] #=> [3, 4, 5] +# 或者指定一个区间 +array[1..3] #=> [2, 3, 4] +  # 将数组逆序  a=[1,2,3]  a.reverse! #=> [3,2,1] -# 或者指定一个区间 -array[1..3] #=> [2, 3, 4] -  # 像这样往数组增加一个元素  array << 6 #=> [1, 2, 3, 4, 5, 6]  # 或者像这样 @@ -217,14 +235,18 @@ hash['number'] #=> 5  # 查询一个不存在的键将会返回nil  hash['nothing here'] #=> nil -# 从Ruby 1.9开始,用符号作为键的时候有特别的记号表示: +# 从 Ruby 1.9 开始,用符号作为键的时候有特别的记号表示:  new_hash = { defcon: 3, action: true }  new_hash.keys #=> [:defcon, :action] +# 检查键值是否存在 +hash.key?(:defcon) #=> true +hash.value?(3) #=> true +  # 小贴士:数组和哈希表都是可枚举的 -# 它们共享一些有用的方法,比如each,map,count等等 +# 它们共享一些有用的方法,比如 each, map, count 等等  # 控制流 @@ -236,6 +258,8 @@ else   "else, also optional"  end +# 循环 +  for counter in 1..5    puts "iteration #{counter}"  end @@ -246,14 +270,14 @@ end  #=> iteration 5 -# 但是,没有人用for循环。 -# 你应该使用"each"方法,然后再传给它一个块。 -# 所谓块就是可以传给像"each"这样的方法的代码段。 -# 它类似于其它语言中的lambdas, 匿名函数或闭包。 +# 但是,没有人用 for 循环。 +# 你应该使用 "each" 方法,然后再传给它一个块。 +# 所谓块就是可以传给像 "each" 这样的方法的代码段。 +# 它类似于其它语言中的 lambdas, 匿名函数或闭包。  # -# 区间上的"each"方法会对区间中的每个元素运行一次块代码。 -# 我们将counter作为一个参数传给了块。 -# 调用带有块的"each"方法看起来如下: +# 区间上的 "each" 方法会对区间中的每个元素运行一次块代码。 +# 我们将 counter 作为一个参数传给了块。 +# 调用带有块的 "each" 方法看起来如下:  (1..5).each do |counter|    puts "iteration #{counter}" @@ -275,7 +299,7 @@ hash.each do |key, value|    puts "#{key} is #{value}"  end -# 如果你还需要索引值,可以使用"each_with_index",并且定义 +# 如果你还需要索引值,可以使用 "each_with_index",并且定义  # 一个索引变量  array.each_with_index do |element, index|    puts "#{element} is number #{index} in the array" @@ -293,7 +317,7 @@ end  #=> iteration 5  # Ruby 中还有很多有用的循环遍历函数, -# 如"map","reduce","inject"等等。 +# 如 "map", "reduce", "inject" 等等。  # 以map为例,它会遍历数组,并根据你在  # 块中定义的逻辑对它进行处理,然后返回  # 一个全新的数组。 @@ -388,19 +412,26 @@ surround { puts 'hello world' }  # {  # hello world  # } +# => nil  # 可以向函数传递一个块  # "&"标记传递的块是一个引用  def guests(&block) -  block.call 'some_argument' +  block.class #=> Proc +  block.call(4)  end +guests { |n| "You have #{n} guests." } +# => "You have 4 guests." +  # 可以传递多个参数,这些参数会转成一个数组,  # 这也是使用星号符 ("*") 的原因:  def guests(*array)    array.each { |guest| puts guest }  end +# 结构 +  # 如果函数返回一个数组,在赋值时可以进行拆分:  def foods      ['pancake', 'sandwich', 'quesadilla'] @@ -409,21 +440,42 @@ breakfast, lunch, dinner = foods  breakfast #=> 'pancake'  dinner #=> 'quesadilla' -# 按照惯例,所有返回布尔值的方法都以?结尾 +# 有些情况下,你会想使用解构操作符 `*` 来解构数组 +ranked_competitors = ["John", "Sally", "Dingus", "Moe", "Marcy"] + +def best(first, second, third) +  puts "Winners are #{first}, #{second}, and #{third}." +end + +best *ranked_competitors.first(3) #=> Winners are John, Sally, and Dingus. + +# 结构操作符也可放在参数里面 +def best(first, second, third, *others) +  puts "Winners are #{first}, #{second}, and #{third}." +  puts "There were #{others.count} other participants." +end + +best *ranked_competitors  +#=> Winners are John, Sally, and Dingus. +#=> There were 2 other participants. + +# 按照惯例,所有返回布尔值的方法都以 ? 结尾  5.even? # false  5.odd? # true -# 如果方法名末尾有!,表示会做一些破坏性的操作,比如修改调用者自身。 -# 很多方法都会有一个!的版本来进行修改,和一个非!的版本 -# 只用来返回更新了的结果 +# 如果方法名末尾有感叹号 !,表示会做一些破坏性的操作,比如修改调用者自身。 +# 很多方法都会有一个 ! 的版本来进行修改, +# 和一个只返回更新结果的非 ! 版本  company_name = "Dunder Mifflin"  company_name.upcase #=> "DUNDER MIFFLIN"  company_name #=> "Dunder Mifflin" -company_name.upcase! # we're mutating company_name this time! +# 这次我们修改了 company_name +company_name.upcase! #=> "DUNDER MIFFLIN"  company_name #=> "DUNDER MIFFLIN" +# 类 -# 用class关键字定义一个类 +# 用 class 关键字定义一个类  class Human    # 一个类变量,它被这个类的所有实例变量共享 @@ -431,30 +483,30 @@ class Human    # 基本构造函数    def initialize(name, age = 0) -    # 将参数值赋给实例变量"name" +    # 将参数值赋给实例变量 "name"      @name = name -    # 如果没有给出age,那么会采用参数列表中的默认值 +    # 如果没有给出 age,那么会采用参数列表中的默认值      @age = age    end -  # 基本的setter方法 +  # 基本的 setter 方法    def name=(name)      @name = name    end -  # 基本地getter方法 +  # 基本地 getter 方法    def name      @name    end -  # 以上的功能也可以用下面的attr_accessor来封装 +  # 以上的功能也可以用下面的 attr_accessor 来封装    attr_accessor :name -  # Getter/setter方法也可以像这样单独创建 +  # Getter/setter 方法也可以像这样单独创建    attr_reader :name    attr_writer :name -  # 类方法通过使用self与实例方法区别开来。 +  # 类方法通过使用 self 与实例方法区别开来。    # 它只能通过类来调用,不能通过实例调用。    def self.say(msg)      puts "#{msg}" @@ -468,7 +520,6 @@ end  # 初始化一个类  jim = Human.new("Jim Halpert") -  dwight = Human.new("Dwight K. Schrute")  # 让我们来调用一些方法 @@ -483,15 +534,15 @@ dwight.name #=> "Dwight K. Schrute"  Human.say('Hi') #=> "Hi"  # 变量的作用域由它们的名字格式定义 -# 以$开头的变量具有全局域 +# 以 $ 开头的变量具有全局域  $var = "I'm a global var"  defined? $var #=> "global-variable" -# 以@开头的变量具有实例作用域 +# 以 @ 开头的变量具有实例作用域  @var = "I'm an instance var"  defined? @var #=> "instance-variable" -# 以@@开头的变量具有类作用域 +# 以 @@ 开头的变量具有类作用域  @@var = "I'm a class var"  defined? @@var #=> "class variable" @@ -568,7 +619,6 @@ Book.foo       # => 'foo'  Book.new.foo   # => NoMethodError: undefined method `foo'  # 当包含或扩展一个模块时,相应的回调代码会被执行。 -  module ConcernExample    def self.included(base)      base.extend(ClassMethods) | 
