From 274067e05bcf37061c192bab4f4fb93d750c9cac Mon Sep 17 00:00:00 2001 From: Serg Date: Sat, 15 Oct 2016 15:32:41 +0300 Subject: [bash/uk-ua] translation fixes --- uk-ua/bash-ua.html.markdown | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/uk-ua/bash-ua.html.markdown b/uk-ua/bash-ua.html.markdown index b7e4a5ba..c6e9ebb1 100644 --- a/uk-ua/bash-ua.html.markdown +++ b/uk-ua/bash-ua.html.markdown @@ -13,13 +13,13 @@ contributors: - ["Etan Reisner", "https://github.com/deryni"] translators: - ["Ehreshi Ivan", "https://github.com/IvanEh"] + - ["Serhii Maksymchuk", "https://github.com/Serg-Maximchuk"] lang: uk-ua --- Bash - командна оболонка unix (unix shell), що також розповсюджувалась як оболонка для операційної системи GNU і зараз використовується як командна оболонка за замовчуванням для Linux i Max OS X. -Почти все нижеприведенные примеры могут быть частью shell-скриптов или исполнены напрямую в shell. Майже всі приклади, що наведені нижче можуть бути частиною shell-скриптів або виконані в оболонці @@ -28,7 +28,7 @@ Bash - командна оболонка unix (unix shell), що також ро ```bash #!/bin/bash # Перший рядок скрипта - це shebang, який вказує системі, як потрібно виконувати -# скрипт. Як ви вже зрозуміли, коментарі починаються з #. Shebang - тоже коментар +# скрипт. Як ви вже зрозуміли, коментарі починаються з #. Shebang - також коментар # Простий приклад hello world: echo Hello world! @@ -123,7 +123,7 @@ fi # Вирази позначаються наступним форматом: echo $(( 10 + 5 )) -# На відмінно від інших мов програмування, Bash - це командна оболонка, а +# На відміну від інших мов програмування, Bash - це командна оболонка, а # отже, працює в контексті поточної директорії ls @@ -135,7 +135,7 @@ ls -l # Показати кожен файл і директорію на окр # Таким чином ми можемо переглянути тільки *.txt файли в поточній директорії: ls -l | grep "\.txt" -# Ви можете перенаправ вхід і вихід команди (stdin, stdout, stderr). +# Ви можете перенаправити вхід і вихід команди (stdin, stdout, stderr). # Наступна команда означає: читати із stdin, поки не зустрінеться ^EOF$, і # перезаписати hello.py наступними рядками (до рядка "EOF"): cat > hello.py << EOF @@ -155,7 +155,7 @@ 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 -# Поток помилок перезапише фпйл, якщо цей файл існує +# Потік помилок перезапише файл, якщо цей файл існує # тому, якщо ви хочете дописувати до файлу, використовуйте ">>": python hello.py >> "output.out" 2>> "error.err" @@ -172,7 +172,6 @@ echo "#helloworld" > output.out echo "#helloworld" | cat > output.out echo "#helloworld" | tee output.out >/dev/null -# Подчистить временные файлы с подробным выводом ('-i' - интерактивый режим) # Очистити тимчасові файли з детальним виводом (додайте '-i' # для інтерактивного режиму) rm -v output.out error.err output-and-error.log @@ -194,7 +193,7 @@ case "$VARIABLE" in esac # Цикл for перебирає елементи передані в аргумент: -# Значення $VARIABLE буде напечатано тричі. +# Значення $VARIABLE буде надруковано тричі. for VARIABLE in {1..3} do echo "$VARIABLE" @@ -260,12 +259,11 @@ uniq -d file.txt cut -d ',' -f 1 file.txt # замінити кожне 'okay' на 'great' у файлі file.txt (підтримується regex) sed -i 's/okay/great/g' file.txt -# вивести в stdout все рядки з file.txt, що задовольняють шаблону regex; +# вивести в stdout всі рядки з file.txt, що задовольняють шаблону regex; # цей приклад виводить рядки, що починаються на foo і закінчуються на bar: grep "^foo.*bar$" file.txt # використайте опцію -c, щоб вивести кількість входжень grep -c "^foo.*bar$" file.txt -# чтобы искать по строке, а не шаблону regex, используйте fgrep (или grep -F) # щоб здійснити пошук по рядку, а не по шаблону regex, використовуйте fgrea (або grep -F) fgrep "^foo.*bar$" file.txt -- cgit v1.2.3 From a19efad7fc938c2e505582a3541a3c083d0f85c8 Mon Sep 17 00:00:00 2001 From: Kyle Rokita Date: Fri, 11 Nov 2016 16:12:13 -0800 Subject: Added nil-coalescing operator --- swift.html.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/swift.html.markdown b/swift.html.markdown index b6554dc6..c17510b6 100644 --- a/swift.html.markdown +++ b/swift.html.markdown @@ -104,6 +104,11 @@ if let someOptionalStringConstant = someOptionalString { } } +// The nil-coalescing operator ?? unwraps an optional if it contains a non-nil value, or returns a default value. +var someOptionalString: String? +let someString = someOptionalString ?? "abc" +print(someString) // abc + // Swift has support for storing a value of any type. // For that purposes there is two keywords: `Any` and `AnyObject` // `AnyObject` == `id` from Objective-C -- cgit v1.2.3 From fa83a136d0fecb1309ebc07ed30b0ddc1ea701f9 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sun, 13 Nov 2016 23:07:52 -0800 Subject: Add issue template --- ISSUE_TEMPLATE.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ISSUE_TEMPLATE.md diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..81acaa77 --- /dev/null +++ b/ISSUE_TEMPLATE.md @@ -0,0 +1,3 @@ +- [ ] Issue title is prepended with `[language/lang-code]` if the language is +already on the site. If it's a request for a new language, use: +`Request: [language/lang-code]` -- cgit v1.2.3 From 809e5d20a91c14adfd5ce54f481e674938c3719e Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sun, 13 Nov 2016 23:15:34 -0800 Subject: Remove checkboxes and make a helpful suggestion to submit a pull request to fix issues if the person is willing and able --- ISSUE_TEMPLATE.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 81acaa77..052de086 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -1,3 +1,6 @@ -- [ ] Issue title is prepended with `[language/lang-code]` if the language is -already on the site. If it's a request for a new language, use: -`Request: [language/lang-code]` +Make sure the issue title is prepended with '[language/lang-code]' if the language is +already on the site. +If it's a request for a new language, use: '[Request] [language/lang-code]' + +Issues are always welcome. If you are able and willing, we welcome any pull requets +as this is a community powered project. -- cgit v1.2.3 From ac6d64168f29f149ab9d8d5ea6b5fe785db229c3 Mon Sep 17 00:00:00 2001 From: Smosker Date: Tue, 15 Nov 2016 16:10:56 +0400 Subject: Fix a bug Should add return to double_numbers function, without it next expression wiil fall with "TypeError: 'NoneType' object is not iterable" error for value in double_numbers(range(1000000)): # `test_non_generator` print value if value > 5: break --- python.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/python.html.markdown b/python.html.markdown index 55f56071..6d881355 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -692,6 +692,7 @@ def double_numbers(iterable): double_arr = [] for i in iterable: double_arr.append(i + i) + return double_arr # Running the following would mean we'll double all values first and return all # of them back to be checked by our condition -- cgit v1.2.3 From ebc70fe2897cd8fddcde60299fb4fd9b0aae5150 Mon Sep 17 00:00:00 2001 From: Chung-Ping Huang Date: Wed, 16 Nov 2016 14:49:32 +0800 Subject: Add a missing semi-colon (#2572) Add a missing semi-colon at Line 470 --- php.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php.html.markdown b/php.html.markdown index 82d27546..c8e73987 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -467,7 +467,7 @@ function variable($word, ...$list) { } } -variable("Separate", "Hello", "World") // Separate || Hello | World | +variable("Separate", "Hello", "World"); // Separate || Hello | World | /******************************** * Includes -- cgit v1.2.3 From ce00d724a1c648b5a735fcc79276c4157d0f883d Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 16 Nov 2016 15:21:24 -0800 Subject: Fix #2573 where ru-ru HTML file did not specify which language it was in the YAML frontmatter --- ru-ru/html-ru.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/ru-ru/html-ru.html.markdown b/ru-ru/html-ru.html.markdown index 5cf95fc4..5069d77f 100644 --- a/ru-ru/html-ru.html.markdown +++ b/ru-ru/html-ru.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Christophe THOMAS", "https://github.com/WinChris"] translators: - ["Lana Tim", "https://github.com/LanaTim"] +lang: ru-ru --- HTML расшифровывается как Hypertext Markup Language(гипертекстовый язык разметки). -- cgit v1.2.3 From 13369ee56c3594d38bf877b39076db56434c7321 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 16 Nov 2016 15:34:24 -0800 Subject: [tcl/en] Fix #2569 and also fit to 79 columns width --- tcl.html.markdown | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/tcl.html.markdown b/tcl.html.markdown index 9118081d..d3e80f87 100644 --- a/tcl.html.markdown +++ b/tcl.html.markdown @@ -57,9 +57,9 @@ lighter that that of Lisp, just gets out of the way. ```tcl #! /bin/env tclsh -################################################################################ +############################################################################### ## 1. Guidelines -################################################################################ +############################################################################### # Tcl is not Bash or C! This needs to be said because standard shell quoting # habits almost work in Tcl and it is common for people to pick up Tcl and try @@ -72,9 +72,9 @@ lighter that that of Lisp, just gets out of the way. # are formatted as lists. -################################################################################ +############################################################################### ## 2. Syntax -################################################################################ +############################################################################### # Every line is a command. The first word is the name of the command, and # subsequent words are arguments to the command. Words are delimited by @@ -151,6 +151,8 @@ set greeting "Hello, [set {first name}]" # To promote the words within a word to individual words of the current # command, use the expansion operator, "{*}". +``` +```tcl set {*}{name Neo} # is equivalent to @@ -171,14 +173,15 @@ namespace eval people { } -#The full name of a variable includes its enclosing namespace(s), delimited by two colons: +# The full name of a variable includes its enclosing namespace(s), delimited by +# two colons: set greeting "Hello $people::person1::name" -################################################################################ +############################################################################### ## 3. A Few Notes -################################################################################ +############################################################################### # All other functionality is implemented via commands. From this point on, # there is no new syntax. Everything else there is to learn about Tcl is about @@ -192,10 +195,11 @@ set greeting "Hello $people::person1::name" namespace delete :: -# Because of name resolution behaviour, it's safer to use the "variable" command to -# declare or to assign a value to a namespace. If a variable called "name" already -# exists in the global namespace, using "set" here will assign a value to the global variable -# instead of creating a new variable in the local namespace. +# Because of name resolution behaviour, it's safer to use the "variable" +# command to declare or to assign a value to a namespace. If a variable called +# "name" already exists in the global namespace, using "set" here will assign +# a value to the global variable instead of creating a new variable in the +# local namespace. namespace eval people { namespace eval person1 { variable name Neo @@ -208,9 +212,9 @@ set people::person1::name Neo -################################################################################ +############################################################################### ## 4. Commands -################################################################################ +############################################################################### # Math can be done with the "expr" command. set a 3 @@ -294,7 +298,8 @@ while {$i < 10} { } -# A list is a specially-formatted string. In the simple case, whitespace is sufficient to delimit values +# A list is a specially-formatted string. In the simple case, whitespace is +# sufficient to delimit values set amounts 10\ 33\ 18 set amount [lindex $amounts 1] @@ -406,7 +411,7 @@ proc set_double {varname value} { } -#get rid of the built-in "while" command. +# Get rid of the built-in "while" command. rename ::while {} -- cgit v1.2.3 From 41d7d73aaac89159a84e551005dcbf4475f29325 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Thu, 17 Nov 2016 22:32:23 -0800 Subject: Fix #2574 --- ISSUE_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 052de086..022dedab 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -2,5 +2,5 @@ Make sure the issue title is prepended with '[language/lang-code]' if the langua already on the site. If it's a request for a new language, use: '[Request] [language/lang-code]' -Issues are always welcome. If you are able and willing, we welcome any pull requets +Issues are always welcome. If you are able and willing, we welcome any pull requests as this is a community powered project. -- cgit v1.2.3 From 03bab0e47b38c113e26c064b11cbd171675214a1 Mon Sep 17 00:00:00 2001 From: Thien Do Date: Mon, 21 Nov 2016 02:31:22 +0700 Subject: Use ts for typescript syntax --- typescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript.html.markdown b/typescript.html.markdown index 1d712369..204b501a 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -13,7 +13,7 @@ This article will focus only on TypeScript extra syntax, as opposed to [JavaScri To test TypeScript's compiler, head to the [Playground] (http://www.typescriptlang.org/Playground) where you will be able to type code, have auto completion and directly see the emitted JavaScript. -```js +```ts // There are 3 basic types in TypeScript var isDone: boolean = false; var lines: number = 42; -- cgit v1.2.3 From ac99d3f1cba2d49a7b2560fe338f6a14044a6eaa Mon Sep 17 00:00:00 2001 From: Thien Do Date: Mon, 21 Nov 2016 03:41:16 +0700 Subject: [typescript/en-us] Clarify function section in typescript (#2575) * Clarify function section in typescript * one-liner to braceless --- typescript.html.markdown | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typescript.html.markdown b/typescript.html.markdown index 1d712369..23e0bab4 100644 --- a/typescript.html.markdown +++ b/typescript.html.markdown @@ -46,10 +46,12 @@ function bigHorribleAlert(): void { var f1 = function(i: number): number { return i * i; } // Return type inferred var f2 = function(i: number) { return i * i; } +// "Fat arrow" syntax var f3 = (i: number): number => { return i * i; } -// Return type inferred +// "Fat arrow" syntax with return type inferred var f4 = (i: number) => { return i * i; } -// Return type inferred, one-liner means no return keyword needed +// "Fat arrow" syntax with return type inferred, braceless means no return +// keyword needed var f5 = (i: number) => i * i; // Interfaces are structural, anything that has the properties is compliant with -- cgit v1.2.3 From e25918acabcafc8f2e3bda35e8e28fa583cb70b9 Mon Sep 17 00:00:00 2001 From: Christopher Lorton Date: Mon, 21 Nov 2016 01:38:39 -0800 Subject: Fix comment in set comprehension example (#2580) The result should be {'a', 'b', 'c'} (not {'d', 'e', 'f'}). --- python.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python.html.markdown b/python.html.markdown index 55f56071..050503c3 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -550,7 +550,7 @@ filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] [x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7] # You can construct set and dict comprehensions as well. -{x for x in 'abcddeef' if x in 'abc'} # => {'d', 'e', 'f'} +{x for x in 'abcddeef' if x in 'abc'} # => {'a', 'b', 'c'} {x: x**2 for x in range(5)} # => {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} -- cgit v1.2.3 From c518beae09eafa02a392a1ea35782871f85c6311 Mon Sep 17 00:00:00 2001 From: derek-austin Date: Tue, 22 Nov 2016 12:45:45 +0100 Subject: Add syntax highlight (#2581) Only the first chunk of code was highlighted --- powershell.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/powershell.html.markdown b/powershell.html.markdown index f34d5b4e..573b5440 100644 --- a/powershell.html.markdown +++ b/powershell.html.markdown @@ -35,7 +35,7 @@ $PSVersionTable Getting help: -``` +```powershell # Find commands Get-Command about_* # alias: gcm Get-Command -Verb Add @@ -52,7 +52,7 @@ Update-Help # Run as admin The tutorial starts here: -``` +```powershell # As you already figured, comments start with # # Simple hello world example: @@ -300,7 +300,7 @@ $Shortcut.Save() Configuring your shell -``` +```powershell # $Profile is the full path for your `Microsoft.PowerShell_profile.ps1` # All code there will be executed when the PS session starts if (-not (Test-Path $Profile)) { -- cgit v1.2.3 From 152fddbd9245c6380f7113eb7639fbf0d1fd1c2c Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 23 Nov 2016 09:43:37 -0800 Subject: Fix backtick that was messing up syntax highlighting on powershell. --- powershell.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powershell.html.markdown b/powershell.html.markdown index 573b5440..bd46051c 100644 --- a/powershell.html.markdown +++ b/powershell.html.markdown @@ -74,7 +74,7 @@ $aHashtable = @{name1='val1'; name2='val2'} # Using variables: echo $aString echo "Interpolation: $aString" -echo "`$aString has length of $($aString.Length)" +echo "$aString has length of $($aString.Length)" echo '$aString' echo @" This is a Here-String -- cgit v1.2.3 From 52bbc815204f8ea2135c3b63eef20dd6fd9033a8 Mon Sep 17 00:00:00 2001 From: Robert Benjamin Date: Tue, 29 Nov 2016 13:51:15 -0800 Subject: Fix minor spacing typo (#2586) --- dynamic-programming.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic-programming.html.markdown b/dynamic-programming.html.markdown index 94be22e9..7df367e7 100644 --- a/dynamic-programming.html.markdown +++ b/dynamic-programming.html.markdown @@ -9,7 +9,7 @@ contributors: ## Introduction -Dynamic Programming is a powerful technique used for solving a particular class of problems as we will see.The idea is very simple, If you have solved a problem with the given input, then save the result for future reference, so as to avoid solving the same problem again. +Dynamic Programming is a powerful technique used for solving a particular class of problems as we will see. The idea is very simple, If you have solved a problem with the given input, then save the result for future reference, so as to avoid solving the same problem again. Always remember! "Those who can't remember the past are condemned to repeat it" -- cgit v1.2.3 From d0918b2576abcefcfca1f439e3b03511f1be0b89 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Wed, 30 Nov 2016 21:01:27 +0900 Subject: [python3/en] Add empty tuple to "False if evaluated" list (#2587) --- python3.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python3.html.markdown b/python3.html.markdown index 839d66fd..04d103f4 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -143,13 +143,13 @@ None # => None "etc" is None # => False None is None # => True -# None, 0, and empty strings/lists/dicts all evaluate to False. +# None, 0, and empty strings/lists/dicts/tuples all evaluate to False. # All other values are True bool(0) # => False bool("") # => False bool([]) # => False bool({}) # => False - +bool(()) # => False #################################################### ## 2. Variables and Collections -- cgit v1.2.3 From 51ce7fda40f3c951b807971587374c56fa9d7916 Mon Sep 17 00:00:00 2001 From: Derek Date: Wed, 30 Nov 2016 15:36:56 -0500 Subject: [racket/en] Expand list section (#2588) * Expand list section * Update backtick --- racket.html.markdown | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/racket.html.markdown b/racket.html.markdown index 96dcaf25..38335bc1 100644 --- a/racket.html.markdown +++ b/racket.html.markdown @@ -164,10 +164,17 @@ my-pet ; => # (cons 1 (cons 2 (cons 3 null))) ; => '(1 2 3) ;; `list' is a convenience variadic constructor for lists (list 1 2 3) ; => '(1 2 3) -;; and a quote can also be used for a literal list value +;; a quote can also be used for a literal list value '(1 2 3) ; => '(1 2 3) +;; a quasiquote (represented by the backtick character) with commas +;; can be used to evaluate functions +`(1 ,(+ 1 1) 3) ; => '(1 2 3) -;; Racket has predefined functions on top of car and cdr, to extract parts of a list +;; With lists, car/cdr work slightly differently +(car '(1 2 3)) ; => 1 +(cdr '(1 2 3)) ; => '(2 3) + +;; Racket also has predefined functions on top of car and cdr, to extract parts of a list (cadr (list 1 2 3)) ; => 2 (car (cdr (list 1 2 3))) ; => 2 -- cgit v1.2.3 From 6cc36cb0902f1b29424b6e52b8ddfaea68c88563 Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 1 Dec 2016 15:19:08 +0100 Subject: fix #2589 --- visualbasic.html.markdown | 8 -------- 1 file changed, 8 deletions(-) diff --git a/visualbasic.html.markdown b/visualbasic.html.markdown index 0371e6f6..f081b907 100644 --- a/visualbasic.html.markdown +++ b/visualbasic.html.markdown @@ -272,11 +272,3 @@ Module Module1 End Module ``` - -## References - -I learnt Visual Basic in the console application. It allowed me to understand the principles of computer programming to go on to learn other programming languages easily. - -I created a more indepth Visual Basic tutorial for those who would like to learn more. - -The entire syntax is valid. Copy the and paste in to the Visual Basic compiler and run (F5) the program. -- cgit v1.2.3 From 7c16ec5ae15ca3d29354179b33f290fb439f434c Mon Sep 17 00:00:00 2001 From: Badal Surana Date: Sat, 3 Dec 2016 16:16:23 +0530 Subject: [php/en] Fix typo (#2590) --- php.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php.html.markdown b/php.html.markdown index c8e73987..ddf38226 100644 --- a/php.html.markdown +++ b/php.html.markdown @@ -824,7 +824,7 @@ echo "Current method is " . __METHOD__; echo "Current namespace is " . __NAMESPACE__; // Get the name of the current trait. Only returns a value when used inside a trait or object declaration. -echo "Current namespace is " . __TRAIT__; +echo "Current trait is " . __TRAIT__; /********************** * Error Handling -- cgit v1.2.3 From c701931feebc96d8b4215dd66e268fab2c1bbacf Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sat, 3 Dec 2016 19:46:32 +0900 Subject: [python3/en] fixed "StopIterator", no such Exception (#2591) * [python3/en] Add empty tuple to "False if evaluated" list * [python3/en] Fixed "StopIterator Exception" - no such exception --- python3.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python3.html.markdown b/python3.html.markdown index 04d103f4..3821d84f 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -491,7 +491,7 @@ next(our_iterator) # => "one" next(our_iterator) # => "two" next(our_iterator) # => "three" -# After the iterator has returned all of its data, it gives you a StopIterator Exception +# After the iterator has returned all of its data, it gives you a StopIteration Exception next(our_iterator) # Raises StopIteration # You can grab all the elements of an iterator by calling list() on it. -- cgit v1.2.3 From 61e0d6e13b72d12111e9a42987ebcb5475ad25b9 Mon Sep 17 00:00:00 2001 From: kakakaya Date: Sun, 4 Dec 2016 18:07:24 +0900 Subject: [python3/ja-jp] New Translation: python3/ja-jp (#2592) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [python3/en] Add empty tuple to "False if evaluated" list * Add python3 to ja-jp directory * Translated section 1 * 2章 * コメントのインデントを変更 * 3章 * [python3/en] Fixed "StopIterator Exception" - no such exception * 4章 * 5章 * 6.0章 * 6.1章 * 7章 * [python3/ja-jp] Fixed filename * Fix filename suffix, lang code --- ja-jp/python3-jp.html.markdown | 898 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 898 insertions(+) create mode 100644 ja-jp/python3-jp.html.markdown diff --git a/ja-jp/python3-jp.html.markdown b/ja-jp/python3-jp.html.markdown new file mode 100644 index 00000000..3b1a0d73 --- /dev/null +++ b/ja-jp/python3-jp.html.markdown @@ -0,0 +1,898 @@ +--- +language: python3 +contributors: + - ["Louie Dinh", "http://pythonpracticeprojects.com"] + - ["Steven Basart", "http://github.com/xksteven"] + - ["Andre Polykanine", "https://github.com/Oire"] + - ["Zachary Ferguson", "http://github.com/zfergus2"] + - ["evuez", "http://github.com/evuez"] +translators: + - ["kakakaya", "https://github.com/kakakaya"] +filename: learnpython3-jp.py +lang: ja-jp +--- + +90年代の初め、Guido Van RossumによってPythonは作成されました。現在となっては、最も有名な言語の1つです。 +私は構文の明快さによって、Pythonと恋に落ちました。 +以下は基本的に実行可能な疑似コードです。 + +フィードバッグは大歓迎です! [@louiedinh](http://twitter.com/louiedinh) または louiedinh [at] [google's email service] にご連絡下さい! + +Note: この記事はPython 3に内容を絞っています。もし古いPython 2.7を学習したいなら、 [こちら](http://learnxinyminutes.com/docs/python/) をご確認下さい。 + +```python + +# 1行のコメントは番号記号(#)から始まります。 + +""" 複数行の文字は、"を3つ繋げることで + 書くことができます。 + また、これはコメントとしてもよく使われます。 +""" + +#################################################### +# 1. プリミティブ型と演算子 +#################################################### + +# 数字です +3 # => 3 + +# 四則演算はあなたの期待通りに動きます。 +1 + 1 # => 2 +8 - 1 # => 7 +10 * 2 # => 20 +35 / 5 # => 7.0 + +# 整数除算の結果は、正負に関わらず小数の切り捨てが行われます。 +5 // 3 # => 1 +5.0 // 3.0 # => 1.0 # 浮動小数点でも同様に動作します。 +-5 // 3 # => -2 +-5.0 // 3.0 # => -2.0 + +# 除算の結果は常に浮動小数点になります。 +10.0 / 3 # => 3.3333333333333335 + +# 剰余の計算 +7 % 3 # => 1 + +# 冪乗 (x**y, x の y 乗) +2**4 # => 16 + +# 括弧により、計算の順番を優先させられます。 +(1 + 3) * 2 # => 8 + +# 真偽値はプリミティブ型です(大文字から始まっていることに注意!) +True +False + +# not で真偽を反転させられます。 +not True # => False +not False # => True + +# ブール演算 +# 注意: "and" と "or" は小文字です +True and False # => False +False or True # => True + +# 整数でブール演算をするときのメモ +0 and 2 # => 0 +-5 or 0 # => -5 +0 == False # => True +2 == True # => False +1 == True # => True + +# 値が等しいか確認するには == +1 == 1 # => True +2 == 1 # => False + +# 値が等しくないか確認するには != +1 != 1 # => False +2 != 1 # => True + +# 他の比較方法 +1 < 10 # => True +1 > 10 # => False +2 <= 2 # => True +2 >= 2 # => True + +# 比較は連結させられます! +1 < 2 < 3 # => True +2 < 3 < 2 # => False + +# (is vs. ==) +# "is" は、2つの変数が同一のオブジェクトを参照しているか確認します。 +# 一方 "==" は、それぞれが参照する2つのオブジェクトが同じ値を持つか確認します。 +a = [1, 2, 3, 4] # a は新しいリストの [1, 2, 3, 4] を指します。 +b = a # b は a が指すリストを指します。 +b is a # => True, a と b は同一のオブジェクトを参照しています。 +b == a # => True, a と b が参照するオブジェクトの値は等しいです。 +b = [1, 2, 3, 4] # b は新しいリストの [1, 2, 3, 4] を指します。 +b is a # => False, a と b は別々のオブジェクトを参照しています。 +b == a # => True, a と b が参照するオブジェクトの値は等しいです。 + +# " または ' を使って文字列を作成します。 +"This is a string." +'This is also a string.' + +# 文字列も加算をすることができます!でも、あまり行わないように。 +"Hello " + "world!" # => "Hello world!" +# '+' を使わなくても連結はできます。 +"Hello " "world!" # => "Hello world!" + +# 文字列は文字のリストであるかのように扱うことができます。 +"This is a string"[0] # => 'T' + +# 文字列の長さを得るにはこのようにします。 +len("This is a string") # => 16 + +# .format で文字列のフォーマットを行えます +"{} can be {}".format("Strings", "interpolated") # => "Strings can be interpolated" + +# 入力を減らすために、フォーマットするときに引数を繰り返し使うことができます。 +"{0} be nimble, {0} be quick, {0} jump over the {1}".format("Jack", "candle stick") +# => "Jack be nimble, Jack be quick, Jack jump over the candle stick" + +# 引数の順番を数えるのがお嫌い?キーワード引数をどうぞ。 +"{name} wants to eat {food}".format(name="Bob", food="lasagna") # => "Bob wants to eat lasagna" + +# もし Python 3 のコードを Python 2.5以下でも使う必要があるなら、 +# 旧式のフォーマット方法を使うこともできます。 +"%s can be %s the %s way" % ("Strings", "interpolated", "old") # => "Strings can be interpolated the old way" + + +# None はオブジェクトです(大文字からです!) +None # => None + +# オブジェクトがNoneであるか確認するのに "==" 演算子を使わないように。 +# 代わりに "is" を使いましょう。オブジェクトの素性を確認できます。 +"etc" is None # => False +None is None # => True + +# None や 0 、空の 文字列/リスト/辞書/タプル は全て False として評価されます。 +# 他の全ての値は True になります。 +bool(0) # => False +bool("") # => False +bool([]) # => False +bool({}) # => False +bool(()) # => False + +#################################################### +# 2. Variables and Collections +#################################################### + +# Python にはprint関数があります。 +print("I'm Python. Nice to meet you!") # => I'm Python. Nice to meet you! + +# 標準では、print関数は最後に改行を出力します。 +# この動作を変更するためには、オプション引数を利用します。 +print("Hello, World", end="!") # => Hello, World! + +# コンソールから入力を得るための簡単な例 +input_string_var = input("Enter some data: ") # 入力を文字列として返します +# Note: Python の初期のバージョンでは、 input() は raw_input() という名前で存在します。 + +# 変数に代入する前に宣言する必要はありません。 +# 慣例的に、小文字でアンダースコア区切り ( lower_case_with_underscores ) の変数が使われます。 +some_var = 5 +some_var # => 5 + +# 代入されていない変数へのアクセスは例外を引き起こします。 +# 例外の取り扱いについては、3章の制御の流れをご確認ください。 +some_unknown_var # NameError を送出します + +# ifは式として使用できます。 +# C言語の「?:(三項演算子)」に対応する例: +"yahoo!" if 3 > 2 else 2 # => "yahoo!" + +# リストは順序を保存します。 +li = [] +# 値の入っているリストも作成できます。 +other_li = [4, 5, 6] + +# append により、リストの末尾にものを入れられます。 +li.append(1) # li is now [1] +li.append(2) # li is now [1, 2] +li.append(4) # li is now [1, 2, 4] +li.append(3) # li is now [1, 2, 4, 3] +# pop でリストの末尾から取り除けます。 +li.pop() # => 3 and li is now [1, 2, 4] +# 元に戻しましょう! +li.append(3) # li is now [1, 2, 4, 3] again. + +# 配列のように、リストにアクセスできます。 +li[0] # => 1 +# 最後の要素を参照できます。 +li[-1] # => 3 + +# 範囲外の要素を参照すると IndexError になります。 +li[4] # IndexError が発生します + +# スライス構文により範囲を参照できます。 +li[1:3] # => [2, 4] +# 先端を取り除く +li[2:] # => [4, 3] +# 末尾を取り除く +li[:3] # => [1, 2, 4] +# 1つ飛ばしで選択する +li[::2] # =>[1, 4] +# 反転したリストを得る +li[::-1] # => [3, 4, 2, 1] +# これらの任意の組み合わせにより、より複雑なスライスを作ることができます。 +# li[start:end:step] + +# スライスにより、深いコピーを1階層分行うことができます。 +li2 = li[:] # => li2 = [1, 2, 4, 3] だが、 (li2 is li) はFalseになる。 + +# "del"によりリストから任意の要素を削除できます。 +del li[2] # li は [1, 2, 3] になりました。 + +# "remove"で最初に出現する要素を削除できます。 +li.remove(2) # li は [1, 3] になりました。 +li.remove(2) # 2はリストの中に存在しないので、 ValueError が発生します。 + +# 要素を好きなところに挿入できます。 +li.insert(1, 2) # li は [1, 2, 3] に戻りました。 + +# "index"で引数の要素が最初に出現する場所のインデックスを得られます。 +li.index(2) # => 1 +li.index(4) # 4はリストの中に存在しないので、 ValueError が発生します。 + +# リスト同士を足すこともできます。 +# Note: li と other_li の値は変更されません。 +li + other_li # => [1, 2, 3, 4, 5, 6] + +# "extend()"で他のリストを連結することができます。 +li.extend(other_li) # li は [1, 2, 3, 4, 5, 6] になります。 + +# リストの中に値が存在するか、 "in" で確認できます。 +1 in li # => True + +# 長さは "len()" で確認できます。 +len(li) # => 6 + + +# タプルはリストのようなものですが、不変であるという違いがあります。 +tup = (1, 2, 3) +tup[0] # => 1 +tup[0] = 3 # 内容を変更しようとすると TypeError が発生します。 + +# 長さが1のタプルを作成するには、要素の後にカンマを付ける必要があります。 +# しかし、それ以外の長さなら、例え長さが0でもそのようにする必要はありません。 +type((1)) # => +type((1,)) # => +type(()) # => + +# 大抵のリスト操作はタプルでも行うことができます。 +len(tup) # => 3 +tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6) +tup[:2] # => (1, 2) +2 in tup # => True + +# タプルやリストから複数の変数に代入することができます。 +a, b, c = (1, 2, 3) # a, b, c にはそれぞれ 1, 2, 3 が代入されました。 +# 拡張記法もあります。 +a, *b, c = (1, 2, 3, 4) # a は 1 、 b は [2, 3] 、c は4 になります。 +# 括弧を作成しなくてもデフォルトでタプルが作成されます。 +d, e, f = 4, 5, 6 +# 2つの変数を交換するのがどれほど簡単か見てみましょう。 +e, d = d, e # d は 5 、 e は e になります。 + + +# 辞書はマップ(キーと値の組み合わせ)を保存できます。 +empty_dict = {} +# 値が入っている辞書を直接作成することもできます。 +filled_dict = {"one": 1, "two": 2, "three": 3} + +# キーは不変の型である必要があります。 +# これは、高速化のため、キーを定数のハッシュ値に変換できるようにするためです。 +# 不変の型の例として、int、float、string、tupleなどが上げられます。 +invalid_dict = {[1, 2, 3]: "123"} # => list はハッシュ化できないので、 TypeError が発生します。 +valid_dict = {(1, 2, 3): [1, 2, 3]} # 一方、キーに対応する値はどのような型でも利用できます。 + +# [] で 値を取り出せます。 +filled_dict["one"] # => 1 + +# "keys()"により、全てのキーを反復可能な形式で取り出せます。 +# これをリストにするために、"list()"で囲んでいます。これについては後程解説します。 +# Note: 辞書のキーの順番は考慮されていません。実行した結果がこれと異なる場合があります。 +list(filled_dict.keys()) # => ["three", "two", "one"] + +# "values()"により、全ての値を反復可能な形式で取り出せます。 +# 前と同じように、これをリストにするために、"list()"で囲んでいます。 +# Note: 辞書の値の順番は考慮されていません。実行した結果がこれと異なる場合があります。 +list(filled_dict.values()) # => [3, 2, 1] + + +# "in" により、辞書のキーが存在するか確認できます。 +"one" in filled_dict # => True +1 in filled_dict # => False + +# 存在しないキーで辞書を参照すると KeyError になります。 +filled_dict["four"] # KeyError + +# "get()" メソッドを使うことで KeyError を回避できます。 +filled_dict.get("one") # => 1 +filled_dict.get("four") # => None +# get ではキーが存在しなかったときのデフォルト値を指定できます。 +filled_dict.get("one", 4) # => 1 +filled_dict.get("four", 4) # => 4 + +# "setdefault()" で、キーが存在しなかった場合のみ、値を設定できます。 +filled_dict.setdefault("five", 5) # filled_dict["five"] は 5 になりました。 +filled_dict.setdefault("five", 6) # filled_dict["five"] は 5 のままです。 + +# 辞書にマップを追加する +filled_dict.update({"four": 4}) # => {"one": 1, "two": 2, "three": 3, "four": 4} +# filled_dict["four"] = 4 # 辞書に追加する別の方法 + +# del により辞書からキーを削除できます。 +del filled_dict["one"] # "one" キーを辞書から削除します。 + +# Python 3.5 以降では、追加の値を取り出す方法があります。 +{'a': 1, **{'b': 2}} # => {'a': 1, 'b': 2} +{'a': 1, **{'a': 2}} # => {'a': 2} + + +# set では集合を表現できます。 +empty_set = set() +# 集合を一連の値で初期化する例です。辞書に似ていますね?ごめんなさい。 +some_set = {1, 1, 2, 2, 3, 4} # some_set is now {1, 2, 3, 4} + +# 辞書のキーのように、集合の値は不変である必要があります。 +invalid_set = {[1], 1} # => list はハッシュ化できないので、 TypeError が送出されます。 +valid_set = {(1,), 1} + +# 新しい値を集合にセットできます。 +filled_set = some_set + +# 集合に新しい要素を追加できます。 +filled_set.add(5) # filled_set は {1, 2, 3, 4, 5} になりました。 + +# & により、集合同士の共通部分が得られます。 +other_set = {3, 4, 5, 6} +filled_set & other_set # => {3, 4, 5} + +# | により、集合同士の合併が得られます。 +filled_set | other_set # => {1, 2, 3, 4, 5, 6} + +# - により、集合同士の差集合が得られます。 +{1, 2, 3, 4} - {2, 3, 5} # => {1, 4} + +# ^ により、集合同士の対象差が得られます。 +{1, 2, 3, 4} ^ {2, 3, 5} # => {1, 4, 5} + +# 左の集合が右の集合の上位集合であるか確認。 +{1, 2} >= {1, 2, 3} # => False + +# 左の集合が右の集合の部分集合であるか確認。 +{1, 2} <= {1, 2, 3} # => True + +# in により値が集合の中に存在するか確認できます。 +2 in filled_set # => True +10 in filled_set # => False + + +#################################################### +# 3. 制御の流れとiterable +#################################################### + +# まずは変数を作りましょう。 +some_var = 5 + +# これはif文です。インデントがPythonでは特徴的ですね! +# 以下の例では"some_var is smaller than 10"と出力されます。 +if some_var > 10: + print("some_var is totally bigger than 10.") +elif some_var < 10: # この elif 節はオプションです。 + print("some_var is smaller than 10.") +else: # この else 節もオプションです。 + print("some_var is indeed 10.") + + +""" +for ループはリストの要素を反復することができます。 +出力: + dog is a mammal + cat is a mammal + mouse is a mammal +""" +for animal in ["dog", "cat", "mouse"]: + # format() を使って文字列に変数を挿入して出力できます。 + print("{} is a mammal".format(animal)) + +""" +"range(数値)" は、ゼロから与えられた数値までのiterableを返します。 +出力: + 0 + 1 + 2 + 3 +""" +for i in range(4): + print(i) + +""" +"range(lower, upper)" は、 lower の数値から upper の数値までのiterableを返します。 +upper の数値は含まれません。 +出力: + 4 + 5 + 6 + 7 +""" +for i in range(4, 8): + print(i) + +""" +"range(lower, upper, step)" は、lower の数値から upper の数値までが、 +step 刻みで表現されるiterableを返します +step が与えられない場合、デフォルトは1になります。 +出力: + 4 + 6 +""" +for i in range(4, 8, 2): + print(i) +""" + +while によるループは条件が成立しなくなるまで実行されます。 +出力: + 0 + 1 + 2 + 3 +""" +x = 0 +while x < 4: + print(x) + x += 1 # x = x + 1 の省略記法 + +# try/except ブロックにより、例外を扱う +try: + # "raise" により例外を発生させます。 + raise IndexError("This is an index error") +except IndexError as e: + pass # pass は、何もしないという命令(no-op)に相当します。普通、ここで例外に対処します。 +except (TypeError, NameError): + pass # もし必要なら、複数の種類の例外を一緒に処理できます。 +else: # try/except ブロックへのオプションの節。他の全てのexceptブロックより後に置かなければなりません。 + print("All good!") # tryで例外が発生しなかった場合のみ実行されます。 +finally: # 例外が発生したか、しなかったか、どのような例外だったかに関らず実行されます。 + print("We can clean up resources here") + +# try/finallyでリソースの始末をする代わりに、 with 文を使うこともできます。 +with open("myfile.txt") as f: + for line in f: + print(line) + +# Pythonは、iterableと呼ばれる基本的な抽象化が提供しています。 +# iterableは、シーケンスとして取り扱えるオブジェクトです。 +# range関数で返されるオブジェクトもiterableの一種です。 +filled_dict = {"one": 1, "two": 2, "three": 3} +our_iterable = filled_dict.keys() +print(our_iterable) # => dict_keys(['one', 'two', 'three']). これはiterableインタフェースを実装するオブジェクトです。 + +# iterableでループを行うことができます。 +for i in our_iterable: + print(i) # Prints one, two, three + +# しかし、インデックスで要素を参照することはできません。 +our_iterable[1] # TypeError が発生します。 + +# iterableは、iteratorの作り方がわかるオブジェクトです。 +our_iterator = iter(our_iterable) + +# iterator は、要素を取り出したときの状態を覚えるオブジェクトです。 +# "next()"により次の要素を取り出せます。 +next(our_iterator) # => "one" + +# 反復(iterate)する度に、状態を更新します。 +next(our_iterator) # => "two" +next(our_iterator) # => "three" + +# iteratorが自身の持つ全てのデータを返したあとは、 StopIteration 例外を発生させます。 +next(our_iterator) # StopIteration が発生します。 + +# "list()"を呼ぶことにより、iteratorの全ての要素を得られます。 +list(filled_dict.keys()) # => ["one", "two", "three"] + + +#################################################### +# 4. 関数 +#################################################### + +# 新しい関数を作成するには "def" を使います。 +def add(x, y): + print("x is {} and y is {}".format(x, y)) + return x + y # return 文で値を返します。 + +# 引数付きで関数を呼んでみましょう。 +add(5, 6) # => "x is 5 and y is 6" と出力し、 11 を返します。 + +# キーワード引数で関数を呼ぶこともできます。 +add(y=6, x=5) # キーワード引数を使うと任意の順番で引数を指定できます。 + + +# 可変数の位置引数を持つ関数を定義できます。 +def varargs(*args): + return args + +varargs(1, 2, 3) # => (1, 2, 3) + + +# 可変数のキーワード引数を持つ関数を定義できます。 +def keyword_args(**kwargs): + return kwargs + +# 何が起こるか、試してみましょう +keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"} + + +# お望みなら、両方一気にやることもできます。 +def all_the_args(*args, **kwargs): + print(args) + print(kwargs) +""" +all_the_args(1, 2, a=3, b=4) prints: + (1, 2) + {"a": 3, "b": 4} +""" + +# 関数を呼ぶとき、 args/kwargs の逆のことをすることができます! +# * を使ってタプルを展開したり、 ** を使って辞書を展開できます。 +args = (1, 2, 3, 4) +kwargs = {"a": 3, "b": 4} +all_the_args(*args) # foo(1, 2, 3, 4) に対応します。 +all_the_args(**kwargs) # foo(a=3, b=4) に対応します。 +all_the_args(*args, **kwargs) # foo(1, 2, 3, 4, a=3, b=4) に対応します。 + + +# タプルで複数の値を返す +def swap(x, y): # 括弧を使わずに、複数の値をタプルとして返すことができます。 + return y, x # (Note: 括弧は使わなくてもいいですが、使うこともできます。) + + +x = 1 +y = 2 +x, y = swap(x, y) # => x = 2, y = 1 +# (x, y) = swap(x,y) # このように、括弧は使っても使わなくてもいいです。 + + +# 関数のスコープ +x = 5 + + +def set_x(num): + # ローカル変数の x はグローバル変数の x とは異なります + x = num # => 43 + print(x) # => 43 + + +def set_global_x(num): + global x + print(x) # => 5 + x = num # グローバル変数の x に 6 が代入されました。 + print(x) # => 6 + +set_x(43) +set_global_x(6) + + +# Pythonは第一級関数をサポートします。 +def create_adder(x): + def adder(y): + return x + y + return adder + +add_10 = create_adder(10) +add_10(3) # => 13 + +# 無名関数もサポートしています。 +(lambda x: x > 2)(3) # => True +(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 + +# 高階関数も組込まれています。 +list(map(add_10, [1, 2, 3])) # => [11, 12, 13] +list(map(max, [1, 2, 3], [4, 2, 1])) # => [4, 2, 3] + +list(filter(lambda x: x > 5, [3, 4, 5, 6, 7])) # => [6, 7] + +# map や filter の代わりに、リスト内包表記を使うことができます。 +# リスト内包表記は、出力を別のリスト内包表記にネストさせることができます。 +[add_10(i) for i in [1, 2, 3]] # => [11, 12, 13] +[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7] + +# 集合(set)や辞書も内包表記ができます。 +{x for x in 'abcddeef' if x not in 'abc'} # => {'d', 'e', 'f'} +{x: x**2 for x in range(5)} # => {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} + + +#################################################### +# 5. モジュール +#################################################### + +# Pythonではモジュールをインポートできます。 +import math +print(math.sqrt(16)) # => 4.0 + +# モジュールの中から特定の関数をインポートすることもできます。 +from math import ceil, floor +print(ceil(3.7)) # => 4.0 +print(floor(3.7)) # => 3.0 + +# 全部の関数をモジュールからインポートすることができます。 +# Warning: この方法は推奨されません。 +from math import * + +# 短い名前でモジュールをインポートすることができます。 +import math as m +math.sqrt(16) == m.sqrt(16) # => True + +# Pythonのモジュールは実際には単なるPythonのファイルです。 +# 自分で書くことも、インポートすることもできます。 +# ファイル名がそのままモジュール名になります。 + +# モジュールで定義されている関数と属性を調べることができます。 +import math +dir(math) + +# もし、現在書いているスクリプトと同じフォルダに「math.py」という +# Pythonのスクリプトが存在する場合、そのmath.pyが +# 組み込みのPythonモジュールの代わりに読み込まれるでしょう。 +# これは、ローカルのフォルダはPythonの組み込みライブラリよりも +# 優先度が高いため発生するのです。 + + +#################################################### +# 6. クラス +#################################################### + +# クラスを作成するために、"class"という演算子を使います。 +class Human: + + # クラスの属性です。このクラスの全てのインスタンスで共有されます。 + species = "H. sapiens" + + # 標準的なイニシャライザで、このクラスがインスタンスを作成するときは毎回呼ばれます。 + # 2つのアンダースコアがオブジェクトや属性の前後についているとき、これらはPythonによって利用され、 + # ユーザーの名前空間には存在しないということに注意してください。 + # __init__ や __str__ 、 __repr__ のようなメソッド(やオブジェクト、属性)は、 + # magic methods (または dunder methods)と呼ばれます。 + # このような名前を自分で発明しないほうがよいでしょう。 + def __init__(self, name): + # 引数をインスタンスのname属性に設定します。 + self.name = name + + # プロパティの初期化 + self.age = 0 + + # インスタンスメソッド。全てのメソッドは"self"を最初の引数に取ります。 + def say(self, msg): + print("{name}: {message}".format(name=self.name, message=msg)) + + # 別のインスタンスメソッドの例。 + def sing(self): + return 'yo... yo... microphone check... one two... one two...' + + # クラスメソッドは全てのインスタンスで共有されます。 + # クラスメソッドではクラスを最初の引数として呼ばれます。 + @classmethod + def get_species(cls): + return cls.species + + # スタティックメソッドはクラスやインスタンスを参照せずに呼ばれます。 + @staticmethod + def grunt(): + return "*grunt*" + + # プロパティはgetterのようなものです。 + # age() メソッドを同名の読取専用属性に変換します。 + @property + def age(self): + return self._age + + # プロパティを設定できるようにします。 + @age.setter + def age(self, age): + self._age = age + + # プロパティを削除できるようにします。 + @age.deleter + def age(self): + del self._age + + +# Pythonインタプリタがソースファイルを読み込んだとき、全てのコードを実行します。 +# この __name__ による確認により、このモジュールがメインのプログラムである場合にのみ、 +# このコードブロックが実行されるようにします。 +if __name__ == '__main__': + # クラスのインスタンスを作成します。 + i = Human(name="Ian") + i.say("hi") # "Ian: hi" + j = Human("Joel") + j.say("hello") # "Joel: hello" + # i と j はHumanのインスタンスです。別の言葉で言うなら、これらはHumanのオブジェクトです。 + + # クラスメソッドを呼んでみましょう。 + i.say(i.get_species()) # "Ian: H. sapiens" + # 共有属性を変更してみましょう。 + Human.species = "H. neanderthalensis" + i.say(i.get_species()) # => "Ian: H. neanderthalensis" + j.say(j.get_species()) # => "Joel: H. neanderthalensis" + + # スタティックメソッドを呼んでみましょう。 + print(Human.grunt()) # => "*grunt*" + print(i.grunt()) # => "*grunt*" + + # インスタンスのプロパティを更新してみましょう。 + i.age = 42 + # プロパティを取得してみましょう。 + i.say(i.age) # => 42 + j.say(j.age) # => 0 + # プロパティを削除してみましょう。 + del i.age + # i.age # => AttributeError が発生します。 + + +#################################################### +# 6.1 多重継承 +#################################################### + +# 別のクラスを定義します。 +class Bat: + + species = 'Baty' + + def __init__(self, can_fly=True): + self.fly = can_fly + + # このクラスも say メソッドを持ちます。 + def say(self, msg): + msg = '... ... ...' + return msg + + # 同様に、独自のメソッドも与えましょう。 + def sonar(self): + return '))) ... (((' + +if __name__ == '__main__': + b = Bat() + print(b.say('hello')) + print(b.fly) + +# ファイル単位のモジュール化を利用するために、上記のクラスを別々のファイルに配置することができます。 +# ここでは、human.pyとbat.pyを作成してみましょう。 + +# 他のファイルから関数をインポートするために、次のような形式を利用してください。 +# from "拡張子無しのファイル名" import "関数またはクラス" + +# superhero.py +from human import Human +from bat import Bat + + +# BatmanはHumanとBatの両方を継承します。 +class Batman(Human, Bat): + + # Batmanは species のクラス属性に独自の値を持ちます。 + species = 'Superhero' + + def __init__(self, *args, **kwargs): + # 通常、属性を継承するにはsuper()を呼び出します。 + # super(Batman, self).__init__(*args, **kwargs) + # しかし、ここでは多重継承を行っているので、 super() はMRO(メソッド解決順序)の次の基本クラスにのみ動作します。 + # なので、全ての祖先に対して明示的に __init__ を呼ぶことにします。 + # *args と **kwargs を使うことで、それぞれの継承元が + # たまねぎの皮を剥がすごとく、引数を用いることができます。 + Human.__init__(self, 'anonymous', *args, **kwargs) + Bat.__init__(self, *args, can_fly=False, **kwargs) + # 名前の属性の値を上書きします。 + self.name = 'Sad Affleck' + + def sing(self): + return 'nan nan nan nan nan batman!' + + +if __name__ == '__main__': + sup = Batman() + + # インスタンスの型を調べてみましょう。 + if isinstance(sup, Human): + print('I am human') + if isinstance(sup, Bat): + print('I am bat') + if type(sup) is Batman: + print('I am Batman') + + # getattr() や super() の両方で使われるMROを取得します。 + # この属性は動的であり、更新が可能です。 + print(Batman.__mro__) # => (, , , ) + + # 親メソッドを呼び出しますが、独自のクラス属性を参照します。 + print(sup.get_species()) # => Superhero + + # オーバーロードされたメソッドを呼び出します。 + print(sup.sing()) # => nan nan nan nan nan batman! + + # 継承順により、Humanから継承されたメソッドを呼び出します。 + sup.say('I agree') # => Sad Affleck: I agree + + # 2番目の先祖にのみ存在するメソッドを呼び出してみます。 + print(sup.sonar()) # => ))) ... ((( + + # 継承されたクラス属性 + sup.age = 100 + print(sup.age) + + # デフォルト値が上書きされて、2番目の先祖から継承された属性 + print('Can I fly? ' + str(sup.fly)) + + +#################################################### +# 7. 発展的内容 +#################################################### + +# ジェネレータは遅延をするコードの作成に役立ちます。 +def double_numbers(iterable): + for i in iterable: + yield i + i + +# 次の値を処理するのに必要なデータしか読み込まないので、ジェネレータはメモリをあまり消費しません。 +# この性質により、他の方法では非常に多くのメモリを消費するような操作が可能になります。 +for i in double_numbers(range(1, 900000000)): # `range` もジェネレータの1つです。 + print(i) + if i >= 30: + break + +# リスト内包表記のように、ジェネータ内包表記を作成することもできます。 +values = (-x for x in [1, 2, 3, 4, 5]) +for x in values: + print(x) # prints -1 -2 -3 -4 -5 + +# ジェネレータ内包表記から直接リストを作成することもできます。 +values = (-x for x in [1, 2, 3, 4, 5]) +gen_to_list = list(values) +print(gen_to_list) # => [-1, -2, -3, -4, -5] + +# デコレータ +# この例では`beg` が `say` を `wraps`します。 +# もし say_please が True なら、出力が変更されます。 +from functools import wraps + + +def beg(target_function): + @wraps(target_function) + def wrapper(*args, **kwargs): + msg, say_please = target_function(*args, **kwargs) + if say_please: + return "{} {}".format(msg, "Please! I am poor :(") + return msg + + return wrapper + + +@beg +def say(say_please=False): + msg = "Can you buy me a beer?" + return msg, say_please + + +print(say()) # Can you buy me a beer? +print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :( +``` + +## Ready For More? + +### Free Online + +* [Automate the Boring Stuff with Python](https://automatetheboringstuff.com) +* [Ideas for Python Projects](http://pythonpracticeprojects.com) +* [The Official Docs](http://docs.python.org/3/) +* [Hitchhiker's Guide to Python](http://docs.python-guide.org/en/latest/) +* [Python Course](http://www.python-course.eu/index.php) +* [First Steps With Python](https://realpython.com/learn/python-first-steps/) +* [A curated list of awesome Python frameworks, libraries and software](https://github.com/vinta/awesome-python) +* [30 Python Language Features and Tricks You May Not Know About](http://sahandsaba.com/thirty-python-language-features-and-tricks-you-may-not-know.html) +* [Official Style Guide for Python](https://www.python.org/dev/peps/pep-0008/) +* [Python 3 Computer Science Circles](http://cscircles.cemc.uwaterloo.ca/) +* [Dive Into Python 3](http://www.diveintopython3.net/index.html) +* [A Crash Course in Python for Scientists](http://nbviewer.jupyter.org/gist/anonymous/5924718) -- cgit v1.2.3 From be9f44cf10ad22547d5f86f69e6c992e3f241302 Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Tue, 13 Dec 2016 09:28:54 +0800 Subject: New translation: less-zh-cn (#2595) --- zh-cn/less-cn.html.markdown | 387 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 387 insertions(+) create mode 100644 zh-cn/less-cn.html.markdown diff --git a/zh-cn/less-cn.html.markdown b/zh-cn/less-cn.html.markdown new file mode 100644 index 00000000..365a0287 --- /dev/null +++ b/zh-cn/less-cn.html.markdown @@ -0,0 +1,387 @@ +--- +language: less +filename: learnless-cn.less +contributors: + - ["Saravanan Ganesh", "http://srrvnn.me"] +translators: + - ["Jiang Haiyun", "http://www.atjiang.com"] +lang: zh-cn +--- + + +Less是一种CSS预处理器,它增加了诸如变量、嵌套、mixin等功能。 +Less(以及其它预处理器,如[Sass](http://sass-lang.com/))能帮助开发人员编写易维护,DRY (Don't Repeat Yourself) 的代码。 + +```css + + +//单行注释在编译成CSS后会被删除。 + +/* 多行注释将保留. */ + + + +/* 变量 +==============================*/ + + +/* 你可以将一个CSS值(如一个颜色值)保存到变量中。 + 使用'@'符号来创建一个变量。*/ + +@primary-color: #a3a4ff; +@secondary-color: #51527f; +@body-font: 'Roboto', sans-serif; + +/* 你可以在你的样式文件中使用这些变量。 + 现在假如你想修改颜色,你只需修改一次即可。*/ + +body { + background-color: @primary-color; + color: @secondary-color; + font-family: @body-font; +} + +/* 以上将编译成: */ + +body { + background-color: #a3a4ff; + color: #51527F; + font-family: 'Roboto', sans-serif; +} + + +/* 相比于在你的样式文件中逐个修改,这种方式维护性更好。 */ + + + +/* Mixins +==============================*/ + + +/* 如果你要为多个元素编写同样的代码, + 你可能想实现轻松地重用。*/ + +.center { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; +} + +/* 你只需简单地将选择子作为样式添加进来就能使用mixin了 */ + +div { + .center; + background-color: @primary-color; +} + +/* 它将编译成: */ + +.center { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; +} +div { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; + background-color: #a3a4ff; +} + +/* 通过在选择子后添加括号,可以使这些mixin代码不被编译 */ + +.center() { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; +} + +div { + .center; + background-color: @primary-color; +} + +/* 将编译成: */ +div { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; + background-color: #a3a4ff; +} + + + +/* 嵌套 +==============================*/ + + +/* Less允许你在选择子中嵌套选择子 */ + +ul { + list-style-type: none; + margin-top: 2em; + + li { + background-color: #f00; + } +} + +/* '&'将被替换成父选择子。*/ +/* 你也可以嵌套伪类。 */ +/* 注意过度嵌套将会导致代码难以维护。 + 最佳实践推荐在嵌套时不超过3层。 + 例如: */ + +ul { + list-style-type: none; + margin-top: 2em; + + li { + background-color: red; + + &:hover { + background-color: blue; + } + + a { + color: white; + } + } +} + +/* 编译成: */ + +ul { + list-style-type: none; + margin-top: 2em; +} + +ul li { + background-color: red; +} + +ul li:hover { + background-color: blue; +} + +ul li a { + color: white; +} + + + +/* 函数 +==============================*/ + + +/* Less提供的函数可以用来完成多种任务。 + 考虑以下情况: */ + +/* 函数可以通过其名称及传入其所需的参数来调用。 */ + +body { + width: round(10.25px); +} + +.header { + background-color: lighten(#000, 0.5); +} + +.footer { + background-color: fadeout(#000, 0.25) +} + +/* 编译成: */ + +body { + width: 10px; +} + +.header { + background-color: #010101; +} + +.footer { + background-color: rgba(0, 0, 0, 0.75); +} + +/* 你也可以定义自己的函数。函数非常类似于mixin。 + 当你在函数和mixin之间抉择时, + 记住mixin最适合用来创建CSS而函数更适合于 + 处理那些可能在你的Less代码中使用的逻辑。 + '数学运算符'部分的例子是转成可重用函数的最佳选择。*/ + +/* 该函数计算两数的平均值: */ + +.average(@x, @y) { + @average-result: ((@x + @y) / 2); +} + +div { + .average(16px, 50px); // "调用"mixin + padding: @average-result; // 使用它的"返回"值 +} + +/* 编译成: */ + +div { + padding: 33px; +} + + + +/* 扩展 (继承) +==============================*/ + + +/* 扩展是在选择子间共享属性的一种方法。 */ + +.display { + height: 50px; +} + +.display-success { + &:extend(.display); + border-color: #22df56; +} + +/* 编译成: */ +.display, +.display-success { + height: 50px; +} +.display-success { + border-color: #22df56; +} + +/* 扩展一条CSS语句优于创建一个mixin, + 这是由其组合所有共享相同基样式的类的方式决定的。 + 如果使用mixin完成,其属性将会在调用了该mixin的每条语句中重复。 + 虽然它不至会影响你的工作流,但它会在由Less编译器 + 生成的的文件中添加不必要的代码。*/ + + + +/* 片段与导入 +==============================*/ + + +/* Less允许你创建片段文件。它有助于你的Less代码保持模块化。 + 片段文件习惯上以'_'开头,例如 _reset.css,并被导入到 + 一个将会被编译成CSS的主less文件中。*/ + +/* 考虑以下的CSS,我们将把它们放入一个叫_reset.css的文件中 */ + +html, +body, +ul, +ol { + margin: 0; + padding: 0; +} + +/* Less提供的@import能用来将片段导入到文件中。 + 它与传统的CSS @import语句不同,无需通过 + HTTP请求获取导入文件。Less提取导入文件 + 并将它们与编译后的代码结合起来。 */ + +@import 'reset'; + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + +/* 编译成: */ + +html, body, ul, ol { + margin: 0; + padding: 0; +} + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + + + +/* 数学运算符 +==============================*/ + + +/* Less提供以下的运算符: +, -, *, /, 和 %。 + 相比于使用你事先手工计算好了的数值,它们 + 对于直接在你的Less文件中计算数值很有用。 + 以下是设置一个两列设计的例子。*/ + +@content-area: 960px; +@main-content: 600px; +@sidebar-content: 300px; + +@main-size: @main-content / @content-area * 100%; +@sidebar-size: @sidebar-content / @content-area * 100%; +@gutter: 100% - (@main-size + @sidebar-size); + +body { + width: 100%; +} + +.main-content { + width: @main-size; +} + +.sidebar { + width: @sidebar-size; +} + +.gutter { + width: @gutter; +} + +/* 编译成: */ + +body { + width: 100%; +} + +.main-content { + width: 62.5%; +} + +.sidebar { + width: 31.25%; +} + +.gutter { + width: 6.25%; +} + + +``` + +## 实践Less + +如果你想在你的浏览器中尝试LESS,参阅: +* [Codepen](http://codepen.io/) +* [LESS2CSS](http://lesscss.org/less-preview/) + +## 兼容性 + +Less可以用于任何项目中,只要你有程序能将它编译成CSS即可。你还需要验证你所使用的CSS是否与你的目标浏览器兼容。 + +[QuirksMode CSS](http://www.quirksmode.org/css/)和[CanIUse](http://caniuse.com) 对于检查兼容性来说都是不错的资源。 + +## 延伸阅读资料 +* [Official Documentation](http://lesscss.org/features/) +* [Less CSS - Beginner's Guide](http://www.hongkiat.com/blog/less-basic/) -- cgit v1.2.3 From 7dbbcd50def4a1d92f95058ad636083edb92a6a9 Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Tue, 13 Dec 2016 09:29:12 +0800 Subject: missing right parenthesis (#2596) --- less.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/less.html.markdown b/less.html.markdown index ee67c1bc..1b26eb99 100644 --- a/less.html.markdown +++ b/less.html.markdown @@ -6,7 +6,7 @@ contributors: --- Less is a CSS pre-processor, that adds features such as variables, nesting, mixins and more. -Less (and other preprocessors, such as [Sass](http://sass-lang.com/) help developers to write maintainable and DRY (Don't Repeat Yourself) code. +Less (and other preprocessors, such as [Sass](http://sass-lang.com/)) help developers to write maintainable and DRY (Don't Repeat Yourself) code. ```css -- cgit v1.2.3 From 98454c39cf3fab390fe794ebfe33436d06ed560d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Polykanine=20A=2EK=2EA=2E=20Menelion=20Elens=C3=BA?= =?UTF-8?q?l=C3=AB?= Date: Wed, 14 Dec 2016 04:24:03 +0200 Subject: Fixes #2593 (#2599) --- fr-fr/javascript-fr.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fr-fr/javascript-fr.html.markdown b/fr-fr/javascript-fr.html.markdown index f1977dac..faa22863 100644 --- a/fr-fr/javascript-fr.html.markdown +++ b/fr-fr/javascript-fr.html.markdown @@ -190,7 +190,7 @@ someNinthVar; // = 9 // Il y a des raccourcis pour les opérations mathématiques: someVar += 5; // équivalent pour someVar = someVar + 5; -someVar *= 10; // de même, someVar = someVar * 100; +someVar *= 10; // de même, someVar = someVar * 10; someVar++; // = someVar += 1; someVar--; // = someVar -= 1; -- cgit v1.2.3 From a65150f706a599dcee2ed2e7107241e847cbaf2c Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Wed, 14 Dec 2016 10:24:49 +0800 Subject: [sass/zh-cn] new translation (#2597) --- zh-cn/sass-cn.html.markdown | 585 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 585 insertions(+) create mode 100644 zh-cn/sass-cn.html.markdown diff --git a/zh-cn/sass-cn.html.markdown b/zh-cn/sass-cn.html.markdown new file mode 100644 index 00000000..985c6470 --- /dev/null +++ b/zh-cn/sass-cn.html.markdown @@ -0,0 +1,585 @@ +--- +language: sass +filename: learnsass-cn.scss +contributors: + - ["Laura Kyle", "https://github.com/LauraNK"] + - ["Sean Corrales", "https://github.com/droidenator"] + - ["Kyle Mendes", "https://github.com/pink401k"] + - ["Keith Miyake", "https://github.com/kaymmm"] +translators: + - ["Jiang Haiyun", "http://www.atjiang.com"] +lang: zh-cn +--- + +Sass是一种CSS扩展语言,它增加了诸如变量、嵌套、mixin等功能。 +Sass(以及其它预处理器,如[Less](http://lesscss.org/)等) 能帮助开发人员编写易维护和 DRY (Don't Repeat Yourself)的代码。 + +Sass有两种不同的语法可选用。SCSS的语法和CSS的相同,但增加了Sass的额外功能。或者Sass(原来的语法),它使用缩进而非大括号和分号。 + +本教程使用SCSS编写。 + +如果你已熟悉CSS3,你可能相对能较快地掌握Sass。它并没有提供任何新的类型属性,而只是提供了一些工具使你能更高效的编写CSS,并且使维护更加容易。 + +```scss + + +// 单行注释当Sass被编译成CSS后会被删除。 + +/* 多行注释将保留. */ + +/* 变量 +============================== */ + + + +/* 你可以将一个CSS值(如一个颜色值)保存到变量中。 +使用'$'符号来创建一个变量。*/ + +$primary-color: #A3A4FF; +$secondary-color: #51527F; +$body-font: 'Roboto', sans-serif; + +/* 你可以在你的样式文件中使用变量。 + 现在假如你想修改颜色,你只需修改一次即可。*/ + +body { + background-color: $primary-color; + color: $secondary-color; + font-family: $body-font; +} + +/* 以上将编译成: */ +body { + background-color: #A3A4FF; + color: #51527F; + font-family: 'Roboto', sans-serif; +} + +/* 相比于在你的样式文件中逐个进行修改,这种方式维护性更好。 */ + + + +/* 控制指令 +============================== */ + +/* Sass允许你使用@if, @else, @for, @while, 和 @each 来控制 + 你的代码如何编译成CSS */ + +/* @if/@else块的行为和你可能预想的会完全相同 */ + +$debug: true !default; + +@mixin debugmode { + @if $debug { + @debug "Debug mode enabled"; + + display: inline-block; + } + @else { + display: none; + } +} + +.info { + @include debugmode; +} + +/* 如果$debug设置为了true, .info 将会显示; 如果设置为false那么 + .info 将不显示。 + +注意: @debug将在命令行中输出调试信息。 +在调试你的SCSS时它对于检查变量很有用。*/ + +.info { + display: inline-block; +} + +/* @for是控制循环,它能遍历区间值。 +它对于设置一组元素的类型特别有用。 +有两种形式,"through"和"to"。前者包括最末那个值, +而后者止于最末那个值。 +*/ + +@for $c from 1 to 4 { + div:nth-of-type(#{$c}) { + left: ($c - 1) * 900 / 3; + } +} + +@for $c from 1 through 3 { + .myclass-#{$c} { + color: rgb($c * 255 / 3, $c * 255 / 3, $c * 255 / 3); + } +} + +/* 将编译成: */ + +div:nth-of-type(1) { + left: 0; +} + +div:nth-of-type(2) { + left: 300; +} + +div:nth-of-type(3) { + left: 600; +} + +.myclass-1 { + color: #555555; +} + +.myclass-2 { + color: #aaaaaa; +} + +.myclass-3 { + color: white; +// SASS automatically converts #FFFFFF to white +} + +/* @while也非常直白: */ + +$columns: 4; +$column-width: 80px; + +@while $columns > 0 { + .col-#{$columns} { + width: $column-width; + left: $column-width * ($columns - 1); + } + + $columns: $columns - 1; +} + +/* 将输出以下CSS: */ + +.col-4 { + width: 80px; + left: 240px; +} + +.col-3 { + width: 80px; + left: 160px; +} + +.col-2 { + width: 80px; + left: 80px; +} + +.col-1 { + width: 80px; + left: 0px; +} + +/* @each函数类似@for, 除了它使用一个列表而不是序列值 +注意: 你指定列表的方式和指定其它变量一样, +用空格作为分隔符。 */ + +$social-links: facebook twitter linkedin reddit; + +.social-links { + @each $sm in $social-links { + .icon-#{$sm} { + background-image: url("images/#{$sm}.png"); + } + } +} + +/* 将输出: */ + +.social-links .icon-facebook { + background-image: url("images/facebook.png"); +} + +.social-links .icon-twitter { + background-image: url("images/twitter.png"); +} + +.social-links .icon-linkedin { + background-image: url("images/linkedin.png"); +} + +.social-links .icon-reddit { + background-image: url("images/reddit.png"); +} + + +/* Mixins +==============================*/ + +/* 如果你发现你要为多个元素编写相同的代码, +你可能想将那些代码保存到一个mixin中。 + +使用'@mixin'指令,再为你的mixin加上一个名称。*/ + +@mixin center { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; +} + +/* 你可以通过'@include'及mixin名来调用mixin。 */ + +div { + @include center; + background-color: $primary-color; +} + +/* 将编译成: */ +div { + display: block; + margin-left: auto; + margin-right: auto; + left: 0; + right: 0; + background-color: #A3A4FF; +} + +/* 你可以使用mixin来创建一个快捷属性。*/ + +@mixin size($width, $height) { + width: $width; + height: $height; +} + +/* 你可以通过传入width和height参数来调用它。*/ + +.rectangle { + @include size(100px, 60px); +} + +.square { + @include size(40px, 40px); +} + +/* 编译成: */ +.rectangle { + width: 100px; + height: 60px; +} + +.square { + width: 40px; + height: 40px; +} + + + +/* 函数 +============================== */ + + + +/* Sass提供的函数可以用来完成各种各样的任务。 + 考虑以下情况 */ + +/* 函数可以通过其名称及传入其所需的参数来调用 */ +body { + width: round(10.25px); +} + +.footer { + background-color: fade_out(#000000, 0.25); +} + +/* 编译成: */ + +body { + width: 10px; +} + +.footer { + background-color: rgba(0, 0, 0, 0.75); +} + +/* 你也可以定义你自己的函数。函数非常类似于mixin。 + 当你在函数和mixin之间抉择时,记住mixin最适合于创建CSS而函数更适合于 + 处理那些可能在你的Sass代码中使用的逻辑。'数学运算符'部分的例子 + 是转成可重用函数的最理想选择。 */ + +/* 该函数将接收一个目标尺寸大小和父结点尺寸大小,然后计算并 + 返回百分数 */ + +@function calculate-percentage($target-size, $parent-size) { + @return $target-size / $parent-size * 100%; +} + +$main-content: calculate-percentage(600px, 960px); + +.main-content { + width: $main-content; +} + +.sidebar { + width: calculate-percentage(300px, 960px); +} + +/* 编译成: */ + +.main-content { + width: 62.5%; +} + +.sidebar { + width: 31.25%; +} + + + +/* 扩展 (继承) +============================== */ + + + +/* 扩展是在选择子间共享属性的一种方法。 */ + +.display { + @include size(5em, 5em); + border: 5px solid $secondary-color; +} + +.display-success { + @extend .display; + border-color: #22df56; +} + +/* 编译成: */ +.display, .display-success { + width: 5em; + height: 5em; + border: 5px solid #51527F; +} + +.display-success { + border-color: #22df56; +} + +/* 扩展一条CSS语句优于创建一个mixin, + 这是由Sass组合所有共享相同基样式的类的方式决定的。 + 如果使用mixin完成,width, height, 和border将会在 + 调用了该mixin的每条语句中重复。虽然它不至于会影响你的工作流, + 但它会在由Sass编译器生成的的文件中添加不必要的代码。*/ + + +/* 嵌套 +============================== */ + + + +/* Sass允许在选择子中嵌套选择子 */ + +ul { + list-style-type: none; + margin-top: 2em; + + li { + background-color: #FF0000; + } +} + +/* '&'将被父选择子替换。*/ +/* 你也可以嵌套伪类。 */ +/* 注意过度嵌套将导致你的代码难以维护。 +最佳实践推荐在嵌套时不超过3层。 +例如: */ + +ul { + list-style-type: none; + margin-top: 2em; + + li { + background-color: red; + + &:hover { + background-color: blue; + } + + a { + color: white; + } + } +} + +/* 编译成: */ + +ul { + list-style-type: none; + margin-top: 2em; +} + +ul li { + background-color: red; +} + +ul li:hover { + background-color: blue; +} + +ul li a { + color: white; +} + + + +/* 片段与导入 +============================== */ + + + +/* Sass允许你创建片段文件。它有助于你的Sass代码保持模块化。 + 片段文件应该以 '_' 开头,例如 _reset.css。 + 片段不会输出到CSS中。*/ + +/* 考虑以下的CSS,我们会将它们放入一个叫作_reset.css的文件中 */ + +html, +body, +ul, +ol { + margin: 0; + padding: 0; +} + +/* Sass提供的@import能用来将片段导入到文件中。 + 它与传统的CSS @import语句不同,不需要通过 + 另外的HTTP请求来获取导入的文件。 + Sass提取导入文件并将它与编译后的代码结合起来。 */ + +@import 'reset'; + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + +/* 编译成: */ + +html, body, ul, ol { + margin: 0; + padding: 0; +} + +body { + font-size: 16px; + font-family: Helvetica, Arial, Sans-serif; +} + + + +/* 占位符选择子 +============================== */ + + + +/* 占位符在创建用于扩展的CSS语句时非常有用。 + 如果你想创建一条只通过@extend使用的CSS语句,你可以利用占位符来实现。 + 占位符以'%'而非'.'或'#'开头。占位符不会出现在编译后的CSS中 */ + +%content-window { + font-size: 14px; + padding: 10px; + color: #000; + border-radius: 4px; +} + +.message-window { + @extend %content-window; + background-color: #0000ff; +} + +/* 编译成: */ + +.message-window { + font-size: 14px; + padding: 10px; + color: #000; + border-radius: 4px; +} + +.message-window { + background-color: #0000ff; +} + + + +/* 数学运算 +============================== */ + + + +/* Sass提供以下的运算符: +, -, *, /, 和 %。它们 + 相比于使用你事先手工计算好了的数值,它们 + 对于直接在你的Sass文件中计算数值很有用。 + 以下是设置一个简单的两列设计的例子。*/ + +$content-area: 960px; +$main-content: 600px; +$sidebar-content: 300px; + +$main-size: $main-content / $content-area * 100%; +$sidebar-size: $sidebar-content / $content-area * 100%; +$gutter: 100% - ($main-size + $sidebar-size); + +body { + width: 100%; +} + +.main-content { + width: $main-size; +} + +.sidebar { + width: $sidebar-size; +} + +.gutter { + width: $gutter; +} + +/* 编译成: */ + +body { + width: 100%; +} + +.main-content { + width: 62.5%; +} + +.sidebar { + width: 31.25%; +} + +.gutter { + width: 6.25%; +} + +``` + +## SASS还是Sass? +该语言的名字,“Sass”,是一个词,不是一个缩写。 +你有没想过Sass是否是一个缩写词?你可能没有,但我反正会告诉你。 +该语言的名字是一个单词,不是一个缩写词。 +由于人们老是将它写成"SASS",语言的作者开玩笑地称它为"Syntactically Awesome StyleSheets"。 + + +## 实践Sass +如果你想在你的浏览器中尝试Sass,参阅[SassMeister](http://sassmeister.com/)。 +你可以选用任一种语法,只需进到设置页然后选择Sass或SCSS。 + + +## 兼容性 +Sass可以用于任何项目中,只要你有程序能将它编译成CSS即可。你还需要验证你所使用的CSS是否与你的目标浏览器兼容。 + +[QuirksMode CSS](http://www.quirksmode.org/css/)和[CanIUse](http://caniuse.com)对于检查兼容性来说都是不错的资源。 + + +## 延伸阅读资料 +* [Official Documentation](http://sass-lang.com/documentation/file.SASS_REFERENCE.html) +* [The Sass Way](http://thesassway.com/) 上提供了教程(初学者-高级)和文章。 -- cgit v1.2.3 From 66e541e9e55d89d705319c2cf0c01e6319be817b Mon Sep 17 00:00:00 2001 From: Yusheng Date: Wed, 14 Dec 2016 18:13:04 +0800 Subject: [r/zh-cn] fix a bug (#2598) * fix a bug * translate comment & fix another bug --- zh-cn/r-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zh-cn/r-cn.html.markdown b/zh-cn/r-cn.html.markdown index 55a29b11..d576db29 100644 --- a/zh-cn/r-cn.html.markdown +++ b/zh-cn/r-cn.html.markdown @@ -303,7 +303,7 @@ if (4 > 3) { # 定义如下 jiggle <- function(x) { - x + rnorm(x, sd=.1) #add in a bit of (controlled) noise + x = x + rnorm(1, sd=.1) # 添加一点(正态)波动 return(x) } -- cgit v1.2.3 From a70f8469c44ac4a985c91ade6d142e7a83c5de04 Mon Sep 17 00:00:00 2001 From: ven Date: Wed, 14 Dec 2016 19:59:16 +0100 Subject: Random -> Safe --- purescript.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/purescript.html.markdown b/purescript.html.markdown index b413a9e3..19346760 100644 --- a/purescript.html.markdown +++ b/purescript.html.markdown @@ -85,7 +85,7 @@ head [1,2,3] -- Just (1) tail [3,2,1] -- Just ([2,1]) init [1,2,3] -- Just ([1,2]) last [3,2,1] -- Just (1) --- Random access - indexing +-- Array access - indexing [3,4,5,6,7] !! 2 -- Just (5) -- Range 1..5 -- [1,2,3,4,5] -- cgit v1.2.3 From f05246ce39a8c3599eee7c69ad5abcf76ecec5fc Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 14 Dec 2016 15:51:22 -0800 Subject: Make the CoffeeScript introduction a little more informative --- coffeescript.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown index 89a29677..27aebe2c 100644 --- a/coffeescript.html.markdown +++ b/coffeescript.html.markdown @@ -12,9 +12,10 @@ As one of the successors to JavaScript, CoffeeScript tries its best to output re See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript. ```coffeescript -# CoffeeScript is a hipster language. -# It goes with the trends of many modern languages. -# So comments are like Ruby and Python, they use number symbols. +# CoffeeScript is a language which compiles to JavaScript. +# It attempts to try and make JavaScript more in line with the trends of many +# modern languages. +# Comments are similar to Ruby and Python, using the hash symbol `#` ### Block comments are like these, and they translate directly to '/ *'s and '* /'s -- cgit v1.2.3 From db8cc8bd782a08c88cfb7d293ffd8c30a53d9fbe Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Wed, 14 Dec 2016 15:53:36 -0800 Subject: Move the description to the beginning with the other text --- coffeescript.html.markdown | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/coffeescript.html.markdown b/coffeescript.html.markdown index 27aebe2c..2aae6966 100644 --- a/coffeescript.html.markdown +++ b/coffeescript.html.markdown @@ -6,15 +6,16 @@ contributors: filename: coffeescript.coffee --- -CoffeeScript is a little language that compiles one-to-one into the equivalent JavaScript, and there is no interpretation at runtime. -As one of the successors to JavaScript, CoffeeScript tries its best to output readable, pretty-printed and smooth-running JavaScript code, which works well in every JavaScript runtime. +CoffeeScript is a little language that compiles one-to-one into the equivalent +JavaScript, and there is no interpretation at runtime. As one of the successors +to JavaScript, CoffeeScript tries its best to output readable, pretty-printed +and smooth-running JavaScript code, which works well in every JavaScript runtime. +It also attempts to try and make JavaScript more in line with the trends of many +modern languages. See also [the CoffeeScript website](http://coffeescript.org/), which has a complete tutorial on CoffeeScript. ```coffeescript -# CoffeeScript is a language which compiles to JavaScript. -# It attempts to try and make JavaScript more in line with the trends of many -# modern languages. # Comments are similar to Ruby and Python, using the hash symbol `#` ### -- cgit v1.2.3 From 919e44f843b4496448078cae8c1184da336c197f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Fernand=C3=A9s?= Date: Sun, 18 Dec 2016 13:40:42 +0100 Subject: [crystal/en] It would be greate to add crystal language :) (#2600) * Add Crystal language * Add Type informations and fix issues * Add missing examples * Add name in contributor list * Update code according to feedback received --- crystal.html.markdown | 553 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 553 insertions(+) create mode 100644 crystal.html.markdown diff --git a/crystal.html.markdown b/crystal.html.markdown new file mode 100644 index 00000000..97375f9b --- /dev/null +++ b/crystal.html.markdown @@ -0,0 +1,553 @@ +--- +language: crystal +filename: learncrystal.cr +contributors: + - ["Vitalii Elenhaupt", "http://veelenga.com"] + - ["Arnaud Fernandés", "https://github.com/TechMagister/"] + +--- + +```crystal + +# This is a comment + +# Everything is an object +nil.class #=> Nil +100.class #=> Int32 +true.class #=> Bool + +# Falsey values are: nil, false and null pointers +!nil #=> true : Bool +!false #=> true : Bool +!0 #=> false : Bool + +# Integers + +1.class #=> Int32 + +# Four signed integer types +1_i8.class #=> Int8 +1_i16.class #=> Int16 +1_i32.class #=> Int32 +1_i64.class #=> Int64 + +# Four unsigned integer types +1_u8.class #=> UInt8 +1_u16.class #=> UInt16 +1_u32.class #=> UInt32 +1_u64.class #=> UInt64 + +2147483648.class #=> Int64 +9223372036854775808.class #=> UInt64 + +# Binary numbers +0b1101 #=> 13 : Int32 + +# Octal numbers +0o123 #=> 83 : Int32 + +# Hexadecimal numbers +0xFE012D #=> 16646445 : Int32 +0xfe012d #=> 16646445 : Int32 + +# Floats + +1.0.class #=> Float64 + +# There are two floating point types +1.0_f32.class #=> Float32 +1_f32.class #=> Float32 + +1e10.class #=> Float64 +1.5e10.class #=> Float64 +1.5e-7.class #=> Float64 + +# Chars + +'a'.class #=> Char + +# Octal codepoint +'\101' #=> 'A' : Char + +# Unicode codepoint +'\u0041' #=> 'A' : Char + +# Strings + +"s".class #=> String + +# Strings are immutable +s = "hello, " #=> "hello, " : String +s.object_id #=> 134667712 : UInt64 +s += "Crystal" #=> "hello, Crystal" : String +s.object_id #=> 142528472 : UInt64 + +# Supports interpolation +"sum = #{1 + 2}" #=> "sum = 3" : String + +# Multiline string +"This is + multiline string" + +# String with double quotes +%(hello "world") #=> "hello \"world\"" + +# Symbols +# Immutable, reusable constants represented internally as Int32 integer value. +# They're often used instead of strings to efficiently convey specific, +# meaningful values + +:symbol.class #=> Symbol + +sentence = :question? # :"question?" : Symbol + +sentence == :question? #=> true : Bool +sentence == :exclamation! #=> false : Bool +sentence == "question?" #=> false : Bool + +# Arrays + +[1, 2, 3].class #=> Array(Int32) +[1, "hello", 'x'].class #=> Array(Int32 | String | Char) + +# Empty arrays should define a type +[] # Syntax error: for empty arrays use '[] of ElementType' +[] of Int32 #=> [] : Array(Int32) +Array(Int32).new #=> [] : Array(Int32) + +# Arrays can be indexed +array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] : Array(Int32) +array[0] #=> 1 : Int32 +array[10] # raises IndexError +array[-6] # raises IndexError +array[10]? #=> nil : (Int32 | Nil) +array[-6]? #=> nil : (Int32 | Nil) + +# From the end +array[-1] #=> 5 + +# With a start index and size +array[2, 3] #=> [3, 4, 5] + +# Or with range +array[1..3] #=> [2, 3, 4] + +# Add to an array +array << 6 #=> [1, 2, 3, 4, 5, 6] + +# Remove from the end of the array +array.pop #=> 6 +array #=> [1, 2, 3, 4, 5] + +# Remove from the beginning of the array +array.shift #=> 1 +array #=> [2, 3, 4, 5] + +# Check if an item exists in an array +array.includes? 3 #=> true + +# Special syntax for an array of string and an array of symbols +%w(one two three) #=> ["one", "two", "three"] : Array(String) +%i(one two three) #=> [:one, :two, :three] : Array(Symbol) + +# There is a special array syntax with other types too, as long as +# they define a .new and a #<< method +set = Set{1, 2, 3} #=> [1, 2, 3] +set.class #=> Set(Int32) + +# The above is equivalent to +set = Set(typeof(1, 2, 3)).new +set << 1 +set << 2 +set << 3 + +# Hashes + +{1 => 2, 3 => 4}.class #=> Hash(Int32, Int32) +{1 => 2, 'a' => 3}.class #=> Hash(Int32 | Char, Int32) + +# Empty hashes should specify a type +{} # Syntax error +{} of Int32 => Int32 # {} +Hash(Int32, Int32).new # {} + +# Hashes can be quickly looked up by key +hash = {"color" => "green", "number" => 5} +hash["color"] #=> "green" +hash["no_such_key"] #=> Missing hash key: "no_such_key" (KeyError) +hash["no_such_key"]? #=> nil + +# Check existence of keys hash +hash.has_key? "color" #=> true + +# Special notation for symbol and string keys +{key1: 'a', key2: 'b'} # {:key1 => 'a', :key2 => 'b'} +{"key1": 'a', "key2": 'b'} # {"key1" => 'a', "key2" => 'b'} + +# Special hash literal syntax with other types too, as long as +# they define a .new and a #[]= methods +class MyType + def []=(key, value) + puts "do stuff" + end +end + +MyType{"foo" => "bar"} + +# The above is equivalent to +tmp = MyType.new +tmp["foo"] = "bar" +tmp + +# Ranges + +1..10 #=> Range(Int32, Int32) +Range.new(1, 10).class #=> Range(Int32, Int32) + +# Can be inclusive or exclusive +(3..5).to_a #=> [3, 4, 5] +(3...5).to_a #=> [3, 4] + +# Check whether range includes the given value or not +(1..8).includes? 2 #=> true + +# Tuples are a fixed-size, immutable, stack-allocated sequence of values of +# possibly different types. +{1, "hello", 'x'}.class #=> Tuple(Int32, String, Char) + +# Acces tuple's value by its index +tuple = {:key1, :key2} +tuple[1] #=> :key2 +tuple[2] #=> syntax error : Index out of bound + +# Can be expanded into multiple variables +a, b, c = {:a, 'b', "c"} +a #=> :a +b #=> 'b' +c #=> "c" + +# Procs represent a function pointer with an optional context (the closure data) +# It is typically created with a proc litteral +proc = ->(x : Int32) { x.to_s } +proc.class # Proc(Int32, String) +# Or using the new method +Proc(Int32, String).new { |x| x.to_s } + +# Invoke proc with call method +proc.call 10 #=> "10" + +# Control statements + +if true + "if statement" +elsif false + "else-if, optional" +else + "else, also optional" +end + +puts "if as a suffix" if true + +# If as an expression +a = if 2 > 1 + 3 + else + 4 + end + +a #=> 3 + +# Ternary if +a = 1 > 2 ? 3 : 4 #=> 4 + +# Case statement +cmd = "move" + +action = case cmd + when "create" + "Creating..." + when "copy" + "Copying..." + when "move" + "Moving..." + when "delete" + "Deleting..." +end + +action #=> "Moving..." + +# Loops +index = 0 +while index <= 3 + puts "Index: #{index}" + index += 1 +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +index = 0 +until index > 3 + puts "Index: #{index}" + index += 1 +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +# But the preferable way is to use each +(1..3).each do |index| + puts "Index: #{index}" +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +# Variable's type depends on the type of the expression +# in control statements +if a < 3 + a = "hello" +else + a = true +end +typeof a #=> (Bool | String) + +if a && b + # here both a and b are guaranteed not to be Nil +end + +if a.is_a? String + a.class #=> String +end + +# Functions + +def double(x) + x * 2 +end + +# Functions (and all blocks) implicitly return the value of the last statement +double(2) #=> 4 + +# Parentheses are optional where the call is unambiguous +double 3 #=> 6 + +double double 3 #=> 12 + +def sum(x, y) + x + y +end + +# Method arguments are separated by a comma +sum 3, 4 #=> 7 + +sum sum(3, 4), 5 #=> 12 + +# yield +# All methods have an implicit, optional block parameter +# it can be called with the 'yield' keyword + +def surround + puts '{' + yield + puts '}' +end + +surround { puts "hello world" } + +# { +# hello world +# } + + +# You can pass a block to a function +# "&" marks a reference to a passed block +def guests(&block) + block.call "some_argument" +end + +# You can pass a list of arguments, which will be converted into an array +# That's what splat operator ("*") is for +def guests(*array) + array.each { |guest| puts guest } +end + +# If a method returns an array, you can use destructuring assignment +def foods + ["pancake", "sandwich", "quesadilla"] +end +breakfast, lunch, dinner = foods +breakfast #=> "pancake" +dinner #=> "quesadilla" + +# By convention, all methods that return booleans end with a question mark +5.even? # false +5.odd? # true + +# And if a method ends with an exclamation mark, it does something destructive +# like mutate the receiver. Some methods have a ! version to make a change, and +# a non-! version to just return a new changed version +company_name = "Dunder Mifflin" +company_name.gsub "Dunder", "Donald" #=> "Donald Mifflin" +company_name #=> "Dunder Mifflin" +company_name.gsub! "Dunder", "Donald" +company_name #=> "Donald Mifflin" + + +# Define a class with the class keyword +class Human + + # A class variable. It is shared by all instances of this class. + @@species = "H. sapiens" + + # type of name is String + @name : String + + # Basic initializer + # Assign the argument to the "name" instance variable for the instance + # If no age given, we will fall back to the default in the arguments list. + def initialize(@name, @age = 0) + end + + # Basic setter method + def name=(name) + @name = name + end + + # Basic getter method + def name + @name + end + + # The above functionality can be encapsulated using the attr_accessor method as follows + property :name + + # Getter/setter methods can also be created individually like this + getter :name + setter :name + + # A class method uses self to distinguish from instance methods. + # It can only be called on the class, not an instance. + def self.say(msg) + puts msg + end + + def species + @@species + end +end + + +# Instantiate a class +jim = Human.new("Jim Halpert") + +dwight = Human.new("Dwight K. Schrute") + +# Let's call a couple of methods +jim.species #=> "H. sapiens" +jim.name #=> "Jim Halpert" +jim.name = "Jim Halpert II" #=> "Jim Halpert II" +jim.name #=> "Jim Halpert II" +dwight.species #=> "H. sapiens" +dwight.name #=> "Dwight K. Schrute" + +# Call the class method +Human.say("Hi") #=> print Hi and returns nil + +# Variables that start with @ have instance scope +class TestClass + @var = "I'm an instance var" +end + +# Variables that start with @@ have class scope +class TestClass + @@var = "I'm a class var" +end +# Variables that start with a capital letter are constants +Var = "I'm a constant" +Var = "can't be updated" # Already initialized constant Var + +# Class is also an object in crystal. So class can have instance variables. +# Class variable is shared among the class and all of its descendants. + +# base class +class Human + @@foo = 0 + + def self.foo + @@foo + end + + def self.foo=(value) + @@foo = value + end +end + +# derived class +class Worker < Human +end + +Human.foo #=> 0 +Worker.foo #=> 0 + +Human.foo = 2 #=> 2 +Worker.foo #=> 0 + +Worker.foo = 3 #=> 3 +Human.foo #=> 2 +Worker.foo #=> 3 + +module ModuleExample + def foo + "foo" + end +end + +# Including modules binds their methods to the class instances +# Extending modules binds their methods to the class itself + +class Person + include ModuleExample +end + +class Book + extend ModuleExample +end + +Person.foo # => undefined method 'foo' for Person:Class +Person.new.foo # => 'foo' +Book.foo # => 'foo' +Book.new.foo # => undefined method 'foo' for Book + + +# Exception handling + +# Define new exception +class MyException < Exception +end + +# Define another exception +class MyAnotherException < Exception; end + +ex = begin + raise MyException.new +rescue ex1 : IndexError + "ex1" +rescue ex2 : MyException | MyAnotherException + "ex2" +rescue ex3 : Exception + "ex3" +rescue ex4 # catch any kind of exception + "ex4" +end + +ex #=> "ex2" + +``` + +## Additional resources + +- [Official Documentation](http://crystal-lang.org/) -- cgit v1.2.3 From 4737819e5da9e399b312b04417b1b2526f8907be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Haberth=C3=BCr?= Date: Tue, 20 Dec 2016 15:04:12 +0100 Subject: Made the file `pep8` compliant (#2601) Actually nearly compliant, I ran `pep8 code.py --ignore=E402,E501,E712` --- python.html.markdown | 261 +++++++++++++++++++++++++++------------------------ 1 file changed, 140 insertions(+), 121 deletions(-) diff --git a/python.html.markdown b/python.html.markdown index 050503c3..52ad6308 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Amin Bandali", "http://aminbandali.com"] - ["Andre Polykanine", "https://github.com/Oire"] - ["evuez", "http://github.com/evuez"] + - ["habi", "http://github.com/habi"] filename: learnpython.py --- @@ -34,9 +35,8 @@ Python 3 tutorial. as comments """ - #################################################### -## 1. Primitive Datatypes and Operators +# 1. Primitive Datatypes and Operators #################################################### # You have numbers @@ -53,41 +53,42 @@ Python 3 tutorial. 5 / 2 # => 2 # To fix division we need to learn about floats. -2.0 # This is a float +2.0 # This is a float 11.0 / 4.0 # => 2.75 ahhh...much better # Result of integer division truncated down both for positive and negative. -5 // 3 # => 1 -5.0 // 3.0 # => 1.0 # works on floats too +5 // 3 # => 1 +5.0 // 3.0 # => 1.0 # works on floats too -5 // 3 # => -2 --5.0 // 3.0 # => -2.0 +-5.0 // 3.0 # => -2.0 # Note that we can also import division module(Section 6 Modules) # to carry out normal division with just one '/'. from __future__ import division -11/4 # => 2.75 ...normal division -11//4 # => 2 ...floored division + +11 / 4 # => 2.75 ...normal division +11 // 4 # => 2 ...floored division # Modulo operation -7 % 3 # => 1 +7 % 3 # => 1 # Exponentiation (x to the yth power) -2**4 # => 16 +2 ** 4 # => 16 # Enforce precedence with parentheses (1 + 3) * 2 # => 8 # Boolean Operators # Note "and" and "or" are case-sensitive -True and False #=> False -False or True #=> True +True and False # => False +False or True # => True # Note using Bool operators with ints -0 and 2 #=> 0 --5 or 0 #=> -5 -0 == False #=> True -2 == True #=> False -1 == True #=> True +0 and 2 # => 0 +-5 or 0 # => -5 +0 == False # => True +2 == True # => False +1 == True # => True # negate with not not True # => False @@ -129,12 +130,12 @@ not False # => True # You can find the length of a string len("This is a string") # => 16 -#String formatting with % -#Even though the % string operator will be deprecated on Python 3.1 and removed -#later at some time, it may still be good to know how it works. +# String formatting with % +# Even though the % string operator will be deprecated on Python 3.1 and removed +# later at some time, it may still be good to know how it works. x = 'apple' y = 'lemon' -z = "The items in the basket are %s and %s" % (x,y) +z = "The items in the basket are %s and %s" % (x, y) # A newer way to format strings is the format method. # This method is the preferred way @@ -170,20 +171,21 @@ bool("") # => False #################################################### -## 2. Variables and Collections +# 2. Variables and Collections #################################################### # Python has a print statement -print "I'm Python. Nice to meet you!" # => I'm Python. Nice to meet you! +print "I'm Python. Nice to meet you!" # => I'm Python. Nice to meet you! # Simple way to get input data from console -input_string_var = raw_input("Enter some data: ") # Returns the data as a string -input_var = input("Enter some data: ") # Evaluates the data as python code +input_string_var = raw_input( + "Enter some data: ") # Returns the data as a string +input_var = input("Enter some data: ") # Evaluates the data as python code # Warning: Caution is recommended for input() method usage # Note: In python 3, input() is deprecated and raw_input() is renamed to input() # No need to declare variables before assigning to them. -some_var = 5 # Convention is to use lower_case_with_underscores +some_var = 5 # Convention is to use lower_case_with_underscores some_var # => 5 # Accessing a previously unassigned variable is an exception. @@ -194,21 +196,20 @@ some_other_var # Raises a name error # Equivalent of C's '?:' ternary operator "yahoo!" if 3 > 2 else 2 # => "yahoo!" - # Lists store sequences li = [] # You can start with a prefilled list other_li = [4, 5, 6] # Add stuff to the end of a list with append -li.append(1) # li is now [1] -li.append(2) # li is now [1, 2] -li.append(4) # li is now [1, 2, 4] -li.append(3) # li is now [1, 2, 4, 3] +li.append(1) # li is now [1] +li.append(2) # li is now [1, 2] +li.append(4) # li is now [1, 2, 4] +li.append(3) # li is now [1, 2, 4, 3] # Remove from the end with pop -li.pop() # => 3 and li is now [1, 2, 4] +li.pop() # => 3 and li is now [1, 2, 4] # Let's put it back -li.append(3) # li is now [1, 2, 4, 3] again. +li.append(3) # li is now [1, 2, 4, 3] again. # Access a list like you would any array li[0] # => 1 @@ -230,21 +231,21 @@ li[2:] # => [4, 3] # Omit the end li[:3] # => [1, 2, 4] # Select every second entry -li[::2] # =>[1, 4] +li[::2] # =>[1, 4] # Reverse a copy of the list -li[::-1] # => [3, 4, 2, 1] +li[::-1] # => [3, 4, 2, 1] # Use any combination of these to make advanced slices # li[start:end:step] # Remove arbitrary elements from a list with "del" -del li[2] # li is now [1, 2, 3] +del li[2] # li is now [1, 2, 3] # You can add lists -li + other_li # => [1, 2, 3, 4, 5, 6] +li + other_li # => [1, 2, 3, 4, 5, 6] # Note: values for li and for other_li are not modified. # Concatenate lists with "extend()" -li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6] +li.extend(other_li) # Now li is [1, 2, 3, 4, 5, 6] # Remove first occurrence of a value li.remove(2) # li is now [1, 3, 4, 5, 6] @@ -258,31 +259,29 @@ li.index(2) # => 1 li.index(7) # Raises a ValueError as 7 is not in the list # Check for existence in a list with "in" -1 in li # => True +1 in li # => True # Examine the length with "len()" -len(li) # => 6 - +len(li) # => 6 # Tuples are like lists but are immutable. tup = (1, 2, 3) -tup[0] # => 1 +tup[0] # => 1 tup[0] = 3 # Raises a TypeError # You can do all those list thingies on tuples too -len(tup) # => 3 -tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6) -tup[:2] # => (1, 2) -2 in tup # => True +len(tup) # => 3 +tup + (4, 5, 6) # => (1, 2, 3, 4, 5, 6) +tup[:2] # => (1, 2) +2 in tup # => True # You can unpack tuples (or lists) into variables -a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3 -d, e, f = 4, 5, 6 # you can leave out the parentheses +a, b, c = (1, 2, 3) # a is now 1, b is now 2 and c is now 3 +d, e, f = 4, 5, 6 # you can leave out the parentheses # Tuples are created by default if you leave out the parentheses -g = 4, 5, 6 # => (4, 5, 6) +g = 4, 5, 6 # => (4, 5, 6) # Now look how easy it is to swap two values -e, d = d, e # d is now 5 and e is now 4 - +e, d = d, e # d is now 5 and e is now 4 # Dictionaries store mappings empty_dict = {} @@ -290,33 +289,33 @@ empty_dict = {} filled_dict = {"one": 1, "two": 2, "three": 3} # Look up values with [] -filled_dict["one"] # => 1 +filled_dict["one"] # => 1 # Get all keys as a list with "keys()" -filled_dict.keys() # => ["three", "two", "one"] +filled_dict.keys() # => ["three", "two", "one"] # Note - Dictionary key ordering is not guaranteed. # Your results might not match this exactly. # Get all values as a list with "values()" -filled_dict.values() # => [3, 2, 1] +filled_dict.values() # => [3, 2, 1] # Note - Same as above regarding key ordering. # Get all key-value pairs as a list of tuples with "items()" -filled_dicts.items() # => [("one", 1), ("two", 2), ("three", 3)] +filled_dicts.items() # => [("one", 1), ("two", 2), ("three", 3)] # Check for existence of keys in a dictionary with "in" -"one" in filled_dict # => True -1 in filled_dict # => False +"one" in filled_dict # => True +1 in filled_dict # => False # Looking up a non-existing key is a KeyError -filled_dict["four"] # KeyError +filled_dict["four"] # KeyError # Use "get()" method to avoid the KeyError -filled_dict.get("one") # => 1 -filled_dict.get("four") # => None +filled_dict.get("one") # => 1 +filled_dict.get("four") # => None # The get method supports a default argument when the value is missing -filled_dict.get("one", 4) # => 1 -filled_dict.get("four", 4) # => 4 +filled_dict.get("one", 4) # => 1 +filled_dict.get("four", 4) # => 4 # note that filled_dict.get("four") is still => None # (get doesn't set the value in the dictionary) @@ -327,47 +326,46 @@ filled_dict["four"] = 4 # now, filled_dict["four"] => 4 filled_dict.setdefault("five", 5) # filled_dict["five"] is set to 5 filled_dict.setdefault("five", 6) # filled_dict["five"] is still 5 - # Sets store ... well sets (which are like lists but can contain no duplicates) empty_set = set() # Initialize a "set()" with a bunch of values -some_set = set([1, 2, 2, 3, 4]) # some_set is now set([1, 2, 3, 4]) +some_set = set([1, 2, 2, 3, 4]) # some_set is now set([1, 2, 3, 4]) # order is not guaranteed, even though it may sometimes look sorted another_set = set([4, 3, 2, 2, 1]) # another_set is now set([1, 2, 3, 4]) # Since Python 2.7, {} can be used to declare a set -filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4} +filled_set = {1, 2, 2, 3, 4} # => {1, 2, 3, 4} # Add more items to a set -filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5} +filled_set.add(5) # filled_set is now {1, 2, 3, 4, 5} # Do set intersection with & other_set = {3, 4, 5, 6} -filled_set & other_set # => {3, 4, 5} +filled_set & other_set # => {3, 4, 5} # Do set union with | -filled_set | other_set # => {1, 2, 3, 4, 5, 6} +filled_set | other_set # => {1, 2, 3, 4, 5, 6} # Do set difference with - -{1, 2, 3, 4} - {2, 3, 5} # => {1, 4} +{1, 2, 3, 4} - {2, 3, 5} # => {1, 4} # Do set symmetric difference with ^ {1, 2, 3, 4} ^ {2, 3, 5} # => {1, 4, 5} # Check if set on the left is a superset of set on the right -{1, 2} >= {1, 2, 3} # => False +{1, 2} >= {1, 2, 3} # => False # Check if set on the left is a subset of set on the right -{1, 2} <= {1, 2, 3} # => True +{1, 2} <= {1, 2, 3} # => True # Check for existence in a set with in -2 in filled_set # => True -10 in filled_set # => False +2 in filled_set # => True +10 in filled_set # => False #################################################### -## 3. Control Flow +# 3. Control Flow #################################################### # Let's just make a variable @@ -377,12 +375,11 @@ some_var = 5 # prints "some_var is smaller than 10" if some_var > 10: print "some_var is totally bigger than 10." -elif some_var < 10: # This elif clause is optional. +elif some_var < 10: # This elif clause is optional. print "some_var is smaller than 10." -else: # This is optional too. +else: # This is optional too. print "some_var is indeed 10." - """ For loops iterate over lists prints: @@ -438,12 +435,12 @@ try: # Use "raise" to raise an error raise IndexError("This is an index error") except IndexError as e: - pass # Pass is just a no-op. Usually you would do recovery here. + pass # Pass is just a no-op. Usually you would do recovery here. except (TypeError, NameError): - pass # Multiple exceptions can be handled together, if required. -else: # Optional clause to the try/except block. Must follow all except blocks - print "All good!" # Runs only if the code in try raises no exceptions -finally: # Execute under all circumstances + pass # Multiple exceptions can be handled together, if required. +else: # Optional clause to the try/except block. Must follow all except blocks + print "All good!" # Runs only if the code in try raises no exceptions +finally: # Execute under all circumstances print "We can clean up resources here" # Instead of try/finally to cleanup resources you can use a with statement @@ -453,19 +450,20 @@ with open("myfile.txt") as f: #################################################### -## 4. Functions +# 4. Functions #################################################### # Use "def" to create new functions def add(x, y): print "x is {0} and y is {1}".format(x, y) - return x + y # Return values with a return statement + return x + y # Return values with a return statement + # Calling functions with parameters -add(5, 6) # => prints out "x is 5 and y is 6" and returns 11 +add(5, 6) # => prints out "x is 5 and y is 6" and returns 11 # Another way to call functions is with keyword arguments -add(y=6, x=5) # Keyword arguments can arrive in any order. +add(y=6, x=5) # Keyword arguments can arrive in any order. # You can define functions that take a variable number of @@ -473,21 +471,26 @@ add(y=6, x=5) # Keyword arguments can arrive in any order. def varargs(*args): return args -varargs(1, 2, 3) # => (1, 2, 3) + +varargs(1, 2, 3) # => (1, 2, 3) + # You can define functions that take a variable number of # keyword args, as well, which will be interpreted as a dict by using ** def keyword_args(**kwargs): return kwargs + # Let's call it to see what happens -keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"} +keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"} # You can do both at once, if you like def all_the_args(*args, **kwargs): print args print kwargs + + """ all_the_args(1, 2, a=3, b=4) prints: (1, 2) @@ -498,9 +501,10 @@ all_the_args(1, 2, a=3, b=4) prints: # Use * to expand positional args and use ** to expand keyword args. args = (1, 2, 3, 4) kwargs = {"a": 3, "b": 4} -all_the_args(*args) # equivalent to foo(1, 2, 3, 4) -all_the_args(**kwargs) # equivalent to foo(a=3, b=4) -all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4) +all_the_args(*args) # equivalent to foo(1, 2, 3, 4) +all_the_args(**kwargs) # equivalent to foo(a=3, b=4) +all_the_args(*args, **kwargs) # equivalent to foo(1, 2, 3, 4, a=3, b=4) + # you can pass args and kwargs along to other functions that take args/kwargs # by expanding them with * and ** respectively @@ -509,58 +513,64 @@ def pass_all_the_args(*args, **kwargs): print varargs(*args) print keyword_args(**kwargs) + # Function Scope x = 5 + def set_x(num): # Local var x not the same as global variable x - x = num # => 43 - print x # => 43 + x = num # => 43 + print x # => 43 + def set_global_x(num): global x - print x # => 5 - x = num # global var x is now set to 6 - print x # => 6 + print x # => 5 + x = num # global var x is now set to 6 + print x # => 6 + set_x(43) set_global_x(6) + # Python has first class functions def create_adder(x): def adder(y): return x + y + return adder + add_10 = create_adder(10) -add_10(3) # => 13 +add_10(3) # => 13 # There are also anonymous functions -(lambda x: x > 2)(3) # => True -(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 +(lambda x: x > 2)(3) # => True +(lambda x, y: x ** 2 + y ** 2)(2, 1) # => 5 # There are built-in higher order functions -map(add_10, [1, 2, 3]) # => [11, 12, 13] -map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3] +map(add_10, [1, 2, 3]) # => [11, 12, 13] +map(max, [1, 2, 3], [4, 2, 1]) # => [4, 2, 3] -filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] +filter(lambda x: x > 5, [3, 4, 5, 6, 7]) # => [6, 7] # We can use list comprehensions for nice maps and filters [add_10(i) for i in [1, 2, 3]] # => [11, 12, 13] -[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7] +[x for x in [3, 4, 5, 6, 7] if x > 5] # => [6, 7] # You can construct set and dict comprehensions as well. {x for x in 'abcddeef' if x in 'abc'} # => {'a', 'b', 'c'} -{x: x**2 for x in range(5)} # => {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} +{x: x ** 2 for x in range(5)} # => {0: 0, 1: 1, 2: 4, 3: 9, 4: 16} #################################################### -## 5. Classes +# 5. Classes #################################################### # We subclass from object to get a class. class Human(object): - # A class attribute. It is shared by all instances of this class species = "H. sapiens" @@ -575,7 +585,6 @@ class Human(object): # Initialize property self.age = 0 - # An instance method. All methods take "self" as the first argument def say(self, msg): return "{0}: {1}".format(self.name, msg) @@ -611,45 +620,46 @@ class Human(object): # Instantiate a class i = Human(name="Ian") -print i.say("hi") # prints out "Ian: hi" +print i.say("hi") # prints out "Ian: hi" j = Human("Joel") print j.say("hello") # prints out "Joel: hello" # Call our class method -i.get_species() # => "H. sapiens" +i.get_species() # => "H. sapiens" # Change the shared attribute Human.species = "H. neanderthalensis" -i.get_species() # => "H. neanderthalensis" -j.get_species() # => "H. neanderthalensis" +i.get_species() # => "H. neanderthalensis" +j.get_species() # => "H. neanderthalensis" # Call the static method -Human.grunt() # => "*grunt*" +Human.grunt() # => "*grunt*" # Update the property i.age = 42 # Get the property -i.age # => 42 +i.age # => 42 # Delete the property del i.age i.age # => raises an AttributeError - #################################################### -## 6. Modules +# 6. Modules #################################################### # You can import modules import math + print math.sqrt(16) # => 4 # You can get specific functions from a module from math import ceil, floor + print ceil(3.7) # => 4.0 -print floor(3.7) # => 3.0 +print floor(3.7) # => 3.0 # You can import all functions from a module. # Warning: this is not recommended @@ -657,9 +667,11 @@ from math import * # You can shorten module names import math as m -math.sqrt(16) == m.sqrt(16) # => True + +math.sqrt(16) == m.sqrt(16) # => True # you can also test that the functions are equivalent from math import sqrt + math.sqrt == m.sqrt == sqrt # => True # Python modules are just ordinary python files. You @@ -669,8 +681,10 @@ math.sqrt == m.sqrt == sqrt # => True # You can find out which functions and attributes # defines a module. import math + dir(math) + # If you have a Python script named math.py in the same # folder as your current script, the file math.py will # be loaded instead of the built-in Python module. @@ -679,7 +693,7 @@ dir(math) #################################################### -## 7. Advanced +# 7. Advanced #################################################### # Generators @@ -693,6 +707,7 @@ def double_numbers(iterable): for i in iterable: double_arr.append(i + i) + # Running the following would mean we'll double all values first and return all # of them back to be checked by our condition for value in double_numbers(range(1000000)): # `test_non_generator` @@ -700,12 +715,14 @@ for value in double_numbers(range(1000000)): # `test_non_generator` if value > 5: break + # We could instead use a generator to "generate" the doubled value as the item # is being requested def double_numbers_generator(iterable): for i in iterable: yield i + i + # Running the same code as before, but with a generator, now allows us to iterate # over the values and doubling them one by one as they are being consumed by # our logic. Hence as soon as we see a value > 5, we break out of the @@ -723,22 +740,22 @@ for value in double_numbers_generator(xrange(1000000)): # `test_generator` # Just as you can create a list comprehension, you can create generator # comprehensions as well. -values = (-x for x in [1,2,3,4,5]) +values = (-x for x in [1, 2, 3, 4, 5]) for x in values: print(x) # prints -1 -2 -3 -4 -5 to console/terminal # You can also cast a generator comprehension directly to a list. -values = (-x for x in [1,2,3,4,5]) +values = (-x for x in [1, 2, 3, 4, 5]) gen_to_list = list(values) print(gen_to_list) # => [-1, -2, -3, -4, -5] - # Decorators # in this example beg wraps say # Beg will call say. If say_please is True then it will change the returned # message from functools import wraps + def beg(target_function): @wraps(target_function) def wrapper(*args, **kwargs): @@ -749,11 +766,13 @@ def beg(target_function): return wrapper + @beg def say(say_please=False): msg = "Can you buy me a beer?" return msg, say_please + print say() # Can you buy me a beer? print say(say_please=True) # Can you buy me a beer? Please! I am poor :( ``` -- cgit v1.2.3 From e7b58390e0bf1c484ac286f8ee9ffe3631077c58 Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Fri, 23 Dec 2016 03:55:06 +0800 Subject: [angularjs/en] typo fix (#2605) --- angularjs.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/angularjs.html.markdown b/angularjs.html.markdown index 89afa291..e72d89ad 100644 --- a/angularjs.html.markdown +++ b/angularjs.html.markdown @@ -53,7 +53,7 @@ Before you study AngularJS, you should have a basic understanding of: * The ng-model directive binds the value of the input field to the application variable name. * The ng-bind directive binds the innerHTML of the

element to the application variable name. */ - Here are content to be intrepreted + Here are content to be interpreted /////////////////////////////////// // AngularJS Expressions @@ -275,7 +275,7 @@ angular.module('myApp', []).controller('namesCtrl', function($scope) { /////////////////////////////////// -// AngularJS Filers +// AngularJS Filters // Filters can be added to expressions and directives using a pipe character. // AngularJS filters can be used to transform data: @@ -326,7 +326,7 @@ angular.module('myApp', []).controller('namesCtrl', function($scope) { //An input filter can be added to a directive with a pipe character (|) //and filter followed by a colon and a model name. -//The filter filter selects a subset of an array: +//The filter selects a subset of an array:

-- cgit v1.2.3 From 0074c8f351fcbeb91ea126526704121b27a60f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Carrascal?= Date: Thu, 22 Dec 2016 15:20:48 -0500 Subject: Add Spanish translation for Elixir (#2604) --- es-es/elixir-es.html.markdown | 457 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 457 insertions(+) create mode 100644 es-es/elixir-es.html.markdown diff --git a/es-es/elixir-es.html.markdown b/es-es/elixir-es.html.markdown new file mode 100644 index 00000000..885165a6 --- /dev/null +++ b/es-es/elixir-es.html.markdown @@ -0,0 +1,457 @@ +--- +language: elixir +contributors: + - ["Joao Marques", "http://github.com/mrshankly"] + - ["Dzianis Dashkevich", "https://github.com/dskecse"] + - ["Ryan Plant", "https://github.com/ryanplant-au"] +translator: + - ["Adrian Carrascal", "https://github.com/acarrascalgarcia"] +filename: learnelixir-es.ex +lang: es-es + +--- + +Elixir es un lenguaje funcional moderno construido sobre la máquina virtual de Erlang. +Es completamente compatibe con Erlang, sin embargo, ofrece una sintaxis más estandar +y otras características más. + +```elixir + +# Los comentarios de única línea +# comienzan con un símbolo numérico. + +# No hay comentarios multilinea, +# pero se pueden apilar varios comentarios. + +# Para usar el shell de elixir se usa el comando `iex`. +# Los módulos se compilan con el comando `elixirc`. + +# Ambos deberían estar en la ruta si elixir se instaló correctamente. + +## --------------------------- +## -- Tipos básicos +## --------------------------- + +# Hay números +3 # integer +0x1F # integer +3.0 # float + +# Átomos, que son literales, una constante con nombre. Comienzan con `:`. +:hello # atom + +# Tuples that are stored contiguously in memory. +# Tuplas que se almacenan contiguamente en memoria. +{1,2,3} # tuple + +# Se puede acceder a un elemento de una tupla con la función `elem`: +elem({1, 2, 3}, 0) #=> 1 + +# Listas que se implementan como listas enlazadas. +[1,2,3] # list + +# Se puede acceder al primer y último elemento de la lista como: +[head | tail] = [1,2,3] +head #=> 1 +tail #=> [2,3] + +# En elixir, solo como Erlang, el `=` denota la coincidencia de patrones y +# no una asignación. +# +# This is how the above example of accessing the head and tail of a list works. +# Así es como el ejemplo anterior de acceder al +# primer y último elemento de una lista trabaja. + +# Una coincidencia de patrón errará cuando los lados no coincidan, en este ejemplo +# las tuplas tienen diferentes tamaños. +# {a, b, c} = {1, 2} #=> ** (MatchError) no match of right hand side value: {1,2} + +# También hay binarios +<<1,2,3>> # binary + +# Cadenas y listas de caracteres +"hello" # string +'hello' # char list + +# Cadenas de varias lineas +""" +I'm a multi-line +string. +""" +#=> "I'm a multi-line\nstring.\n" + +# Todas las cadenas se codifican en UTF-8: +"héllò" #=> "héllò" + +# Las cadenas son solo binarios realmente, y la lista de caracteres solo listas. +<> #=> "abc" +[?a, ?b, ?c] #=> 'abc' + +# `?a` en elixir devuelve el valor ASCII para el caracter `a` +?a #=> 97 + +# Para concatenar listas se usa `++`, para binarios `<>` +[1,2,3] ++ [4,5] #=> [1,2,3,4,5] +'hello ' ++ 'world' #=> 'hello world' + +<<1,2,3>> <> <<4,5>> #=> <<1,2,3,4,5>> +"hello " <> "world" #=> "hello world" + +# Los rangos se representan como `start..end` (Es inclusivo) +1..10 #=> 1..10 +lower..upper = 1..10 # Se puede usar la coincidencia de patrones en los rangos también +[lower, upper] #=> [1, 10] + +# Los mapas son pares de llave-valor +genders = %{"david" => "male", "gillian" => "female"} +genders["david"] #=> "male" + +# Los mapas con llaves de tipo átomo se pueden usar como esto +genders = %{david: "male", gillian: "female"} +genders.gillian #=> "female" + +## --------------------------- +## -- Opetadores +## --------------------------- + +# Aritméticos +1 + 1 #=> 2 +10 - 5 #=> 5 +5 * 2 #=> 10 +10 / 2 #=> 5.0 + +# En elixir el operador `/` siempre devuelve un número flotante + +# Para hacer la división de número entero se debe usar `div` +div(10, 2) #=> 5 + +# Para obtener el residuo de la división se debe usar `rem` +rem(10, 3) #=> 1 + +# También hay operadores lógicos: `or`, `and` y `not`. +# Estos operadores esperan un boolean como su primer argumento. +true and true #=> true +false or true #=> true +# 1 and true #=> ** (ArgumentError) argument error + +# Elixir también provee `||`, `&&` y `!` donde acepta argumentos de cualquier tipo. +# Todos los valores excepto `false` y `nil` se evaluarán como verdadero. +1 || true #=> 1 +false && 1 #=> false +nil && 20 #=> nil +!true #=> false + +# Para comparaciones se tiene: `==`, `!=`, `===`, `!==`, `<=`, `>=`, `<` y `>` +1 == 1 #=> true +1 != 1 #=> false +1 < 2 #=> true + +# `===` y `!==` son más estrictos cuando comparan números: +1 == 1.0 #=> true +1 === 1.0 #=> false + +# También se puede comparar dos tipos de datos diferentes: +1 < :hello #=> true + +# No se necesita memorizar el orden pero es importante tenerlo en cuenta: +# number < atom < reference < functions < port < pid < tuple < list < bit string + +## --------------------------- +## -- Control de flujo +## --------------------------- + +# Expresión `if` +if false do + "This will never be seen" +else + "This will" +end + +# También está la expresión `unless` +unless true do + "This will never be seen" +else + "This will" +end + +# Se acuerda de la coincidencia de patrones? +# Muchas estructuras de control de flujo en elixir confían en ella. + +# `case` permite comparar un valor con muchos patrones: +case {:one, :two} do + {:four, :five} -> + "This won't match" + {:one, x} -> + "This will match and bind `x` to `:two` in this clause" + _ -> + "This will match any value" +end + +# Es común vincular el valor a `_` si no se necesita. +# Por ejemplo, si unicamente el primer elemento de la lista es importante: +[head | _] = [1,2,3] +head #=> 1 + +# Para una mejor lectura se puede hace lo siguiente: +[head | _tail] = [:a, :b, :c] +head #=> :a + +# `cond` permite comprobar muchas condiciones al mismo tiempo. +# Usar `cond` en vez de muchas expresiones `if` anidadas. +cond do + 1 + 1 == 3 -> + "I will never be seen" + 2 * 5 == 12 -> + "Me neither" + 1 + 2 == 3 -> + "But I will" +end + +# Es común estabecer la última condición como `true`, donde siempre va a coincidir. +cond do + 1 + 1 == 3 -> + "I will never be seen" + 2 * 5 == 12 -> + "Me neither" + true -> + "But I will (this is essentially an else)" +end + +# `try/catch` se usa para atrapar valores que se lanzan, también soporta una +# clausula `after` que se invoca sin importar si un valor se atrapó o no. +try do + throw(:hello) +catch + message -> "Got #{message}." +after + IO.puts("I'm the after clause.") +end +#=> I'm the after clause +# "Got :hello" + +## --------------------------- +## -- Módulos y Funciones +## --------------------------- + +# Anonymous functions (notice the dot) +# Funciones anónimas (Ver el punto `.`) +square = fn(x) -> x * x end +square.(5) #=> 25 + +# También aceptan muchas cláusulas y guards. +# Los guards permiten afinar las coincidencias de patrones, +# se indican por la palabra reservada `when`: +f = fn + x, y when x > 0 -> x + y + x, y -> x * y +end + +f.(1, 3) #=> 4 +f.(-1, 3) #=> -3 + +# Elixir también provee muchas funciones incorporadas. +# Esas están disponibles en el ámbito actual. +is_number(10) #=> true +is_list("hello") #=> false +elem({1,2,3}, 0) #=> 1 + +# Se pueden agrupar varias funciones en un módulo. Dentro de un módulo +# se usa `def` para definir las funciones. +defmodule Math do + def sum(a, b) do + a + b + end + + def square(x) do + x * x + end +end + +Math.sum(1, 2) #=> 3 +Math.square(3) #=> 9 + +# Para compilar el módulo simple de Math se guarda como `math.ex` y se usa `elixirc` +# en la terminal: elixirc math.ex + +# Dentro de un módulo se puede definir funciones con `def` y funciones privadas con `defp`. +# Una función definida con `def` está disponible para ser invocada desde otros módulos, +# una función privada se puede solo invocar localmente. +defmodule PrivateMath do + def sum(a, b) do + do_sum(a, b) + end + + defp do_sum(a, b) do + a + b + end +end + +PrivateMath.sum(1, 2) #=> 3 +# PrivateMath.do_sum(1, 2) #=> ** (UndefinedFunctionError) + +# La declaración de funciones también soportan guards y múltiples cláusulas: +defmodule Geometry do + def area({:rectangle, w, h}) do + w * h + end + + def area({:circle, r}) when is_number(r) do + 3.14 * r * r + end +end + +Geometry.area({:rectangle, 2, 3}) #=> 6 +Geometry.area({:circle, 3}) #=> 28.25999999999999801048 +# Geometry.area({:circle, "not_a_number"}) +#=> ** (FunctionClauseError) no function clause matching in Geometry.area/1 + +# Debido a la inmutabilidad, la recursión es una gran parte de elixir +defmodule Recursion do + def sum_list([head | tail], acc) do + sum_list(tail, acc + head) + end + + def sum_list([], acc) do + acc + end +end + +Recursion.sum_list([1,2,3], 0) #=> 6 + +# Los módulos de Elixir soportan atributos, hay atributos incorporados y +# se pueden agregar otros personalizados. +defmodule MyMod do + @moduledoc """ + This is a built-in attribute on a example module. + """ + + @my_data 100 # This is a custom attribute. + IO.inspect(@my_data) #=> 100 +end + +# El operador pipe |> permite que se pase la salida de una expresión +# como el primer parámetro en una función. + +Range.new(1,10) +|> Enum.map(fn x -> x * x end) +|> Enum.filter(fn x -> rem(x, 2) == 0 end) +#=> [4, 16, 36, 64, 100] + +## --------------------------- +## -- Structs and Excepciones +## --------------------------- + +# Los Structs son extensiones de los mapas que traen valores por defecto, +# garantes en tiempo de compilación y polimorfismo en Elixir. +defmodule Person do + defstruct name: nil, age: 0, height: 0 +end + +joe_info = %Person{ name: "Joe", age: 30, height: 180 } +#=> %Person{age: 30, height: 180, name: "Joe"} + +# Acceder al valor de name +joe_info.name #=> "Joe" + +# Actualizar el valor de age +older_joe_info = %{ joe_info | age: 31 } +#=> %Person{age: 31, height: 180, name: "Joe"} + +# El bloque `try` con la palabra reservada `rescue` se usa para manejar excepciones +try do + raise "some error" +rescue + RuntimeError -> "rescued a runtime error" + _error -> "this will rescue any error" +end +#=> "rescued a runtime error" + +# Todas las excepciones tienen un mensaje +try do + raise "some error" +rescue + x in [RuntimeError] -> + x.message +end +#=> "some error" + +## --------------------------- +## -- Concurrencia +## --------------------------- + +# Elixir confía en el modelo actor para la concurrencia. Todo lo que se necesita para escribir +# programas concurrentes en elixir son tres primitivas: procesos de desove, +# envío de mensajes y recepción de mensajes. + +# Para empezar un nuevo proceso se usa la función `spawn`, +# donde toma una función como argumento. +f = fn -> 2 * 2 end #=> #Function +spawn(f) #=> #PID<0.40.0> + +# `spawn` devuelve un pid (identificador de proceso), se puede usar este pid para enviar +# mensajes para el proceso. Para hacer que un mensaje pase se usa el operador `send`. +# Para que todo esto se útil se necesita estar disponibles para recibir mensajes. Esto se +# alcanza con el mecanismo `receive`: + +# El bloque `receive do` se usa para escuchar los mensajes y procesarlos +# cuando se reciben. Un bloque `receive do` solo procesará +# un mensaje recibido. Para procesar múltiples mensajes, +# una función con un bloque `receive do` tiene que llamarse recursivamente +# para entrar en el bloque `receive do` otra vez. + +defmodule Geometry do + def area_loop do + receive do + {:rectangle, w, h} -> + IO.puts("Area = #{w * h}") + area_loop() + {:circle, r} -> + IO.puts("Area = #{3.14 * r * r}") + area_loop() + end + end +end + +# Compilar el módulo y crear un proceso que evalue `area_loop` en el shell +pid = spawn(fn -> Geometry.area_loop() end) #=> #PID<0.40.0> +# Como alternativa +pid = spawn(Geometry, :area_loop, []) + +# Enviar un mensaje al `pid` que coincidirá con un patrón en el que recibe una sentencia +send pid, {:rectangle, 2, 3} +#=> Area = 6 +# {:rectangle,2,3} + +send pid, {:circle, 2} +#=> Area = 12.56000000000000049738 +# {:circle,2} + +# El shell también es un proceso, se puede usar `self` para obtener el pid actual +self() #=> #PID<0.27.0> + +## --------------------------- +## -- Agentes +## --------------------------- + +# Un agente es un proceso que mantiene el seguimiento de algún valor cambiante + +# Un agente se crea con `Agent.start_link`, introducuendole una función +# El estado inicial del agente será lo que sea que la función devuelva +{ok, my_agent} = Agent.start_link(fn -> ["red, green"] end) + +# `Agent.get` toma un nombre de agente y un `fn` que se pasa como el estado actual +# Lo que sea que este `fn` devuelva es lo que se obtendrá de vuelta +Agent.get(my_agent, fn colors -> colors end) #=> ["red, "green"] + +# El estado del agente se actualiza de la misma manera +Agent.update(my_agent, fn colors -> ["blue" | colors] end) +``` + +## Referencias + +* [Getting started guide](http://elixir-lang.org/getting-started/introduction.html) from the [Elixir website](http://elixir-lang.org) +* [Elixir Documentation](http://elixir-lang.org/docs/master/) +* ["Programming Elixir"](https://pragprog.com/book/elixir/programming-elixir) by Dave Thomas +* [Elixir Cheat Sheet](http://media.pragprog.com/titles/elixir/ElixirCheat.pdf) +* ["Learn You Some Erlang for Great Good!"](http://learnyousomeerlang.com/) by Fred Hebert +* ["Programming Erlang: Software for a Concurrent World"](https://pragprog.com/book/jaerlang2/programming-erlang) by Joe Armstrong -- cgit v1.2.3 From 601aae91ae16ff1968899f08f29f10433daad92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Fernand=C3=A9s?= Date: Fri, 23 Dec 2016 01:06:39 +0100 Subject: [crystal/fr] French language for crystal (#2602) * Add Crystal/FR * Spell checking --- crystal.html.markdown | 2 +- fr-fr/crystal-fr.html.markdown | 555 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 556 insertions(+), 1 deletion(-) create mode 100644 fr-fr/crystal-fr.html.markdown diff --git a/crystal.html.markdown b/crystal.html.markdown index 97375f9b..1449ff81 100644 --- a/crystal.html.markdown +++ b/crystal.html.markdown @@ -110,7 +110,7 @@ sentence == "question?" #=> false : Bool [1, 2, 3].class #=> Array(Int32) [1, "hello", 'x'].class #=> Array(Int32 | String | Char) -# Empty arrays should define a type +# Empty arrays should specify a type [] # Syntax error: for empty arrays use '[] of ElementType' [] of Int32 #=> [] : Array(Int32) Array(Int32).new #=> [] : Array(Int32) diff --git a/fr-fr/crystal-fr.html.markdown b/fr-fr/crystal-fr.html.markdown new file mode 100644 index 00000000..0bf6889c --- /dev/null +++ b/fr-fr/crystal-fr.html.markdown @@ -0,0 +1,555 @@ +--- +language: crystal +filename: learncrystal-fr.cr +contributors: + - ["Vitalii Elenhaupt", "http://veelenga.com"] + - ["Arnaud Fernandés", "https://github.com/TechMagister/"] +translators: + - ["Arnaud Fernandés", "http://github.com/TechMagister/"] +lang: fr-fr +--- + +```crystal + +# Ceci est un commentaire + +# Tout est object +nil.class #=> Nil +100.class #=> Int32 +true.class #=> Bool + +# Les valeurs fausses sont : nil, false et les pointeurs null +!nil #=> true : Bool +!false #=> true : Bool +!0 #=> false : Bool + +# Entiers + +1.class #=> Int32 + +# Quatre types d'entiers signés +1_i8.class #=> Int8 +1_i16.class #=> Int16 +1_i32.class #=> Int32 +1_i64.class #=> Int64 + +# Quatre types d'entiers non signés +1_u8.class #=> UInt8 +1_u16.class #=> UInt16 +1_u32.class #=> UInt32 +1_u64.class #=> UInt64 + +2147483648.class #=> Int64 +9223372036854775808.class #=> UInt64 + +# Nombre en base binaire +0b1101 #=> 13 : Int32 + +# Nombre en base octale +0o123 #=> 83 : Int32 + +# Nombres hexadécimaux +0xFE012D #=> 16646445 : Int32 +0xfe012d #=> 16646445 : Int32 + +# Nombres à virgule + +1.0.class #=> Float64 + +# Il y a deux types de nombres à virgule +1.0_f32.class #=> Float32 +1_f32.class #=> Float32 + +1e10.class #=> Float64 +1.5e10.class #=> Float64 +1.5e-7.class #=> Float64 + +# Caractères + +'a'.class #=> Char + +# Notation octale des caratères +'\101' #=> 'A' : Char + +# Notation unicode +'\u0041' #=> 'A' : Char + +# Chaînes de caratères + +"s".class #=> String + +# Les chaînes de caractères sont immuables +s = "hello, " #=> "hello, " : String +s.object_id #=> 134667712 : UInt64 +s += "Crystal" #=> "hello, Crystal" : String +s.object_id #=> 142528472 : UInt64 + +# Interpolation +"sum = #{1 + 2}" #=> "sum = 3" : String + +# Chaînes multilignes +"Ceci est une chaine sur +plusieurs lignes" + +# Une autre notation pour les chaînes de caratères +# qui permet d'insérer des guillemets +%(hello "world") #=> "hello \"world\"" + +# Symboles +# Ils sont immuables et réutilisables, ils sont représentés en interne par +# un Int32. Ils sont souvent utilisés à la place des chaînes de caractères +# quand l'identité est plus importante que le contenu + +:symbol.class #=> Symbol + +sentence = :question? # :"question?" : Symbol + +sentence == :question? #=> true : Bool +sentence == :exclamation! #=> false : Bool +sentence == "question?" #=> false : Bool + +# Tableaux + +[1, 2, 3].class #=> Array(Int32) +[1, "hello", 'x'].class #=> Array(Int32 | String | Char) + +# Un type doit être spécifié pour les tableaux vides +[] # Syntax error: for empty arrays use '[] of ElementType' +[] of Int32 #=> [] : Array(Int32) +Array(Int32).new #=> [] : Array(Int32) + +# Les tableaux peuvent être indexés +array = [1, 2, 3, 4, 5] #=> [1, 2, 3, 4, 5] : Array(Int32) +array[0] #=> 1 : Int32 +array[10] # lève l'exception IndexError +array[-6] # lève l'exception IndexError +array[10]? #=> nil : (Int32 | Nil) +array[-6]? #=> nil : (Int32 | Nil) + +# À partir de la fin +array[-1] #=> 5 + +# Avec un index de début et la taille +array[2, 3] #=> [3, 4, 5] + +# Ou avec un intervalle +array[1..3] #=> [2, 3, 4] + +# L'ajout à un tableau peut se faire avec l'opérateur << +array << 6 #=> [1, 2, 3, 4, 5, 6] + +# Enlève la dernière entrée +array.pop #=> 6 +array #=> [1, 2, 3, 4, 5] + +# Enlève la première entrée +array.shift #=> 1 +array #=> [2, 3, 4, 5] + +# Vérifie si un élément est présent dans le tableau +array.includes? 3 #=> true + +# Syntaxe spéciale pour un tableau de chaîne de caractères ou de symboles +%w(one two three) #=> ["one", "two", "three"] : Array(String) +%i(one two three) #=> [:one, :two, :three] : Array(Symbol) + +# Il y a une syntaxe spéciale pour les tableaux et autres types +# du moment qu'ils définissent une méthode .new et #<< +set = Set{1, 2, 3} #=> [1, 2, 3] +set.class #=> Set(Int32) + +# Ce qui est ci dessus est équivalent à : +set = Set(typeof(1, 2, 3)).new +set << 1 +set << 2 +set << 3 + +# Tableaux associatifs + +{1 => 2, 3 => 4}.class #=> Hash(Int32, Int32) +{1 => 2, 'a' => 3}.class #=> Hash(Int32 | Char, Int32) + +# Un type doit être spécifié pour les tableaux associatifs vides +{} # Syntax error +{} of Int32 => Int32 # {} +Hash(Int32, Int32).new # {} + +# L'accès se fait via une clé +hash = {"color" => "green", "number" => 5} +hash["color"] #=> "green" +hash["no_such_key"] #=> Missing hash key: "no_such_key" (KeyError) +hash["no_such_key"]? #=> nil + +# Vérifie l'existence d'une clé +hash.has_key? "color" #=> true + +# Notation spéciale pour les clés si ce sont des symboles +# ou chaînes de caractères +{key1: 'a', key2: 'b'} # {:key1 => 'a', :key2 => 'b'} +{"key1": 'a', "key2": 'b'} # {"key1" => 'a', "key2" => 'b'} + +# De même que pour les tableaux simples, une syntaxe spéciale +# existe du moment que le type définit une méthode .new et #[]= +class MyType + def []=(key, value) + puts "do stuff" + end +end + +MyType{"foo" => "bar"} + +# Ce qui est équivalent à : +tmp = MyType.new +tmp["foo"] = "bar" +tmp + +# Intervalle + +1..10 #=> Range(Int32, Int32) +Range.new(1, 10).class #=> Range(Int32, Int32) + +# Ils peuvent être inclusifs ou exclusifs +(3..5).to_a #=> [3, 4, 5] +(3...5).to_a #=> [3, 4] + +# Vérifie si un intervalle contient une valeur +(1..8).includes? 2 #=> true + +# les tuples sont fixés en taille, immuables et alloués sur la pile +{1, "hello", 'x'}.class #=> Tuple(Int32, String, Char) + +# L'accès peut se faire en utilisant un index +tuple = {:key1, :key2} +tuple[1] #=> :key2 +tuple[2] #=> syntax error : Index out of bound + +# Ils peuvent être scindés en plusieurs variables +a, b, c = {:a, 'b', "c"} +a #=> :a +b #=> 'b' +c #=> "c" + +# Les procédures ( Proc ) sont des pointeurs de fonction +# avec un contexte optionel. Ils sont généralement créés avec +# cette notation : +proc = ->(x : Int32) { x.to_s } +proc.class # Proc(Int32, String) +# Ou en utilisant la méthode new +Proc(Int32, String).new { |x| x.to_s } + +# On les invoque avec la méthode call +proc.call 10 #=> "10" + +# Contrôle de flux + +if true + "if statement" +elsif false + "else-if, optional" +else + "else, also optional" +end + +puts "if as a suffix" if true + +# Le si ( if ) peut être utilisé pour une déclaration +a = if 2 > 1 + 3 + else + 4 + end + +a #=> 3 + +# Opérateur ternaire +a = 1 > 2 ? 3 : 4 #=> 4 + +# Aiguillage à l'aide du mot clé "case" +cmd = "move" + +action = case cmd + when "create" + "Creating..." + when "copy" + "Copying..." + when "move" + "Moving..." + when "delete" + "Deleting..." +end + +action #=> "Moving..." + +# Boucle +index = 0 +while index <= 3 + puts "Index: #{index}" + index += 1 +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +index = 0 +until index > 3 + puts "Index: #{index}" + index += 1 +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +# Mais il est préférable d'utiliser #each +(1..3).each do |index| + puts "Index: #{index}" +end +# Index: 0 +# Index: 1 +# Index: 2 +# Index: 3 + +# Le type d'une variable dépend du type de l'expression +# dans la déclaration du if +if a < 3 + a = "hello" +else + a = true +end +typeof a #=> (Bool | String) + +if a && b + # ici a et b ne sont pas null +end + +if a.is_a? String + a.class #=> String +end + +# Fonctions + +def double(x) + x * 2 +end + +# Les fonctions et tous les blocs retournent la valeur de la dernière évaluation +double(2) #=> 4 + +# Les parenthèses sont optionnelle quand l'appel n'est pas ambigü +double 3 #=> 6 + +double double 3 #=> 12 + +def sum(x, y) + x + y +end + +# Les arguments sont séparés par une virgule +sum 3, 4 #=> 7 + +sum sum(3, 4), 5 #=> 12 + +# yield +# Toutes les méthodes on un paramètre optionel et implicite de type bloc +# il peut être appelé avec le mot clé 'yield' +def surround + puts '{' + yield + puts '}' +end + +surround { puts "hello world" } + +# { +# hello world +# } + +# Un bloc peut être passé à une fonction +# Le "&" marque une référence à un bloc +def guests(&block) + block.call "some_argument" +end + +# Une liste d'arguments peut être donnée, qui sera convertie en tableau +# Pour cela, utilisez l'opérateur "*" +def guests(*array) + array.each { |guest| puts guest } +end + +# Si une méthode retourne un tableau, il peut être scindé +def foods + ["pancake", "sandwich", "quesadilla"] +end +breakfast, lunch, dinner = foods +breakfast #=> "pancake" +dinner #=> "quesadilla" + +# Par convention, toutes les méthodes qui retournent un booléen +# finissent par un point d'interrogation +5.even? # false +5.odd? # true + +# Si une méthode finit avec un point d'exclamation, c'est qu'elle fait une +# opération destructrice. Quelques méthodes ont une version "!" pour faire +# des changements et une version non-"!" pour retourner une nouvelle version +company_name = "Dunder Mifflin" +company_name.gsub "Dunder", "Donald" #=> "Donald Mifflin" +company_name #=> "Dunder Mifflin" +company_name.gsub! "Dunder", "Donald" +company_name #=> "Donald Mifflin" + + +# Les classes se définissent avec le mot clé "class" +class Human + + # Une variable de classe, partagée par toutes les instances + @@species = "H. sapiens" + + # "name" est une chaine de caratère ( String ) + @name : String + + # Constructeur basique, assigne l'argument à la variable "name" + # si l'age n'est pas donné, sa valeur sera de 0 + def initialize(@name, @age = 0) + end + + # Mutateur + def name=(name) + @name = name + end + + # Accesseur + def name + @name + end + + # La macro "property" va générer les deux précédentes méthodes + property :name + + # Les accesseurs/mutateurs peuvent aussi être créés individuellement + getter :name + setter :name + + # Une méthode de classe utilise "self" pour se distinguer d'une + # méthode d'instance. Elle ne peut être appelée qu'à partir de la classe + def self.say(msg) + puts msg + end + + def species + @@species + end +end + + +# Instantie une classe +jim = Human.new("Jim Halpert") + +dwight = Human.new("Dwight K. Schrute") + +# Appelons quelques méthodes +jim.species #=> "H. sapiens" +jim.name #=> "Jim Halpert" +jim.name = "Jim Halpert II" #=> "Jim Halpert II" +jim.name #=> "Jim Halpert II" +dwight.species #=> "H. sapiens" +dwight.name #=> "Dwight K. Schrute" + +# Appel de la méthode de classe +Human.say("Hi") #=> Affiche "Hi" et retourne nil + +# Les variables qui commencent par @ ont une portée d'instance +class TestClass + @var = "Je suis une variable d'instance" +end + +# Les variables qui commencent par @@ ont une portée de classe +class TestClass + @@var = "Je suis une variable de classe" +end +# Les constantes commencent par une lettre majuscule +Var = "Je suis constante" +Var = "impossible" # Already initialized constant Var + +# La classe est aussi un objet +# Les variables de classe sont partagées avec les descendants + +# Classe de base +class Human + @@foo = 0 + + def self.foo + @@foo + end + + def self.foo=(value) + @@foo = value + end +end + +# Classe dérivée +class Worker < Human +end + +Human.foo #=> 0 +Worker.foo #=> 0 + +Human.foo = 2 #=> 2 +Worker.foo #=> 0 + +Worker.foo = 3 #=> 3 +Human.foo #=> 2 +Worker.foo #=> 3 + +module ModuleExample + def foo + "foo" + end +end + +# Inclure (include) des modules ajoute leurs méthodes aux instances +# Étendre (extend) ajoute les méthodes à la classe + +class Person + include ModuleExample +end + +class Book + extend ModuleExample +end + +Person.foo # => undefined method 'foo' for Person:Class +Person.new.foo # => 'foo' +Book.foo # => 'foo' +Book.new.foo # => undefined method 'foo' for Book + + +# Gestion des exceptions + +# Définit un type d'exeption +class MyException < Exception +end + +# Définit une autre exception +class MyAnotherException < Exception; end + +ex = begin + raise MyException.new +rescue ex1 : IndexError + "ex1" +rescue ex2 : MyException | MyAnotherException + "ex2" +rescue ex3 : Exception + "ex3" +rescue ex4 # attrape toutes les autres exceptions + "ex4" +end + +ex #=> "ex2" + +``` + +## Ressources additionnelles + +- [Documentation Officielle (EN)](http://crystal-lang.org/) -- cgit v1.2.3 From 728852dea14ffc77786121af3f5af298337cf5da Mon Sep 17 00:00:00 2001 From: ven Date: Fri, 23 Dec 2016 01:08:03 +0100 Subject: follow-up fixes for #2602 --- fr-fr/crystal-fr.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fr-fr/crystal-fr.html.markdown b/fr-fr/crystal-fr.html.markdown index 0bf6889c..2c4e3dad 100644 --- a/fr-fr/crystal-fr.html.markdown +++ b/fr-fr/crystal-fr.html.markdown @@ -13,7 +13,7 @@ lang: fr-fr # Ceci est un commentaire -# Tout est object +# Tout est objet nil.class #=> Nil 100.class #=> Int32 true.class #=> Bool @@ -68,7 +68,7 @@ true.class #=> Bool 'a'.class #=> Char -# Notation octale des caratères +# Notation octale des caractères '\101' #=> 'A' : Char # Notation unicode -- cgit v1.2.3 From 2b6e4601ca1dc80fa83c2580539cb843f1c217e7 Mon Sep 17 00:00:00 2001 From: ven Date: Fri, 23 Dec 2016 12:18:23 +0100 Subject: Update angularjs.html.markdown --- angularjs.html.markdown | 5 ----- 1 file changed, 5 deletions(-) diff --git a/angularjs.html.markdown b/angularjs.html.markdown index e72d89ad..737b99c7 100644 --- a/angularjs.html.markdown +++ b/angularjs.html.markdown @@ -706,8 +706,3 @@ app.controller('myCtrl', function($scope) { - http://www.w3schools.com/angular/angular_ref_directives.asp - http://www.w3schools.com/angular/default.asp - https://teamtreehouse.com/library/angular-basics/ - -Feedback is welcome! You can find me in: -[@WalterC_87](https://twitter.com/WalterC_87), or -[me@waltercordero.com](mailto:me@waltercordero.com). - -- cgit v1.2.3 From 68569341b3e8cc484ff3dc3b890f9a043e08f6b2 Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Fri, 23 Dec 2016 19:33:54 +0800 Subject: [jquery/en] typo fix (#2608) --- jquery.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.html.markdown b/jquery.html.markdown index d498733d..9326c74b 100644 --- a/jquery.html.markdown +++ b/jquery.html.markdown @@ -125,4 +125,4 @@ $('p').each(function() { }); -`` +``` -- cgit v1.2.3 From 393bab2f6e5ebfb6e924929785e821ac6e602efa Mon Sep 17 00:00:00 2001 From: Jiang Haiyun Date: Fri, 23 Dec 2016 23:07:15 +0800 Subject: [AngularJS/zh-cn] new translation (#2607) * .. * [angularjs/zh-cn] new translation * Update angularjs-cn.html.markdown --- zh-cn/angularjs-cn.html.markdown | 710 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 710 insertions(+) create mode 100644 zh-cn/angularjs-cn.html.markdown diff --git a/zh-cn/angularjs-cn.html.markdown b/zh-cn/angularjs-cn.html.markdown new file mode 100644 index 00000000..418a817d --- /dev/null +++ b/zh-cn/angularjs-cn.html.markdown @@ -0,0 +1,710 @@ +--- +category: tool +tool: AngularJS +contributors: + - ["Walter Cordero", "http://waltercordero.com"] +filename: learnangular-cn.html +translators: + - ["Jiang Haiyun", "http://www.atjiang.com"] +lang: zh-cn +--- + +## AngularJS 教程。 + +AngularJS 1.0 版在 2012 年发布。 +Miško Hevery, 一位 Google 员工, 从 2009 年开始开发 AngularJS。 +结果发现这个想法很好,从而该项目现在也被 Google 官方所支持了。 + +AngularJS 是一个 JavaScript 框架。它可以通过一个 "script" 标签添加到一个 HTML 页面中。 +AngularJS 通过指令扩展了 HTML 属性,并且通过表达式将数据绑定到 HTML。 + +## 你应该已经了解了的知识 + +在学习 AngularJS 之前, 你应该对以下知识有了基本的了解: + +- HTML +- CSS +- JavaScript + +```html +// AngularJS 是一个 JavaScript 框架。它是一个用 JavaScript 写的库。 +// AngularJS 以一个 JavaScript 文件的形式发布,并且能通过一个 script 标签添加到一个网页中: +// + +/////////////////////////////////// +// AngularJS 扩展 HTML + +//AngularJS 通过 ng-directives 扩展 HTML。 +//ng-app 指令定义一个 AngularJS 应用。 +//ng-model 指令将 HTML 控件 (input, select, textarea) 的值绑定到应用的数据上。 +//ng-bind 指令将应用的数据绑定到 HTML 视图上。 + + + + +
+

Name:

+

+
+ + + +/* + * 例子解析: + * AngularJS 在网页加载后自动开启。 + * ng-app 指令告诉 AngularJS:
元素是 AngularJS 应用的 "所有者"。 + * ng-model 指令将 input 输入框的值绑定到应用的 name 变量上。 + * ng-bind 指令将

元素的 innerHTML 绑定到应用的 name 变量上。 +*/ + 这里是要解析的内容 + +/////////////////////////////////// +// AngularJS 表达式 + +// AngularJS 表达式写在双括号内: {{ 表达式 }}。 +// AngularJS 表达式采用和 ng-bind 指令一样的方式将数据绑定到 HTML。 +// AngularJS 将在编写表达式的原样位置上 "输出" 数据。 +// AngularJS 表达式非常像 JavaScript 表达式:它们能包含文本,运算符和变量。 +// 例如 {{ 5 + 5 }} 或 {{ firstName + " " + lastName }} + + + + +

+

My first expression: {{ 5 + 5 }}

+
+ + + +//如果你删除了 ng-app 指令, HTML 将原样显示表达式,不对它进行解析: + + + + +
+

My first expression: {{ 5 + 5 }}

+
+ + + +// AngularJS 表达式采用和 ng-bind 指令一样的方式将 AngularJS 数据绑定到 HTML。 + + + + +
+

Name:

+

{{name}}

+
+ + + +// AngularJS 的数字类似 JavaScript 的数字: +
+

Total in dollar: {{ quantity * cost }}

+
+ +//AngularJS 的字符串类似 JavaScript 的字符串: +
+

The name is

+
+ +//AngularJS 的对象类似 JavaScript 的对象: +
+

The name is {{ person.lastName }}

+
+ +//AngularJS 的数组类似 JavaScript 的数组: +
+

The third result is {{ points[2] }}

+
+ +// 和 JavaScript 表达式一样, AngularJS 表达式能包含文本,运算符和变量。 +// 和 JavaScript 表达式不同, AngularJS 表达式能写在 HTML 内。 +// AngularJS 表达式不支持条件,循环和异常,而 JavaScript 表达式却支持。 +// AngularJS 表达式支持过滤器,而 JavaScript 表达式不支持。 + +/////////////////////////////////// +// AngularJS 指令 + + +//AngularJS 指令使用前缀 ng- 扩展 HTML 属性。 +//ng-app 指令初始化一个 AngularJS 应用。 +//ng-init 指令初始化应用的数据。 +//ng-model 指令将 HTML 控件 (input, select, textarea) 的值绑定到应用的数据上。 +
+

Name:

+

You wrote: {{ firstName }}

+
+ +//使用 ng-init 并不常见。你将在有关控制器的章节中学习如何初始化数据。 + +//ng-repeat 指令会重复一个 HTML 元素: +
+
    +
  • + {{ x }} +
  • +
+
+ +//ng-repeat 指令用在一个对象数组上: +
+
    +
  • + {{ x.name + ', ' + x.country }} +
  • +
+
+ +// AngularJS 最适合用于数据库 CRUD (Create Read Update Delete) 的应用。 +// 只需设想这些对象都是来自一个数据库的记录。 + +// ng-app 指令定义一个 AngularJS 应用的根元素。 +// ng-app 指令将在页面加载后自动启动(自动初始化)应用。 +// 稍后你将学习如何为 ng-app 设置一个值(如 ng-app="myModule"), 来连接代码模块。 + +// ng-init 指令为一个 AngularJS 应用定义初始值。 +// 通常,你不太使用 ng-init。你会转而使用一个控制器或模块。 +// 你将在稍后学到更多有关控制器和模块的内容。 + +//ng-model 指令将 HTML 控件 (input, select, textarea) 的值绑定到应用的数据上。 +//ng-model 指令还能: +//为应用的数据提供类型验证 (number, email, required)。 +//为应用的数据提供状态信息 (invalid, dirty, touched, error)。 +//为 HTML 元素提供 CSS 类。 +//将 HTML 元素绑定到 HTML 表单。 + +//ng-repeat 指令为集合(一个数组)中的每个元素克隆出 HTML 元素。 + +/////////////////////////////////// +// AngularJS 控制器 + +// AngularJS 控制器控制 AngularJS 应用中的数据。 +// AngularJS 控制器就是常规的 JavaScript 对象。 + +// AngularJS 应用由控制器控制。 +// ng-controller 指令定义应用的控制器。 +// 一个控制器就是一个 JavaScript 对象, 通过标准的 JavaScript 对象构建器创建。 + +
+ +First Name:
+Last Name:
+
+Full Name: {{firstName + " " + lastName}} + +
+ + + +//应用的解析: + +//AngularJS 应用通过 ng-app="myApp" 定义。该应用运行在
内。 +//ng-controller="myCtrl" 属性是一个 AngularJS 指令。它定义了一个控制器。 +//myCtrl 函数是一个 JavaScript 函数。 +//AngularJS 将使用一个 $scope 对象来调用控制器。 +//AngularJS 中, $scope 就是该应用对象(应用的变量和函数的所有者)。 +//该控制器在 $scope 内创建了两个属性(即变量 firstName 和 lastName)。 +//ng-model 指令将输入表单项绑定到控制器的属性上(firstName 和 lastName)。 + +//以上的例子演示了一个包含有两个属性 lastName 和 firstName 的控制器。 +//一个控制器也可以有方法(函数的变量): +
+ +First Name:
+Last Name:
+
+Full Name: {{fullName()}} + +
+ + + +//在较大型的应用中, 通常是将控制器代码保存在外部文件中。 +//只需将 标签之间的代码复制到一个名为 personController.js 的外部文件中: + +
+ +First Name:
+Last Name:
+
+Full Name: {{firstName + " " + lastName}} + +
+ + + +// 为方便下个例子使用,我们将创建一个新的控制器文件: +angular.module('myApp', []).controller('namesCtrl', function($scope) { + $scope.names = [ + {name:'Jani',country:'Norway'}, + {name:'Hege',country:'Sweden'}, + {name:'Kai',country:'Denmark'} + ]; +}); + +//将文件保存为 namesController.js: +//然后在一个应用中使用该控制器: + +
+ +
    +
  • + {{ x.name + ', ' + x.country }} +
  • +
+ +
+ + + +/////////////////////////////////// +// AngularJS 过滤器 + +// 过滤器可以通过一个管道符添加到表达式和指令上。 +// AngularJS 过滤器能用来转换数据: + +- **currency**: 将一个数字格式化成货币格式。 +- **filter**: 从一个数组中选择一组子集元素。 +- **lowercase**: 将一个字符串格式化成小写形式。 +- **orderBy**: 依据一个表达式排序一个数组。 +- **upper**: 将一个字符串格式化成大写形式。 + +//一个过滤器可以通过一个管道符 (|) 及一个过滤器表达式添加到一个表达式上。 +//(在下面的两个例子中,我们将使用前一章中的 person 控制器) +//uppercase 过滤器将字符串格式化成大写格式: +
+ +

The name is {{ lastName | uppercase }}

+ +
+ +//lowercase 过滤器将字符串格式化成小写格式: +
+ +

The name is {{ lastName | lowercase }}

+ +
+ +//currency 过滤器将一个数字格式化成货币格式: +
+ + + + +

Total = {{ (quantity * price) | currency }}

+ +
+ +//一个过滤器可以通过一个管道符 (|) 及一个过滤器表达式添加到一个指令上。 +//orderBy 过滤器根据一个表达式排序一个数组: +
+ +
    +
  • + {{ x.name + ', ' + x.country }} +
  • +
+ +
+ +//一个输入框过滤器可以通过一个管道符 (|) +//以及后跟一个冒号和模式名的 filter 添加到一个指令上。 +//该过滤器从一个数组中选择一个子集: + +
+ +

+ +
    +
  • + {{ (x.name | uppercase) + ', ' + x.country }} +
  • +
+ +
+ +/////////////////////////////////// +// AngularJS AJAX - $http + +//$http 是一个从远程服务器读取数据的 AngularJS 服务。 + +// 以下数据可由一个 web 服务器提供: +// http://www.w3schools.com/angular/customers.php +// **访问 URL 来查看数据格式** + +// AngularJS $http 是一个从 web 服务器上读取数据的核心服务。 +// $http.get(url) 这个函数用来读取服务器数据。 +
+ +
    +
  • + {{ x.Name + ', ' + x.Country }} +
  • +
+ +
+ + + +// 应用解析: + +// AngularJS 应用由 ng-app 定义。该应用运行在一个
中。 +// ng-controller 指令命名控制器对象。 +// customersCtrl 函数是一个标准的 JavaScript 对象构造器。 +// AngularJS 会使用一个 $scope 和 $http 对象来调用 customersCtrl。 +// $scope 就是该应用对象(应用的变量和函数的所有者)。 +// $http 是一个用于请求外部数据的 XMLHttpRequest 对象。 +// $http.get() 从 http://www.w3schools.com/angular/customers.php 读取 JSON 数据。 +// 如果成功, 该控制器会根据来自服务器的 JSON 数据,在 $scope 中创建一个属性 (names)。 + + +// 向不同的服务器(不同于请求页)请求数据,称作跨站 HTTP 请求。 +// 跨站请求在网站上很普遍。许多网页会从不同的服务器加载 CSS,图片和脚本。 +// 在现代浏览器中,基于安全原因,从脚本内进行跨站 HTTP 请求是被禁止的。 +// 下面的这行代码,已被加入到我们的 PHP 例子中,以便允许跨站访问。 +header("Access-Control-Allow-Origin: *"); + + +/////////////////////////////////// +// AngularJS 表格 + +// 使用 angular 显示表格非常简单: +
+ + + + + + +
{{ x.Name }}{{ x.Country }}
+ +
+ + + +// 要排序表格,添加一个 orderBy 过滤器: + + + + + +
{{ x.Name }}{{ x.Country }}
+ +// 要显示表格索引值,添加一个带有 $index 的 : + + + + + + +
{{ $index + 1 }}{{ x.Name }}{{ x.Country }}
+ +// 使用 $even 和 $odd + + + + + + + +
{{ x.Name }}{{ x.Name }}{{ x.Country }}{{ x.Country }}
+ +/////////////////////////////////// +// AngularJS HTML DOM + +//AngularJS 有用于将应用的数据绑定到 HTML DOM 元素属性的指令。 + +// ng-disabled 指令将 AngularJS 应用的数据绑定到 HTML 元素的 disabled 属性上。 + +
+ +

+ +

+ +

+Button +

+ +
+ +//应用解析: + +// ng-disabled 指令将应用的 mySwitch 数据绑定到 HTML 按钮的 disabled 属性上。 +// ng-model 指令将 HTML checkbox 元素的值绑定到 mySwitch 的值上。 +// 如果 mySwitch 的值求值为 true,则该按钮将被禁用: +

+ +

+ +// 如果 mySwitch 的值求值为 false,则该按钮将不会被禁用: +

+ +

+ +// ng-show 指令显示或隐藏一个 HTML 元素。 + +
+ +

I am visible.

+ +

I am not visible.

+ +
+ +// ng-show 指令基于 ng-show 的值显示(或隐藏)一个 HTML 元素。 +// 你可以使用任何能求值成 true 或 false 的表达式: +
+

I am visible.

+
+ +/////////////////////////////////// +// AngularJS 事件 + +// AngularJS 有它自己的 HTML 事件指令。 + +// ng-click 指令定义一个 AngularJS 点击事件。 +
+ + + +

{{ count }}

+ +
+ + +// ng-hide 指令可用于设置一个应用的部分区域的可见性。 +// 值 ng-hide="true" 使得一个 HTML 元素不可见。 +// 值 ng-hide="false" 使得一个 HTML 元素可见。 +
+ + + +

+First Name:
+Last Name:
+
+Full Name: {{firstName + " " + lastName}} +

+ +
+ + + +//应用解析: + +// personController 的第一部分和讲述控制器章节中的一样。 +// 该应用有一个默认属性(一个变量):$scope.myVar = false: +// ng-hide 指令依据 myVar 的值(true 或 false), +// 设置

元素的可见性,该元素含有两个输入框。 +// 函数 toggle() 将 myVar 在 true 和 false 间进行切换。 +// 值 ng-hide="true" 使得该元素不可见。 + + +// ng-show 指令也能用来设置一个应用的某部分的可见性。 +// 值 ng-show="false" 使得一个 HTML 元素不可见。 +// 值 ng-show="true" 使得一个 HTML 元素可见。 +// 这个例子与上面的一样,但用 ng-show 替代了 ng-hide: +

+ + + +

+First Name:
+Last Name:
+
+Full Name: {{firstName + " " + lastName}} +

+ +
+ + + +/////////////////////////////////// +// AngularJS 模块 + +// 一个 AngularJS 模块定义一个应用。 +// 模块是一个应用的不同部分所在的一个容器。 +// 模块是应用控制器的一个容器。 +// 控制器总是隶属于一个模块。 + +// 这个应用 ("myApp") 有一个控制器 ("myCtrl"): + + + + + + +
+{{ firstName + " " + lastName }} +
+ + + + + + +// 在 AngularJS 应用中通常将模块和控制器放置在 JavaScript 文件中。 +// 在本例中,"myApp.js" 包含了一个应用模块的定义,而 "myCtrl.js" 包含了控制器: + + + + + + +
+{{ firstName + " " + lastName }} +
+ + + + + + + +//myApp.js +var app = angular.module("myApp", []); + +// 模块定义中的 [] 参数可用来定义依赖的模块。 + +// myCtrl.js +app.controller("myCtrl", function($scope) { + $scope.firstName = "John"; + $scope.lastName= "Doe"; +}); + +// JavaScript 中应该避免使用全局函数。它们会非常容易地被覆盖 +// 或被其它脚本破坏。 + +// AngularJS 脚本通过将所有函数保存在模块内,缓解了这种问题。 + +// 虽然 HTML 应用中通常是将脚本放置在 +// 元素的末尾,但还是推荐你要么在 +// 中要么在 的开头处加载 AngularJS 库。 + +// 这是因为对 angular.module 的调用只有在库被加载后才能被编译。 + + + + + + +
+{{ firstName + " " + lastName }} +
+ + + + + + + +/////////////////////////////////// +// AngularJS 应用 + +// AngularJS 模块定义 AngularJS 应用。 +// AngularJS 控制器控制 AngularJS 应用。 +// ng-app 指令定义该应用,ng-controller 定义该控制器。 +
+ First Name:
+ Last Name:
+
+ Full Name: {{firstName + " " + lastName}} +
+ + +// AngularJS 模块定义应用: +var app = angular.module('myApp', []); + +// AngularJS 控制器控制应用: +app.controller('myCtrl', function($scope) { + $scope.firstName= "John"; + $scope.lastName= "Doe"; +}); +``` + +## 来源 & 参考 + +**例子** + +- http://www.w3schools.com/angular/angular_examples.asp + +**参考** + +- http://www.w3schools.com/angular/angular_ref_directives.asp +- http://www.w3schools.com/angular/default.asp -- cgit v1.2.3 From 9453efb8453d57b719c68620c5f7ce36751cfc90 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Fri, 23 Dec 2016 10:47:03 -0800 Subject: solidity contract name convention CamelCase to CapWords (#2606) --- solidity.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solidity.html.markdown b/solidity.html.markdown index 0ad8af32..5b0ac3a3 100644 --- a/solidity.html.markdown +++ b/solidity.html.markdown @@ -45,7 +45,7 @@ features are typically marked, and subject to change. Pull requests welcome. /* 'contract' has similarities to 'class' in other languages (class variables, inheritance, etc.) */ -contract SimpleBank { // CamelCase +contract SimpleBank { // CapWords // Declare state variables outside function, persist through life of contract // dictionary that maps addresses to balances -- cgit v1.2.3 From e5ff868d155781c50beca2be705021257839b379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Fro=C5=82ow?= Date: Tue, 27 Dec 2016 13:06:36 +0100 Subject: [elm/en] Fixes #2584 (#2610) --- elm.html.markdown | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/elm.html.markdown b/elm.html.markdown index 96554e84..99c23980 100644 --- a/elm.html.markdown +++ b/elm.html.markdown @@ -51,18 +51,18 @@ not False -- True ["the", "quick", "brown", "fox"] [1, 2, 3, 4, 5] -- The second example can also be written with two dots. -[1..5] +List.range 1 5 -- Append lists just like strings. -[1..5] ++ [6..10] == [1..10] -- True +List.range 1 5 ++ List.range 6 10 == List.range 1 10 -- True -- To add one item, use "cons". -0 :: [1..5] -- [0, 1, 2, 3, 4, 5] +0 :: List.range 1 5 -- [0, 1, 2, 3, 4, 5] -- The head and tail of a list are returned as a Maybe. Instead of checking -- every value to see if it's null, you deal with missing values explicitly. -List.head [1..5] -- Just 1 -List.tail [1..5] -- Just [2, 3, 4, 5] +List.head (List.range 1 5) -- Just 1 +List.tail (List.range 1 5) -- Just [2, 3, 4, 5] List.head [] -- Nothing -- List.functionName means the function lives in the List module. @@ -150,10 +150,10 @@ answer = 42 -- Pass functions as arguments to other functions. -List.map double [1..4] -- [2, 4, 6, 8] +List.map double (List.range 1 4) -- [2, 4, 6, 8] -- Or write an anonymous function. -List.map (\a -> a * 2) [1..4] -- [2, 4, 6, 8] +List.map (\a -> a * 2) (List.range 1 4) -- [2, 4, 6, 8] -- You can pattern match in function definitions when there's only one case. -- This function takes one tuple rather than two arguments. @@ -180,7 +180,7 @@ fib n = else fib (n - 1) + fib (n - 2) -List.map fib [0..8] -- [1, 1, 2, 3, 5, 8, 13, 21, 34] +List.map fib (List.range 0 8) -- [1, 1, 2, 3, 5, 8, 13, 21, 34] -- Another recursive function (use List.length in real code). listLength aList = @@ -335,10 +335,10 @@ $ elm repl -- Packages are identified by GitHub username and repo name. -- Install a new package, and record it in elm-package.json. -$ elm package install evancz/elm-html +$ elm package install elm-lang/html -- See what changed between versions of a package. -$ elm package diff evancz/elm-html 3.0.0 4.0.2 +$ elm package diff elm-lang/html 1.1.0 2.0.0 -- Elm's package manager enforces semantic versioning, so minor version bumps -- will never break your build! ``` -- cgit v1.2.3 From 584ae4f5fca558a9c9c3f89ef7383f16a32d45a3 Mon Sep 17 00:00:00 2001 From: Alan Jeon Date: Wed, 28 Dec 2016 01:18:03 +0900 Subject: [kotlin/ko-kr] Add korean translation for kotlin (#2609) * Add korean translation for kotlin * Add (EN) tag to english links --- ko-kr/kotlin-kr.html.markdown | 376 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 376 insertions(+) create mode 100644 ko-kr/kotlin-kr.html.markdown diff --git a/ko-kr/kotlin-kr.html.markdown b/ko-kr/kotlin-kr.html.markdown new file mode 100644 index 00000000..9b2294d4 --- /dev/null +++ b/ko-kr/kotlin-kr.html.markdown @@ -0,0 +1,376 @@ +--- +language: kotlin +contributors: + - ["S Webber", "https://github.com/s-webber"] +translators: + - ["Alan Jeon", "https://github.com/skyisle"] +lang: ko-kr +filename: LearnKotlin-kr.kt +--- + +Kotlin 은 정적 타입 프로그래밍 언어로 JVM, 안드로이드, 브라우져를 지원하며 Java 와 100% 상호 운용이 가능합니다. +[자세한 내용은 다음을 참고하세요.](https://kotlinlang.org/) + +```kotlin +// 한 줄짜리 주석은 // 로 시작합니다. +/* +여러 줄 주석은 이와 같이 표시합니다. +*/ + +// "package" 예약어는 자바와 동일하게 사용됩니다. +package com.learnxinyminutes.kotlin + +/* +Kotlin 프로그램의 진입점은 main 이라는 함수명으로 지정됩니다. +이 함수에 명령행 인수가 배열로 전달됩니다. +*/ +fun main(args: Array) { + /* + 값을 선언할때는 "var" 또는 "val"이 사용됩니다. + "var"와는 다르게 "val"로 선언된 변수에는 값을 재할당 할 수 없습니다. + */ + val fooVal = 10 // fooVal 에 다른 값을 다시 할당 할 수 없습니다. + var fooVar = 10 + fooVar = 20 // fooVar 에는 선언 이후에도 다른 값을 할당 할 수 있습니다 + + /* + 대부분의 경우, Kotlin 에서는 변수 타입을 판단할 수 있기때문에 명시적으로 지정해 주지 않을 수 있습니다. + 다음과 같이 변수의 타입을 명시적으로 지정할 수 있습니다. + */ + val foo : Int = 7 + + /* + 문자형은 Java와 비슷하게 표시될 수 있습니다. + 이스케이핑에는 백슬래시를 사용합니다. + */ + val fooString = "My String Is Here!" + val barString = "Printing on a new line?\nNo Problem!" + val bazString = "Do you want to add a tab?\tNo Problem!" + println(fooString) + println(barString) + println(bazString) + + /* + Raw 문자열은 쌍따옴표 3개(""")로 표기합니다. + Raw 문자열에는 줄바꿈이나 모든 다른 문자들을 사용할 수 있습니다. + */ + val fooRawString = """ +fun helloWorld(val name : String) { + println("Hello, world!") +} +""" + println(fooRawString) + + /* + 문자열은 템플릿 표현식을 포함할 수 있습니다. + 템플릿은 달러 기호($)로 시작합니다. + */ + val fooTemplateString = "$fooString has ${fooString.length} characters" + println(fooTemplateString) + + /* + 변수가 null 값을 가지려면 이를 명시적으로 선언해야 합니다. + 변수 선언시 타입에 ? 표시를 붙여 nullable 을 표시합니다. + ?. 연산자를 사용해 nullable 변수에 접근합니다. + ?: 연산자를 이용해서 변수 값이 null 일때 사용할 값을 지정합니다. + */ + var fooNullable: String? = "abc" + println(fooNullable?.length) // => 3 + println(fooNullable?.length ?: -1) // => 3 + fooNullable = null + println(fooNullable?.length) // => null + println(fooNullable?.length ?: -1) // => -1 + + /* + 함수는 "fun" 예약어를 사용해 선언합니다. + 함수명 이후 괄호 안에 인자를 기술합니다. + 함수 인자에 기본 값을 지정할 수도 있습니다. + 함수에 리턴값이 있을 때, 필요한 경우 인자 뒤에 타입을 명시합니다. + */ + fun hello(name: String = "world"): String { + return "Hello, $name!" + } + println(hello("foo")) // => Hello, foo! + println(hello(name = "bar")) // => Hello, bar! + println(hello()) // => Hello, world! + + /* + 함수에 가변 인자를 넘기려면 인자에 "vararg" 예약어를 사용합니다. + */ + fun varargExample(vararg names: Int) { + println("Argument has ${names.size} elements") + } + varargExample() // => 인자가 0개 인 경우 + varargExample(1) // => 인자가 1개인 경우 + varargExample(1, 2, 3) // => 인자가 3개인 경우 + + /* + 함수가 단일 표현식으로 이루어진 경우에 중괄호를 생략할 수 있습니다. + 이때 함수 구현부는 = 기호 이후에 기술합니다. + */ + fun odd(x: Int): Boolean = x % 2 == 1 + println(odd(6)) // => false + println(odd(7)) // => true + + // 리턴 타입이 유추 가능한 경우 이를 명시하지 않아도 됩니다. + fun even(x: Int) = x % 2 == 0 + println(even(6)) // => true + println(even(7)) // => false + + // 함수는 함수를 인자를 받을 수 있고 함수를 리턴할 수 있습니다. + fun not(f: (Int) -> Boolean): (Int) -> Boolean { + return {n -> !f.invoke(n)} + } + // 함수는 :: 연산자를 사용해서 다른 함수에 인자로 넘길 수 있습니다. + val notOdd = not(::odd) + val notEven = not(::even) + // 람다식을 인자로 사용할 수 있습니다. + val notZero = not {n -> n == 0} + /* + 하나의 인자를 가지는 람다식의 선언부와 -> 연산자는 생략될 수 있습니다. + 이때 그 인자명은 it로 지정됩니다. + */ + val notPositive = not {it > 0} + for (i in 0..4) { + println("${notOdd(i)} ${notEven(i)} ${notZero(i)} ${notPositive(i)}") + } + + // "class" 예약어는 클래스를 선언할 때 사용됩니다. + class ExampleClass(val x: Int) { + fun memberFunction(y: Int): Int { + return x + y + } + + infix fun infixMemberFunction(y: Int): Int { + return x * y + } + } + /* + 새로운 객체를 생성하기 위해서는 생성자를 바로 호출합니다. + Kotlin 에서는 new 예약어가 없다는 걸 기억하세요. + */ + val fooExampleClass = ExampleClass(7) + // 맴버 함수는 dot 표기로 호출할 수 있습니다. + println(fooExampleClass.memberFunction(4)) // => 11 + /* + 함수 선언에 "infix" 예약어를 사용하면 이 함수를 중위 표현식(infix notation)으로 호출할 수 있습니다 + */ + println(fooExampleClass infixMemberFunction 4) // => 28 + + /* + 데이터 클래스로 데이터만을 가지고 있는 클래스를 손쉽게 선언할 수 있습니다. + "hashCode"/"equals" 와 "toString" 는 자동으로 생성됩니다. + */ + data class DataClassExample (val x: Int, val y: Int, val z: Int) + val fooData = DataClassExample(1, 2, 4) + println(fooData) // => DataClassExample(x=1, y=2, z=4) + + // 데이터 클래스는 copy 함수를 가지고 있습니다. + val fooCopy = fooData.copy(y = 100) + println(fooCopy) // => DataClassExample(x=1, y=100, z=4) + + // 객체를 여러 변수로 분리할 수 있습니다. + val (a, b, c) = fooCopy + println("$a $b $c") // => 1 100 4 + + // "for" 루프에서 변수 분리 하기 + for ((a, b, c) in listOf(fooData)) { + println("$a $b $c") // => 1 100 4 + } + + val mapData = mapOf("a" to 1, "b" to 2) + // Map.Entry 또한 키와 값으로 분리가 가능합니다. + for ((key, value) in mapData) { + println("$key -> $value") + } + + // "with" 함수는 JavaScript 의 "with" 구문과 비슷하게 사용됩니다. + data class MutableDataClassExample (var x: Int, var y: Int, var z: Int) + val fooMutableDate = MutableDataClassExample(7, 4, 9) + with (fooMutableDate) { + x -= 2 + y += 2 + z-- + } + println(fooMutableDate) // => MutableDataClassExample(x=5, y=6, z=8) + + /* + "listOf" 함수로 리스트를 만들 수 있습니다. + 리스트는 변경 불가능(immutable)하게 만들어져 항목의 추가 삭제가 불가능합니다. + */ + val fooList = listOf("a", "b", "c") + println(fooList.size) // => 3 + println(fooList.first()) // => a + println(fooList.last()) // => c + // 각 항목은 인덱스로 접근이 가능합니다. + println(fooList[1]) // => b + + // 변경가능한(mutable) 리스트는 "mutableListOf" 함수로 만들 수 있습니다. + val fooMutableList = mutableListOf("a", "b", "c") + fooMutableList.add("d") + println(fooMutableList.last()) // => d + println(fooMutableList.size) // => 4 + + // 집합(set)은 "setOf" 함수로 만들 수 있습니다. + val fooSet = setOf("a", "b", "c") + println(fooSet.contains("a")) // => true + println(fooSet.contains("z")) // => false + + // 맵은 "mapOf" 함수로 만들 수 있습니다. + val fooMap = mapOf("a" to 8, "b" to 7, "c" to 9) + // 맵은 키를 통해 그 값에 접근할 수 있습니다. Map values can be accessed by their key. + println(fooMap["a"]) // => 8 + + /* + 시퀀스는 지연 평가되는 컬랙션을 말합니다. Sequences represent lazily-evaluated collections. + "generateSequence" 를 사용해 시퀀스를 만들 수 있습니다. We can create a sequence using the "generateSequence" function. + */ + val fooSequence = generateSequence(1, { it + 1 }) + val x = fooSequence.take(10).toList() + println(x) // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + + // 다음은 시퀀스를 사용해서 피보나치 수열을 생성하는 예입니다. + fun fibonacciSequence(): Sequence { + var a = 0L + var b = 1L + + fun next(): Long { + val result = a + b + a = b + b = result + return a + } + + return generateSequence(::next) + } + val y = fibonacciSequence().take(10).toList() + println(y) // => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] + + // Kotlin 은 컬랙션에서 사용할 수 있는 고차(higher-order)함수를 제공합니다. + val z = (1..9).map {it * 3} + .filter {it < 20} + .groupBy {it % 2 == 0} + .mapKeys {if (it.key) "even" else "odd"} + println(z) // => {odd=[3, 9, 15], even=[6, 12, 18]} + + // "for" 루프는 이터레이터를 제공하는 어떤 것과도 함께 사용할 수 있습니다. + for (c in "hello") { + println(c) + } + + // "while" 루프는 다른 언어들과 동일하게 사용됩니다. + var ctr = 0 + while (ctr < 5) { + println(ctr) + ctr++ + } + do { + println(ctr) + ctr++ + } while (ctr < 10) + + /* + "if"는 값을 리턴하는 표현으로 사용될 수 있습니다. + 그래서 Kotlin 에서는 삼항 ?: 연산자가 필요하지 않습니다. + */ + val num = 5 + val message = if (num % 2 == 0) "even" else "odd" + println("$num is $message") // => 5 is odd + + // "when"은 "if-else if" 를 대체할때 사용할 수 있습니다. + val i = 10 + when { + i < 7 -> println("first block") + fooString.startsWith("hello") -> println("second block") + else -> println("else block") + } + + // "when"은 인수와 함께 사용될 수 있습니다. + when (i) { + 0, 21 -> println("0 or 21") + in 1..20 -> println("in the range 1 to 20") + else -> println("none of the above") + } + + // "when"은 값을 리턴하는 함수처럼 사용될 수 있습니다. + var result = when (i) { + 0, 21 -> "0 or 21" + in 1..20 -> "in the range 1 to 20" + else -> "none of the above" + } + println(result) + + /* + 객체가 어떤 타입인지를 확인하기 위해 "is" 연산자를 사용할 수 있습니다. + 타입 체크를 통과하면 객체의 명시적인 형변환 없이도 그 타입 값으로 사용될 수 있습니다. + 이를 스마트 변환(Smartcast)이라 부릅니다. + */ + fun smartCastExample(x: Any) : Boolean { + if (x is Boolean) { + // x is automatically cast to Boolean + return x + } else if (x is Int) { + // x is automatically cast to Int + return x > 0 + } else if (x is String) { + // x is automatically cast to String + return x.isNotEmpty() + } else { + return false + } + } + println(smartCastExample("Hello, world!")) // => true + println(smartCastExample("")) // => false + println(smartCastExample(5)) // => true + println(smartCastExample(0)) // => false + println(smartCastExample(true)) // => true + + // 스마트 변환은 when 블럭과도 함께 사용됩니다. + fun smartCastWhenExample(x: Any) = when (x) { + is Boolean -> x + is Int -> x > 0 + is String -> x.isNotEmpty() + else -> false + } + + /* + 확장(Extensions)을 이용해 클래스에 새로운 기능을 추가할 수 있습니다. + C#에서의 확장 매서드와 유사합니다. + */ + fun String.remove(c: Char): String { + return this.filter {it != c} + } + println("Hello, world!".remove('l')) // => Heo, word! + + println(EnumExample.A) // => A + println(ObjectExample.hello()) // => hello +} + +// Enum 클래스는 자바의 enum 타입과 유사합니다. +enum class EnumExample { + A, B, C +} + +/* +"object" 예약어는 싱클톤 객체를 생성할 때 사용됩니다. +객체를 새로 생성할 수는 없지만 이름을 가지고 접근해 사용할 수 있습니다. +이는 스칼라의 싱글톤 객체와 유사합니다. +*/ +object ObjectExample { + fun hello(): String { + return "hello" + } +} + +fun useObject() { + ObjectExample.hello() + val someRef: Any = ObjectExample // 객체의 이름을 그대로 사용합니다. +} + +``` + +### 더 알아보기 + +* [Kotlin tutorials (EN)](https://kotlinlang.org/docs/tutorials/) +* [Try Kotlin in your browser (EN)](http://try.kotlinlang.org/) +* [A list of Kotlin resources (EN)](http://kotlin.link/) -- cgit v1.2.3 From ade786a71c1e8e9f1c8dc127ef07ba5d5013ea7b Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Wed, 28 Dec 2016 19:32:05 -0500 Subject: Update Guard Sequences link and change format (#2612) It updates an old link, and changes the way the URL is formated. It shouldn't be markdown style as it's inside a comment --- erlang.html.markdown | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/erlang.html.markdown b/erlang.html.markdown index a57f295f..2f05ea87 100644 --- a/erlang.html.markdown +++ b/erlang.html.markdown @@ -183,9 +183,10 @@ is_pet(A) -> false. % Warning: not all valid Erlang expressions can be used as guard expressions; % in particular, our `is_cat` and `is_dog` functions cannot be used within the % guard sequence in `is_pet`'s definition. For a description of the -% expressions allowed in guard sequences, refer to this -% [section](http://erlang.org/doc/reference_manual/expressions.html#id81912) -% of the Erlang reference manual. +% expressions allowed in guard sequences, refer to the specific section +% in the Erlang reference manual: +% http://erlang.org/doc/reference_manual/expressions.html#id84508 + % Records provide a method for associating a name with a particular element in a % tuple. -- cgit v1.2.3 From 60bba321d3237a2fd1e9557e52e3e6f1ac3d977e Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Wed, 28 Dec 2016 19:41:35 -0500 Subject: [erlang] Update guard sequences URL to use named id (#2613) it uses a named id, not a number --- erlang.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erlang.html.markdown b/erlang.html.markdown index 2f05ea87..a9d280d7 100644 --- a/erlang.html.markdown +++ b/erlang.html.markdown @@ -185,7 +185,7 @@ is_pet(A) -> false. % guard sequence in `is_pet`'s definition. For a description of the % expressions allowed in guard sequences, refer to the specific section % in the Erlang reference manual: -% http://erlang.org/doc/reference_manual/expressions.html#id84508 +% http://erlang.org/doc/reference_manual/expressions.html#guards % Records provide a method for associating a name with a particular element in a -- cgit v1.2.3 From ff3d2d1784cce6ff6b87f8ea47887aa8eee78036 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 15:25:24 -0800 Subject: Set bf, chapel, d and dart to use the language's highlighting Previously were using other languages with similar syntax, but now we have Pygments. --- bf.html.markdown | 2 +- chapel.html.markdown | 2 +- d.html.markdown | 12 ++++++------ dart.html.markdown | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bf.html.markdown b/bf.html.markdown index c8bbee61..9c603303 100644 --- a/bf.html.markdown +++ b/bf.html.markdown @@ -10,7 +10,7 @@ minimal Turing-complete programming language with just 8 commands. You can try brainfuck on your browser with [brainfuck-visualizer](http://fatiherikli.github.io/brainfuck-visualizer/). -``` +```bf Any character not "><+-.,[]" (excluding quotation marks) is ignored. Brainfuck is represented by an array with 30,000 cells initialized to zero diff --git a/chapel.html.markdown b/chapel.html.markdown index 9c1daf40..4619785e 100644 --- a/chapel.html.markdown +++ b/chapel.html.markdown @@ -10,7 +10,7 @@ In short, Chapel is an open-source, high-productivity, parallel-programming lang More information and support can be found at the bottom of this document. -```c +```chapel // Comments are C-family style // one line comment /* diff --git a/d.html.markdown b/d.html.markdown index edb3bff5..c682cfb5 100644 --- a/d.html.markdown +++ b/d.html.markdown @@ -6,7 +6,7 @@ contributors: lang: en --- -```c +```d // You know what's coming... module hello; @@ -28,7 +28,7 @@ D is actively developed by a large group of super-smart people and is spearheade [Andrei Alexandrescu](https://en.wikipedia.org/wiki/Andrei_Alexandrescu). With all that out of the way, let's look at some examples! -```c +```d import std.stdio; void main() { @@ -73,7 +73,7 @@ We can define new types with `struct`, `class`, `union`, and `enum`. Structs and are passed to functions by value (i.e. copied) and classes are passed by reference. Furthermore, we can use templates to parameterize all of these on both types and values! -```c +```d // Here, 'T' is a type parameter. Think '' from C++/C#/Java. struct LinkedList(T) { T data = null; @@ -136,7 +136,7 @@ is roughly a function that may act like an lvalue, so we can have the syntax of POD structures (`structure.x = 7`) with the semantics of getter and setter methods (`object.setX(7)`)! -```c +```d // Consider a class parameterized on types 'T' & 'U'. class MyClass(T, U) { T _data; @@ -209,7 +209,7 @@ functions, and immutable data. In addition, all of your favorite functional algorithms (map, filter, reduce and friends) can be found in the wonderful `std.algorithm` module! -```c +```d import std.algorithm : map, filter, reduce; import std.range : iota; // builds an end-exclusive range @@ -237,7 +237,7 @@ is of some type A on any expression of type A as a method. I like parallelism. Anyone else like parallelism? Sure you do. Let's do some! -```c +```d // Let's say we want to populate a large array with the square root of all // consecutive integers starting from 1 (up until the size of the array), and we // want to do this concurrently taking advantage of as many cores as we have diff --git a/dart.html.markdown b/dart.html.markdown index fc7b220e..5027dc3e 100644 --- a/dart.html.markdown +++ b/dart.html.markdown @@ -11,7 +11,7 @@ its JavaScript sibling. Like JavaScript, Dart aims for great browser integration Dart's most controversial feature must be its Optional Typing. -```javascript +```dart import "dart:collection"; import "dart:math" as DM; -- cgit v1.2.3 From f7e27eb94b6c3c3bb1c9698d016d742967da3c61 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 15:27:27 -0800 Subject: Have perl6 highlight as perl6 now Also remove some trailing spaces. --- perl6.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/perl6.html.markdown b/perl6.html.markdown index 34ad70b7..defd1315 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -18,7 +18,7 @@ double paragraphs, and single notes. `#=>` represents the output of a command. -```perl +```perl6 # Single line comment start with a pound #`( @@ -813,7 +813,7 @@ die X::AdHoc.new(payload => 'Error!'); # Undefined values include: `Nil`, `Mu` and `Failure` as well as `Int`, `Str` # and other types that have not been initialized to any value yet. # You can check if something is defined or not using the defined method: -my $uninitialized; +my $uninitialized; say $uninitiazilzed.defined; #> False # When using `orelse` it will disarm the exception and alias $_ to that failure # This will avoid it being automatically handled and printing lots of scary @@ -1092,7 +1092,7 @@ say (1, 10, (20, 10) ).flat; #> (1 10 20 10) Now the iterable is flat # - `lazy` - Defer actual evaluation until value is fetched (forces lazy context) my @lazy-array = (1..100).lazy; -say @lazy-array.is-lazy; #> True # Check for lazyness with the `is-lazy` method. +say @lazy-array.is-lazy; #> True # Check for lazyness with the `is-lazy` method. say @lazy-array; #> [...] List has not been iterated on! my @lazy-array { .print }; # This works and will only do as much work as is # needed. -- cgit v1.2.3 From d44e95095613383deb306ea40ee89b57b22f56bd Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 15:36:08 -0800 Subject: Set syntax highlighting for coldfusion --- coldfusion.html.markdown | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/coldfusion.html.markdown b/coldfusion.html.markdown index 482612fe..97259f56 100644 --- a/coldfusion.html.markdown +++ b/coldfusion.html.markdown @@ -13,7 +13,7 @@ ColdFusion is a scripting language for web development. _**C**old**F**usion **M**arkup **L**anguage_ ColdFusion started as a tag-based language. Almost all functionality is available using tags. -```html +```cfm HTML tags have been provided for output readability " ---> @@ -232,7 +232,8 @@ ColdFusion started as a tag-based language. Almost all functionality is availabl

Components

Code for reference (Functions must return something to support IE) - +``` +```cfs -- cgit v1.2.3 From 4d4dae03ea40240ffb6db74c1707279693e58844 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 15:43:35 -0800 Subject: set highlighter for sass and red --- red.html.markdown | 3 ++- sass.html.markdown | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/red.html.markdown b/red.html.markdown index 6d10fe8f..0c979ce1 100644 --- a/red.html.markdown +++ b/red.html.markdown @@ -34,7 +34,8 @@ brackets can be filled with useful information about this script or program: the author's name, the filename, the version, the license, a summary of what the program does or any other files it needs. The red/System header is just like the red header, only saying "red/System" and not "red". - +``` +```red Red [] ;this is a commented line diff --git a/sass.html.markdown b/sass.html.markdown index 860e550a..224db80e 100644 --- a/sass.html.markdown +++ b/sass.html.markdown @@ -16,7 +16,7 @@ This tutorial is written using SCSS. If you're already familiar with CSS3, you'll be able to pick up Sass relatively quickly. It does not provide any new styling properties but rather the tools to write your CSS more efficiently and make maintenance much easier. -```scss +```sass //Single line comments are removed when Sass is compiled to CSS. -- cgit v1.2.3 From 921952f852652e282a56b09928697255698c65bf Mon Sep 17 00:00:00 2001 From: Jesse Paroz Date: Sun, 1 Jan 2017 13:46:13 +1000 Subject: Use forth syntax highlighting --- forth.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forth.html.markdown b/forth.html.markdown index 55d755b2..09f3beb0 100644 --- a/forth.html.markdown +++ b/forth.html.markdown @@ -12,7 +12,7 @@ such as Open Firmware. It's also used by NASA. Note: This article focuses predominantly on the Gforth implementation of Forth, but most of what is written here should work elsewhere. -``` +```forth \ This is a comment ( This is also a comment but it's only used when defining words ) -- cgit v1.2.3 From eb6b74a568facc1c20e3c347b196fa143a1fa976 Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Sat, 31 Dec 2016 20:20:26 -0800 Subject: Add highlighting for fortran and logtalk --- fortran95.html.markdown | 2 +- logtalk.html.markdown | 62 ++++++++++++++++++++++++------------------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/fortran95.html.markdown b/fortran95.html.markdown index 5d1424bf..8479fef8 100644 --- a/fortran95.html.markdown +++ b/fortran95.html.markdown @@ -17,7 +17,7 @@ This overview will discuss the features of Fortran 95 since it is the most widely implemented of the more recent specifications and the later versions are largely similar (by comparison FORTRAN 77 is a very different language). -``` +```fortran ! This is a comment. diff --git a/logtalk.html.markdown b/logtalk.html.markdown index 385e38f9..d4010f8b 100644 --- a/logtalk.html.markdown +++ b/logtalk.html.markdown @@ -29,7 +29,7 @@ Logtalk provides _objects_, _protocols_, and _categories_ as first-class entitie An object encapsulates predicate declarations and definitions. Objects can be created dynamically but are usually static and defined in source files. A single source file can contain any number of entity definitions. A simple object, defining a list member public predicate: -``` +```logtalk :- object(list). :- public(member/2). @@ -44,7 +44,7 @@ An object encapsulates predicate declarations and definitions. Objects can be cr Assuming that the code above for the `list` object is saved in a `list.lgt` file, it can be compiled and loaded using the `logtalk_load/1` built-in predicate or its abbreviation, `{}/1`, with the file path as argument (the extension can be omitted): -``` +```logtalk ?- {list}. yes ``` @@ -53,7 +53,7 @@ yes The `::/2` infix operator is used to send a message to an object. As in Prolog, we can backtrack for alternative solutions: -``` +```logtalk ?- list::member(X, [1,2,3]). X = 1 ; X = 2 ; @@ -63,7 +63,7 @@ yes Encapsulation is enforced. A predicate can be declared _public_, _protected_, or _private_. It can also be _local_ when there is no scope directive for it. For example: -``` +```logtalk :- object(scopes). :- private(bar/0). @@ -76,7 +76,7 @@ Encapsulation is enforced. A predicate can be declared _public_, _protected_, or Assuming the object is saved in a `scopes.lgt` file: -``` +```logtalk ?- {scopes}. yes @@ -97,7 +97,7 @@ yes When the predicate in a message is unknown for the object (the role it plays determines the lookup procedures), we also get an error. For example: -``` +```logtalk ?- catch(scopes::unknown, Error, true). Error = error( existence_error(predicate_declaration, unknown/0), @@ -112,7 +112,7 @@ A subtle point is that predicate scope directives specify predicate _calling_ se Protocols contain predicate declarations that can be implemented by any number of objects and categories: -``` +```logtalk :- protocol(listp). :- public(member/2). @@ -131,7 +131,7 @@ Protocols contain predicate declarations that can be implemented by any number o The scope of the protocol predicates can be restricted using protected or private implementation. For example: -``` +```logtalk :- object(stack, implements(private::listp)). @@ -144,7 +144,7 @@ In fact, all entity relations (in an entity opening directive) can be qualified An object without an _instantiation_ or _specialization_ relation with another object plays the role of a prototype. A prototype can _extend_ another object, its parent prototype. -``` +```logtalk % clyde, our prototypical elephant :- object(clyde). @@ -167,7 +167,7 @@ An object without an _instantiation_ or _specialization_ relation with another o When answering a message sent to an object playing the role of a prototype, we validate the message and look for an answer first in the prototype itself and, if not found, we delegate to the prototype parents if any: -``` +```logtalk ?- fred::number_of_legs(N). N = 4 yes @@ -179,7 +179,7 @@ yes A message is valid if the corresponding predicate is declared (and the sender is within scope) but it will fail, rather then throwing an error, if the predicate is not defined. This is called the _closed-world assumption_. For example, consider the following object, saved in a `foo.lgt` file: -``` +```logtalk :- object(foo). :- public(bar). @@ -189,7 +189,7 @@ A message is valid if the corresponding predicate is declared (and the sender is Loading the file and trying to call the `bar/0` predicate fails as expected. Note that this is different from calling an _unknown_ predicate, which results in an error: -``` +```logtalk ?- {foo}. yes @@ -208,7 +208,7 @@ yes In order to define objects playing the role of classes and/or instances, an object must have at least an instantiation or a specialization relation with another object. Objects playing the role of meta-classes can be used when we need to see a class also as an instance. We use the following example to also illustrate how to dynamically create new objects at runtime: -``` +```logtalk % a simple, generic, metaclass defining a new/2 predicate for its instances :- object(metaclass, instantiates(metaclass)). @@ -245,7 +245,7 @@ In order to define objects playing the role of classes and/or instances, an obje When answering a message sent to an object playing the role of an instance, we validate the message by starting in its class and going up to its class superclasses if necessary. Assuming that the message is valid, then we look for an answer starting in the instance itself: -``` +```logtalk ?- person::new(Instance, [name(paulo)]). Instance = o1 yes @@ -267,7 +267,7 @@ yes A category is a fine grained unit of code reuse, used to encapsulate a _cohesive_ set of predicate declarations and definitions, implementing a _single_ functionality, that can be imported into any object. A category can thus be seen as the dual concept of a protocol. In the following example, we define categories representing car engines and then import them into car objects: -``` +```logtalk % a protocol describing engine characteristics :- protocol(carenginep). @@ -321,7 +321,7 @@ A category is a fine grained unit of code reuse, used to encapsulate a _cohesive Categories are independently compiled and thus allow importing objects to be updated by simple updating the imported categories without requiring object recompilation. Categories also provide _runtime transparency_. I.e. the category protocol adds to the protocol of the objects importing the category: -``` +```logtalk ?- sedan::current_predicate(Predicate). Predicate = reference/1 ; Predicate = capacity/1 ; @@ -336,7 +336,7 @@ yes Categories can be also be used for hot-patching objects. A category can add new predicates to an object and/or replace object predicate definitions. For example, consider the following object: -``` +```logtalk :- object(buggy). :- public(p/0). @@ -347,7 +347,7 @@ Categories can be also be used for hot-patching objects. A category can add new Assume that the object prints the wrong string when sent the message `p/0`: -``` +```logtalk ?- {buggy}. yes @@ -358,7 +358,7 @@ yes If the object source code is not available and we need to fix an application running the object code, we can simply define a category that fixes the buggy predicate: -``` +```logtalk :- category(patch, complements(buggy)). @@ -370,7 +370,7 @@ If the object source code is not available and we need to fix an application run After compiling and loading the category into the running application we will now get: -``` +```logtalk ?- {patch}. yes @@ -385,7 +385,7 @@ As hot-patching forcefully breaks encapsulation, there is a `complements` compil Objects and categories can be parameterized by using as identifier a compound term instead of an atom. Object and category parameters are _logical variables_ shared with all encapsulated predicates. An example with geometric circles: -``` +```logtalk :- object(circle(_Radius, _Color)). :- public([ @@ -405,7 +405,7 @@ Objects and categories can be parameterized by using as identifier a compound te Parametric objects are used just as any other object, usually providing values for the parameters when sending a message: -``` +```logtalk ?- circle(1.23, blue)::area(Area). Area = 4.75291 yes @@ -413,7 +413,7 @@ yes Parametric objects also provide a simple way of associating a set of predicates with a plain Prolog predicate. Prolog facts can be interpreted as _parametric object proxies_ when they have the same functor and arity as the identifiers of parametric objects. Handy syntax is provided to for working with proxies. For example, assuming the following clauses for a `circle/2` predicate: -``` +```logtalk circle(1.23, blue). circle(3.71, yellow). circle(0.39, green). @@ -423,7 +423,7 @@ circle(8.32, cyan). With these clauses loaded, we can easily compute for example a list with the areas of all the circles: -``` +```logtalk ?- findall(Area, {circle(_, _)}::area(Area), Areas). Areas = [4.75291, 43.2412, 0.477836, 103.508, 217.468] yes @@ -435,7 +435,7 @@ The `{Goal}::Message` construct proves `Goal`, possibly instantiating any variab Logtalk supports _event-driven programming_ by allowing defining events and monitors for those events. An event is simply the sending of a message to an object. Interpreting message sending as an atomic activity, a _before_ event and an _after_ event are recognized. Event monitors define event handler predicates, `before/3` and `after/3`, and can query, register, and delete a system-wide event registry that associates events with monitors. For example, a simple tracer for any message being sent using the `::/2` control construct can be defined as: -``` +```logtalk :- object(tracer, implements(monitoring)). % built-in protocol for event handlers @@ -454,7 +454,7 @@ Logtalk supports _event-driven programming_ by allowing defining events and moni Assuming that the `tracer` object and the `list` object defined earlier are compiled and loaded, we can observe the event handlers in action by sending a message: -``` +```logtalk ?- list::member(X, [1,2,3]). call: list <-- member(X, [1,2,3]) from user @@ -475,7 +475,7 @@ Event-driven programming can be seen as a form of _computational reflection_. Bu Logtalk supports lambda expressions. Lambda parameters are represented using a list with the `(>>)/2` infix operator connecting them to the lambda. Some simple examples using library meta-predicates: -``` +```logtalk ?- {library(metapredicates_loader)}. yes @@ -486,7 +486,7 @@ yes Currying is also supported: -``` +```logtalk ?- meta::map([X]>>([Y]>>(Y is 2*X)), [1,2,3], Ys). Ys = [2,4,6] yes @@ -498,7 +498,7 @@ Lambda free variables can be expressed using the extended syntax `{Free1, ...}/[ Terms and goals in source files can be _expanded_ at compile time by specifying a _hook object_ that defines term-expansion and goal-expansion rules. For example, consider the following simple object, saved in a `source.lgt` file: -``` +```logtalk :- object(source). :- public(bar/1). @@ -511,7 +511,7 @@ Terms and goals in source files can be _expanded_ at compile time by specifying Assume the following hook object, saved in a `my_macros.lgt` file, that expands clauses and calls to the `foo/1` local predicate: -``` +```logtalk :- object(my_macros, implements(expanding)). % built-in protocol for expanding predicates @@ -525,7 +525,7 @@ Assume the following hook object, saved in a `my_macros.lgt` file, that expands After loading the macros file, we can then expand our source file with it using the `hook` compiler flag: -``` +```logtalk ?- logtalk_load(my_macros), logtalk_load(source, [hook(my_macros)]). yes -- cgit v1.2.3 From 30d63b3709472daed27b2d837c0834ca1db84888 Mon Sep 17 00:00:00 2001 From: raph Date: Mon, 2 Jan 2017 16:13:26 +0100 Subject: Update rust-fr.html.markdown (#2616) --- fr-fr/rust-fr.html.markdown | 51 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/fr-fr/rust-fr.html.markdown b/fr-fr/rust-fr.html.markdown index 6ab559a3..5a384864 100644 --- a/fr-fr/rust-fr.html.markdown +++ b/fr-fr/rust-fr.html.markdown @@ -19,11 +19,11 @@ Le 15 mai 2015, Rust 1.0 a été libéré avec une garantie complète de compati Bien que Rust soit un langage relativement bas niveau, Rust a quelques concepts fonctionnels qui se trouvent généralement dans les langues de niveau supérieur. Cela rend Rust non seulement rapide, mais aussi efficace et facile à coder. ```rust -// Ceci est un commentaire. commentaires de ligne ressemblent à ceci ... -// Et prolonger plusieurs lignes comme celle-ci. +// Ceci est un commentaire. Les commentaires de ligne ressemblent à ceci... +// et continuent sur plusieurs lignes comme cela. -/// Les commentaires de documentation ressemblent à ceci et à soutenir -/// la notation de démarques. +/// Les commentaires de documentation ressemblent à ça et supportent la +/// syntaxe Markdown. /// # Exemples /// /// ``` @@ -37,7 +37,7 @@ Bien que Rust soit un langage relativement bas niveau, Rust a quelques concepts // Les fonctions // `I32` est le type 32 bits entiers signés fn add2(x: i32, y: i32) -> i32 { -    // Retour implicite (pas virgule) +    // Retour implicite (pas de point virgule)     x + y } @@ -45,19 +45,19 @@ fn add2(x: i32, y: i32) -> i32 { fn main() {     // Nombres // -    // Reliures immutable +    // Liaison immutable     let x: i32 = 1; -    // Entier suffixes/float +    // Suffixes entiers et flottants     let y: I32 = 13i32;     let f: f64 = 1.3f64; -    // Type Inférence -    // La plupart du temps, le compilateur Rust peut déduire le type de variable - // est, donc vous ne devez pas écrire une annotation de type explicite. +    // Inférence de type +    // La plupart du temps, le compilateur Rust peut déduire quel est le type + // de variable, donc vous n'avez pas à écrire une annotation de type explicite.     // Tout au long de ce tutoriel, les types sont explicitement annotées dans // de nombreux endroits, mais seulement à des fins de démonstration. - // L'inférence de type peut gérer cela pour vous la plupart du temps. + // L'inférence de type peut les générer pour vous la plupart du temps.     let implicit_x = 1;     let implicit_f = 1,3; @@ -71,22 +71,22 @@ fn main() {     // Chaînes // -    // Littéraux chaîne -    let x: &str = "Bonjour tout le monde!"; +    // Chaîne littérales +    let x: &str = "Bonjour tout le monde !"; -    // Impression +    // Affichage     println!("{} {}", f, x); // 1.3 Bonjour tout le monde -    // A `Chaîne` - une chaîne de tas alloué +    // Une `Chaîne` - une chaîne de tas alloué     let s: String = "Bonjour tout le monde".to_string(); -    // Une tranche de chaîne - une vue immutable dans une else chaîne. -    // Ceci est essentiellement un pointeur immutable à une chaîne - il n'a pas -    // contient effectivement le contenu d'une chaîne, juste un pointeur vers -    // quelque chose qui fait(dans ce cas, `s`). +    // Un morceau de chaîne - une vue immutable sur une autre chaîne. +    // C'est essentiellement un pointeur immutable sur une chaîne - ça ne +    // contient effectivement pas le contenu d'une chaîne, juste un pointeur vers +    // le début et la fin de la chaîne.     let s_slice: &str = &s; -    println!("{} {}", s, s_slice); // Bonjour monde Bonjour tout le monde +    println!("{} {}", s, s_slice); // Bonjour tout le monde Bonjour tout le monde     // Vecteurs/tableau // @@ -97,20 +97,19 @@ fn main() {     let mut vecteur: Vec = vec![1, 2, 3, 4];     vecteur.push(5); -    // Une tranche - une vue immutable dans un vecteur ou un tableau. -    // Ceci est un peu comme une tranche de chaîne, mais pour les vecteurs. +    // Une tranche - une vue immutable sur un vecteur ou un tableau. +    // Ceci est un peu comme un morceau de chaîne, mais pour les vecteurs.     let tranche: &[i32] = &vecteur; -    // Utiliser `{:?}` pour imprimer quelque chose de débogage de style +    // Utiliser `{:?}` pour afficher quelque chose en mode debug     println!("{:?} {:?}", vecteur, tranche); // [1, 2, 3, 4, 5] [1, 2, 3, 4, 5]     // Tuples // -    // Un tuple est un ensemble de valeurs de peut-être différents types. - // de taille fixe +    // Un tuple est un ensemble de valeurs qui peuvent être de différents types.     let x:(i32, &str, f64) = (1, "bonjour", 3.4); -    // Déstructurante `let` +    // Déstructurer `let`     let (a, b, c) = x;     println!("{} {} {}", a, b, c); // 1 bonjour 3.4 -- cgit v1.2.3 From ae16d450781aecd9ff4423deb2cf67317d309080 Mon Sep 17 00:00:00 2001 From: omgee Date: Tue, 3 Jan 2017 09:41:35 +0200 Subject: [c++/en,es,it,br,ru,ch] Fix forgotten namespace std:: (#2619) --- c++.html.markdown | 2 +- es-es/c++-es.html.markdown | 126 ++++++++++++++++++++++----------------------- it-it/c++-it.html.markdown | 6 +-- pt-br/c++-pt.html.markdown | 52 +++++++++---------- ru-ru/c++-ru.html.markdown | 10 ++-- zh-cn/c++-cn.html.markdown | 2 +- 6 files changed, 99 insertions(+), 99 deletions(-) diff --git a/c++.html.markdown b/c++.html.markdown index 24d38df7..5220fb0b 100644 --- a/c++.html.markdown +++ b/c++.html.markdown @@ -456,7 +456,7 @@ void Dog::print() const Dog::~Dog() { - cout << "Goodbye " << name << "\n"; + std::cout << "Goodbye " << name << "\n"; } int main() { diff --git a/es-es/c++-es.html.markdown b/es-es/c++-es.html.markdown index 07c8bc03..bd1ad07c 100644 --- a/es-es/c++-es.html.markdown +++ b/es-es/c++-es.html.markdown @@ -20,11 +20,11 @@ fue diseñado para - soportar programación orientada a objetos - soportar programación genérica -Aunque su sintaxis puede ser más difícil o compleja que los nuevos lenguajes, -es ampliamente utilizado, ya que compila instrucciones nativas que pueden ser -directamente ejecutadas por el procesador y ofrece un estricto control sobre -el hardware (como C), mientras ofrece características de alto nivel como -genericidad, excepciones, y clases. Esta combinación de velocidad y +Aunque su sintaxis puede ser más difícil o compleja que los nuevos lenguajes, +es ampliamente utilizado, ya que compila instrucciones nativas que pueden ser +directamente ejecutadas por el procesador y ofrece un estricto control sobre +el hardware (como C), mientras ofrece características de alto nivel como +genericidad, excepciones, y clases. Esta combinación de velocidad y funcionalidad hace de C ++ uno de los lenguajes de programación más utilizados. ```c++ @@ -32,22 +32,22 @@ funcionalidad hace de C ++ uno de los lenguajes de programación más utilizados // Comparación con C //////////////////// -// C ++ es _casi_ un superconjunto de C y comparte su sintaxis básica para las +// C ++ es _casi_ un superconjunto de C y comparte su sintaxis básica para las // declaraciones de variables, tipos primitivos y funciones. -// Al igual que en C, el punto de entrada de tu programa es una función llamada -// main con un retorno de tipo entero. +// Al igual que en C, el punto de entrada de tu programa es una función llamada +// main con un retorno de tipo entero. // Este valor sirve como código de salida del programa. // Mira http://en.wikipedia.org/wiki/Exit_status para mayor información. int main(int argc, char** argv) { - // Los argumentos de la línea de comandos se pasan por argc y argv de la + // Los argumentos de la línea de comandos se pasan por argc y argv de la // misma manera que en C. - // argc indica el número de argumentos, - // y argv es un arreglo de strings de estilo C (char*) + // argc indica el número de argumentos, + // y argv es un arreglo de strings de estilo C (char*) // representando los argumentos. // El primer argumento es el nombre con el que el programa es llamado. - // argc y argv pueden omitirse si no te preocupan los argumentos, + // argc y argv pueden omitirse si no te preocupan los argumentos, // dejando la definición de la función como int main () // Un estado de salida 0 indica éxito. @@ -72,7 +72,7 @@ void func(); // función que puede aceptar cualquier número de argumentos // Use nullptr en lugar de NULL en C++ int* ip = nullptr; -// Las cabeceras (headers) estándar de C están disponibles en C ++, +// Las cabeceras (headers) estándar de C están disponibles en C ++, // pero tienen el prefijo "c" y no tienen sufijo .h. #include @@ -109,7 +109,7 @@ int main() // Argumentos de función por defecto //////////////////////////////////// -// Puedes proporcionar argumentos por defecto para una función si no son +// Puedes proporcionar argumentos por defecto para una función si no son // proporcionados por quien la llama. void doSomethingWithInts(int a = 1, int b = 4) @@ -134,7 +134,7 @@ void invalidDeclaration(int a = 1, int b) // Error! // Espacios de nombre ///////////////////// -// Espacios de nombres proporcionan ámbitos separados para variable, función y +// Espacios de nombres proporcionan ámbitos separados para variable, función y // otras declaraciones. // Los espacios de nombres se pueden anidar. @@ -162,8 +162,8 @@ void foo() int main() { - // Incluye todos los símbolos del espacio de nombre Second en el ámbito - // actual. Tenga en cuenta que simplemente foo() no funciona, ya que ahora + // Incluye todos los símbolos del espacio de nombre Second en el ámbito + // actual. Tenga en cuenta que simplemente foo() no funciona, ya que ahora // es ambigua si estamos llamando a foo en espacio de nombres Second o en // el nivel superior. using namespace Second; @@ -254,7 +254,7 @@ const string& barRef = bar; // Crea una referencia constante a bar. // modificados. barRef += ". Hola!"; // Error, referencia constante no puede ser modificada. -// Sidetrack: Antes de hablar más sobre referencias, hay que introducir un +// Sidetrack: Antes de hablar más sobre referencias, hay que introducir un // concepto llamado objeto temporal. Supongamos que tenemos el siguiente código: string tempObjectFun() { ... } string retVal = tempObjectFun(); @@ -267,16 +267,16 @@ string retVal = tempObjectFun(); // El objeto devuelto se llama objeto temporal. Objetos temporales son // creados cada vez que una función devuelve un objeto, y es destruido en el // fin de la evaluación de la expresión que encierra (Bueno, esto es lo que la -// norma dice, pero los compiladores están autorizados a cambiar este -// comportamiento. Busca "return value optimization" para ver mas detalles). +// norma dice, pero los compiladores están autorizados a cambiar este +// comportamiento. Busca "return value optimization" para ver mas detalles). // Así que en este código: foo(bar(tempObjectFun())) // Suponiendo que foo y bar existen, el objeto retornado de tempObjectFun es // pasado al bar, y se destruye antes de llamar foo. -// Ahora, de vuelta a las referencias. La excepción a la regla "en el extremo -// de la expresión encerrada" es si un objeto temporal se une a una +// Ahora, de vuelta a las referencias. La excepción a la regla "en el extremo +// de la expresión encerrada" es si un objeto temporal se une a una // referencia constante, en cuyo caso su vida se extiende al ámbito actual: void constReferenceTempObjectFun() { @@ -287,7 +287,7 @@ void constReferenceTempObjectFun() { } // Otro tipo de referencia introducida en C ++ 11 es específicamente para -// objetos temporales. No se puede tener una variable de este tipo, pero tiene +// objetos temporales. No se puede tener una variable de este tipo, pero tiene // prioridad en resolución de sobrecarga: void someFun(string& s) { ... } // Referencia regular @@ -302,7 +302,7 @@ someFun(tempObjectFun()); // Llama la versión con referencia temporal basic_string(const basic_string& other); basic_string(basic_string&& other); -// La idea es que si estamos construyendo una nueva cadena de un objeto temporal +// La idea es que si estamos construyendo una nueva cadena de un objeto temporal // (que va a ser destruido pronto de todos modos), podemos tener un constructor // mas eficiente que "rescata" partes de esa cadena temporal. Usted verá este // Concepto denominado "movimiento semántico". @@ -341,13 +341,13 @@ public: // Funciones que no modifican el estado del objeto // Deben marcarse como const. // Esto le permite llamarlas si se envia una referencia constante al objeto. - // También tenga en cuenta que las funciones deben ser declaradas - // explícitamente como _virtual_ para que sea reemplazada en las clases + // También tenga en cuenta que las funciones deben ser declaradas + // explícitamente como _virtual_ para que sea reemplazada en las clases // derivadas. - // Las funciones no son virtuales por defecto por razones de rendimiento. + // Las funciones no son virtuales por defecto por razones de rendimiento. virtual void print() const; - // Las funciones también se pueden definir en el interior + // Las funciones también se pueden definir en el interior // del cuerpo de la clase. // Funciones definidas como tales están entre líneas automáticamente. void bark() const { std::cout << name << " barks!\n"; } @@ -358,7 +358,7 @@ public: // (mira abajo) // El destructor debe ser virtual si una clase es dervada desde el; // Si no es virtual, entonces la clase derivada destructor - // No será llamada si el objeto se destruye a través de una referencia de + // No será llamada si el objeto se destruye a través de una referencia de // la clase base o puntero. virtual ~Dog(); @@ -392,7 +392,7 @@ void Dog::print() const Dog::~Dog() { - cout << "Adiós " << name << "\n"; + std::cout << "Adiós " << name << "\n"; } int main() { @@ -410,7 +410,7 @@ class OwnedDog : public Dog { void setOwner(const std::string& dogsOwner); - // Reemplaza el comportamiento de la función de impresión + // Reemplaza el comportamiento de la función de impresión // de todos los OwnedDogs. Mira // http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Subtyping // Para una introducción más general si no está familiarizado con el @@ -442,7 +442,7 @@ void OwnedDog::print() const // Inicialización y sobrecarga de operadores //////////////////////////////////////////// -// En C ++ se puede sobrecargar el comportamiento +// En C ++ se puede sobrecargar el comportamiento // de los operadores como +, -, *, /, etc. // Esto se hace mediante la definición de una función que es llamada // cada vez que se utiliza el operador. @@ -505,14 +505,14 @@ int main () { // Plantillas (Templates) ///////////////////////// -// Las plantillas en C++ se utilizan sobre todo en la programación genérica, -// a pesar de que son mucho más poderoso que los constructores genéricos -// en otros lenguajes. Ellos también soportan especialización explícita y -// parcial y clases de tipo estilo funcional; de hecho, son un lenguaje +// Las plantillas en C++ se utilizan sobre todo en la programación genérica, +// a pesar de que son mucho más poderoso que los constructores genéricos +// en otros lenguajes. Ellos también soportan especialización explícita y +// parcial y clases de tipo estilo funcional; de hecho, son un lenguaje // funcional Turing-completo incrustado en C ++! -// Empezamos con el tipo de programación genérica que podría estar -// familiarizado. +// Empezamos con el tipo de programación genérica que podría estar +// familiarizado. // Para definir una clase o función que toma un parámetro de tipo: template class Box { @@ -521,9 +521,9 @@ public: void insert(const T&) { ... } }; -// Durante la compilación, el compilador realmente genera copias de cada -// plantilla con parámetros sustituidos, por lo que la definición completa -// de la clase debe estar presente en cada invocación. +// Durante la compilación, el compilador realmente genera copias de cada +// plantilla con parámetros sustituidos, por lo que la definición completa +// de la clase debe estar presente en cada invocación. // Es por esto que usted verá clases de plantilla definidas // Enteramente en archivos de cabecera. @@ -537,8 +537,8 @@ intBox.insert(123); Box > boxOfBox; boxOfBox.insert(intBox); -// Hasta C++11, había que colocar un espacio entre los dos '>'s, -// de lo contrario '>>' serían analizados como el operador de desplazamiento +// Hasta C++11, había que colocar un espacio entre los dos '>'s, +// de lo contrario '>>' serían analizados como el operador de desplazamiento // a la derecha. @@ -558,9 +558,9 @@ void barkThreeTimes(const T& input) input.bark(); } -// Observe que no se especifica nada acerca de los tipos de parámetros aquí. -// El compilador generará y comprobará cada invocación de la plantilla, -// por lo que la función anterior funciona con cualquier tipo "T" +// Observe que no se especifica nada acerca de los tipos de parámetros aquí. +// El compilador generará y comprobará cada invocación de la plantilla, +// por lo que la función anterior funciona con cualquier tipo "T" // que tenga un método 'bark' constante! @@ -574,12 +574,12 @@ void printMessage() { cout << "Aprende C++ en " << Y << " minutos!" << endl; } -// Y usted puede especializar explícitamente plantillas -// para código más eficiente. -// Por supuesto, la mayor parte del mundo real que utiliza una especialización +// Y usted puede especializar explícitamente plantillas +// para código más eficiente. +// Por supuesto, la mayor parte del mundo real que utiliza una especialización // no son tan triviales como esta. -// Tenga en cuenta que usted todavía tiene que declarar la función (o clase) -// como plantilla incluso si ha especificado de forma explícita todos +// Tenga en cuenta que usted todavía tiene que declarar la función (o clase) +// como plantilla incluso si ha especificado de forma explícita todos // los parámetros. template<> @@ -601,7 +601,7 @@ printMessage<10>(); // Prints "Aprende C++ rapido en solo 10 minutos!" #include #include -//Todas las excepciones lanzadas dentro del bloque _try_ pueden ser +//Todas las excepciones lanzadas dentro del bloque _try_ pueden ser // capturados por los siguientes manejadores _catch_. try { // No asignar excepciones en el heap usando _new_. @@ -651,7 +651,7 @@ void doSomethingWithAFile(const char* filename) // (Excepciones son la mejor forma de manejar los fallos, // pero algunos programadores, especialmente los que tienen un fondo C, // estan en desacuerdo sobre la utilidad de las excepciones). -// Ahora tenemos que comprobar cada llamado por fallos y cerrar el manejador +// Ahora tenemos que comprobar cada llamado por fallos y cerrar el manejador // del archivo si se ha producido un problema. bool doSomethingWithAFile(const char* filename) { @@ -716,7 +716,7 @@ void doSomethingWithAFile(const char* filename) // Compare esto con el uso de la clase de flujo de archivos de C++ (fstream) // fstream utiliza su destructor para cerrar el archivo. -// Los destructores son llamados automáticamente +// Los destructores son llamados automáticamente // cuando un objeto queda fuera del ámbito. void doSomethingWithAFile(const std::string& filename) { @@ -734,7 +734,7 @@ void doSomethingWithAFile(const std::string& filename) // 1. No importa lo que pase, // El recurso (en este caso el manejador de archivo) será limpiado. // Una vez que escribes el destructor correctamente, -// Es _imposible_ olvidar cerrar el identificador y permitir +// Es _imposible_ olvidar cerrar el identificador y permitir // fugas del recurso. // 2. Tenga en cuenta que el código es mucho más limpio. // El destructor se encarga de cerrar el archivo detrás de cámaras @@ -743,13 +743,13 @@ void doSomethingWithAFile(const std::string& filename) // Una excepción puede ser lanzado en cualquier lugar de la función // y la limpieza ocurrirá. -// Todo el código idiomático C++ utiliza RAII ampliamente para todos los +// Todo el código idiomático C++ utiliza RAII ampliamente para todos los // recursos. // Otros ejemplos incluyen // - Memoria usando unique_ptr y shared_ptr // - Contenedores (Containers) - la biblioteca estándar linked list, // vector (es decir, array con auto-cambio de tamaño), hash maps, etc. -// Destruimos todos sus contenidos de forma automática +// Destruimos todos sus contenidos de forma automática // cuando quedan fuera del ámbito. // - Mutex utilizando lock_guard y unique_lock @@ -758,9 +758,9 @@ void doSomethingWithAFile(const std::string& filename) // Cosas divertidas ///////////////////// -// Aspectos de C ++ que pueden sorprender a los recién llegados +// Aspectos de C ++ que pueden sorprender a los recién llegados // (e incluso algunos veteranos). -// Esta sección es, por desgracia, salvajemente incompleta; +// Esta sección es, por desgracia, salvajemente incompleta; // C++ es uno de los lenguajes con los que mas facil te disparas en el pie. // Tu puedes sobreescribir métodos privados! @@ -788,13 +788,13 @@ pt2 = nullptr; // Establece pt2 como null. *pt = nullptr; // Esto todavía compila, a pesar de que '*pt' es un bool! // '=' != '=' != '='! -// Llama Foo::Foo(const Foo&) o alguna variante (mira movimientos semanticos) +// Llama Foo::Foo(const Foo&) o alguna variante (mira movimientos semanticos) // copia del constructor. Foo f2; Foo f1 = f2; // Llama Foo::Foo(const Foo&) o variante, pero solo copia el 'Foo' parte de -// 'fooSub'. Cualquier miembro extra de 'fooSub' se descarta. Este +// 'fooSub'. Cualquier miembro extra de 'fooSub' se descarta. Este // comportamiento horrible se llama "Corte de objetos." FooSub fooSub; Foo f1 = fooSub; @@ -809,13 +809,13 @@ class Foo { ... }; vector v; for (int i = 0; i < 10; ++i) v.push_back(Foo()); -// La siguiente línea establece el tamaño de v en 0, +// La siguiente línea establece el tamaño de v en 0, // pero los destructores no son llamados y los recursos no se liberan! v.empty(); v.push_back(Foo()); // Nuevo valor se copia en el primer Foo que insertamos -// En verdad destruye todos los valores en v. +// En verdad destruye todos los valores en v. // Consulta la sección acerca de los objetos temporales para la // explicación de por qué esto funciona. v.swap(vector()); diff --git a/it-it/c++-it.html.markdown b/it-it/c++-it.html.markdown index 4af30176..b4f9c50e 100644 --- a/it-it/c++-it.html.markdown +++ b/it-it/c++-it.html.markdown @@ -461,7 +461,7 @@ void Cane::print() const Cane::~Cane() { - cout << "Ciao ciao " << nome << "\n"; + std::cout << "Ciao ciao " << nome << "\n"; } int main() { @@ -647,7 +647,7 @@ void stampaMessaggio<10>() { printMessage<20>(); // Stampa "impara il C++ in 20 minuti!" printMessage<10>(); // Stampa "Impara il C++ più velocemente in soli 10 minuti!" - + //////////////////////////// // Gestione delle eccezioni /////////////////////////// @@ -658,7 +658,7 @@ printMessage<10>(); // Stampa "Impara il C++ più velocemente in soli 10 minuti #include #include -// Tutte le eccezioni lanciate all'interno del blocco _try_ possono essere catturate dai successivi +// Tutte le eccezioni lanciate all'interno del blocco _try_ possono essere catturate dai successivi // handlers _catch_. try { // Non allocare eccezioni nello heap usando _new_. diff --git a/pt-br/c++-pt.html.markdown b/pt-br/c++-pt.html.markdown index e2e95268..fd392b9e 100644 --- a/pt-br/c++-pt.html.markdown +++ b/pt-br/c++-pt.html.markdown @@ -19,9 +19,9 @@ foi concebida para - suportar programação genérica Embora sua sintaxe pode ser mais difícil ou complexa do que as linguagens mais -recentes, C++ é amplamente utilizado porque compila para instruções nativas que -podem ser executadas diretamente pelo processador e oferece um controlo rígido sobre hardware (como C), enquanto oferece recursos de alto nível, como os -genéricos, exceções e classes. Esta combinação de velocidade e funcionalidade +recentes, C++ é amplamente utilizado porque compila para instruções nativas que +podem ser executadas diretamente pelo processador e oferece um controlo rígido sobre hardware (como C), enquanto oferece recursos de alto nível, como os +genéricos, exceções e classes. Esta combinação de velocidade e funcionalidade faz C++ uma das linguagens de programação mais utilizadas. ```c++ @@ -33,7 +33,7 @@ faz C++ uma das linguagens de programação mais utilizadas. // declarações de variáveis, tipos primitivos, e funções. No entanto, C++ varia // em algumas das seguintes maneiras: -// A função main() em C++ deve retornar um int, embora void main() é aceita +// A função main() em C++ deve retornar um int, embora void main() é aceita // pela maioria dos compiladores (gcc, bumbum, etc.) // Este valor serve como o status de saída do programa. // Veja http://en.wikipedia.org/wiki/Exit_status para mais informações. @@ -105,7 +105,7 @@ int main() // Parâmetros padrão de função ///////////////////////////// -// Você pode fornecer argumentos padrões para uma função se eles não são +// Você pode fornecer argumentos padrões para uma função se eles não são // fornecidos pelo chamador. void doSomethingWithInts(int a = 1, int b = 4) @@ -157,7 +157,7 @@ void foo() int main() { - // Assuma que tudo é do namespace "Second" a menos que especificado de + // Assuma que tudo é do namespace "Second" a menos que especificado de // outra forma. using namespace Second; @@ -222,7 +222,7 @@ cout << myString; // "Hello Dog" // Além de indicadores como os de C, C++ têm _referências_. Esses são tipos de // ponteiro que não pode ser reatribuída uma vez definidos e não pode ser nulo. -// Eles também têm a mesma sintaxe que a própria variável: Não * é necessário +// Eles também têm a mesma sintaxe que a própria variável: Não * é necessário // para _dereferencing_ e & (endereço de) não é usado para atribuição. using namespace std; @@ -258,7 +258,7 @@ class Dog { std::string name; int weight; -// Todos os membros a seguir este são públicos até que "private:" ou +// Todos os membros a seguir este são públicos até que "private:" ou // "protected:" é encontrado. public: @@ -274,13 +274,13 @@ public: void setWeight(int dogsWeight); - // Funções que não modificam o estado do objecto devem ser marcadas como + // Funções que não modificam o estado do objecto devem ser marcadas como // const. Isso permite que você chamá-los se for dada uma referência const // para o objeto. Além disso, observe as funções devem ser explicitamente - // declarados como _virtual_, a fim de ser substituídas em classes - // derivadas. As funções não são virtuais por padrão por razões de + // declarados como _virtual_, a fim de ser substituídas em classes + // derivadas. As funções não são virtuais por padrão por razões de // performance. - + virtual void print() const; // As funções também podem ser definidas no interior do corpo da classe. @@ -291,7 +291,7 @@ public: // Estes são chamados quando um objeto é excluído ou fica fora do escopo. // Isto permite paradigmas poderosos, como RAII // (veja abaixo) - // Destruidores devem ser virtual para permitir que as classes de ser + // Destruidores devem ser virtual para permitir que as classes de ser // derivada desta. virtual ~Dog(); @@ -323,7 +323,7 @@ void Dog::print() const void Dog::~Dog() { - cout << "Goodbye " << name << "\n"; + std::cout << "Goodbye " << name << "\n"; } int main() { @@ -343,8 +343,8 @@ class OwnedDog : public Dog { // Substituir o comportamento da função de impressão de todas OwnedDogs. // Ver http://en.wikipedia.org/wiki/Polymorphism_(computer_science)#Subtyping - // Para uma introdução mais geral, se você não estiver familiarizado com o - // polimorfismo subtipo. A palavra-chave override é opcional, mas torna-se + // Para uma introdução mais geral, se você não estiver familiarizado com o + // polimorfismo subtipo. A palavra-chave override é opcional, mas torna-se // na verdade você está substituindo o método em uma classe base. void print() const override; @@ -371,8 +371,8 @@ void OwnedDog::print() const // Inicialização e Sobrecarga de Operadores ////////////////////////////////////////// -// Em C ++, você pode sobrecarregar o comportamento dos operadores, tais como -// +, -, *, /, etc. Isto é feito através da definição de uma função que é +// Em C ++, você pode sobrecarregar o comportamento dos operadores, tais como +// +, -, *, /, etc. Isto é feito através da definição de uma função que é // chamado sempre que o operador é usado. #include @@ -438,7 +438,7 @@ int main () { // mas qualquer tipo pode ser jogado como uma exceção #include -// Todas as exceções lançadas dentro do bloco try pode ser capturado por +// Todas as exceções lançadas dentro do bloco try pode ser capturado por // manipuladores de captura subseqüentes try { // Não aloca exceções no heap usando _new_. @@ -460,7 +460,7 @@ catch (const std::exception& ex) /////// // RAII significa alocação de recursos é de inicialização. -// Muitas vezes, é considerado o paradigma mais poderoso em C++, e é o +// Muitas vezes, é considerado o paradigma mais poderoso em C++, e é o // conceito simples que um construtor para um objeto adquire recursos daquele // objeto e o destruidor liberá-los. @@ -479,11 +479,11 @@ void doSomethingWithAFile(const char* filename) } // Infelizmente, as coisas são levemente complicadas para tratamento de erros. -// Suponha que fopen pode falhar, e que doSomethingWithTheFile e -// doSomethingElseWithIt retornam códigos de erro se eles falharem. (As -// exceções são a forma preferida de lidar com o fracasso, mas alguns -// programadores, especialmente aqueles com um conhecimento em C, discordam -// sobre a utilidade de exceções). Agora temos que verificar cada chamada para +// Suponha que fopen pode falhar, e que doSomethingWithTheFile e +// doSomethingElseWithIt retornam códigos de erro se eles falharem. (As +// exceções são a forma preferida de lidar com o fracasso, mas alguns +// programadores, especialmente aqueles com um conhecimento em C, discordam +// sobre a utilidade de exceções). Agora temos que verificar cada chamada para // o fracasso e fechar o identificador de arquivo se ocorreu um problema. bool doSomethingWithAFile(const char* filename) @@ -609,7 +609,7 @@ h=sum(f,g); ``` Leitura Adicional: -Uma referência atualizada da linguagem pode ser encontrada em +Uma referência atualizada da linguagem pode ser encontrada em Uma fonte adicional pode ser encontrada em diff --git a/ru-ru/c++-ru.html.markdown b/ru-ru/c++-ru.html.markdown index 0cf580d5..cef5ab7e 100644 --- a/ru-ru/c++-ru.html.markdown +++ b/ru-ru/c++-ru.html.markdown @@ -304,7 +304,7 @@ someFun(tempObjectFun()); // Выполняет версию с временн basic_string(const basic_string& other); basic_string(basic_string&& other); -// Идея в том, что если мы конструируем новую строку из временного объекта (который +// Идея в том, что если мы конструируем новую строку из временного объекта (который // так или иначе будет уничтожен), мы можем использовать более эффективный конструктор, // который "спасает" части этой временной строки. Эта концепция была названа // "move semantics". @@ -329,7 +329,7 @@ ECarTypes GetPreferredCarType() } // На момент выхода C++11 есть простой способ назначения типа перечисления, что -// полезно в случае сериализации данных и преобразований между конечным типом и +// полезно в случае сериализации данных и преобразований между конечным типом и // соответствующими константами. enum ECarTypes : uint8_t { @@ -453,7 +453,7 @@ void Dog::print() const Dog::~Dog() { - cout << "Goodbye " << name << "\n"; + std::cout << "Goodbye " << name << "\n"; } int main() { @@ -521,7 +521,7 @@ public: // по умолчанию (0, 0) Point() { }; - // Следующий синтаксис известен как список инициализации и является верным способом + // Следующий синтаксис известен как список инициализации и является верным способом // инициализировать значения членов класса. Point (double a, double b) : x(a), @@ -793,7 +793,7 @@ void doSomethingWithAFile(const std::string& filename) // Весь идиоматический код на С++ широко использует RAII для всех ресурсов. // Дополнительные примеры включат: // - Использование памяти unique_ptr и shared_ptr -// - Контейнеры - стандартная библиотека связанных списков, векторы +// - Контейнеры - стандартная библиотека связанных списков, векторы // (т.е. самоизменяемые массивы), хэш-таблицы и все остальное автоматически // уничтожается сразу же, когда выходит за пределы области видимости. // - Ипользование мьютексов lock_guard и unique_lock diff --git a/zh-cn/c++-cn.html.markdown b/zh-cn/c++-cn.html.markdown index d71aa8d6..87951bc3 100644 --- a/zh-cn/c++-cn.html.markdown +++ b/zh-cn/c++-cn.html.markdown @@ -315,7 +315,7 @@ void Dog::print() const void Dog::~Dog() { - cout << "Goodbye " << name << "\n"; + std::cout << "Goodbye " << name << "\n"; } int main() { -- cgit v1.2.3 From f2a5bc8a91ab7da393a1c8548956d6e858bf2c11 Mon Sep 17 00:00:00 2001 From: Sean Nam Date: Tue, 3 Jan 2017 00:48:44 -0800 Subject: Updated Java (en-us) to include Input using Scanner and System.in --- java.html.markdown | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/java.html.markdown b/java.html.markdown index 12de0c73..9bb036cd 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -10,6 +10,7 @@ contributors: - ["Rachel Stiyer", "https://github.com/rstiyer"] - ["Michael Dähnert", "https://github.com/JaXt0r"] - ["Rob Rose", "https://github.com/RobRoseKnows"] + - ["Sean Nam", "https://github.com/seannam"] filename: LearnJava.java --- @@ -51,6 +52,14 @@ public class LearnJava { // point. public static void main (String[] args) { + /////////////////////////////////////// + // Input/Output + /////////////////////////////////////// + + /* + * Ouput + */ + // Use System.out.println() to print lines. System.out.println("Hello World!"); System.out.println( @@ -65,6 +74,32 @@ public class LearnJava { // Use System.out.printf() for easy formatted printing. System.out.printf("pi = %.5f", Math.PI); // => pi = 3.14159 + /* + * Input + */ + + // use Scanner to read input + // must import java.util.Scanner; + Scanner scanner = new Scanner(System.in); + + // read string input + String name = scanner.next(); + + // read byte input + byte numByte = scanner.nextByte(); + + // read int input + int numInt = scanner.nextInt(); + + // read long input + float numFloat - scanner.nextFloat(); + + // read double input + double numDouble = scanner.nextDouble(); + + // read boolean input + boolean bool = scanner.nextBoolean(); + /////////////////////////////////////// // Variables /////////////////////////////////////// -- cgit v1.2.3 From fb9c7b91021fd25058e6ba31728dae6c2d8397ba Mon Sep 17 00:00:00 2001 From: Wooseop Kim Date: Fri, 6 Jan 2017 21:33:35 +0900 Subject: [bash/ko] Translate Bash to Korean (#2623) * Translate Bash to Korean * Fix front matter --- ko-kr/bash-kr.html.markdown | 382 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 ko-kr/bash-kr.html.markdown diff --git a/ko-kr/bash-kr.html.markdown b/ko-kr/bash-kr.html.markdown new file mode 100644 index 00000000..8e271d1f --- /dev/null +++ b/ko-kr/bash-kr.html.markdown @@ -0,0 +1,382 @@ +--- +category: tool +tool: bash +contributors: + - ["Max Yankov", "https://github.com/golergka"] + - ["Darren Lin", "https://github.com/CogBear"] + - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"] + - ["Denis Arh", "https://github.com/darh"] + - ["akirahirose", "https://twitter.com/akirahirose"] + - ["Anton Strömkvist", "http://lutic.org/"] + - ["Rahil Momin", "https://github.com/iamrahil"] + - ["Gregrory Kielian", "https://github.com/gskielian"] + - ["Etan Reisner", "https://github.com/deryni"] + - ["Jonathan Wang", "https://github.com/Jonathansw"] + - ["Leo Rudberg", "https://github.com/LOZORD"] + - ["Betsy Lorton", "https://github.com/schbetsy"] + - ["John Detter", "https://github.com/jdetter"] +translators: + - ["Wooseop Kim", "https://github.com/linterpreteur"] +filename: LearnBash-kr.sh +lang: ko-kr +--- + +Bash는 유닉스 셸의 이름이며, 리눅스와 맥 OS X의 기본 셸로 그리고 GNU 운영체제를 위한 셸로서 배포되었습니다. +이하의 거의 모든 예시들은 셸 스크립트의 일부이거나 셸에서 바로 실행할 수 있습니다. + +[(영어) 이곳에서 더 알아보세요.](http://www.gnu.org/software/bash/manual/bashref.html) + +```bash +#!/bin/bash +# 스크립트의 첫 줄은 시스템에게 스크립트의 실행법을 알려주는 '셔뱅'입니다. +# https://ko.wikipedia.org/wiki/%EC%85%94%EB%B1%85 +# 이미 보았듯이 주석은 #으로 시작합니다. 셔뱅 또한 주석입니다. + +# 간단한 헬로 월드 +echo 헬로 월드! + +# 각각의 명령어는 개행 혹은 세미콜론 이후에 시작됩니다. +echo '첫번째 줄'; echo '두번째 줄' + +# 변수 선언은 다음과 같습니다. +Variable="어떤 문자열" + +# 하지만 다음은 틀린 형태입니다. +Variable = "어떤 문자열" +# Bash는 Variable이 실행해야 하는 명령어라고 판단할 것이고, 해당 명령어를 찾을 +# 수 없기 때문에 에러를 발생시킬 것입니다. + +# 다음도 같습니다. +Variable= '어떤 문자열' +# Bash는 '어떤 문자열'이 실행해야 하는 명령어라고 판단하여 에러를 발생시킬 것입니다. +# (이 경우에 'Variable=' 부분은 '어떤 문자열' 명령어의 스코프에서만 유효한 +# 변수 할당으로 해석됩니다.) + +# 변수 사용은 다음과 같습니다. +echo $Variable +echo "$Variable" +echo '$Variable' +# 할당, 내보내기 등 변수 자체를 사용할 때에는 $ 없이 이름을 적습니다. +# 변수의 값을 사용할 때에는 $를 사용해야 합니다. +# 작은 따옴표는 변수를 확장시키지 않는다는 사실에 주의하세요. +# (역자 주: '$Variable'은 변수 Variable의 값이 아닌 문자열 "$Variable"입니다.) + +# 인수 확장은 ${ }입니다. +echo ${Variable} +# 이는 인수 확장의 간단한 예시입니다. +# 인수 확장은 변수로부터 값을 받아 그 값을 "확장"하거나 출력합니다. +# 확장을 통해 인수나 그 값이 변경될 수 있습니다. +# 이하는 확장에 대한 다른 예시들입니다. + +# 변수에서의 문자열 치환 +echo ${Variable/Some/A} +# 처음으로 나타나는 "Some"를 "A"로 치환합니다. + +# 변수의 부분열 +Length=7 +echo ${Variable:0:Length} +# 변수 값에서 처음 7개 문자만을 반환합니다. + +# 변수의 기본값 +echo ${Foo:-"Foo가_없거나_비어_있을_때의_기본값"} +# null(Foo=) 값이나 빈 문자열(Foo="")일 경우에만 작동합니다. 0은 (Foo=0)은 0입니다. +# 기본값을 반환할 뿐 변수 값을 변경하지는 않는다는 사실에 주목하세요. + +# 중괄호 확장 { } +# 임의의 문자열을 생성합니다. +echo {1..10} +echo {a..z} +# 시작 값으로부터 끝 값까지의 범위를 출력합니다. + +# 내장 변수 +# 유용한 내장 변수들이 있습니다. +echo "마지막 프로그램의 반환값: $?" +echo "스크립트의 PID: $$" +echo "스크립트에 넘겨진 인자의 개수: $#" +echo "스크립트에 넘겨진 모든 인자: $@" +echo "각각 변수로 쪼개진 스크립트 인자: $1 $2..." + +# echo와 변수의 사용법을 알게 되었으니, +# bash의 기초를 조금 더 배워봅시다! + +# 현재 디렉토리는 `pwd` 명령어로 알 수 있습니다. +# `pwd`는 "print working directory(작업 디렉토리 출력)"의 약자입니다. +# 내장 변수`$PWD`를 사용할 수도 있습니다. +# 이하는 모두 동일합니다. +echo "I'm in $(pwd)" # `pwd`를 실행하여 문자열에 보간 +echo "I'm in $PWD" # 변수를 보간 + +# 터미널이나 결과의 출력물이 너무 많다면 +# 명령어 `clear`를 이용해 화면을 지울 수 있습니다. +clear +# 컨트롤+L 또한 화면을 지울 수 있습니다. + +# 입력 값 읽기 +echo "이름이 뭐에요?" +read Name # 변수 선언이 필요 없다는 데 주목하세요. +echo $Name님, 안녕하세요! + +# 평범한 if 구조도 있습니다. +# 'man test'로 조건문에 대해 더 알아보세요. +if [ $Name != $USER ] +then + echo "사용자가 아닙니다." +else + echo "사용자입니다." +fi + +# $Name이 비어 있다면, bash는 위의 조건을 다음과 같이 인식합니다. +if [ != $USER ] +# 이는 문법적으로 유효하지 않습니다. +# 따라서 bash에서 비어 있을 수 있는 변수를 "안전하게" 사용하는 법은 다음과 같습니다. +if [ "$Name" != $USER ] ... +# $Name이 비어 있다면 bash는 +if [ "" != $USER ] ... +# 와 같이 인식하여 예상한 대로 동작합니다. + +# 조건부 실행도 있습니다. +echo "항상 실행" || echo "첫 명령어가 실패해야 실행" +echo "항상 실행" && echo "첫 명령어가 실패하지 않아야 실행" + +# if문과 함께 &&와 ||을 사용하려면, 대괄호가 여러 쌍 필요합니다. +if [ "$Name" == "철수" ] && [ "$Age" -eq 15 ] +then + echo "$Name이 철수이고 $Age가 15일 때 실행" +fi + +if [ "$Name" == "민희" ] || [ "$Name" == "상민" ] +then + echo "$Name이 민희이거나 상민일 때 실행" +fi + +# 표현식은 다음 형식으로 표기됩니다. +echo $(( 10 + 5 )) + +# 다른 프로그래밍 언어와는 달리, bash는 셸이기 때문에 현재 디렉토리의 컨텍스트에서 +# 실행됩니다. 현재 디렉토리의 파일과 디렉토리를 ls 명령어로 나열할 수 있습니다. +ls + +# 다음은 실행을 제어하는 옵션의 예시입니다. +ls -l # 모든 파일과 디렉토리를 분리된 줄에 나열 +ls -t # 디렉토리 내용을 마지막으로 수정된 날짜(내림차순)에 따라 정렬 +ls -R # 이 디렉토리와 그 안의 모든 디렉토리에 대해 재귀적으로 `ls` 실행 + +# 이전 명령어의 결과는 다음 명령어에 입력될 수 있습니다. +# grep 명령어는 입력을 주어진 패턴에 따라 필터링합니다. 다음은 현재 디렉토리의 +# .txt 파일을 나열하는 방법입니다. +ls -l | grep "\.txt" + +# `cat`을 이용해 stdout으로 파일을 출력합니다. +cat file.txt + +# `cat`으로 파일을 읽을 수도 있습니다. +Contents=$(cat file.txt) +echo "파일 시작\n$Contents\n파일 끝" + +# `cp`를 이용해 파일이나 디렉토리를 다른 곳으로 복사할 수 있습니다. +# `cp`는 원본의 새로운 버전을 생성하므로 사본을 편집하는 것은 +# 원본에 영향을 주지 않으며 그 반대도 마찬가지입니다. +# 목표 위치에 이미 파일이 있다면 덮어쓰게 됩니다. +cp srcFile.txt clone.txt +cp -r srcDirectory/ dst/ # 재귀적으로 복사 + +# 컴퓨터 간에 파일을 공유하려고 한다면 `scp` 혹은 `sftp`를 사용합니다. +# `scp`는 `cp`와 매우 유사하게 동작하며 +# `sftp`는 더 상호작용적입니다. + +# `mv`로 파일 혹은 디렉토리를 다른 곳으로 이동합니다. +# `mv`는 `cp`와 유사하지만 원본을 삭제합니다. +# 또한 `mv`로 파일의 이름을 바꿀 수도 있습니다. +mv s0urc3.txt dst.txt # sorry, l33t hackers... + +# bash는 현재 디렉토리의 컨텍스트에서 실행되기 때문에, 다른 디렉토리에서 명령어를 +# 실행하고 싶으실 수 있습니다. cd를 이용해 위치를 변경합니다. +cd ~ # 홈 디렉토리로 변경 +cd .. # 한 디렉토리 위로 이동 + # (즉 /home/username/Downloads에서 /home/username로) +cd /home/username/Documents # 특정 디렉토리로 이동 +cd ~/Documents/.. # 아직도 홈 디렉토리... 아닌가?? + +# 서브셸로 디렉토리를 넘어서 작업할 수도 있습니다. +(echo "처음엔 여기 $PWD") && (cd 어딘가; echo "이제는 여기 $PWD") +pwd # 아직도 첫 디렉토리에 있음 + +# `mkdir`로 새 디렉토리를 만듭니다. +mkdir myNewDir +# `-p` 플래그는 필요하다면 해당 디렉토리의 경로 중간에 있는 디렉토리를 생성합니다. +mkdir -p myNewDir/with/intermediate/directories + +# (stdin, stdout, stderr로) 명령어의 입출력을 리디렉션할 수 있습니다. +# stdin의 내용을 ^EOF$까지 읽고 hello.py에 그 내용을 덮어씁니다. +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 + +# stdin, stdoutk, stderr을 다양한 방법으로 리디렉션하여 hello.py를 실행합니다. +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 +# 출력 오류는 이미 파일이 있을 경우 덮어쓰지만, +# 덮어쓰는 대신에 내용에 추가하고 싶다면 ">>"를 사용합니다. +python hello.py >> "output.out" 2>> "error.err" + +# output.out에 덮어쓰고, error.err에 추가하고, 줄을 세기 +info bash 'Basic Shell Features' 'Redirections' > output.out 2>> error.err +wc -l output.out error.err + +# 명령어를 실행하고 그 파일 디스크립터를 출력 (예: /dev/fd/123) +# man fd 참고 +echo <(echo "#helloworld") + +# output.out을 "#helloworld"으로 덮어쓰기 +cat > output.out <(echo "#helloworld") +echo "#helloworld" > output.out +echo "#helloworld" | cat > output.out +echo "#helloworld" | tee output.out >/dev/null + +# 임시 파일을 지울 수 있습니다. ('-i'로 대화식 실행) +# 경고: `rm` 명령어는 되돌릴 수 없습니다. +rm -v output.out error.err output-and-error.log +rm -r tempDir/ # 재귀적으로 삭제 + +# 다른 명령어에서 $()을 이용해 명령어를 치환할 수도 있습니다. +# 다음 명령어는 현재 디렉토리의 파일 및 디렉토리의 수를 표시합니다. +echo "$(ls | wc -l)개 항목이 있습니다." + +# 백틱(``)을 이용할 수도 있지만 이 방식을 이용하면 중첩할 수 없기 때문에 +# $()을 사용하는 것이 더 좋습니다. +echo "`ls | wc -l`개 항목이 있습니다." + +# 자바나 C++의 switch와 비슷하게 동작하는 case 문을 사용할 수 있습니다. +case "$Variable" in + # 충족시킬 조건을 나열 + 0) echo "0입니다.";; + 1) echo "1입니다.";; + *) echo "널이 아닌 값입니다.";; +esac + +# for 반복문은 주어진 인자만큼 반복합니다. +# 다음은 $Variable을 세 번 출력합니다. +for Variable in {1..3} +do + echo "$Variable" +done + +# 혹은 "전통적인 for 반복문" 방식을 쓸 수도 있습니다. +for ((a=1; a <= 3; a++)) +do + echo $a +done + +# 파일에도 적용될 수 있습니다. +# 다음은 file1과 file2에 'cat' 명령어를 실행합니다. +for Variable in file1 file2 +do + cat "$Variable" +done + +# 혹은 명령어의 결과에도 이용할 수 있습니다. +# 다음은 ls의 결과를 cat합니다. +for Output in $(ls) +do + cat "$Output" +done + +# while 반복문 +while [ true ] +do + echo "반복문 몸체" + break +done + +# 함수를 정의할 수도 있습니다. +# 정의: +function foo () +{ + echo "인자는 함수 인자처럼 작동합니다. $@" + echo "그리고 $1 $2..." + echo "함수입니다." + return 0 +} + +# 혹은 단순하게 +bar () +{ + echo "함수를 선언하는 다른 방법" + return 0 +} + +# 함수 호출 +foo "My name is" $Name + +# 몇 가지 유용한 명령어를 알아두면 좋습니다. +# file.txt의 마지막 10줄 출력 +tail -n 10 file.txt +# file.txt의 첫 10줄 출력 +head -n 10 file.txt +# file.txt 줄 별로 정렬 +sort file.txt +# 중복되는 줄을 생략하거나 -d를 이용하여 보고 +uniq -d file.txt +# ',' 문자 이전의 첫 열만 출력 +cut -d ',' -f 1 file.txt +# file.txt에서 'okay'를 모두 'great'로 교체 (정규식 호환) +sed -i 's/okay/great/g' file.txt +# file.txt에서 정규식에 맞는 모든 줄을 stdin에 출력 +# 다음 예시는 "foo"로 시작해 "bar"로 끝나는 줄 출력 +grep "^foo.*bar$" file.txt +# "-c" 옵션을 넘겨 줄 번호를 대신 출력 +grep -c "^foo.*bar$" file.txt +# 다른 유용한 옵션 +grep -r "^foo.*bar$" someDir/ # 재귀적으로 `grep` +grep -n "^foo.*bar$" file.txt # 줄 번호 매기기 +grep -rI "^foo.*bar$" someDir/ # 재귀적으로 `grep`하되 바이너리 파일은 무시 +# 같은 검색으로 시작하여 "baz"를 포함하는 줄만 필터 +grep "^foo.*bar$" file.txt | grep -v "baz" + +# 정규식이 아니라 문자열로 검색하고 싶다면 +# fgrep 혹은 grep -F +fgrep "foobar" file.txt + +# trap 명령어로 스크립트에서 신호를 받을 때 명령어를 실행할 수 있습니다. +# 다음 명령어는 셋 중 한 가지 신호를 받으면 rm 명령어를 실행합니다. +trap "rm $TEMP_FILE; exit" SIGHUP SIGINT SIGTERM + +# `sudo`를 통해 슈퍼이용자로 명령어를 실행합니다. +NAME1=$(whoami) +NAME2=$(sudo whoami) +echo "$NAME1였다가 더 강한 $NAME2가 되었다" + +# 'help' 명령어로 내장 문서를 읽을 수 있습니다. +help +help help +help for +help return +help source +help . + +# man으로 매뉴얼을 읽을 수도 있습니다. +apropos bash +man 1 bash +man bash + +# info 명령어로 문서를 읽습니다. (?로 도움말) +apropos info | grep '^info.*(' +man info +info info +info 5 info + +# bash의 info 문서를 읽어 보세요. +info bash +info bash 'Bash Features' +info bash 6 +info --apropos bash +``` -- cgit v1.2.3 From 33b1476f38b7036eb16a20fbc43c8ef42b4bf4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Polykanine=20A=2EK=2EA=2E=20Menelion=20Elens=C3=BA?= =?UTF-8?q?l=C3=AB?= Date: Fri, 6 Jan 2017 23:02:45 +0200 Subject: [rst/en] Correcting English language --- rst.html.markdown | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/rst.html.markdown b/rst.html.markdown index 161a0610..8897ec2f 100644 --- a/rst.html.markdown +++ b/rst.html.markdown @@ -5,9 +5,9 @@ contributors: filename: restructuredtext.rst --- -RST is file format formely created by Python community to write documentation (and so, is part of Docutils). +RST is a file format formely created by Python community to write documentation (and so, is part of Docutils). -RST files are simple text files with lightweight syntaxe (comparing to HTML). +RST files are simple text files with lightweight syntax (comparing to HTML). ## Installation @@ -20,25 +20,25 @@ To use Restructured Text, you will have to install [Python](http://www.python.or $ easy_install docutils ``` -If your system have `pip`, you can use it too: +If your system has `pip`, you can use it too: ```bash $ pip install docutils ``` -## File syntaxe +## File syntax A simple example of the file syntax: ```rst -.. Line with two dotes are special commands. But if no command can be found, the line is considered as a comment +.. Lines starting with two dots are special commands. But if no command can be found, the line is considered as a comment ========================================================= Main titles are written using equals signs over and under ========================================================= -Note that theire must be as many equals signs as title characters. +Note that there must be as many equals signs as title characters. Title are underlined with equals signs too ========================================== @@ -46,12 +46,12 @@ Title are underlined with equals signs too Subtitles with dashes --------------------- -And sub-subtitles with tilde +And sub-subtitles with tildes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can put text in *italic* or in **bold**, you can "mark" text as code with double backquote ``: ``print()``. -Lists are as simple as markdown: +Lists are as simple as in Markdown: - First item - Second item @@ -72,22 +72,22 @@ France Paris Japan Tokyo =========== ======== -More complexe tabless can be done easily (merged columns and/or rows) but I suggest you to read the complete doc for this :) +More complex tabless can be done easily (merged columns and/or rows) but I suggest you to read the complete doc for this :) -Their is multiple ways to make links: +There are multiple ways to make links: -- By adding an underscore after a word : Github_ and by adding the target after the text (this have the advantage to not insert un-necessary URL inside the readed text). -- By typing a full comprehensible URL : https://github.com/ (will be automatically converted in link) -- By making a more "markdown" link: `Github `_ . +- By adding an underscore after a word : Github_ and by adding the target URL after the text (this way has the advantage to not insert unnecessary URLs inside readable text). +- By typing a full comprehensible URL : https://github.com/ (will be automatically converted to a link) +- By making a more Markdown-like link: `Github `_ . .. _Github https://github.com/ ``` -## How to use it +## How to Use It -RST comes with docutils in which you have `rst2html` for exemple: +RST comes with docutils where you have `rst2html`, for example: ```bash $ rst2html myfile.rst output.html @@ -95,13 +95,13 @@ $ rst2html myfile.rst output.html *Note : On some systems the command could be rst2html.py* -But their is more complexe applications that uses RST file format: +But there are more complex applications that use the RST format: - [Pelican](http://blog.getpelican.com/), a static site generator - [Sphinx](http://sphinx-doc.org/), a documentation generator - and many others -## Readings +## Reading - [Official quick reference](http://docutils.sourceforge.net/docs/user/rst/quickref.html) -- cgit v1.2.3 From c3fb66cd6dfe79d9c8357e6f65230c750f78b3a7 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 09:45:11 +0100 Subject: Initial commit --- pl-pl/haskell-pl.html.markdown | 450 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 450 insertions(+) create mode 100644 pl-pl/haskell-pl.html.markdown diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown new file mode 100644 index 00000000..196ad9a6 --- /dev/null +++ b/pl-pl/haskell-pl.html.markdown @@ -0,0 +1,450 @@ +--- +language: Haskell +lang: pl-pl +contributors: + - ["Remigiusz Suwalski", "https://github.com/remigiusz-suwalski"] +--- + +Haskell został zaprojektowany jako praktyczy, czysto funkcyjny język +programowania. Jest znany przede wszystkim ze względu na jego monady oraz system +typów, ale ja lubię do niego wracać przez jego elegancję. Sprawił on, że +programowanie jest prawdziwą przyjemnością. + +```haskell +-- Komentarze jednolinijkowe zaczynają się od dwóch myślników +{- Komentarze wielolinijkowe należy +zamykać w bloki klamrami. +-} + +---------------------------------------------------- +-- 1. Primitive Datatypes and Operators +---------------------------------------------------- + +-- You have numbers +3 -- 3 + +-- Math is what you would expect +1 + 1 -- 2 +8 - 1 -- 7 +10 * 2 -- 20 +35 / 5 -- 7.0 + +-- Division is not integer division by default +35 / 4 -- 8.75 + +-- integer division +35 `div` 4 -- 8 + +-- Boolean values are primitives +True +False + +-- Boolean operations +not True -- False +not False -- True +1 == 1 -- True +1 /= 1 -- False +1 < 10 -- True + +-- In the above examples, `not` is a function that takes one value. +-- Haskell doesn't need parentheses for function calls...all the arguments +-- are just listed after the function. So the general pattern is: +-- func arg1 arg2 arg3... +-- See the section on functions for information on how to write your own. + +-- Strings and characters +"This is a string." +'a' -- character +'You cant use single quotes for strings.' -- error! + +-- Strings can be concatenated +"Hello " ++ "world!" -- "Hello world!" + +-- A string is a list of characters +['H', 'e', 'l', 'l', 'o'] -- "Hello" +"This is a string" !! 0 -- 'T' + + +---------------------------------------------------- +-- Lists and Tuples +---------------------------------------------------- + +-- Every element in a list must have the same type. +-- These two lists are the same: +[1, 2, 3, 4, 5] +[1..5] + +-- Ranges are versatile. +['A'..'F'] -- "ABCDEF" + +-- You can create a step in a range. +[0,2..10] -- [0, 2, 4, 6, 8, 10] +[5..1] -- This doesn't work because Haskell defaults to incrementing. +[5,4..1] -- [5, 4, 3, 2, 1] + +-- indexing into a list +[1..10] !! 3 -- 4 + +-- You can also have infinite lists in Haskell! +[1..] -- a list of all the natural numbers + +-- Infinite lists work because Haskell has "lazy evaluation". This means +-- that Haskell only evaluates things when it needs to. So you can ask for +-- the 1000th element of your list and Haskell will give it to you: + +[1..] !! 999 -- 1000 + +-- And now Haskell has evaluated elements 1 - 1000 of this list...but the +-- rest of the elements of this "infinite" list don't exist yet! Haskell won't +-- actually evaluate them until it needs to. + +-- joining two lists +[1..5] ++ [6..10] + +-- adding to the head of a list +0:[1..5] -- [0, 1, 2, 3, 4, 5] + +-- more list operations +head [1..5] -- 1 +tail [1..5] -- [2, 3, 4, 5] +init [1..5] -- [1, 2, 3, 4] +last [1..5] -- 5 + +-- list comprehensions +[x*2 | x <- [1..5]] -- [2, 4, 6, 8, 10] + +-- with a conditional +[x*2 | x <- [1..5], x*2 > 4] -- [6, 8, 10] + +-- Every element in a tuple can be a different type, but a tuple has a +-- fixed length. +-- A tuple: +("haskell", 1) + +-- accessing elements of a pair (i.e. a tuple of length 2) +fst ("haskell", 1) -- "haskell" +snd ("haskell", 1) -- 1 + +---------------------------------------------------- +-- 3. Functions +---------------------------------------------------- +-- A simple function that takes two variables +add a b = a + b + +-- Note that if you are using ghci (the Haskell interpreter) +-- You'll need to use `let`, i.e. +-- let add a b = a + b + +-- Using the function +add 1 2 -- 3 + +-- You can also put the function name between the two arguments +-- with backticks: +1 `add` 2 -- 3 + +-- You can also define functions that have no letters! This lets +-- you define your own operators! Here's an operator that does +-- integer division +(//) a b = a `div` b +35 // 4 -- 8 + +-- Guards: an easy way to do branching in functions +fib x + | x < 2 = 1 + | otherwise = fib (x - 1) + fib (x - 2) + +-- Pattern matching is similar. Here we have given three different +-- definitions for fib. Haskell will automatically call the first +-- function that matches the pattern of the value. +fib 1 = 1 +fib 2 = 2 +fib x = fib (x - 1) + fib (x - 2) + +-- Pattern matching on tuples: +foo (x, y) = (x + 1, y + 2) + +-- Pattern matching on lists. Here `x` is the first element +-- in the list, and `xs` is the rest of the list. We can write +-- our own map function: +myMap func [] = [] +myMap func (x:xs) = func x:(myMap func xs) + +-- Anonymous functions are created with a backslash followed by +-- all the arguments. +myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7] + +-- using fold (called `inject` in some languages) with an anonymous +-- function. foldl1 means fold left, and use the first value in the +-- list as the initial value for the accumulator. +foldl1 (\acc x -> acc + x) [1..5] -- 15 + +---------------------------------------------------- +-- 4. More functions +---------------------------------------------------- + +-- partial application: if you don't pass in all the arguments to a function, +-- it gets "partially applied". That means it returns a function that takes the +-- rest of the arguments. + +add a b = a + b +foo = add 10 -- foo is now a function that takes a number and adds 10 to it +foo 5 -- 15 + +-- Another way to write the same thing +foo = (10+) +foo 5 -- 15 + +-- function composition +-- the operator `.` 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 4, and then returns the final value. +foo = (4*) . (10+) + +-- 4*(10 + 5) = 60 +foo 5 -- 60 + +-- fixing precedence +-- Haskell has another operator called `$`. This operator applies a function +-- to a given parameter. In contrast to standard function application, which +-- has highest possible priority of 10 and is left-associative, the `$` operator +-- has priority of 0 and is right-associative. Such a low priority means that +-- the expression on its right is applied as the parameter to the function on its left. + +-- before +even (fib 7) -- false + +-- equivalently +even $ fib 7 -- false + +-- composing functions +even . fib $ 7 -- false + + +---------------------------------------------------- +-- 5. Type signatures +---------------------------------------------------- + +-- Haskell has a very strong type system, and every valid expression has a type. + +-- Some basic types: +5 :: Integer +"hello" :: String +True :: Bool + +-- Functions have types too. +-- `not` takes a boolean and returns a boolean: +-- not :: Bool -> Bool + +-- Here's a function that takes two arguments: +-- add :: Integer -> Integer -> Integer + +-- When you define a value, it's good practice to write its type above it: +double :: Integer -> Integer +double x = x * 2 + +---------------------------------------------------- +-- 6. Control Flow and If Expressions +---------------------------------------------------- + +-- if expressions +haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome" + +-- if expressions can be on multiple lines too, indentation is important +haskell = if 1 == 1 + then "awesome" + else "awful" + +-- case expressions: Here's how you could parse command line arguments +case args of + "help" -> printHelp + "start" -> startProgram + _ -> putStrLn "bad args" + +-- Haskell doesn't have loops; it uses recursion instead. +-- map applies a function over every element in a list + +map (*2) [1..5] -- [2, 4, 6, 8, 10] + +-- you can make a for function using map +for array func = map func array + +-- and then use it +for [0..5] $ \i -> show i + +-- we could've written that like this too: +for [0..5] show + +-- You can use foldl or foldr to reduce a list +-- foldl +foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 + +-- This is the same as +(2 * (2 * (2 * 4 + 1) + 2) + 3) + +-- foldl is left-handed, foldr is right-handed +foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 + +-- This is now the same as +(2 * 1 + (2 * 2 + (2 * 3 + 4))) + +---------------------------------------------------- +-- 7. Data Types +---------------------------------------------------- + +-- Here's how you make your own data type in Haskell + +data Color = Red | Blue | Green + +-- Now you can use it in a function: + + +say :: Color -> String +say Red = "You are Red!" +say Blue = "You are Blue!" +say Green = "You are Green!" + +-- Your data types can have parameters too: + +data Maybe a = Nothing | Just a + +-- These are all of type Maybe +Just "hello" -- of type `Maybe String` +Just 1 -- of type `Maybe Int` +Nothing -- of type `Maybe a` for any `a` + +---------------------------------------------------- +-- 8. Haskell IO +---------------------------------------------------- + +-- While IO can't be explained fully without explaining monads, +-- it is not hard to explain enough to get going. + +-- When a Haskell program is executed, `main` is +-- called. It must return a value of type `IO a` for some type `a`. For example: + +main :: IO () +main = putStrLn $ "Hello, sky! " ++ (say Blue) +-- putStrLn has type String -> IO () + +-- It is easiest to do IO if you can implement your program as +-- a function from String to String. The function +-- interact :: (String -> String) -> IO () +-- inputs some text, runs a function on it, and prints out the +-- output. + +countLines :: String -> String +countLines = show . length . lines + +main' = interact countLines + +-- You can think of a value of type `IO ()` as representing a +-- sequence of actions for the computer to do, much like a +-- computer program written in an imperative language. We can use +-- the `do` notation to chain actions together. For example: + +sayHello :: IO () +sayHello = do + putStrLn "What is your name?" + name <- getLine -- this gets a line and gives it the name "name" + putStrLn $ "Hello, " ++ name + +-- Exercise: write your own version of `interact` that only reads +-- one line of input. + +-- The code in `sayHello` will never be executed, however. The only +-- action that ever gets executed is the value of `main`. +-- To run `sayHello` comment out the above definition of `main` +-- and replace it with: +-- main = sayHello + +-- Let's understand better how the function `getLine` we just +-- used works. Its type is: +-- getLine :: IO String +-- You can think of a value of type `IO a` as representing a +-- computer program that will generate a value of type `a` +-- when executed (in addition to anything else it does). We can +-- name and reuse this value using `<-`. We can also +-- make our own action of type `IO String`: + +action :: IO String +action = do + putStrLn "This is a line. Duh" + input1 <- getLine + input2 <- getLine + -- The type of the `do` statement is that of its last line. + -- `return` is not a keyword, but merely a function + return (input1 ++ "\n" ++ input2) -- return :: String -> IO String + +-- We can use this just like we used `getLine`: + +main'' = do + putStrLn "I will echo two lines!" + result <- action + putStrLn result + putStrLn "This was all, folks!" + +-- The type `IO` is an example of a "monad". The way Haskell uses a monad to +-- do IO allows it to be a purely functional language. Any function that +-- interacts with the outside world (i.e. does IO) gets marked as `IO` in its +-- type signature. This lets us reason about what functions are "pure" (don't +-- interact with the outside world or modify state) and what functions aren't. + +-- This is a powerful feature, because it's easy to run pure functions +-- concurrently; so, concurrency in Haskell is very easy. + + +---------------------------------------------------- +-- 9. The Haskell REPL +---------------------------------------------------- + +-- Start the repl by typing `ghci`. +-- Now you can type in Haskell code. Any new values +-- need to be created with `let`: + +let foo = 5 + +-- You can see the type of any value or expression with `:t`: + +> :t foo +foo :: Integer + +-- Operators, such as `+`, `:` and `$`, are functions. +-- Their type can be inspected by putting the operator in parentheses: + +> :t (:) +(:) :: a -> [a] -> [a] + +-- You can get additional information on any `name` using `:i`: + +> :i (+) +class Num a where + (+) :: a -> a -> a + ... + -- Defined in ‘GHC.Num’ +infixl 6 + + +-- You can also run any action of type `IO ()` + +> sayHello +What is your name? +Friend! +Hello, Friend! + +``` + +There's a lot more to Haskell, including typeclasses and monads. These are the +big ideas that make Haskell such fun to code in. I'll leave you with one final +Haskell example: an implementation of a quicksort variant in Haskell: + +```haskell +qsort [] = [] +qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater + where lesser = filter (< p) xs + greater = filter (>= p) xs +``` + +There are two popular ways to install Haskell: The traditional [Cabal-based installation](http://www.haskell.org/platform/), and the newer [Stack-based process](https://www.stackage.org/install). + +You can find a much gentler introduction from the excellent +[Learn you a Haskell](http://learnyouahaskell.com/) or +[Real World Haskell](http://book.realworldhaskell.org/). -- cgit v1.2.3 From fb5dac4b3cbc92abd16187974eb7bb0608f3e9be Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 09:58:12 +0100 Subject: Lists and tuples --- pl-pl/haskell-pl.html.markdown | 46 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index 196ad9a6..cc65be27 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -66,45 +66,46 @@ not False -- True ---------------------------------------------------- --- Lists and Tuples +-- Listy oraz krotki ---------------------------------------------------- --- Every element in a list must have the same type. --- These two lists are the same: +-- Wszystkie elementy listy muszą być tego samego typu. +-- Poniższe dwie listy są identyczne: [1, 2, 3, 4, 5] [1..5] --- Ranges are versatile. +-- Zakresy są uniwersalne. ['A'..'F'] -- "ABCDEF" --- You can create a step in a range. +-- Przy tworzeniu zakresów można określić krok. [0,2..10] -- [0, 2, 4, 6, 8, 10] -[5..1] -- This doesn't work because Haskell defaults to incrementing. +[5..1] -- To nie zadziała, gdyż w Haskellu zakresy tworzone są domyślnie rosnąco [5,4..1] -- [5, 4, 3, 2, 1] --- indexing into a list +-- indeksowanie listy od zera [1..10] !! 3 -- 4 --- You can also have infinite lists in Haskell! -[1..] -- a list of all the natural numbers +-- Można nawet tworzyć listy nieskończone! +[1..] -- lista wszystkich liczb naturalnych --- Infinite lists work because Haskell has "lazy evaluation". This means --- that Haskell only evaluates things when it needs to. So you can ask for --- the 1000th element of your list and Haskell will give it to you: +-- Nieskończone listy mają prawo działać, ponieważ Haskell cechuje się leniwym +-- wartościowaniem. To oznacza, że obliczane są jedynie te elementy listy, +-- których istotnie potrzebujemy. Możemy poprosić o tysiączny element i +-- dostaniemy go: [1..] !! 999 -- 1000 --- And now Haskell has evaluated elements 1 - 1000 of this list...but the --- rest of the elements of this "infinite" list don't exist yet! Haskell won't --- actually evaluate them until it needs to. +-- Haskell wyznaczył pierwsze tysiąc elementów listy, ale cała jej reszta +-- jeszcze nie istnieje! Nie zostanie obliczona ich wartość, póki nie zajdzie +-- taka potrzeba. --- joining two lists +-- łączenie dwóch list [1..5] ++ [6..10] --- adding to the head of a list +-- dodawanie pojedynczego elementu na początek listy 0:[1..5] -- [0, 1, 2, 3, 4, 5] --- more list operations +-- więcej operacji na listach head [1..5] -- 1 tail [1..5] -- [2, 3, 4, 5] init [1..5] -- [1, 2, 3, 4] @@ -113,15 +114,14 @@ last [1..5] -- 5 -- list comprehensions [x*2 | x <- [1..5]] -- [2, 4, 6, 8, 10] --- with a conditional +-- z dodatkowym warunkiem [x*2 | x <- [1..5], x*2 > 4] -- [6, 8, 10] --- Every element in a tuple can be a different type, but a tuple has a --- fixed length. --- A tuple: +-- każdy element krotki może być innego typu, jednak sama krotka musi być stałej +-- długości. Przykładowo: ("haskell", 1) --- accessing elements of a pair (i.e. a tuple of length 2) +-- dostęp do elementów pary (krotki długości 2): fst ("haskell", 1) -- "haskell" snd ("haskell", 1) -- 1 -- cgit v1.2.3 From 7e3b7a5326c948ec80e79c687e462d62538fe319 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 10:04:14 +0100 Subject: Translate functions --- pl-pl/haskell-pl.html.markdown | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index cc65be27..b747ebb3 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -17,53 +17,52 @@ zamykać w bloki klamrami. -} ---------------------------------------------------- --- 1. Primitive Datatypes and Operators +-- 1. Podstawowe typy danych oraz operatory ---------------------------------------------------- --- You have numbers +-- Mamy liczby 3 -- 3 --- Math is what you would expect +-- Podstawowe działania działają tak, jak powinny 1 + 1 -- 2 8 - 1 -- 7 10 * 2 -- 20 35 / 5 -- 7.0 --- Division is not integer division by default +-- dzielenie domyślnie zwraca ,,dokładny'' wynik 35 / 4 -- 8.75 --- integer division +-- dzielenie całkowitoliczbowe 35 `div` 4 -- 8 --- Boolean values are primitives +-- wartości logiczne także są podstawowym typem danych: True False --- Boolean operations +-- operacje logiczne: negacja oraz porównania not True -- False not False -- True 1 == 1 -- True 1 /= 1 -- False 1 < 10 -- True --- In the above examples, `not` is a function that takes one value. --- Haskell doesn't need parentheses for function calls...all the arguments --- are just listed after the function. So the general pattern is: --- func arg1 arg2 arg3... --- See the section on functions for information on how to write your own. +-- W powyższych przykładach, `not` jest funkcją przyjmującą jeden argument. +-- Haskell nie potrzebuje nawiasów, by wywołać funkcję: argumenty są po prostu +-- wypisywane jeden za drugim. Ogólnie wygląda to tak: +-- funkcja arg1 arg2 arg3... +-- Sekcja poświęcona funkcjom zawiera informacje, jak stworzyć własne. --- Strings and characters -"This is a string." -'a' -- character -'You cant use single quotes for strings.' -- error! +-- Łańcuchy znaków (stringi) i pojedyncze znaki: +"To jest lancuch." +'a' -- znak +'Nie mozna laczyc apostrofow z lancuchami.' -- błąd! --- Strings can be concatenated +-- Łańcuchy można sklejać "Hello " ++ "world!" -- "Hello world!" --- A string is a list of characters +-- Łańcuch jest listą własnych znaków ['H', 'e', 'l', 'l', 'o'] -- "Hello" -"This is a string" !! 0 -- 'T' - +"To jest lancuch" !! 0 -- 'T' ---------------------------------------------------- -- Listy oraz krotki -- cgit v1.2.3 From cc0bd98aeed7bb0b03b78422c63c382907eced77 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 10:06:27 +0100 Subject: Translate data types --- pl-pl/haskell-pl.html.markdown | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index b747ebb3..ae44cd9a 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -287,29 +287,28 @@ foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 (2 * 1 + (2 * 2 + (2 * 3 + 4))) ---------------------------------------------------- --- 7. Data Types +-- 7. Typy danych ---------------------------------------------------- --- Here's how you make your own data type in Haskell +-- Oto jak tworzy się nowe typy danych w Haskellu: data Color = Red | Blue | Green --- Now you can use it in a function: - +-- Teraz można używać ich we własnych funkcjach: say :: Color -> String say Red = "You are Red!" say Blue = "You are Blue!" say Green = "You are Green!" --- Your data types can have parameters too: +-- Twoje typy danych mogą posiadać nawet parametry: data Maybe a = Nothing | Just a --- These are all of type Maybe -Just "hello" -- of type `Maybe String` -Just 1 -- of type `Maybe Int` -Nothing -- of type `Maybe a` for any `a` +-- Wszystkie poniższe są typu Maybe +Just "hello" -- typu `Maybe String` +Just 1 -- typu `Maybe Int` +Nothing -- typu `Maybe a` for any `a` ---------------------------------------------------- -- 8. Haskell IO -- cgit v1.2.3 From fd89a692838344ab3776334984a7afced5defe93 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 10:10:04 +0100 Subject: Translate type signatures --- pl-pl/haskell-pl.html.markdown | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index ae44cd9a..a3c2d187 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -220,24 +220,26 @@ even . fib $ 7 -- false ---------------------------------------------------- --- 5. Type signatures +-- 5. Sygnatury typów ---------------------------------------------------- --- Haskell has a very strong type system, and every valid expression has a type. +-- Haskell posiada wyjątkowo silny system typów, w którym każde poprawne +-- wyrażenie ma swój typ. --- Some basic types: +-- Kilka podstawowych typów: 5 :: Integer "hello" :: String True :: Bool --- Functions have types too. --- `not` takes a boolean and returns a boolean: +-- Funkcje też są określonego typu. +-- `not` przyjmuje wartość logiczną i taką też zwraca: -- not :: Bool -> Bool --- Here's a function that takes two arguments: +-- Przykład funkcji przyjmującej dwa argumenty -- add :: Integer -> Integer -> Integer --- When you define a value, it's good practice to write its type above it: +-- Dobrą praktyką podczas definiowania wartości jest napisanie nad nią +-- także jej typu: double :: Integer -> Integer double x = x * 2 -- cgit v1.2.3 From 6fa14954a506717535f29c3ff97d9703a80ddca5 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Tue, 10 Jan 2017 18:29:33 +0100 Subject: Translate Flow control --- pl-pl/haskell-pl.html.markdown | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index a3c2d187..59fc090e 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -244,48 +244,49 @@ double :: Integer -> Integer double x = x * 2 ---------------------------------------------------- --- 6. Control Flow and If Expressions +-- 6. Wyrażenia warunkowe ---------------------------------------------------- --- if expressions -haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome" +-- wyrażenie warunkowe +haskell = if 1 == 1 then "wspaniale" else "paskudnie" -- haskell = "wspaniale" --- if expressions can be on multiple lines too, indentation is important +-- wyrażenie warunkowe można rozbić na wiele linii, +-- ale trzeba uważać na wcięcia w kodzie haskell = if 1 == 1 - then "awesome" - else "awful" + then "wspaniale" + else "paskudnie" --- case expressions: Here's how you could parse command line arguments +-- rozpatrywanie przypadków: oto jak można parsować argumenty z linii poleceń: case args of "help" -> printHelp "start" -> startProgram _ -> putStrLn "bad args" --- Haskell doesn't have loops; it uses recursion instead. --- map applies a function over every element in a list +-- Haskell zastępuje pętle (których nie ma) rekurencyjnymi wywołaniami funkcji. +-- map aplikuje funkcję do każdego elementu listy: map (*2) [1..5] -- [2, 4, 6, 8, 10] --- you can make a for function using map +-- możesz zdefiniować funkcję for przy użyciu map: for array func = map func array --- and then use it +-- a następnie użyć jej: for [0..5] $ \i -> show i --- we could've written that like this too: +-- mogliśmy użyć krótszego zapisu bez zmiany działania funkcji for: for [0..5] show --- You can use foldl or foldr to reduce a list +-- Do redukcji listy służy polecenie foldl (foldr): -- foldl foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 --- This is the same as +-- Jest to równoważne z: (2 * (2 * (2 * 4 + 1) + 2) + 3) --- foldl is left-handed, foldr is right-handed +-- foldl składa od od lewej strony, foldr od prawej foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 --- This is now the same as +-- To zaś równoważne jest: (2 * 1 + (2 * 2 + (2 * 3 + 4))) ---------------------------------------------------- -- cgit v1.2.3 From b80c70b4a3e4646c15f21f1c86fed9242ddbd793 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Wed, 11 Jan 2017 10:21:38 +0100 Subject: Translate REPL --- pl-pl/haskell-pl.html.markdown | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index 59fc090e..f2c31bb4 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -395,27 +395,27 @@ main'' = do ---------------------------------------------------- --- 9. The Haskell REPL +-- 9. Interaktywne środowisko programowania ---------------------------------------------------- --- Start the repl by typing `ghci`. --- Now you can type in Haskell code. Any new values --- need to be created with `let`: +-- Aby uruchomić repl (read-eval-print loop, interaktywne środowisko), należy +-- wpisać `ghci`. Można już programować. Do definiowania nowych wartości służy +-- słowo kluczowe `let`: let foo = 5 --- You can see the type of any value or expression with `:t`: +-- Do sprawdzania typów dowolnej wartości (wyrażenia) wykorzystuje się `:t`: > :t foo foo :: Integer --- Operators, such as `+`, `:` and `$`, are functions. --- Their type can be inspected by putting the operator in parentheses: +-- Działania takie jak `+`, `:` czy `$`, są funkcjami. +-- Przed sprawdzeniem ich typu należy otoczyć je nawiasami: > :t (:) (:) :: a -> [a] -> [a] --- You can get additional information on any `name` using `:i`: +-- Dodatkowych informacji dostarcza `:i`: > :i (+) class Num a where @@ -424,7 +424,7 @@ class Num a where -- Defined in ‘GHC.Num’ infixl 6 + --- You can also run any action of type `IO ()` +-- Można nawet wykonywać akcje typu `IO ()`! > sayHello What is your name? @@ -433,9 +433,9 @@ Hello, Friend! ``` -There's a lot more to Haskell, including typeclasses and monads. These are the -big ideas that make Haskell such fun to code in. I'll leave you with one final -Haskell example: an implementation of a quicksort variant in Haskell: +Pominęliśmy wiele aspektów Haskella, wliczając w to monady. To właśnie one +sprawiają, że programowanie w Haskellu sprawia tyle frajdy. Na zakończenie +pokażę Tobie implementację algorytmu quicksort w Haskellu: ```haskell qsort [] = [] @@ -444,8 +444,10 @@ qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater greater = filter (>= p) xs ``` -There are two popular ways to install Haskell: The traditional [Cabal-based installation](http://www.haskell.org/platform/), and the newer [Stack-based process](https://www.stackage.org/install). +Haskell może zostać zainstalowany na co najmniej dwa sposoby: + - tradycyjnie [przy użyciu Cabala](http://www.haskell.org/platform/), + - nowocześnie [z pomocą Stack](https://www.stackage.org/install). -You can find a much gentler introduction from the excellent -[Learn you a Haskell](http://learnyouahaskell.com/) or +Godnymi poleceniami wprowadzeniami są wspaniałe +[Learn you a Haskell](http://learnyouahaskell.com/) albo [Real World Haskell](http://book.realworldhaskell.org/). -- cgit v1.2.3 From cd034269f85d51843de5ada03c000a02ff892f98 Mon Sep 17 00:00:00 2001 From: Ader Date: Wed, 11 Jan 2017 15:17:23 +0000 Subject: a word was duplicated, I took it off. (#2626) --- html.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/html.html.markdown b/html.html.markdown index b64cec33..3c855b5c 100644 --- a/html.html.markdown +++ b/html.html.markdown @@ -9,7 +9,7 @@ translators: HTML stands for HyperText Markup Language. It is a language which allows us to write pages for the world wide web. -It is a markup language, it enables us to write to write webpages using code to indicate how text and data should be displayed. +It is a markup language, it enables us to write webpages using code to indicate how text and data should be displayed. In fact, html files are simple text files. What is this markup? It is a method of organising the page's data by surrounding it with opening tags and closing tags. This markup serves to give significance to the text that it encloses. -- cgit v1.2.3 From 81c7372cea986cf6c790c25aa221a79e88220553 Mon Sep 17 00:00:00 2001 From: Wooseop Kim Date: Thu, 12 Jan 2017 18:00:40 +0900 Subject: Translate Vim doc to Korean (#2628) --- ko-kr/vim-kr.html.markdown | 235 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 ko-kr/vim-kr.html.markdown diff --git a/ko-kr/vim-kr.html.markdown b/ko-kr/vim-kr.html.markdown new file mode 100644 index 00000000..a4cb32ec --- /dev/null +++ b/ko-kr/vim-kr.html.markdown @@ -0,0 +1,235 @@ +--- +category: tool +tool: vim +contributors: + - ["RadhikaG", "https://github.com/RadhikaG"] +translators: + - ["Wooseop Kim", "https://github.com/linterpreteur"] +filename: LearnVim-kr.txt +lang: ko-kr +--- + +[Vim](www.vim.org) +(Vi IMproved)은 유닉스의 인기 있는 vi 에디터의 클론입니다. Vim은 속도와 생산성을 위해 +설계된 텍스트 에디터로, 대부분의 유닉스 기반 시스템에 내장되어 있습니다. 다양한 단축 키를 통해 +파일 안에서 빠르게 이동하고 편집할 수 있습니다. + +## Vim 조작의 기본 + +``` + vim # vim으로 열기 + :q # vim 종료 + :w # 현재 파일 저장 + :wq # 파일 저장 후 종료 + :q! # 저장하지 않고 종료 + # ! *강제로* :q를 실행하여, 저장 없이 종료 + :x # 파일 저장 후 종료 (짧은 :wq) + + u # 동작 취소 + CTRL+R # 되돌리기 + + h # 한 글자 왼쪽으로 이동 + j # 아래로 한 줄 이동 + k # 위로 한 줄 이동 + l # 한 글자 오른쪽으로 이동 + + # 줄 안에서의 이동 + + 0 # 줄 시작으로 이동 + $ # 줄 끝으로 이동 + ^ # 줄의 공백이 아닌 첫 문자로 이동 + + # 텍스트 검색 + + /word # 커서 뒤에 나타나는 해당 단어를 모두 하이라이트 + ?word # 커서 앞에 나타나는 해당 단어를 모두 하이라이트 + n # 해당 단어를 검색 후 다음으로 나타나는 위치로 이동 + N # 이전에 나타나는 위치로 이동 + + :%s/foo/bar/g # 파일 모든 줄에 있는 'foo'를 'bar'로 치환 + :s/foo/bar/g # 현재 줄에 있는 'foo'를 'bar'로 치환 + + # 문자로 이동 + + f # 로 건너뛰기 + t # 의 바로 뒤로 건너뛰기 + + # 예를 들어, + f< # <로 건너뛰기 + t< # <의 바로 뒤로 건너뛰기 + + # 단어 단위로 이동 + + w # 한 단어 오른쪽으로 이동 + b # 한 단어 왼쪽으로 이동 + e # 현재 단어의 끝으로 이동 + + # 기타 이동 명령어 + + gg # 파일 맨 위로 이동 + G # 파일 맨 아래로 이동 + :NUM # 줄 수 NUM(숫자)로 가기 + H # 화면 꼭대기로 이동 + M # 화면 중간으로 이동 + L # 화면 바닥으로 이동 +``` + +## 모드 + +Vim은 **모드**의 개념에 기초를 두고 있습니다. + +명령어 모드 - vim을 시작하면 처음에 이 모드입니다. 이동과 명령어 입력에 사용합니다. +삽입 모드 - 파일을 수정합니다. +비주얼 모드 - 텍스트를 하이라이트하고 그 텍스트에 대한 작업을 합니다. +실행 모드 - ':' 이후 명령어를 입력합니다. + +``` + i # 커서 위치 앞에서 삽입 모드로 변경 + a # 커서 위치 뒤에서 삽입 모드로 변경 + v # 비주얼 모드로 변경 + : # 실행 모드로 변경 + # 현재 모드를 벗어나 명령어 모드로 변경 + + # 복사와 붙여넣기 + + y # 선택한 객체 복사(Yank) + yy # 현재 줄 복사 + d # 선택한 객체 삭제 + dd # 현재 줄 삭제 + p # 커서 위치 뒤에 복사한 텍스트 붙여넣기 + P # 커서 위치 뒤에 복사한 텍스트 붙여넣기 + x # 현재 커서 위치의 문자 삭제 +``` + +## vim의 문법 + +Vim의 명령어는 '서술어-수식어-목적어'로 생각할 수 있습니다. + +서술어 - 취할 동작 +수식어 - 동작을 취할 방식 +목적어 - 동작을 취할 객체 + +'서술어', '수식어', '목적어'의 예시는 다음과 같습니다. + +``` + # '서술어' + + d # 지운다 + c # 바꾼다 + y # 복사한다 + v # 선택한다 + + # '수식어' + + i # 안에 + a # 근처에 + NUM # (숫자) + f # 찾아서 그곳에 + t # 찾아서 그 앞에 + / # 문자열을 커서 뒤로 찾아서 + ? # 문자열을 커서 앞으로 찾아서 + + # '목적어' + + w # 단어를 + s # 문장을 + p # 문단을 + b # 블락을 + + # 예시 '문장' (명령어) + + d2w # 단어 2개를 지운다 + cis # 문장 안을 바꾼다 + yip # 문단 안을 복사한다 + ct< # 여는 괄호까지 바꾼다 + # 현재 위치에서 다음 여는 괄호까지의 텍스트를 바꾼다 + d$ # 줄 끝까지 지운다 +``` + +## 몇 가지 트릭 + + +``` + > # 선택한 영역 한 칸 들여쓰기 + < # 선택한 영역 한 칸 내어쓰기 + :earlier 15m # 15분 전의 상태로 되돌리기 + :later 15m # 위의 명령어를 취소 + ddp # 이어지는 줄과 위치 맞바꾸기 (dd 후 p) + . # 이전 동작 반복 + :w !sudo tee % # 현재 파일을 루트 권한으로 저장 +``` + +## 매크로 + +매크로는 기본적으로 녹화할 수 있는 동작을 말합니다. +매크로를 녹화하기 시작하면, 끝날 때까지 **모든** 동작과 명령어가 녹화됩니다. +매크로를 호출하면 선택한 텍스트에 대해 정확히 같은 순서의 동작과 명령어가 실행됩니다. + +``` + qa # 'a'라는 이름의 매크로 녹화 시작 + q # 녹화 중지 + @a # 매크로 실행 +``` + +### ~/.vimrc 설정 + +.vimrc 파일은 Vim이 시작할 때의 설정을 결정합니다. + +다음은 ~/.vimrc 파일의 예시입니다. + +``` +" ~/.vimrc 예시 +" 2015.10 + +" vim이 iMprove 되려면 필요 +set nocompatible + +" 자동 들여쓰기 등을 위해 파일 명으로부터 타입 결정 +filetype indent plugin on + +" 신택스 하이라이팅 켜기 +syntax on + +" 커맨드 라인 완성 향상 +set wildmenu + +" 대문자를 썼을 때가 아니면 대소문자 구분하지 않고 검색 +set ignorecase +set smartcase + +" 줄넘김을 했을 때 파일에 따른 들여쓰기가 켜져 있지 않다면 +" 현재 줄과 같은 들여쓰기를 유지 +set autoindent + +" 좌측에 줄 번호 표시 +set number + +" 들여쓰기 설정 (개인 기호에 따라 변경) + +" 탭 하나와 시각적으로 같을 스페이스 개수 +set tabstop=4 + +" 편집할 때 탭 하나에 들어갈 스페이스 수 +set softtabstop=4 + +" 들여쓰기 혹은 내어쓰기 작업(>>, <<)을 했을 때 움직일 스페이스 개수 +set shiftwidth=4 + +" 탭을 스페이스로 변환 +set expandtab + +" 들여쓰기와 정렬에 자동 탭 및 스페이스 사용 +set smarttab +``` + +### 참고 자료 + +[(영어) Vim 홈페이지](http://www.vim.org/index.php) + +`$ vimtutor` + +[(영어) vim 입문과 기초](https://danielmiessler.com/study/vim/) + +[(영어) 엄마가 말해주지 않은 Vim의 어두운 구석들 (Stack Overflow 게시물)](http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about) + +[(영어) 아치 리눅스 위키](https://wiki.archlinux.org/index.php/Vim) -- cgit v1.2.3 From bd1a18fb4472ae4819b551774759a4deb64bcaff Mon Sep 17 00:00:00 2001 From: Ader Date: Thu, 12 Jan 2017 09:02:19 +0000 Subject: [HTML/ar] Translate HTML to Arabic (#2627) Create ar-ar dir and save the file into it. This is just a translation of the html English file. Please consider forcing right-to-left when (and if) this will be added to the website. --- ar-ar/html-ar.html.markdown | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 ar-ar/html-ar.html.markdown diff --git a/ar-ar/html-ar.html.markdown b/ar-ar/html-ar.html.markdown new file mode 100644 index 00000000..2f8ea019 --- /dev/null +++ b/ar-ar/html-ar.html.markdown @@ -0,0 +1,120 @@ +--- +language: html +filename: learnhtml-tf.html +contributors: + - ["Christophe THOMAS", "https://github.com/WinChris"] +translators: + - ["Ader", "https://github.com/y1n0"] +--- + +HTML اختصار ل HyperText Markup Language، أي "لغة ترميز النص التشعبي". +هي لغة تمكننا من كتابة صفحات موجهة لشبكة الويب العالمي. +هي لغة توصيف للنص، تسمح بكتابة صفحات ويب عن طريق تحديد كيفية عرض النصوص والمعلومات. +في الحقيقة، ملفات html هي ملفات تحتوي على نصوص بسيطة. +ما هو توصيف النص هذا؟ هو طريقة لتنظيم معلومات النص عن طريق إحاطته بوُسوم فتح ووسوم غلق. +هذه الوسوم تعطي معاني محددة للنص الذي تحيطه. +كباقي لغات الحاسوب، هناك الكثير من إصدارات HTML. سنتحدث هنا عن HTLM5. + +**ملاحظة:** يمكنك تجريب مختلف الوسوم والعناصر بينما تقرأ الدرس عبر موقع كـ [codepen](http://codepen.io/pen/) حتى ترى تأثيرها وتعرف كيف تعمل وتتعود على استعمالها. +هذه المادة تُعنى أساسا بتركيب HTML .وبعض النصائح المفيدة + + +```html + + + + + + + + + + موقعي + + +

مرحبا بالعالم!

+ الق نظرة كيف يبدو هذا من هنا +

هذه فقرة.

+

هذه فقرة أخرى.

+
    +
  • هذا عنصر من لائحة غير مرقمة. (لائحة بالعرائض)
  • +
  • هذا عنصر آخر
  • +
  • وهذا آخر عنصر في اللائحة
  • +
+ + + + + + + + + + + + + + + + + + + + + موقعي + + + + + + + +

مرحبا بالعالم!

+ + ألق نظرة كيف يبدو هذا من هنا +

هذه فقرة.

+

هذه فقرة أخرى.

+
    + +
  • هذا عنصر من لائحة غير مرقمة. (لائحة بالعرائض)
  • +
  • هذا عنصر آخر
  • +
  • وهذا آخر عنصر في اللائحة
  • +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
العنوان الأول العنوان الثاني
الصف الأول، العمود الأول الصف الأول، العمود الثاني
الصف الثاني، العمود الأولالصف الثاني، العمود الأول
+ +``` + +## الاستعمال + +HTML يُكتب في ملفات تنتهي بـ `.html`. + +## لمعرفة المزيد + +* [wikipedia](https://en.wikipedia.org/wiki/HTML) +* [HTML tutorial](https://developer.mozilla.org/en-US/docs/Web/HTML) +* [W3School](http://www.w3schools.com/html/html_intro.asp) -- cgit v1.2.3 From b57b771dd3aba673c73cddf02b94c454f17b6b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Pokorn=C3=BD?= Date: Thu, 12 Jan 2017 16:00:48 +0100 Subject: [elm/cs] Fixes #2584 for Czech (#2629) --- cs-cz/elm.html.markdown | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cs-cz/elm.html.markdown b/cs-cz/elm.html.markdown index babd46a2..f19f9e8b 100644 --- a/cs-cz/elm.html.markdown +++ b/cs-cz/elm.html.markdown @@ -54,19 +54,19 @@ not False -- True ["příliš", "žluťoučký", "kůň", "úpěl"] [1, 2, 3, 4, 5] -- Druhý příklad lze zapsat také pomocí dvou teček. -[1..5] +List.range 1 5 -- Spojovat seznamy lze stejně jako řetězce. -[1..5] ++ [6..10] == [1..10] -- True +List.range 1 5 ++ List.range 6 10 == List.range 1 10 -- True -- K přidání položky do seznamu použijte funkci "cons". -0 :: [1..5] -- [0, 1, 2, 3, 4, 5] +0 :: List.range 1 5 -- [0, 1, 2, 3, 4, 5] -- Funkce "head" pro získání první položky seznamu i funkce "tail" pro získání následujích položek -- vrací typ Maybe. Místo zjišťování, jestli nějaká položka není null, -- se s chybějcími hodnotami vypořádáme explicitně. -List.head [1..5] -- Just 1 -List.tail [1..5] -- Just [2, 3, 4, 5] +List.head (List.range 1 5) -- Just 1 +List.tail (List.range 1 5) -- Just [2, 3, 4, 5] List.head [] -- Nothing -- List.nazevFunkce odkazuje na funkci, která žije v modulu List. @@ -82,7 +82,7 @@ snd ("elm", 42) -- 42 -- Je to jediná hodnota svého typu, který se také nazývá "Unit". () --- Záznamy jsou podobné n-ticím, ale prvky jsou pojmenovány. Na pořadí nezáleží. +-- Záznamy jsou podobné n-ticím, ale prvky jsou pojmenovány. Na pořadí nezáleží. -- Povšimněte si, že hodnoty vlastností se přiřazují rovnítky, ne dvojtečkami. { x = 3, y = 7 } @@ -153,10 +153,10 @@ odpoved = 42 -- Předejte funkci jako parametr jiným funkcím. -List.map zdvoj [1..4] -- [2, 4, 6, 8] +List.map zdvoj (List.range 1 4) -- [2, 4, 6, 8] -- Nebo použijte anonymní funkci. -List.map (\a -> a * 2) [1..4] -- [2, 4, 6, 8] +List.map (\a -> a * 2) (List.range 1 4) -- [2, 4, 6, 8] -- V definici funkce lze zapsat vzor, může-li nastat pouze jeden případ. -- Tato funkce přijímá jednu dvojici místo dvou parametrů. @@ -182,7 +182,7 @@ fib n = else fib (n - 1) + fib (n - 2) -List.map fib [0..8] -- [1, 1, 2, 3, 5, 8, 13, 21, 34] +List.map fib (List.range 0 8) -- [1, 1, 2, 3, 5, 8, 13, 21, 34] -- Jiná rekurzivní funkce (v praxi použijte List.length). delkaSeznamu seznam = @@ -339,11 +339,11 @@ $ elm repl -- Balíčky jsou určeny uživatelským jménem na GitHubu a názvem repozitáře. -- Nainstalujte nový balíček a uložte jej v souboru elm-package.json. -$ elm package install evancz/elm-html +$ elm package install evancz/elm-lang/html -- Porovnejte změny mezi verzemi jednoho balíčku. -$ elm package diff evancz/elm-html 3.0.0 4.0.2 --- Správce balíčků v Elmu vyžaduje sémantické verzování, +$ elm package diff elm-lang/html 1.1.0 2.0.0 +-- Správce balíčků v Elmu vyžaduje sémantické verzování, -- takže minor verze nikdy nerozbije váš build. ``` -- cgit v1.2.3 From ac680b6a7fe84e55c5ee5ae77034150603f4a028 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Fri, 13 Jan 2017 10:10:10 +0100 Subject: Translate Haskell IO --- pl-pl/haskell-pl.html.markdown | 62 +++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 34 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index f2c31bb4..23de1949 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -317,31 +317,29 @@ Nothing -- typu `Maybe a` for any `a` -- 8. Haskell IO ---------------------------------------------------- --- While IO can't be explained fully without explaining monads, --- it is not hard to explain enough to get going. +-- Chociaż obsługa wejścia i wyjścia nie może zostać wyjaśniona przez poznaniem +-- monad, spróbujemy zrobić to częściowo --- When a Haskell program is executed, `main` is --- called. It must return a value of type `IO a` for some type `a`. For example: +-- Wykonanie programu napisanego w Haskellu wywołuje funkcję `main` +-- Musi zwrócić wartość typu `IO a` dla pewnego `a`. Przykład: main :: IO () main = putStrLn $ "Hello, sky! " ++ (say Blue) -- putStrLn has type String -> IO () --- It is easiest to do IO if you can implement your program as --- a function from String to String. The function +-- Najłatwiej obsłużyć wejście i wyjście, kiedy program zostanie +-- zaimplementowany jako funkcja String -> String. Funkcja -- interact :: (String -> String) -> IO () --- inputs some text, runs a function on it, and prints out the --- output. +-- pobiera pewien tekst, wykonuje na nim operacje, po czym wypisuje wynik. countLines :: String -> String countLines = show . length . lines main' = interact countLines --- You can think of a value of type `IO ()` as representing a --- sequence of actions for the computer to do, much like a --- computer program written in an imperative language. We can use --- the `do` notation to chain actions together. For example: +-- Możesz myśleć o wartości typu `IO ()` jako reprezentującej ciąg czynności, +-- które komputer ma wykonać, zupełnie niczym program komputerowy w imperatywnym +-- języku programowania. Akcje można łączyć przy użyciu notacji `do`: sayHello :: IO () sayHello = do @@ -349,23 +347,20 @@ sayHello = do name <- getLine -- this gets a line and gives it the name "name" putStrLn $ "Hello, " ++ name --- Exercise: write your own version of `interact` that only reads --- one line of input. +-- Ćwiczenie: napisz własną wersję `interact`, +-- która czyta tylko jedną linię wejścia. --- The code in `sayHello` will never be executed, however. The only --- action that ever gets executed is the value of `main`. --- To run `sayHello` comment out the above definition of `main` --- and replace it with: +-- Kod w `sayHello` nigdy się nie wykona. Jedyną akcją, która zostanie +-- uruchomiona, jest wartość `main`. +-- Aby uruchomić `sayHello`, należy zastąpić poprzednią definicję `main` przez -- main = sayHello --- Let's understand better how the function `getLine` we just --- used works. Its type is: +-- Spróbujmy lepiej zrozumieć, jak działa funkcja `getLine`, której właśnie +-- użyliśmy. Jej typem jest -- getLine :: IO String --- You can think of a value of type `IO a` as representing a --- computer program that will generate a value of type `a` --- when executed (in addition to anything else it does). We can --- name and reuse this value using `<-`. We can also --- make our own action of type `IO String`: +-- Możesz myśleć o wartości typu `IO a` jako reprezentującej program, który +-- wygeneruje wartość typu `a`, poza wszystkim innym, co jeszcze zrobi. +-- Możemy także tworzyć własne akcje typu `IO String`: action :: IO String action = do @@ -376,7 +371,7 @@ action = do -- `return` is not a keyword, but merely a function return (input1 ++ "\n" ++ input2) -- return :: String -> IO String --- We can use this just like we used `getLine`: +-- Możemy użyć tego tak jak używaliśmy `getLine`: main'' = do putStrLn "I will echo two lines!" @@ -384,15 +379,14 @@ main'' = do putStrLn result putStrLn "This was all, folks!" --- The type `IO` is an example of a "monad". The way Haskell uses a monad to --- do IO allows it to be a purely functional language. Any function that --- interacts with the outside world (i.e. does IO) gets marked as `IO` in its --- type signature. This lets us reason about what functions are "pure" (don't --- interact with the outside world or modify state) and what functions aren't. - --- This is a powerful feature, because it's easy to run pure functions --- concurrently; so, concurrency in Haskell is very easy. +-- Typ `IO` jest przykładem monady. Sposób w jakim Haskell używa monad do +-- obsługi wejścia i wyjścia pozwala mu być czysto funkcyjnym językiem. +-- Każda funkcja, która wchodzi w interakcje ze światem zewnętrznym, oznaczana +-- jest jako `IO` w jej sygnaturze typu, co umożliwia odróżnianie funkcji +-- czystych od zależnych od świata lub modyfikujących stan. +-- To naprawdę użyteczna własność, dzięki której jesteśmy w stanie uruchamiać +-- czyste funkcje jednocześnie. ---------------------------------------------------- -- 9. Interaktywne środowisko programowania -- cgit v1.2.3 From ca0d124a8e26dc0e9de2534395708ccd6bead7f2 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Fri, 13 Jan 2017 10:31:24 +0100 Subject: Translate more functions --- pl-pl/haskell-pl.html.markdown | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index 23de1949..4de76281 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -178,45 +178,45 @@ myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7] foldl1 (\acc x -> acc + x) [1..5] -- 15 ---------------------------------------------------- --- 4. More functions +-- 4. Więcej funkcji ---------------------------------------------------- --- partial application: if you don't pass in all the arguments to a function, --- it gets "partially applied". That means it returns a function that takes the --- rest of the arguments. +-- częściowe nakładanie: jeśli funkcja nie otrzyma wszystkich swoich argumentów, +-- zostaje cześciowo nałożona - zwraca funkcję, która przyjmuje pozostałe, +-- brakujące argumenty. add a b = a + b -foo = add 10 -- foo is now a function that takes a number and adds 10 to it +foo = add 10 -- foo jest teraz funkcją, która przyjmuje liczbę, zwiększa ją o 10 foo 5 -- 15 --- Another way to write the same thing +-- Inny sposób na zapisanie tego samego: foo = (10+) foo 5 -- 15 --- function composition --- the operator `.` 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 4, and then returns the final value. +-- składanie funkcji: +-- operator `.` składa wiele funkcji w jedną. +-- Dla przykładu, foo jest funkcją, która powiększa swój argument o 10, mnoży +-- tak uzyskaną liczbę przez 4 i zwraca wynik: foo = (4*) . (10+) -- 4*(10 + 5) = 60 foo 5 -- 60 --- fixing precedence --- Haskell has another operator called `$`. This operator applies a function --- to a given parameter. In contrast to standard function application, which --- has highest possible priority of 10 and is left-associative, the `$` operator --- has priority of 0 and is right-associative. Such a low priority means that --- the expression on its right is applied as the parameter to the function on its left. +-- ustalanie kolejności +-- Haskell posiada inny operator, `$`, który nakłada funkcję do podanego +-- parametru. W przeciwieństwie do zwykłego lewostronnie łącznego nakładania +-- funkcji, którego priorytet jest najwyższy (10), operator `$` posiada +-- priorytet 0 i jest prawostronnie łączny. Tak niski priorytet oznacza, że +-- wyrażenie po prawej traktowane jest jako parametr funkcji po lewej --- before -even (fib 7) -- false +-- wcześniej +even (fib 7) -- fałsz --- equivalently -even $ fib 7 -- false +-- równoważnie +even $ fib 7 -- fałsz --- composing functions -even . fib $ 7 -- false +-- składanie funkcji +even . fib $ 7 -- fałsz ---------------------------------------------------- -- cgit v1.2.3 From 5a1df9e1dabda88d1fd83aaa2fc8e6209dd275e0 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Fri, 13 Jan 2017 10:47:08 +0100 Subject: Translate functions --- pl-pl/haskell-pl.html.markdown | 43 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index 4de76281..4c6b0243 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -125,56 +125,53 @@ fst ("haskell", 1) -- "haskell" snd ("haskell", 1) -- 1 ---------------------------------------------------- --- 3. Functions +-- 3. Funkcje ---------------------------------------------------- --- A simple function that takes two variables +-- Prosta funkcja przyjmująca dwa argumenty add a b = a + b --- Note that if you are using ghci (the Haskell interpreter) --- You'll need to use `let`, i.e. +-- Pamiętaj, że podczas stosowania ghci, interpretera Haskella, wszelkie +-- definicje muszą zostać poprzedzone słowem `let`, na przykład: -- let add a b = a + b --- Using the function +-- Używanie funkcji: add 1 2 -- 3 --- You can also put the function name between the two arguments --- with backticks: +-- Nazwę funkcji można podać między dwoma argumentami, ale wtedy musi zostać +-- otoczona grawisami: 1 `add` 2 -- 3 --- You can also define functions that have no letters! This lets --- you define your own operators! Here's an operator that does --- integer division +-- Nazwa funkcji nie musi zawierać żadnych liter, przykładem czego jest +-- operator dzielenia: (//) a b = a `div` b 35 // 4 -- 8 --- Guards: an easy way to do branching in functions +-- Strażnicy: prosty sposób na rozbijanie funkcji na przypadki fib x | x < 2 = 1 | otherwise = fib (x - 1) + fib (x - 2) --- Pattern matching is similar. Here we have given three different --- definitions for fib. Haskell will automatically call the first --- function that matches the pattern of the value. +-- Dopasowanie wzorca jest podobne. Haskell sam automatycznie wybierze, która +-- z poniższych definicji fib powinna zostać użyta: fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) --- Pattern matching on tuples: +-- Dopasowanie z krotkami: foo (x, y) = (x + 1, y + 2) --- Pattern matching on lists. Here `x` is the first element --- in the list, and `xs` is the rest of the list. We can write --- our own map function: +-- Dopasowanie z listami. Tutaj `x` jest pierwszym elementem listy, +-- natomiast `xs` to jej reszta (ogon). Poniższa funkcja nakłada funkcję +-- na każdy z elementów listy: myMap func [] = [] myMap func (x:xs) = func x:(myMap func xs) --- Anonymous functions are created with a backslash followed by --- all the arguments. +-- Funkcje anonimowe tworzone są przy użyciu w-tył-ciachu, po którym następują +-- wszystkie argumenty: myMap (\x -> x + 2) [1..5] -- [3, 4, 5, 6, 7] --- using fold (called `inject` in some languages) with an anonymous --- function. foldl1 means fold left, and use the first value in the --- list as the initial value for the accumulator. +-- używanie zwijania z anonimowymi funkcjami: foldl1 zwija z lewej strony, +-- przyjmując jako wartość początkową zbieracza pierwszy element listy. foldl1 (\acc x -> acc + x) [1..5] -- 15 ---------------------------------------------------- -- cgit v1.2.3 From 5ef6b1074930c552b1dd4a30e556f4e3ffd0e396 Mon Sep 17 00:00:00 2001 From: Remigiusz Suwalski Date: Fri, 13 Jan 2017 18:05:03 +0100 Subject: Add a missing letter --- pl-pl/haskell-pl.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pl-pl/haskell-pl.html.markdown b/pl-pl/haskell-pl.html.markdown index 4c6b0243..5eb68e2e 100644 --- a/pl-pl/haskell-pl.html.markdown +++ b/pl-pl/haskell-pl.html.markdown @@ -5,7 +5,7 @@ contributors: - ["Remigiusz Suwalski", "https://github.com/remigiusz-suwalski"] --- -Haskell został zaprojektowany jako praktyczy, czysto funkcyjny język +Haskell został zaprojektowany jako praktyczny, czysto funkcyjny język programowania. Jest znany przede wszystkim ze względu na jego monady oraz system typów, ale ja lubię do niego wracać przez jego elegancję. Sprawił on, że programowanie jest prawdziwą przyjemnością. -- cgit v1.2.3 From 01a84007d6464dd8044c7792c0d2e45158b8c707 Mon Sep 17 00:00:00 2001 From: Siddharth Gupta Date: Fri, 13 Jan 2017 22:53:13 +0530 Subject: edit broken link in julia.html.markdown --- julia.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/julia.html.markdown b/julia.html.markdown index 5b3f6fd8..a3154f09 100644 --- a/julia.html.markdown +++ b/julia.html.markdown @@ -773,6 +773,6 @@ code_native(circle_area, (Float64,)) ## Further Reading -You can get a lot more detail from [The Julia Manual](http://docs.julialang.org/en/latest/manual/) +You can get a lot more detail from [The Julia Manual](http://docs.julialang.org/en/latest/#Manual-1) The best place to get help with Julia is the (very friendly) [mailing list](https://groups.google.com/forum/#!forum/julia-users). -- cgit v1.2.3 From 96a46ef4c1f706a06e050bf5e39472c8ef744369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Polykanine=20A=2EK=2EA=2E=20Menelion=20Elens=C3=BA?= =?UTF-8?q?l=C3=AB?= Date: Fri, 13 Jan 2017 23:54:30 +0200 Subject: Reverting to Readings as suggested by @sidgupta234; adding myself to contributors --- rst.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rst.html.markdown b/rst.html.markdown index 8897ec2f..59a29daa 100644 --- a/rst.html.markdown +++ b/rst.html.markdown @@ -2,6 +2,7 @@ language: restructured text contributors: - ["DamienVGN", "https://github.com/martin-damien"] + - ["Andre Polykanine", "https://github.com/Oire"] filename: restructuredtext.rst --- @@ -102,6 +103,6 @@ But there are more complex applications that use the RST format: - and many others -## Reading +## Readings - [Official quick reference](http://docutils.sourceforge.net/docs/user/rst/quickref.html) -- cgit v1.2.3 From ff362fc01fa798727c8423d20f093e25702af52b Mon Sep 17 00:00:00 2001 From: Dan Book Date: Sat, 21 Jan 2017 06:06:52 -0500 Subject: [perl/en] how to write to files (#2633) --- perl.html.markdown | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/perl.html.markdown b/perl.html.markdown index 3cbd2801..908f300b 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -170,8 +170,11 @@ $x =~ s/foo/bar/g; # replaces ALL INSTANCES of foo with bar in $x # You can open a file for input or output using the "open()" function. +# For reading: open(my $in, "<", "input.txt") or die "Can't open input.txt: $!"; +# For writing (clears file if it exists): open(my $out, ">", "output.txt") or die "Can't open output.txt: $!"; +# For writing (appends to end of file): open(my $log, ">>", "my.log") or die "Can't open my.log: $!"; # You can read from an open filehandle using the "<>" operator. In @@ -182,6 +185,12 @@ open(my $log, ">>", "my.log") or die "Can't open my.log: $!"; my $line = <$in>; my @lines = <$in>; +# You can write to an open filehandle using the standard "print" +# function. + +print $out @lines; +print $log $msg, "\n"; + #### Writing subroutines # Writing subroutines is easy: -- cgit v1.2.3 From 05614d0920804799aec69fddadac4356c91020a2 Mon Sep 17 00:00:00 2001 From: Dan Book Date: Sat, 21 Jan 2017 07:20:42 -0500 Subject: [perl/en] some more examples of interacting with arrays and hashes (#2632) --- perl.html.markdown | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/perl.html.markdown b/perl.html.markdown index 908f300b..a29fdf1f 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -51,6 +51,13 @@ my @mixed = ("camel", 42, 1.23); # indicate one value will be returned. my $second = $animals[1]; +# The size of an array is retrieved by accessing the array in a scalar +# context, such as assigning it to a scalar variable or using the +# "scalar" operator. + +my $num_animals = @animals; +print "Number of numbers: ", scalar(@numbers), "\n"; + ## Hashes # A hash represents a set of key/value pairs: @@ -67,6 +74,11 @@ my %fruit_color = ( # Hash elements are accessed using curly braces, again with the $ sigil. my $color = $fruit_color{apple}; +# All of the keys or values that exist in a hash can be accessed using +# the "keys" and "values" functions. +my @fruits = keys %fruit_color; +my @colors = values %fruit_color; + # Scalars, arrays and hashes are documented more fully in perldata. # (perldoc perldata). @@ -144,6 +156,12 @@ for (@elements) { print; } +# iterating through a hash (for and foreach are equivalent) + +foreach my $key (keys %hash) { + print $key, ': ', $hash{$key}, "\n"; +} + # the Perlish post-condition way again print for @elements; -- cgit v1.2.3 From 99bd27111258428f247d185e11919a5d0299a161 Mon Sep 17 00:00:00 2001 From: Francieli Viane Date: Thu, 26 Jan 2017 11:57:30 -0200 Subject: [PT-BR/Scala] Translates Scala file to Brazilian Portuguese (#2634) * Translates Scala to brazillian portuguese * Add lang information to file header * [Scala/Pt-Br] adds contributor to translation header --- pt-br/scala-pt.html.markdown | 668 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 668 insertions(+) create mode 100644 pt-br/scala-pt.html.markdown diff --git a/pt-br/scala-pt.html.markdown b/pt-br/scala-pt.html.markdown new file mode 100644 index 00000000..3459f567 --- /dev/null +++ b/pt-br/scala-pt.html.markdown @@ -0,0 +1,668 @@ +--- +language: Scala +filename: learnscala-pt.scala +contributors: + - ["George Petrov", "http://github.com/petrovg"] + - ["Dominic Bou-Samra", "http://dbousamra.github.com"] + - ["Geoff Liu", "http://geoffliu.me"] + - ["Ha-Duong Nguyen", "http://reference-error.org"] +translators: + - ["Francieli Viane", "https://github.com/FFrancieli"] +lang: pt-br +--- + +Scala - a linguagem escalável + +```scala + +///////////////////////////////////////////////// +// 0. O básico +///////////////////////////////////////////////// +/* + Configurando o Scala: + + 1) Baixe o instalador do Scala - http://www.scala-lang.org/downloads + 2) Extraia (unzip ou tar) para sua localização favorita e coloque o subdiretório + bin na variável de ambiente `PATH` +*/ + +/* + Tente o REPL + + Scala tem uma ferramenta chamada REPL (Read-Eval-Print Loop) que é análogo a + interpretadores de linha de comando de outras linguagens. Você pode digitar + qualquer expressão de Scala e o resultado será calculado e impresso. + + O REPL é uma ferramenta muito conveniente para testar e verificar código. Use-o + enquanto você lê o tutorial para explorar os conceitos rapidamente por conta própria. +*/ + +//Inicialize um REPL de Scala executando o comando scala no terminal. Você deve ver o prompt: +$ scala +scala> + +//Por padrão, cada expressão que você executa é salva como um novo valor enumerado: +scala> 2 + 2 +res0: Int = 4 + +// Valores padrões podem ser reutilizados. Observe o tipo do valor exibido no resultado... +scala> res0 + 2 +res1: Int = 6 + +// Scala é uma linguagem fortemente tipada. Você pode usar o REPL para verfificar o tipo +// sem avaliar uma expressão. + +scala> :type (true, 2.0) +(Boolean, Double) + +// As sessões do REPL podem ser salvas +scala> :save /sites/repl-test.scala + +//Arquivos podem ser carregados no REPL +scala> :load /sites/repl-test.scala +Loading /sites/repl-test.scala... +res2: Int = 4 +res3: Int = 6 + +// Você pode pesquisar em seu histórico recente +scala> :h? +1 2 + 2 +2 res0 + 2 +3 :save /sites/repl-test.scala +4 :load /sites/repl-test.scala +5 :h? + +// Agora que você já sabe brincar, vamos aprender um pouco de Scala... + +///////////////////////////////////////////////// +// 1. Introdução +///////////////////////////////////////////////// + +// Comentários de uma linha começam com duas barras + +/* + Comentários com múltiplas linhas, como você já pode ver, são assim. +*/ + +// Imprimir e forçar uma linha na próxima impressão +println("Hello world!") +println(10) +// Hello world! +// 10 + +//Imprimir sem forçar uma nova linha na próxima impressão +print("Hello world") +print(10) +// Hello world10 + +//A declaração de valores pode ser feita usando tanto o var quanto o val. +// Declarações feitas com `val` são imutáveis, enquanto que declarações feitas +// com var são mutáveis. Imutabilidade é uma coisa boa. +val x = 10 // x is now 10 +x = 20 // error: reassignment to val +var y = 10 + = 20 // y agora é 20 + +/* + Scala é uma linguagem estaticamente tipada. Observe ainda que nas declarações + acima nós não especificamos um tipo. Isso se deve a um recurso da linguagem + chamado de inferência. Na maioria dos casos, o compilador do Scala consegue + adivinhar qual tipo é, de forma que você não precisa digitar sempre. Nós + podemos declarar o tipo da variável de maneira explícita asim: +*/ + +val z: Int = 10 +val a: Double = 1.0 + +// Note que a conversão automática de Int para Double, o resultado é 10.0, não 10 +val b: Double = 10 + +//Valores booleanos +true +false + +//Operações booleanas +!true // false +!false // true +true == false // false +10 > 5 // true + +// Matemática é como o de costume +1 + 1 // 2 +2 - 1 // 1 +5 * 3 // 15 +6 / 2 // 3 +6 / 4 // 1 +6.0 / 4 // 1.5 +6 / 4.0 // 1.5 + +// Calcular uma expressão no REPL te dá o tipo e o valor do resultado +1 + 7 + +/* A linha acima resulta em: + scala> 1 + 7 + res29: Int = 8 + + Isso significa que o resultado ao culcular 1 + 7 é um objeto do tipo Int com + valor 8. + + Note que "res29" é o nome de uma variável gerada sequencialmente para guardar + os resultados das expressões que você executa, logo seu nome pode ser + diferente. +*/ + +"Strings em Scala são delimitadas por aspas duplas" +'a' // Um caractere em Scala +// 'Strings com aspas simples não existem em Scala.' <= isso causa um erro. + +// Strings possuem os métodos comuns de Java definidos +"hello world".length +"hello world".substring(2, 6) +"hello world".replace("C", "3") + +// Elas também possuem alguns métodos extras do Scala. Veja também: +scala.collection.immutable.StringOps +"hello world".take(5) +"hello world".drop(5) + +//Interpolação de string: observe o prefixo "s" +val n = 45 +s"We have $n apples" // => "We have 45 apples" + +// Também é possível ter expressões dentro de interpolação de strings +val a = Array(11, 9, 6) +s"My second daughter is ${a(0) - a(2)} years old." // => "My second daughter is 5 years old." +s"We have double the amount of ${n / 2.0} in apples." // => "We have double the amount of 22.5 in apples." +s"Power of 2: ${math.pow(2, 2)}" // => "Power of 2: 4" + +// Formatação de strings interpoladas com o prefixo "f" +f"Power of 5: ${math.pow(5, 2)}%1.0f" // "Power of 5: 25" +f"Square root of 122: ${math.sqrt(122)}%1.4f" // "Square root of 122: 11.0454" + + +// Strings cruas, ignorando caracteres especiais +raw"New line feed: \n. Carriage return: \r." // => "New line feed: \n. Carriage return: \r." + +//Alguns caracteres precisam ser "escapados", ex. uma aspa dupla dentro de uma string + +"They stood outside the \"Rose and Crown\"" // => "They stood outside the "Rose and Crown"" + +// Aspas triplas permitem strings a abrangerem múltiplas linhas e conter Aspas +val html = """
+

Press belo', Joe

+ +
""" + + +///////////////////////////////////////////////// +// 2. Funções +///////////////////////////////////////////////// + +// Funções são definidas da seguinte maneira: +// +// def nomeDaFuncao(args ...): TipoDeRetorno = {body ...} +// +// Se você vem de linguagens mais tradicionais, note a omissão da palavra chave +//return. Em Scala a última expressão no bloco da função é o valor de retorno +def sumOfSquares(x: Int, y: Int): Int = { + val x2 = x * x + val y2 = y * y + x2 + y2 +} + +// As { } podem ser omitidas se o corpo da função possui apenas uma expressão: +def sumOfSquaresShort(x: Int, y: Int): Int = x * x + y * y + +// A sintaxe para chamar funções é familiar: +sumOfSquares(3, 4) // => 25 + +// Você poode usar o nome dos parâmetros para especificá-los numa ordem diferente +def subtract(x: Int, y: Int): Int = x - y + +subtract(10, 3) // => 7 +subtract(y=10, x=3) // => -7 + +// Na maioria dos casos (sendo funções recursivas a a exceção mais notável) o +// tipo de retorno da função pode ser omitido, e o mesmo tipo de inferência que +// vimos nas variáveis funcionará com o valor de retorno da função: +def sq(x: Int) = x * x // O compilador consegue adivinhar que o tipo de retorno é Int + +// Funções podem ter parâmetros padrão: +def addWithDefault(x: Int, y: Int = 5) = x + y +addWithDefault(1, 2) // => 3 +addWithDefault(1) // => 6 + +// Funções anônimas são semelhantes a essa: +(x: Int) => x * x + +// Diferente de defs, até mesmo a entrada de funções anônimas podem ser omitidas +// se o contexto deixar isso claro. Observe o tipo "Int => Int", que significa +// uma função que recebe umn Int e retorna um Int. +val sq: Int => Int = x => x * x + +// Se cada argumento na sua função anônima é usado apenas uma vez, Scala te fornece +// uma maneira ainda mais curta de definí-lo. Estas funções anônimas acabam por +// ser muito comuns, como será mostrado na sessão de estrutura de dados. +val addOne: Int => Int = _ + 1 +val weirdSum: (Int, Int) => Int = (_ * 2 + _ * 3) + +addOne(5) // => 6 +weirdSum(2, 4) // => 16 + +// A palavra chave return existe em Scala, mas só retorna do def mais profundo que o cerca. +//AVISO: O uso do return em Scala é propenso a erros e deve ser evitado. +//Não há efeito em funções anônimas. Per exemplo: +def foo(x: Int): Int = { + val anonFunc: Int => Int = { z => + if (z > 5) + return z // Esta linha faz Z retornar o valor de foo! + else + z + 2 // Esta linha retorna o valor de anonFunc + } + anonFunc(x) // Esta linha retorna o valor de foo +} + +///////////////////////////////////////////////// +// 3. Controle de Fluxo +///////////////////////////////////////////////// + +1 to 5 +val r = 1 to 5 +r.foreach(println) + +r foreach println +///N.B.: Scala é bem flexível quando se fala de pontos e parêntesis - estude as regras +//separadamente. Isso ajuda a escrever DSLs e APIs que são lidas como inglês. + +(5 to 1 by -1) foreach (println) + +// Um loop while +var i = 0 +while (i < 10) { println("i " + i); i += 1 } + +while (i < 10) { println("i " + i); i += 1 } // Sim, de novo. O que aconteceu? Por quê? + +i // Exibe o valor de i. Note que o while é um loop no senso clássico - + // executa sequencialmente enquanto muda a variável do loop. While é muito + // rápido, mas usar os combinadores e compreenões acima é mais fácil + // para entender e paralizar + +// Um loop do-while +i = 0 +do { + println("i ainda é menor que 10") + i += 1 +} while (i < 10) + + +// Recursão é a forma mais idiomática de repetir uma ação em Scala (assim como na +// maioria das linguagens de programação funcional) +// Funções recursivas precisam de um tipo de retorno explícito, o compilador não +// consegue inferir; +// Aqui está o Unit +def showNumbersInRange(a: Int, b: Int): Unit = { + print(a) + if (a < b) + showNumbersInRange(a + 1, b) +} +showNumbersInRange(1, 14) + +// Condicionais + +al x = 10 + +if (x == 1) println("yeah") +if (x == 10) println("yeah") +if (x == 11) println("yeah") +if (x == 11) println("yeah") else println("nay") + +println(if (x == 10) "yeah" else "nope") +val text = if (x == 10) "yeah" else "nope" + +///////////////////////////////////////////////// +// 4. Estrutura de Dados +///////////////////////////////////////////////// + +val a = Array(1, 2, 3, 5, 8, 13) +a(0) // Int = 1 +a(3) // Int = 5 +a(21) // Lança uma exceção + +val safeM = m.withDefaultValue("no lo se") +safeM("bottle") // java.lang.String = no lo se + +val s = Set(1, 3, 7) +s(0) // Boolean = false +s(1) // Boolean = true + +/* Veja a documantação do map aqui - + * http://www.scala-lang.org/api/current/index.html#scala.collection.immutable.Map + * e garanta que você leia + */ + + // Tuplas + + (1, 2) + + (4, 3, 2) + + (1, 2, "three") + + (a, 2, "three") + + //Por que ter isso? + val divideInts = (x: Int, y: Int) => (x / y, x % y) + +//A função divideInts te dá o resultado e o resultado +divideInts(10, 3) // (Int, Int) = (3,1) + +//Para acessar os elementos de uma tupla, use _._n onde n é o índex do elemento + +val d = divideInts(10, 3) // (Int, Int) = (3,1) + +d._1 // Int = 3 +d._2 // Int = 1 + +// Alternativamente, você pode atribuir múltiplas variáveis para uma tupla, o +// que é mais conveniente e legível em muitos casos +val (div, mod) = divideInts(10, 3) + +div // Int = 3 +mod // Int = 1 + +///////////////////////////////////////////////// +// 5. Object Oriented Programming +///////////////////////////////////////////////// + +/* + Tudo o que vimos até agora neste tutorial foram expressões simples (valores, funções, etc). + Essas expressões são boas para digitar no interpretador da linha de comando para + testes rápidos, mas elas não podem existir por si só em um arquivo Scala. Por exemplo, + você não pode ter simplesmente "val x = 5" em um arquivo Scala. Ao invés disso, os únicos + construtores de alto nível permitidos em Scala são: + + - objects + - classes + - case classes + - traits + + E agora vamos explicar o que é cada um deles. +*/ + +//classes são similares a classes em outras linguagens. Os argumentos do construtor +// são declarados logo depois do nome da classe e a inicialização é feita no corpo da classe. + +class Dog(br: String) { + // codigo do construtor aqui + var breed: String = br + + // Define um método chamado bark que retorna uma String + def bark = "Woof, woof!" + + // Assume-se que os métodos e valores são públicos. As palavras chave "protected" + // e "private" também estão disponíveis. + private def sleep(hours: Int) = + println(s"I'm sleeping for $hours hours") + + // Métodos abstratos são simplesmente métodos sem corpo. Se a gente remover o + // comentário da próxima linha a classe Dog teria que ser declarada como abstrata + + // abstract class Dog(...) { ... } + // def chaseAfter(what: String): String +} + +// A palavra chave "object" cria um tipo e uma instância singlenton desse tipo. +// É comum para classes em Scala ter um "companion object" (objeto companheiro), +// onde, por exemlo, o comportamento é capturado pelas classes em si, mas o comportamento +// relacionado a toda instância da classe vai em objects. A diferença é semelhante +// a métodos versus métodos estáticos em outras linguagens. Note que objects e +// classes podem ter o mesmo nome. + +object Dog { + def allKnownBreeds = List("pitbull", "shepherd", "retriever") + def createDog(breed: String) = new Dog(breed) +} + +// Case classes são classes que possuem uma funcionalidade extra incorporada. +// Uma dúvida comum para iniciantes em Scala é quando usar classes e quando usar +// case classes. A linha é bem tênue, mas em geral classes tendem a focar em encapsulamento, +// polimorfismo e comportamento. Os valores nestas classes tendem a ser privados e +// apenas métodos ficam expostos. O propósito primário de uma case class é guardar +// dados imutáveis. Às vezes as case classes possuem alguns poucos métodos, os quais +// raramente possuem efeitos colaterais (side effects). +case class Person(name: String, phoneNumber: String) + +// Cria uma nova instância. Observe que case classes não precisam de usar "new" ao serem instanciadas +val george = Person("George", "1234") +val kate = Person("Kate", "4567") + +// Com case classes você ganha algumas regalias, como getters: +// With case classes, you get a few perks for free, like getters: +george.phoneNumber // => "1234" + +// Verificação de igualdade por campo (sem a necessidade de sobrescrever o método equals) +Person("George", "1234") == Person("Kate", "1236") // => false + +// Uma maneira fácil de copiar +// otherGeorge == Person("george", "9876") +val otherGeorge = george.copy(phoneNumber = "9876") + +// E muitas outras. Case classes também possuem pattern matching de graça. Veja no próximo tópico. + +// Traits a caminho. + + +///////////////////////////////////////////////// +// 6. Pattern Matching +///////////////////////////////////////////////// + +// Pattern matching é um recurso muito poderoso e muito usado em Scala. Aqui +// mostramos como o seu pattern se adequa a uma case class. +// NB: Diferente de outras linguagens, Scala não precisa de quebras. Entrar em +// todas as condições do pattern matching simples não acontece. + +def matchPerson(person: Person): String = person match { + // Enrão você especifica os padrões + case Person("George", number) => "We found George! His number is " + number + case Person("Kate", number) => "We found Kate! Her number is " + number + case Person(name, number) => "We matched someone : " + name + ", phone : " + number +} + +val email = "(.*)@(.*)".r // Define uma regex para o próximo exemplo. + +// Pattern matching pode parecer com o comando switch nas liguagens da família C, +// mas é muito mais poderoso. Em Scala você pode encontrar mais correpondências: + +def matchEverything(obj: Any): String = obj match { + // Você pode encontrar valores correspondentes: + case "Hello world" => "Got the string Hello world" + + // Você pode fazer correspondência por tipo: + case x: Double => "Got a Double: " + x + + // Você pode especificar condições: + case x: Int if x > 10000 => "Got a pretty big number!" + + // Você pode encontrar correspondência com case classes, como fizemos antes: + case Person(name, number) => s"Got contact info for $name!" + + // Você pode encontrar correspondências por regex: + case email(name, domain) => s"Got email address $name@$domain" + + // Você pode encontrar correspondencias por tuplas: + case (a: Int, b: Double, c: String) => s"Got a tuple: $a, $b, $c" + + // Você pode encontrar corresponências por estruturas de dados: + case List(1, b, c) => s"Got a list with three elements and starts with 1: 1, $b, $c" + + // Você pode aninhar padrões: + case List(List((1, 2, "YAY"))) => "Got a list of list of tuple" + + // Retornar qualquer valor (padrão - default) caso nenhuma das possibilidades é correspondente. + case _ => "Got unknown object" + + // Na verdade, você pode fazer correspondência de padrão de qualquer objeto que + // tenha o método "unnaply". Este recurso é tão poderoso que o Scala te deixa + // criar funções inteiras como patterns: + + val patternFunc: Person => String = { + case Person("George", number) => s"George's number: $number" + case Person(name, number) => s"Random person's number: $number" + } +} + +///////////////////////////////////////////////// +// 7. Programação Funcional +///////////////////////////////////////////////// + +// Scala permite que métodos e funções recebam ou retornem outras funções ou métodos. + +val add10: Int => Int = _ + 10 // A function taking an Int and returning an Int +List(1, 2, 3) map add10 // List(11, 12, 13) - add10 is applied to each element + +// Funções anônimas podem ser usadas ao invés de funções com nomes: +List(1, 2, 3) map (x => x + 10) + +// E o símbolo underline ("_") pode ser usado quando há apenas um argumento para a função anônima. +List(1, 2, 3) map (_ + 10) + +// Se tanto o bloco animo quanto a função que você estiver usando receberem apenas +// um argumento, você pode inclusive omitir o símbolo _ +List(1, 2, 3) map (_ + 10) + +// Combinadores + +s.map(sq) + +val sSquared = s. map(sq) + +sSquared.filter(_ < 10) + +sSquared.reduce (_+_) + +// A função filter recebe um predicado (uma função do tipo A -> Boolean) e seleciona +// todos os elementos que satisfazem o predicado. +List(1, 2, 3) filter (_ > 2) // List(3) +case class Person(name: String, age: Int) +List( + Person(name = "Dom", age = 23), + Person(name = "Bob", age = 30) +).filter(_.age > 25) // List(Person("Bob", 30)) + +// Scala tem o método foreach definido em algumas collections em específico, o qual +// recebe um tipo e retorna Unit (um método void) +val aListOfNumbers = List(1, 2, 3, 4, 10, 20, 100) +aListOfNumbers foreach (x => println(x)) +aListOfNumbers foreach println + +/* NB Ests não são laços for. A semântica dos laços for é 'repetir' enquanto um + for-comprehension define um relacionamento entre dois conjuntos de dados */ + + +///////////////////////////////////////////////// +// 8. Implicits +///////////////////////////////////////////////// + +/* ALERTA ALERTA: + Implicits são um conjunto de recursos poderosos de Scala e consequentemente é + fácil abusar deles. Iniciantes em Scala deveriam resistir a tentação de usá-los + até que eles entendam não apenas como eles funcionam mas também as melhores práticas + deles. Incluimos uma sessão neste tutorial sobre isso porque implicits são tão + corriqueiros em bibliotecas do Scala que é impossível fazer qualqeuer coisa expressiva + sem utilizar uma biblioteca que usa implicits. Isto é para você entender e trabalhar + com implicits. Não declare seus próprios implicits por conta própria. +*/ + +// qualquer valor (val, function, objects, etc) pode ser declarado para ser implícito +// usando a, você adivinhou, palavra chave "implicit". Usaremos a classe Dog definida +// na sessão 5 para os próximos exemplos. +implicit val myImplicitInt = 100 +implicit def myImplicitFunction(breed: String) = new Dog("Golden " + breed) + +// A palavra chave implicit não muda o comportamento do valor por si só, então +// os valores acima podem ser usados como de costume. +myImplicitInt + 2 // => 102 +myImplicitFunction("Pitbull").breed // => "Golden Pitbull" + +A diferença é que agora esses valores são elegíveis para serem usados quando outra +// parte do código "precisa" de um valor implícito. Uma situação é uma função +// com argumentos implícitos: +def sendGreetings(toWhom: String)(implicit howMany: Int) = + s"Hello $toWhom, $howMany blessings to you and yours!" + +// Se fornecermos um valor para "howMany" a função se comporta como sempre +sendGreetings("John")(1000) // => "Hello John, 1000 blessings to you and yours!" + +// Mas se omitirmos o parâmetro implícito um valor implícito de mesmo tipo é usado, +// neste caso, "myImplicitInt": +sendGreetings("Jane") // => "Hello Jane, 100 blessings to you and yours!" + +// Parâmetros implícitos de funções nos permitem simular type classes em outras +//linguagens funcionais. As linhas abaixo são a mesma coisa: +// def foo[T](implicit c: C[T]) = ... +// def foo[T : C] = ... + +// Outro caso no qual o compilador procura por um implicit é quando você tem obj.method(...) +// mas "obj" não possui "method" como um método. Neste caso, se houver uma conversão +// de implicit do tipo A => B, onde A é o tipo do "obj" e B tem um método chamado +// "method", a conversão é aplicada. Então, tendo myImplicitFunction acima em escopo, podemos dizer: +"Retriever".breed // => "Golden Retriever" +"Sheperd".bark // => "Woof, woof!" + +// Aqui, a String é convertida para Dog usando nossa função acima, então o método +// apropriado é chamado. Isso é um recurso extremamente poderoso, mas de novo, não +// é para ser usado de maneira leviana. Na verdade, quando você define a função +// implícita, o seu compilador deve exibir um aviso de que você não deveria fazer isso, +// a menos que você realmente saiba o que você está fazendo. + +///////////////////////////////////////////////// +// 9. Misc +///////////////////////////////////////////////// + +// Importando coisas +import scala.collection.immutable.List + +// Importando todos os sub pacotes +import scala.collection.immutable._ + +// Importando várias classes em um único comando +import scala.collection.immutable.{List, Map} + +// Renomeando um import usando '=>' +import scala.collection.immutable.{List => ImmutableList} + +// Importa todas as classes, com exceção de algumas. O import abaixo importa todas as classes excluindo Map e Set: +import scala.collection.immutable.{Map => _, Set => _, _} + +// Classes Java também podem ser importadas. A syntaxe de Scala pode ser usada: +import java.swing.{JFrame, JWindow} + +// O ponto de entrada do seu programa é definido em um arquivo Scala usando um object com um único método main: +object Application { + def main(args: Array[String]): Unit = { + // o código fica aqui + } +} + +// Arquivos podem ter múltiplas classes e objects. Compile com scalac + +// Entrada e saída + +// Para ler um arquivo linha a linha +import scala.io.Source +for(line <- Source.fromFile("myfile.txt").getLines()) + println(line) + +// Para escrever um arquivo use o PrintWriter do Javaval writer = new PrintWriter("myfile.txt") +writer.write("Writing line for line" + util.Properties.lineSeparator) +writer.write("Another line here" + util.Properties.lineSeparator) +writer.close() + +## Recursos adicionais + +* [Scala for the impatient](http://horstmann.com/scala/) +* [Twitter Scala school](http://twitter.github.io/scala_school/) +* [Documentação de Scala](http://docs.scala-lang.org/) +* [Tente Scala no seu navegador](http://scalatutorials.com/tour/) +* Junte [Scala user group](https://groups.google.com/forum/#!forum/scala-user) +``` -- cgit v1.2.3 From 20b2a9a29d485a52b8ab455b6b0fae65678174ef Mon Sep 17 00:00:00 2001 From: ven Date: Sat, 28 Jan 2017 10:22:30 +0100 Subject: Fix swift-tr filename fixes #2635 --- tr-tr/swift-tr.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tr-tr/swift-tr.html.markdown b/tr-tr/swift-tr.html.markdown index 15056bb8..e694d95d 100644 --- a/tr-tr/swift-tr.html.markdown +++ b/tr-tr/swift-tr.html.markdown @@ -2,7 +2,7 @@ language: swift contributors: - ["Özgür Şahin", "https://github.com/ozgurshn/"] -filename: learnswift.swift +filename: learnswift-tr.swift lang: tr-tr --- -- cgit v1.2.3 From 05e4c41cb3e912e19867f9c5adcdaa1b087722f3 Mon Sep 17 00:00:00 2001 From: ghostduck Date: Sat, 28 Jan 2017 17:38:26 +0800 Subject: [python3/en] Add examples to Bool operators with ints (#2639) --- python3.html.markdown | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python3.html.markdown b/python3.html.markdown index 3821d84f..02745117 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -71,11 +71,14 @@ True and False # => False False or True # => True # Note using Bool operators with ints +# False is 0 and True is 1 +# Don't mix up with bool(ints) and bitwise and/or (&,|) 0 and 2 # => 0 -5 or 0 # => -5 0 == False # => True 2 == True # => False 1 == True # => True +-5 != False != True #=> True # Equality is == 1 == 1 # => True -- cgit v1.2.3 From c65e45121aaeca4406111d65d6030391b48f34c3 Mon Sep 17 00:00:00 2001 From: siva008 Date: Sun, 29 Jan 2017 00:15:03 +0530 Subject: Update tcl.html.markdown (#2640) Fixed fold example to return actual result instead of the word "res" --- tcl.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcl.html.markdown b/tcl.html.markdown index d3e80f87..e3e84268 100644 --- a/tcl.html.markdown +++ b/tcl.html.markdown @@ -268,7 +268,7 @@ proc fold {cmd args} { foreach arg $args { set res [$cmd $res $arg] } - return res + return $res } fold ::tcl::mathop::* 5 3 3 ;# -> 45 -- cgit v1.2.3 From 43b7377051ed469fd2f3217246e37baf2242cf86 Mon Sep 17 00:00:00 2001 From: enra Date: Tue, 31 Jan 2017 08:46:07 +0100 Subject: [bash/no-nb] removes to lines of english (#2641) removes to lines of english already translated in the two lines below --- no-nb/bash-no.html.markdown | 2 -- 1 file changed, 2 deletions(-) diff --git a/no-nb/bash-no.html.markdown b/no-nb/bash-no.html.markdown index ab0c064f..481aecbd 100644 --- a/no-nb/bash-no.html.markdown +++ b/no-nb/bash-no.html.markdown @@ -217,8 +217,6 @@ bar () # Å kalle en funksjon: foo "Mitt navn er" $NAME -# There are a lot of useful commands you should learn: -# prints last 10 lines of file.txt # Det er mange nyttige kommandoer du bør lære deg: # "tail" skriver ut slutten av en fil, i dette tilfellet de siste 10 linjene tail -n 10 file.txt -- cgit v1.2.3 From 7f0fff0adf38fb47b36da4a8c319c6c9c28c546d Mon Sep 17 00:00:00 2001 From: Samantha McVey Date: Mon, 6 Feb 2017 23:36:02 -0800 Subject: Fit some more things into 80 columns in the Perl 6 doc --- perl6.html.markdown | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/perl6.html.markdown b/perl6.html.markdown index defd1315..e813978a 100644 --- a/perl6.html.markdown +++ b/perl6.html.markdown @@ -86,10 +86,10 @@ my %hash = key1 => 'value1', key2 => 'value2'; # same result as above # You can also use the "colon pair" syntax: # (especially handy for named parameters that you'll see later) -my %hash = :w(1), # equivalent to `w => 1` - # this is useful for the `True` shortcut: - :truey, # equivalent to `:truey(True)`, or `truey => True` - # and for the `False` one: +my %hash = :w(1), # equivalent to `w => 1` + # this is useful for the `True` shortcut: + :truey, # equivalent to `:truey(True)`, or `truey => True` + # and for the `False` one: :!falsey, # equivalent to `:falsey(False)`, or `falsey => False` ; @@ -125,8 +125,8 @@ hello-to; #=> Hello, World ! hello-to(); #=> Hello, World ! hello-to('You'); #=> Hello, You ! -## You can also, by using a syntax akin to the one of hashes (yay unified syntax !), -## pass *named* arguments to a `sub`. +## You can also, by using a syntax akin to the one of hashes +## (yay unified syntax !), pass *named* arguments to a `sub`. # They're optional, and will default to "Any". sub with-named($normal-arg, :$named) { say $normal-arg + $named; @@ -145,8 +145,8 @@ sub with-mandatory-named(:$str!) { say "$str !"; } with-mandatory-named(str => "My String"); #=> My String ! -with-mandatory-named; # run time error: "Required named parameter not passed" -with-mandatory-named(3); # run time error: "Too many positional parameters passed" +with-mandatory-named; # run time error: "Required named parameter not passed" +with-mandatory-named(3);# run time error:"Too many positional parameters passed" ## If a sub takes a named boolean argument ... sub takes-a-bool($name, :$bool) { @@ -169,9 +169,9 @@ my &s = &say-hello; my &other-s = sub { say "Anonymous function !" } # A sub can have a "slurpy" parameter, or "doesn't-matter-how-many" -sub as-many($head, *@rest) { # `*@` (slurpy) will basically "take everything else". - # Note: you can have parameters *before* (like here) - # a slurpy one, but not *after*. +sub as-many($head, *@rest) { #`*@` (slurpy) will "take everything else" +# Note: you can have parameters *before* a slurpy one (like here), +# but not *after*. say @rest.join(' / ') ~ " !"; } say as-many('Happy', 'Happy', 'Birthday'); #=> Happy / Birthday ! @@ -223,9 +223,9 @@ say $x; #=> 52 # - `if` # Before talking about `if`, we need to know which values are "Truthy" -# (represent True), and which are "Falsey" (or "Falsy") -- represent False. -# Only these values are Falsey: 0, (), {}, "", Nil, A type (like `Str` or `Int`), -# and of course False itself. +# (represent True), and which are "Falsey" (or "Falsy") -- represent False. +# Only these values are Falsey: 0, (), {}, "", Nil, A type (like `Str` or `Int`) +# and of course False itself. # Every other value is Truthy. if True { say "It's true !"; @@ -265,13 +265,14 @@ say $age > 18 ?? "You are an adult" !! "You are under 18"; given "foo bar" { say $_; #=> foo bar - when /foo/ { # Don't worry about smart matching yet – just know `when` uses it. + when /foo/ { # Don't worry about smart matching yet – just know `when` uses it # This is equivalent to `if $_ ~~ /foo/`. say "Yay !"; } - when $_.chars > 50 { # smart matching anything with True (`$a ~~ True`) is True, + when $_.chars > 50 { # smart matching anything with True is True, + # i.e. (`$a ~~ True`) # so you can also put "normal" conditionals. - # This when is equivalent to this `if`: + # This `when` is equivalent to this `if`: # if $_ ~~ ($_.chars > 50) {...} # Which means: # if $_.chars > 50 {...} @@ -288,7 +289,8 @@ given "foo bar" { # but can also be a C-style `for` loop: loop { say "This is an infinite loop !"; - last; # last breaks out of the loop, like the `break` keyword in other languages + last; # last breaks out of the loop, like the `break` keyword in other + # languages } loop (my $i = 0; $i < 5; $i++) { -- cgit v1.2.3 From 3bfb74042f1bb682e729fc79d017cdbb3c8024ba Mon Sep 17 00:00:00 2001 From: Sean Nam Date: Wed, 8 Feb 2017 23:36:49 -0800 Subject: Changed indentation to 4 spaces --- java.html.markdown | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 9bb036cd..c92c09dc 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -52,13 +52,13 @@ public class LearnJava { // point. public static void main (String[] args) { - /////////////////////////////////////// - // Input/Output - /////////////////////////////////////// + /////////////////////////////////////// + // Input/Output + /////////////////////////////////////// - /* - * Ouput - */ + /* + * Ouput + */ // Use System.out.println() to print lines. System.out.println("Hello World!"); -- cgit v1.2.3 From 52ff8f41e4ef9de074081b5ef22c5dfa4dd86f0a Mon Sep 17 00:00:00 2001 From: Sean Nam Date: Wed, 8 Feb 2017 23:39:49 -0800 Subject: Changed more indentation to 4 spaces --- java.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index c92c09dc..7f224e17 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -75,8 +75,8 @@ public class LearnJava { System.out.printf("pi = %.5f", Math.PI); // => pi = 3.14159 /* - * Input - */ + * Input + */ // use Scanner to read input // must import java.util.Scanner; -- cgit v1.2.3 From ade62f5b50ceac56bec6f5b3b2cc961b9e9aa4a4 Mon Sep 17 00:00:00 2001 From: coelhotopetudo Date: Thu, 9 Feb 2017 13:19:42 -0200 Subject: Brief explanation about ' (quote) (#2449) --- elisp.html.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/elisp.html.markdown b/elisp.html.markdown index c88d97f0..16a0311c 100644 --- a/elisp.html.markdown +++ b/elisp.html.markdown @@ -225,6 +225,8 @@ filename: learn-emacs-lisp.el ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Let's store a list of names: +;; If you want to create a literal list of data, use ' to stop it from +;; being evaluated - literally, "quote" the data. (setq list-of-names '("Sarah" "Chloe" "Mathilde")) ;; Get the first element of this list with `car': -- cgit v1.2.3 From 2370ece88c454bc6456ba0c98ed79b189662950f Mon Sep 17 00:00:00 2001 From: Yuri Alessandro Martins Date: Thu, 9 Feb 2017 12:22:42 -0300 Subject: Some translation fixes. (#2421) Improving the consistency of a few sentences. --- pt-br/java-pt.html.markdown | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pt-br/java-pt.html.markdown b/pt-br/java-pt.html.markdown index db087a5f..d2e07225 100644 --- a/pt-br/java-pt.html.markdown +++ b/pt-br/java-pt.html.markdown @@ -7,6 +7,7 @@ contributors: translators: - ["Victor Kléber Santos L. Melo", "http://victormelo.com.br/blog"] - ["Renê Douglas N. de Morais", "mailto:rene.douglas.bsi@gmail.com"] + - ["Yuri Alessandro D. T. Martins", "https://github.com/YuriAlessandro"] lang: pt-br filename: LearnJava-pt.java @@ -407,7 +408,7 @@ class Velocipede extends Bicicleta { // Interfaces // Sintaxe de declaração de Interface -// Interface extends { +// interface extends { // // Constantes // // Declarações de método //} @@ -415,11 +416,15 @@ class Velocipede extends Bicicleta { // Exemplo - Comida: public interface Comestivel { public void comer(); // Qualquer classe que implementa essa interface, deve -                        // Implementar este método. +                        // implementar este método. } public interface Digestivel { public void digerir(); + // Em Java 8, interfaces podem ter métodos default. + // public void digerir() { + // System.out.println("digerindo ..."); + // } } @@ -438,7 +443,7 @@ public class Fruta implements Comestivel, Digestivel { } // Em Java, você pode estender somente uma classe, mas você pode implementar muitas -// Interfaces. Por exemplo: +// interfaces. Por exemplo: public class ClasseExemplo extends ExemploClassePai implements InterfaceUm, InterfaceDois { @@ -461,8 +466,8 @@ public class ClasseExemplo extends ExemploClassePai implements InterfaceUm, //} // Marcar uma classe como abstrata significa que ela contém métodos abstratos que devem -// ser definido em uma classe filha. Semelhante às interfaces, classes abstratas não podem -// ser instanciadas, ao invés disso devem ser extendidas e os métodos abstratos +// ser definidos em uma classe filha. Semelhante às interfaces, classes abstratas não podem +// ser instanciadas, ao invés disso devem ser estendidas e os métodos abstratos // definidos. Diferente de interfaces, classes abstratas podem conter uma mistura de // métodos concretos e abstratos. Métodos em uma interface não podem ter um corpo, // a menos que o método seja estático, e as variáveis sejam finais, por padrão, ao contrário de um @@ -482,7 +487,7 @@ public abstract class Animal // Não há necessidade de inicializar, no entanto, em uma interface     // a variável é implicitamente final e, portanto, tem -    // de ser inicializado. +    // de ser inicializada. protected int idade; public void mostrarIdade() @@ -501,7 +506,7 @@ class Cachorro extends Animal { // Nota: ainda precisamos substituir os métodos abstratos na -    // classe abstrata +    // classe abstrata. @Override public void fazerSom() { @@ -532,13 +537,13 @@ class Cachorro extends Animal //} // Classes finais são classes que não podem ser herdadas e são, portanto, um -// filha final. De certa forma, as classes finais são o oposto de classes abstratas -// Porque classes abstratas devem ser estendidas, mas as classes finais não pode ser +// filho final. De certa forma, as classes finais são o oposto de classes abstratas, +// porque classes abstratas devem ser estendidas, mas as classes finais não podem ser // estendidas. public final class TigreDenteDeSabre extends Animal { // Nota: Ainda precisamos substituir os métodos abstratos na -     // classe abstrata. +    // classe abstrata. @Override public void fazerSom(); { @@ -552,7 +557,7 @@ public abstract class Mamifero() // Sintaxe de Métodos Finais: // final () - // Métodos finais, como, classes finais não podem ser substituídas por uma classe filha, + // Métodos finais, como classes finais, não podem ser substituídos por uma classe filha,     // e são, portanto, a implementação final do método. public final boolean EImpulsivo() { -- cgit v1.2.3 From 7408bd9e43b0847ba438668a75369c3c3820dcef Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 9 Feb 2017 16:23:02 +0100 Subject: Update java-pt.html.markdown --- pt-br/java-pt.html.markdown | 1 - 1 file changed, 1 deletion(-) diff --git a/pt-br/java-pt.html.markdown b/pt-br/java-pt.html.markdown index d2e07225..82989502 100644 --- a/pt-br/java-pt.html.markdown +++ b/pt-br/java-pt.html.markdown @@ -7,7 +7,6 @@ contributors: translators: - ["Victor Kléber Santos L. Melo", "http://victormelo.com.br/blog"] - ["Renê Douglas N. de Morais", "mailto:rene.douglas.bsi@gmail.com"] - - ["Yuri Alessandro D. T. Martins", "https://github.com/YuriAlessandro"] lang: pt-br filename: LearnJava-pt.java -- cgit v1.2.3 From e800bf6f3dca32ded6d70c9fb468f5cbc373ee0b Mon Sep 17 00:00:00 2001 From: Andrew Gallasch Date: Fri, 10 Feb 2017 01:53:20 +1030 Subject: Remove duplicate int declarations (#2521) Duplicate declarations break the build --- java.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java.html.markdown b/java.html.markdown index 12de0c73..772dc25d 100644 --- a/java.html.markdown +++ b/java.html.markdown @@ -83,11 +83,11 @@ public class LearnJava { */ // Initialize a variable using = - int fooInt = 1; + int barInt = 1; // Initialize multiple variables of same type with same // value , , = - int fooInt1, fooInt2, fooInt3; - fooInt1 = fooInt2 = fooInt3 = 1; + int barInt1, barInt2, barInt3; + barInt1 = barInt2 = barInt3 = 1; /* * Variable types -- cgit v1.2.3 From 0ddb15b6b9e124aaaf2109ba5c2b3ac11b1722bb Mon Sep 17 00:00:00 2001 From: Senuros Date: Thu, 9 Feb 2017 16:24:22 +0100 Subject: [yaml/de] improved on german translation for better understanding (#2533) --- de-de/yaml-de.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de-de/yaml-de.html.markdown b/de-de/yaml-de.html.markdown index a46c30f6..54e299ed 100644 --- a/de-de/yaml-de.html.markdown +++ b/de-de/yaml-de.html.markdown @@ -10,7 +10,7 @@ lang: de-de YAML ist eine Sprache zur Datenserialisierung, die sofort von Menschenhand geschrieben und gelesen werden kann. -YAML ist eine Erweiterung von JSON, mit der Erweiterung von syntaktisch wichtigen Zeilenumbrüche und Einrückung sowie in Python. Anders als in Python erlaubt YAML keine Tabulator-Zeichen. +YAML ist ein Superset von JSON mit der Erweiterung um syntaktisch wichtige Zeilenumbrüche und Einrückungen, ähnlich wie auch in Python. Anders als in Python allerdings erlaubt YAML keine Tabulator-Zeichen. ```yaml # Kommentare in YAML schauen so aus. -- cgit v1.2.3 From 5d6fe5601e040455eb5bc9f2a94bcd31332bdd38 Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 9 Feb 2017 16:24:58 +0100 Subject: #2533 --- de-de/yaml-de.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/de-de/yaml-de.html.markdown b/de-de/yaml-de.html.markdown index 54e299ed..25f2edc4 100644 --- a/de-de/yaml-de.html.markdown +++ b/de-de/yaml-de.html.markdown @@ -10,7 +10,7 @@ lang: de-de YAML ist eine Sprache zur Datenserialisierung, die sofort von Menschenhand geschrieben und gelesen werden kann. -YAML ist ein Superset von JSON mit der Erweiterung um syntaktisch wichtige Zeilenumbrüche und Einrückungen, ähnlich wie auch in Python. Anders als in Python allerdings erlaubt YAML keine Tabulator-Zeichen. +YAML ist ein Erweiterung von von JSON mit der Erweiterung um syntaktisch wichtige Zeilenumbrüche und Einrückungen, ähnlich wie auch in Python. Anders als in Python allerdings erlaubt YAML keine Tabulator-Zeichen. ```yaml # Kommentare in YAML schauen so aus. -- cgit v1.2.3 From d064763e9599f3ef4b7bccc1ed7d9df3687367ac Mon Sep 17 00:00:00 2001 From: Patrik Jansson Date: Thu, 9 Feb 2017 16:26:11 +0100 Subject: [haskell/en] some minor fixes (#2550) * [haskell/en] some minor fixes * Minor fixes after comments from @vendethiel --- haskell.html.markdown | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/haskell.html.markdown b/haskell.html.markdown index 4ce1a839..2b6aa2f7 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -68,7 +68,7 @@ not False -- True ---------------------------------------------------- -- Every element in a list must have the same type. --- These two lists are the same: +-- These two lists are equal: [1, 2, 3, 4, 5] [1..5] @@ -77,11 +77,11 @@ not False -- True -- You can create a step in a range. [0,2..10] -- [0, 2, 4, 6, 8, 10] -[5..1] -- This doesn't work because Haskell defaults to incrementing. +[5..1] -- [] (Haskell defaults to incrementing) [5,4..1] -- [5, 4, 3, 2, 1] -- indexing into a list -[1..10] !! 3 -- 4 +[1..10] !! 3 -- 4 (zero-based indexing) -- You can also have infinite lists in Haskell! [1..] -- a list of all the natural numbers @@ -152,8 +152,8 @@ fib x | otherwise = fib (x - 1) + fib (x - 2) -- Pattern matching is similar. Here we have given three different --- definitions for fib. Haskell will automatically call the first --- function that matches the pattern of the value. +-- equations for fib. Haskell will automatically use the first +-- equation whose left hand side pattern matches the value. fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) @@ -198,11 +198,11 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (4*) . (10+) --- 4*(10 + 5) = 60 +-- 4*(10+ 5) = 60 foo 5 -- 60 -- fixing precedence --- Haskell has another operator called `$`. This operator applies a function +-- Haskell has an operator called `$`. This operator applies a function -- to a given parameter. In contrast to standard function application, which -- has highest possible priority of 10 and is left-associative, the `$` operator -- has priority of 0 and is right-associative. Such a low priority means that @@ -244,10 +244,10 @@ double x = x * 2 -- 6. Control Flow and If Expressions ---------------------------------------------------- --- if expressions +-- if-expressions haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome" --- if expressions can be on multiple lines too, indentation is important +-- if-expressions can be on multiple lines too, indentation is important haskell = if 1 == 1 then "awesome" else "awful" @@ -295,11 +295,10 @@ data Color = Red | Blue | Green -- Now you can use it in a function: - say :: Color -> String -say Red = "You are Red!" -say Blue = "You are Blue!" -say Green = "You are Green!" +say Red = "You are Red!" +say Blue = "You are Blue!" +say Green = "You are Green!" -- Your data types can have parameters too: @@ -384,8 +383,8 @@ main'' = do -- The type `IO` is an example of a "monad". The way Haskell uses a monad to -- do IO allows it to be a purely functional language. Any function that -- interacts with the outside world (i.e. does IO) gets marked as `IO` in its --- type signature. This lets us reason about what functions are "pure" (don't --- interact with the outside world or modify state) and what functions aren't. +-- type signature. This lets us reason about which functions are "pure" (don't +-- interact with the outside world or modify state) and which functions aren't. -- This is a powerful feature, because it's easy to run pure functions -- concurrently; so, concurrency in Haskell is very easy. -- cgit v1.2.3 From 0a0080a955c11c9b29757d20c74412e6ced67f16 Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 9 Feb 2017 16:27:29 +0100 Subject: #2550 --- haskell.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haskell.html.markdown b/haskell.html.markdown index 2b6aa2f7..ce804415 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -152,7 +152,7 @@ fib x | otherwise = fib (x - 1) + fib (x - 2) -- Pattern matching is similar. Here we have given three different --- equations for fib. Haskell will automatically use the first +-- equations that define fib. Haskell will automatically use the first -- equation whose left hand side pattern matches the value. fib 1 = 1 fib 2 = 2 @@ -198,7 +198,7 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (4*) . (10+) --- 4*(10+ 5) = 60 +-- 4*(10+5) = 60 foo 5 -- 60 -- fixing precedence -- cgit v1.2.3 From 4e6d0775566f332f78ac3b334533ca18eeb96e4a Mon Sep 17 00:00:00 2001 From: Abhishek C Sharma Date: Thu, 9 Feb 2017 21:00:34 +0530 Subject: Small modifications to definitions of functions (#2495) --- asymptotic-notation.html.markdown | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/asymptotic-notation.html.markdown b/asymptotic-notation.html.markdown index a23ef1c8..6a6df968 100644 --- a/asymptotic-notation.html.markdown +++ b/asymptotic-notation.html.markdown @@ -92,8 +92,8 @@ case, or ceiling of growth for a given function. It provides us with an _**asymptotic upper bound**_ for the growth rate of runtime of an algorithm. Say `f(n)` is your algorithm runtime, and `g(n)` is an arbitrary time complexity you are trying to relate to your algorithm. `f(n)` is O(g(n)), if -for some real constant c (c > 0), `f(n)` <= `c g(n)` for every input size -n (n > 0). +for some real constants c (c > 0) and n0, `f(n)` <= `c g(n)` for every input size +n (n > n0). *Example 1* @@ -110,7 +110,7 @@ Let's look to the definition of Big-O. 3log n + 100 <= c * log n ``` -Is there some constant c that satisfies this for all n? +Is there some pair of constants c, n0 that satisfies this for all n > 0? ``` 3log n + 100 <= 150 * log n, n > 2 (undefined at n = 1) @@ -133,7 +133,7 @@ Let's look at the definition of Big-O. 3 * n^2 <= c * n ``` -Is there some constant c that satisfies this for all n? +Is there some pair of constants c, n0 that satisfies this for all n > 0? No, there isn't. `f(n)` is NOT O(g(n)). ### Big-Omega @@ -141,8 +141,8 @@ Big-Omega, commonly written as **Ω**, is an Asymptotic Notation for the best case, or a floor growth rate for a given function. It provides us with an _**asymptotic lower bound**_ for the growth rate of runtime of an algorithm. -`f(n)` is Ω(g(n)), if for some real constant c (c > 0), `f(n)` is >= `c g(n)` -for every input size n (n > 0). +`f(n)` is Ω(g(n)), if for some real constants c (c > 0) and n0 (n0 > 0), `f(n)` is >= `c g(n)` +for every input size n (n > n0). ### Note @@ -155,8 +155,8 @@ Small-o, commonly written as **o**, is an Asymptotic Notation to denote the upper bound (that is not asymptotically tight) on the growth rate of runtime of an algorithm. -`f(n)` is o(g(n)), if for any real constant c (c > 0), `f(n)` is < `c g(n)` -for every input size n (n > 0). +`f(n)` is o(g(n)), if for some real constants c (c > 0) and n0 (n0 > 0), `f(n)` is < `c g(n)` +for every input size n (n > n0). The definitions of O-notation and o-notation are similar. The main difference is that in f(n) = O(g(n)), the bound f(n) <= g(n) holds for _**some**_ @@ -168,8 +168,8 @@ Small-omega, commonly written as **ω**, is an Asymptotic Notation to denote the lower bound (that is not asymptotically tight) on the growth rate of runtime of an algorithm. -`f(n)` is ω(g(n)), if for any real constant c (c > 0), `f(n)` is > `c g(n)` -for every input size n (n > 0). +`f(n)` is ω(g(n)), if for some real constants c (c > 0) and n0 (n0 > 0), `f(n)` is > `c g(n)` +for every input size n (n > n0). The definitions of Ω-notation and ω-notation are similar. The main difference is that in f(n) = Ω(g(n)), the bound f(n) >= g(n) holds for _**some**_ @@ -180,8 +180,8 @@ _**all**_ constants c > 0. Theta, commonly written as **Θ**, is an Asymptotic Notation to denote the _**asymptotically tight bound**_ on the growth rate of runtime of an algorithm. -`f(n)` is Θ(g(n)), if for some real constants c1, c2 (c1 > 0, c2 > 0), -`c1 g(n)` is < `f(n)` is < `c2 g(n)` for every input size n (n > 0). +`f(n)` is Θ(g(n)), if for some real constants c1, c2 and n0 (c1 > 0, c2 > 0, n0 > 0), +`c1 g(n)` is < `f(n)` is < `c2 g(n)` for every input size n (n > n0). ∴ `f(n)` is Θ(g(n)) implies `f(n)` is O(g(n)) as well as `f(n)` is Ω(g(n)). -- cgit v1.2.3 From 447986c19d2e40536872c4c97c1e5f7a82c29d0d Mon Sep 17 00:00:00 2001 From: Chris C Date: Thu, 9 Feb 2017 09:31:22 -0600 Subject: [perl/en] more perlish iterations on perl5 (#2489) * more perlish iteration c-style 'for' isn't perlish * Update perl.html.markdown removed one of the array iterator loops --- perl.html.markdown | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/perl.html.markdown b/perl.html.markdown index a29fdf1f..93eabea9 100644 --- a/perl.html.markdown +++ b/perl.html.markdown @@ -138,18 +138,16 @@ while (condition) { # for loops and iteration -for (my $i = 0; $i < $max; $i++) { +for my $i (0 .. $max) { print "index is $i"; } -for (my $i = 0; $i < @elements; $i++) { - print "Current element is " . $elements[$i]; -} - for my $element (@elements) { print $element; } +map {print} @elements; + # implicitly for (@elements) { -- cgit v1.2.3 From 7afc3bc59ea6f9f3dfdcdc1bfc65aeb0b9fb67a7 Mon Sep 17 00:00:00 2001 From: c4605 Date: Thu, 9 Feb 2017 23:35:04 +0800 Subject: =?UTF-8?q?[zh-cn/common-lisp]=20when=20describe=20return=20values?= =?UTF-8?q?=20of=20gethash,=20=E4=B8=A4=E4=B8=AA=E5=80=BC=E6=98=AFt=20->?= =?UTF-8?q?=20=E7=AC=AC=E4=BA=8C=E4=B8=AA=E5=80=BC=E6=98=AFt=20(#2614)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/common-lisp-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zh-cn/common-lisp-cn.html.markdown b/zh-cn/common-lisp-cn.html.markdown index c7fe7e2c..b8979ed0 100644 --- a/zh-cn/common-lisp-cn.html.markdown +++ b/zh-cn/common-lisp-cn.html.markdown @@ -289,7 +289,7 @@ nil ; 逻辑假,或者空列表 ;; (通过键)检索对应的值 (gethash 'a *m*) ; => 1, t -;; 注意此处有一细节:Common Lisp往往返回多个值。`gethash`返回的两个值是t,代表找到了这个元素;返回nil表示没有找到这个元素。 +;; 注意此处有一细节:Common Lisp往往返回多个值。`gethash`返回的第二个值是t,代表找到了这个元素;返回nil表示没有找到这个元素。 ;;(译者注:返回的第一个值表示给定的键所对应的值或者nil;) ;;(第二个是一个布尔值,表示在哈希表中是否存在这个给定的键) ;; 例如,如果可以找到给定的键所对应的值,则返回一个t,否则返回nil -- cgit v1.2.3 From 1d99d5a7fddb7f05f91686584ec05b88c49f57c3 Mon Sep 17 00:00:00 2001 From: Jonny Press Date: Thu, 9 Feb 2017 15:38:11 +0000 Subject: added group information (#2568) --- kdb+.html.markdown | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kdb+.html.markdown b/kdb+.html.markdown index 772c8a47..099d1529 100644 --- a/kdb+.html.markdown +++ b/kdb+.html.markdown @@ -2,7 +2,7 @@ language: kdb+ contributors: - ["Matt Doherty", "https://github.com/picodoc"] - - ["Jonny Press", "jonny.press@aquaq.co.uk"] + - ["Jonny Press", "https://github.com/jonnypress"] filename: learnkdb.q --- @@ -26,6 +26,8 @@ separable so this distinction is not really useful. All Feedback welcome! You can reach me at matt.doherty@aquaq.co.uk, or Jonny at jonny.press@aquaq.co.uk +To learn more about kdb+ you can join the [Personal kdb+](https://groups.google.com/forum/#!forum/personal-kdbplus) or [TorQ kdb+](https://groups.google.com/forum/#!forum/kdbtorq) group. + ``` / Single line comments start with a forward-slash / These can also be used in-line, so long as at least one whitespace character -- cgit v1.2.3 From b4ca1f76e2d5b955b011ea8d9b38212634fb1777 Mon Sep 17 00:00:00 2001 From: Evan Date: Thu, 9 Feb 2017 17:57:30 +0200 Subject: Python decorators example added (#2408) --- python.html.markdown | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/python.html.markdown b/python.html.markdown index bd6090c7..f8936e65 100644 --- a/python.html.markdown +++ b/python.html.markdown @@ -5,6 +5,7 @@ contributors: - ["Amin Bandali", "http://aminbandali.com"] - ["Andre Polykanine", "https://github.com/Oire"] - ["evuez", "http://github.com/evuez"] + - ["asyne", "https://github.com/justblah"] - ["habi", "http://github.com/habi"] filename: learnpython.py --- @@ -751,6 +752,24 @@ gen_to_list = list(values) print(gen_to_list) # => [-1, -2, -3, -4, -5] # Decorators +# A decorator is a higher order function, which accepts and returns a function. +# Simple usage example – add_apples decorator will add 'Apple' element into +# fruits list returned by get_fruits target function. +def add_apples(func): + def get_fruits(): + fruits = func() + fruits.append('Apple') + return fruits + return get_fruits + +@add_apples +def get_fruits(): + return ['Banana', 'Mango', 'Orange'] + +# Prints out the list of fruits with 'Apple' element in it: +# Banana, Mango, Orange, Apple +print ', '.join(get_fruits()) + # in this example beg wraps say # Beg will call say. If say_please is True then it will change the returned # message -- cgit v1.2.3 From eb1ed1729b9d9539e16e17590cfb911cd72a279e Mon Sep 17 00:00:00 2001 From: angelsl Date: Fri, 10 Feb 2017 00:40:04 +0800 Subject: [csharp/en] Add exception filters, pragma directives (#2409) * [csharp/en] Add exception filters, pragma directives * Remove redundant catch --- csharp.html.markdown | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-) diff --git a/csharp.html.markdown b/csharp.html.markdown index 442700a6..cca99fb0 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -1006,15 +1006,101 @@ on a new line! ""Wow!"", the masses cried"; // x?.y will return null immediately if x is null; y is not evaluated => GenieName?.ToUpper(); } + + static class MagicService + { + private static bool LogException(Exception ex) + { + /* log exception somewhere */ + return false; + } + + public static bool CastSpell(string spell) + { + try + { + // Pretend we call API here + throw new MagicServiceException("Spell failed", 42); + + // Spell succeeded + return true; + } + // Only catch if Code is 42 i.e. spell failed + catch(MagicServiceException ex) when (ex.Code == 42) + { + // Spell failed + return false; + } + // Other exceptions, or MagicServiceException where Code is not 42 + catch(Exception ex) when (LogException(ex)) + { + // Execution never reaches this block + // The stack is not unwound + } + return false; + // Note that catching a MagicServiceException and rethrowing if Code + // is not 42 or 117 is different, as then the final catch-all block + // will not catch the rethrown exception + } + } + + public class MagicServiceException : Exception + { + public int Code { get; } + + public MagicServiceException(string message, int code) : base(message) + { + Code = code; + } + } + + public static class PragmaWarning { + // Obsolete attribute + [Obsolete("Use NewMethod instead", false)] + public static void ObsoleteMethod() + { + /* obsolete code */ + } + + public static void NewMethod() + { + /* new code */ + } + + public static void Main() + { + ObsoleteMethod(); // CS0618: 'ObsoleteMethod is obsolete: Use NewMethod instead' +#pragma warning disable CS0618 + ObsoleteMethod(); // no warning +#pragma warning restore CS0618 + ObsoleteMethod(); // CS0618: 'ObsoleteMethod is obsolete: Use NewMethod instead' + } + } } // End Namespace + +using System; +// C# 6, static using +using static System.Math; + +namespace Learning.More.CSharp +{ + class StaticUsing + { + static void Main() + { + // Without a static using statement.. + Console.WriteLine("The square root of 4 is {}.", Math.Sqrt(4)); + // With one + Console.WriteLine("The square root of 4 is {}.", Sqrt(4)); + } + } +} ``` ## Topics Not Covered * Attributes - * async/await, pragma directives - * Exception filters - * `using static` + * async/await * Web Development * ASP.NET MVC & WebApi (new) * ASP.NET Web Forms (old) -- cgit v1.2.3 From feff890a569cfa3df3715a0283f87a7ef3e169f1 Mon Sep 17 00:00:00 2001 From: Bastien Date: Thu, 9 Feb 2017 17:41:11 +0100 Subject: `[fr/elisp]` Add french translation of the elisp tutorial (#2570) * clojure.html.markdown: Fix an error (s/value/key) * Add french translation of the elisp tutorial. * elisp: s/http/https * fr-fr/elisp: Fix typo and missing translation. * fr-fr/elisp: Fix spaces * elisp: Add contributor. * fr-fr/elisp: s/mini-buffer/minibuffer. * fr-fr/elisp: Fix translation. * fr-fr/elisp: Fix translation. * fr-fr/elisp: Fix typo. * fr-fr/elisp: Fix missing translation. * fr-fr/elisp: Fix content. * fr-fr/elisp: Fix typo. * fr-fr/elisp: Fix keybindings display. * fr-fr/elisp: Fix double space. * fr-fr/elisp: Fix double space. * fr-fr/elisp: Fix more spaces. * fr-fr:elisp: Fix double space. --- elisp.html.markdown | 4 +- fr-fr/elisp-fr.html.markdown | 372 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 374 insertions(+), 2 deletions(-) create mode 100644 fr-fr/elisp-fr.html.markdown diff --git a/elisp.html.markdown b/elisp.html.markdown index 16a0311c..bda5f00f 100644 --- a/elisp.html.markdown +++ b/elisp.html.markdown @@ -1,7 +1,7 @@ --- language: elisp contributors: - - ["Bastien Guerry", "http://bzg.fr"] + - ["Bastien Guerry", "https://bzg.fr"] - ["Saurabh Sandav", "http://github.com/SaurabhSandav"] filename: learn-emacs-lisp.el --- @@ -9,7 +9,7 @@ filename: learn-emacs-lisp.el ```scheme ;; This gives an introduction to Emacs Lisp in 15 minutes (v0.2d) ;; -;; Author: Bastien / @bzg2 / http://bzg.fr +;; Author: Bastien / @bzg2 / https://bzg.fr ;; ;; First make sure you read this text by Peter Norvig: ;; http://norvig.com/21-days.html diff --git a/fr-fr/elisp-fr.html.markdown b/fr-fr/elisp-fr.html.markdown new file mode 100644 index 00000000..2e0a9408 --- /dev/null +++ b/fr-fr/elisp-fr.html.markdown @@ -0,0 +1,372 @@ +--- +language: elisp +contributors: + - ["Bastien Guerry", "https://bzg.fr"] + - ["Saurabh Sandav", "http://github.com/SaurabhSandav"] +translators: + - ["Bastien Guerry", "https://bzg.fr"] +filename: learn-emacs-lisp-fr.el +lang: fr-fr +--- + +```scheme +;; Ceci est une introduction à Emacs Lisp en 15 minutes (v0.2d) +;; +;; Auteur : Bastien / @bzg2 / https://bzg.fr +;; +;; Prenez d'abord le temps de lire ce texte en anglais de Peter Norvig : +;; http://norvig.com/21-days.html +;; +;; Ensuite installez GNU Emacs 24.3 (ou une version ultérieure) : +;; +;; Debian : apt-get install emacs (voir les instructions pour votre distribution) +;; MacOSX : http://emacsformacosx.com/emacs-builds/Emacs-24.3-universal-10.6.8.dmg +;; Windows : http://ftp.gnu.org/gnu/windows/emacs/emacs-24.3-bin-i386.zip +;; +;; Vous trouverez plus d'informations sur l'installation : +;; http://www.gnu.org/software/emacs/#Obtaining + +;; Avertissement important : +;; +;; Suivre ce tutoriel ne risque pas d'endommager votre ordinateur, +;; sauf si vous vous énervez au point de le jeter par terre. En tout +;; cas, je décline toute responsabilité en cas de problème. +;; Amusez-vous bien ! + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Lancez Emacs. +;; +;; Tapez la touche "q" pour enlever le message d'accueil. +;; +;; Maintenant regardez la ligne grise au pied de la fenêtre : +;; +;; "*scratch*" est le nom de l'espace d'édition dans lequel vous vous +;; trouvez. Cet espace d'édition est appelé un "buffer". +;; +;; Le buffer scratch est le buffer par défaut quand on ouvre Emacs. +;; Vous n'éditez jamais de fichier directement : vous éditez des +;; buffers que vous pouvez sauvegarder dans des fichiers. +;; +;; "Lisp interaction" désigne le jeu de commandes disponible ici. +;; +;; Emacs a un jeu de commandes par défaut pour chaque buffer, et +;; plusieurs autres jeux de commandes disponibles quand vous activez +;; un mode particulier. Ici nous utilisons `lisp-interaction-mode', +;; qui propose des commandes pour évaluer et naviguer dans du code +;; Elisp. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Le point-virgule commence un commentaire partout sur une ligne. +;; +;; Les programmes Elisp sont composés d'expressions symboliques aussi +;; appelées "sexps" : +(+ 2 2) + +;; Cette expression symbolique se lit "Ajouter 2 à 2". + +;; Les sexps sont placées entre parenthèses, possiblement sur +;; plusieurs niveaux : +(+ 2 (+ 1 1)) + +;; Une expression symbolique contient des atomes ou d'autres +;; expressions symboliques. Dans les exemples ci-dessus, 1 et 2 sont +;; des atomes et (+ 2 (+ 1 1)) et (+ 1 1) des expressions symboliques. + +;; Dans le mode `lisp-interaction-mode' vous pouvez évaluer les sexps. +;; Placez le curseur juste après la parenthèse fermante, tenez la +;; touche "Control" enfoncée et appuyez sur la touche "j" (soit le +;; raccourci "C-j"). + +(+ 3 (+ 1 2)) +;; ^ curseur ici +;; `C-j' => 6 + +;; `C-j' insère le résultat de l'évaluation dans le buffer. + +;; `C-x C-e' affiche le même résultat dans la ligne tout en bas +;; d'Emacs, appelée le "minibuffer". On utilise en général `C-x C-e', +;; pour ne pas encombrer le buffer avec du texte inutile. + +;; `setq' assigne une valeur à une variable : +(setq my-name "Bastien") +;; `C-x C-e' => "Bastien" (affiché dans le minibuffer) + +;; `insert' va insérer "Hello!" là où se trouve le curseur : +(insert "Hello!") +;; `C-x C-e' => "Hello!" + +;; Nous utilisons `insert' avec un seul argument "Hello!", mais +;; nous pouvons passer plus d'arguments - ici nous en passons deux : + +(insert "Hello" " world!") +;; `C-x C-e' => "Hello world!" + +;; Vous pouvez utiliser des variables au lieu de chaînes de caractères : +(insert "Hello, I am " my-name) +;; `C-x C-e' => "Hello, I am Bastien" + +;; Vous pouvez combiner les sexps en fonctions : +(defun hello () (insert "Hello, I am " my-name)) +;; `C-x C-e' => hello + +;; Vous pouvez évaluer les fonctions : +(hello) +;; `C-x C-e' => Hello, I am Bastien + +;; Les parenthèses vides dans la définition de la fonction signifient +;; qu'elle ne prend pas d'argument. Mais toujours utiliser `my-name' +;; est ennuyant, demandons à la fonction d'accepter un argument (ici +;; l'argument est appelé "name") : + +(defun hello (name) (insert "Hello " name)) +;; `C-x C-e' => hello + +;; Maintenant appelons la fonction avec la chaîne de caractères "you" +;; comme valeur de son unique argument : +(hello "you") +;; `C-x C-e' => "Hello you" + +;; Youpi! + +;; Faites une pause. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Maintenant ouvrez un nouveau buffer appelé "*test*" dans une +;; nouvelle fenêtre : + +(switch-to-buffer-other-window "*test*") +;; `C-x C-e' +;; => [l'écran a deux fenêtres et le curseur est dans le buffer *test*] + +;; Placez la souris sur la fenêtre du haut et cliquez-gauche pour +;; retourner dans cette fenêtre. Ou bien utilisez `C-x o' (i.e. tenez +;; control-x appuyé et appuyez sur o) pour aller dans l'autre fenêtre +;; interactivement. + +;; Vous pouvez combiner plusieurs sexps avec `progn' : +(progn + (switch-to-buffer-other-window "*test*") + (hello "you")) +;; `C-x C-e' +;; => [L'écran a deux fenêtres et le curseur est dans le buffer *test*] + +;; Maintenant si ça ne vous dérange pas, je vais arrêter de vous +;; demander de faire `C-x C-e' : faites-le pour chaque sexp qui suit. + +;; Retournez toujours dans le buffer *scratch* avec la souris ou `C-x o'. + +;; Il est souvent utile d'effacer le contenu du buffer : +(progn + (switch-to-buffer-other-window "*test*") + (erase-buffer) + (hello "there")) + +;; Ou d'aller à l'autre fenêtre : +(progn + (switch-to-buffer-other-window "*test*") + (erase-buffer) + (hello "you") + (other-window 1)) + +;; Vous pouvez associer une valeur à une variable locale avec `let' : +(let ((local-name "you")) + (switch-to-buffer-other-window "*test*") + (erase-buffer) + (hello local-name) + (other-window 1)) + +;; Dans ce cas pas besoin d'utiliser `progn' puisque `let' combine +;; aussi plusieurs sexps. + +;; Mettons en forme une chaîne de caractères : +(format "Hello %s!\n" "visitor") + +;; %s désigne l'emplacement de la chaîne, remplacé par "visitor". +;; \n est le caractère de saut de ligne. + +;; Améliorons notre fonction en utilisant "format" : +(defun hello (name) + (insert (format "Hello %s!\n" name))) + +(hello "you") + +;; Créons une autre fonction qui utilise `let' : +(defun greeting (name) + (let ((your-name "Bastien")) + (insert (format "Hello %s!\n\nI am %s." + name ; l'argument de la fonction + your-name ; la variable "let-bindée" "Bastien" + )))) + +;; Et évaluons-la : +(greeting "you") + +;; Certaines fonctions sont interactives : +(read-from-minibuffer "Enter your name: ") + +;; Évaluer cette fonction va renvoyer ce que vous avez saisi dans le +;; minibuffer. + +;; Faisons que notre fonction `greeting' vous demande votre nom : +(defun greeting (from-name) + (let ((your-name (read-from-minibuffer "Enter your name: "))) + (insert (format "Hello!\n\nI am %s and you are %s." + from-name ; l'argument de la fonction + your-name ; la variable "let-bindée", entrée dans le minibuffer + )))) + +(greeting "Bastien") + +;; Complétons la fonction pour qu'elle affiche le résultat dans +;; l'autre fenêtre : +(defun greeting (from-name) + (let ((your-name (read-from-minibuffer "Enter your name: "))) + (switch-to-buffer-other-window "*test*") + (erase-buffer) + (insert (format "Hello %s!\n\nI am %s." your-name from-name)) + (other-window 1))) + +;; Maintenant testons : +(greeting "Bastien") + +;; Faites une pause. + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; Stockons une liste de noms : +(setq list-of-names '("Sarah" "Chloe" "Mathilde")) + +;; Récupérez le premier élément de la liste avec `car' : +(car list-of-names) + +;; Récupérez tous les élements sauf le premier avec `cdr' : +(cdr list-of-names) + +;; Ajoutez un élément au début avec `push' : +(push "Stephanie" list-of-names) + +;; Note : `car' et `cdr' ne modifient pas la liste, mais `push' oui. +;; C'est une différence importante : certaines fonctions n'ont pas +;; d'effets de bord (comme `car') et d'autres oui (comme `push'). + +;; Évaluons `hello' pour tous les éléments dans `list-of-names' : +(mapcar 'hello list-of-names) + +;; Améliorons `greeting' pour dire hello aux noms de `list-of-names' : +(defun greeting () + (switch-to-buffer-other-window "*test*") + (erase-buffer) + (mapcar 'hello list-of-names) + (other-window 1)) + +(greeting) + +;; Vous vous souvenez de la fonction `hello' définie ci-dessus ? Elle +;; prend seulement un argument, un nom. `mapcar' appelle `hello' en +;; utilisant successivement chaque élément de `list-of-names' comme +;; argument de `hello'. + +;; Maintenant arrangeons un peu ce qui est affiché dans le buffer : + +(defun replace-hello-by-bonjour () + (switch-to-buffer-other-window "*test*") + (goto-char (point-min)) + (while (search-forward "Hello") + (replace-match "Bonjour")) + (other-window 1)) + +;; (goto-char (point-min)) va au début du buffer. +;; (search-forward "Hello") cherche la chaîne "Hello". +;; (while x y) évalue la sexp(s) y tant que x renvoie quelque chose. +;; Si x renvoie `nil' (rien), nous sortons de la boucle. + +(replace-hello-by-bonjour) + +;; Vous devriez voir toutes les occurrences de "Hello" dans le buffer +;; *test* remplacées par "Bonjour". + +;; Vous devriez aussi avoir une erreur : "Search failed: Hello". +;; +;; Pour éviter cette erreur, il faut dire à `search-forward' si la +;; recherche doit s'arrêter à un certain point du buffer, et si elle +;; doit s'arrêter silencieusement si aucune chaîne n'est trouvée. + +;; (search-forward "Hello" nil t) fait ça : + +;; L'argument `nil' indique que la recherche n'est pas limitée à une +;; position. L'argument `t' indique de s'arrêter silencieusement si +;; rien n'est trouvé. + +;; Nous utilisons cette sexp dans la fonction ci-dessous, qui ne +;; renvoie pas d'erreur : + +(defun hello-to-bonjour () + (switch-to-buffer-other-window "*test*") + (erase-buffer) + ;; Dit hello aux noms de `list-of-names' + (mapcar 'hello list-of-names) + (goto-char (point-min)) + ;; Remplace "Hello" par "Bonjour" + (while (search-forward "Hello" nil t) + (replace-match "Bonjour")) + (other-window 1)) + +(hello-to-bonjour) + +;; Mettons les noms en gras : + +(defun boldify-names () + (switch-to-buffer-other-window "*test*") + (goto-char (point-min)) + (while (re-search-forward "Bonjour \\(.+\\)!" nil t) + (add-text-properties (match-beginning 1) + (match-end 1) + (list 'face 'bold))) + (other-window 1)) + +;; Cette fonction introduit `re-search-forward' : au lieu de chercher +;; la chaîne "Bonjour", nous cherchons un "pattern" en utilisant une +;; "expression régulière" (le préfixe "re-" signifie "regular +;; expression"). + +;; L'expression régulière est "Bonjour \\(.+\\)!" et se lit : +;; la chaîne "Bonjour ", et +;; un groupe de | c'est la syntaxe \\( ... \\) +;; n'importe quel caractère | c'est le . +;; une ou plusieurs fois | c'est le + +;; et la chaîne "!". + +;; Prêt ? Testons ! + +(boldify-names) + +;; `add-text-properties' ajoute des propriétés textuelles telle que +;; des "faces" (une "face" définit la fonte, la couleur, la taille et +;; d'autres propriétés du texte.) + +;; Et voilà, c'est fini. Happy hacking! + +;; Si vous voulez en savoir plus sur une variable ou une fonction : +;; +;; C-h v une-variable RET +;; C-h f une-fonction RET +;; +;; Pour lire le manuel Emacs Lisp avec Emacs : +;; +;; C-h i m elisp RET +;; +;; Pour lire en ligne une introduction à Emacs Lisp : +;; https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html + +;; Merci à ces personnes pour leurs retours et suggetions : +;; - Wes Hardaker +;; - notbob +;; - Kevin Montuori +;; - Arne Babenhauserheide +;; - Alan Schmitt +;; - LinXitoW +;; - Aaron Meurer +``` -- cgit v1.2.3 From 45de0120d641cfaac0bb60b25a24782ec106e719 Mon Sep 17 00:00:00 2001 From: zygimantus Date: Thu, 9 Feb 2017 21:01:50 +0200 Subject: tmux lithuanian translation added (#2582) --- lt-lt/tmux-lt.html.markdown | 254 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 lt-lt/tmux-lt.html.markdown diff --git a/lt-lt/tmux-lt.html.markdown b/lt-lt/tmux-lt.html.markdown new file mode 100644 index 00000000..b5b3de05 --- /dev/null +++ b/lt-lt/tmux-lt.html.markdown @@ -0,0 +1,254 @@ +--- +category: tool +tool: tmux +filename: tmux.json +lang: lt-lt +contributors: + - ["mdln", "https://github.com/mdln"] +translators: + - ["Zygimantus", "https://github.com/zygimantus"] +--- + + +[tmux](http://tmux.sourceforge.net) +yra terminalo daugintuvas: jis leidžia vienu metu sukurti, turėti +ir valdyti kelis terminalus viename ekrane. tmux gali būti atjungtas +nuo ekrano ir veikti fone, o vėliau gali būti vėl prijungtas. + + +``` + + tmux [komanda] # Vykdyti komandą + # 'tmux' be komandų sukurs naują sesiją + + new # Sukurti naują sesiją + -s "Session" # Sukurti pavadintą sesiją + -n "Window" # Sukurti pavadintą langą + -c "/dir" # Pradėti nurodytoje direktorijoje + + attach # Priskirti paskutinę/prienamą sesiją + -t "#" # Priskirti nurodytą sesiją + -d # Atjungti sesiją nuo kitų langų + + ls # Aktyvių sesijų sąrašas + -a # Visų aktyvių sesijų sąrašas + + lsw # Langų sąrašas + -a # Visų langų sąrašas + -s # Visų langų sesijoje sąrašas + + lsp # Skydelių sąrašas + -a # Visų skydelių sąrašas + -s # Visų skydelių sesijoje sąrašas + -t # Visų skydelių taikinyje sąrašas + + kill-window # Užbaigti dabartinį langą + -t "#" # Užbaigti nurodytą langą + -a # Užbaigti visus langus + -a -t "#" # Užbaigti visus langus, bet ne taikinį + + kill-session # Užbaigti dabartinę sesiją + -t "#" # Užbaigti nurodytą sesiją + -a # Užbaigti visas sesijas + -a -t "#" # Užbaigti visas sesijas, bet ne taikinį + +``` + + +### Klavišai + +Priskirta tmux sesija yra valdoma klavišų kompinacijomis. + +``` +---------------------------------------------------------------------- + (C-b) = Ctrl + b # Kombinacija reikalinga norint naudoti klavišus + + (M-1) = Meta + 1 -or- Alt + 1 +---------------------------------------------------------------------- + + ? # Rodo visų klavišų kombinacijų sąrašą + : # Įjungiama tmux komandinė eilutė + r # Priverstinai perpiešiamas prijungtas klientas + c # Sukurti naują langą + + ! # Iškelia esamą skydelį iš lango. + % # Perskelia esamą skydelį į du, kairįjį ir dešinį + " # Perskelia esamą skydelį į du, viršutinį ir apatinį + + n # Pakeičia į kitą langą + p # Pakeičia į buvusį langą + { # Apkeičia dabartinį skydėlį su buvusiu + } # Apkeičia dabartinį skydėlį su sekančiu + + s # Pasirinkti naują sesiją prijungtam klientui interaktyviai + w # Pasirinkti dabartinį langą interaktyviai + 0 to 9 # Pasirinkti langą nuo 0 iki 9 + + d # Atjungti dabartinį klientą + D # Pasirinkti klientą, kurį atjungti + + & # Užbaigti dabartinį langą + x # Užbaigti dabartinį skydelį + + Up, Down # Pakeisti į skydelį viršuje, apačioje, kairėje arba + dešinėje + Left, Right + + M-1 to M-5 # Rikiuoti skydelius: + # 1) even-horizontal + # 2) even-vertical + # 3) main-horizontal + # 4) main-vertical + # 5) tiled + + C-Up, C-Down # Keisti esamo skydelio dydį vienos ląstelės žingsniu + C-Left, C-Right + + M-Up, M-Down # Keisti esamo skydelio dydį penkių ląstelių žingsniu + M-Left, M-Right + +``` + + +### Configuring ~/.tmux.conf + +tmux.conf gali būti nustatytas automatiškai paleidimo metu, panašiai kaip ir +.vimrc arba init.el. + +``` +# Pavyzdys tmux.conf +# 2014.10 + + +### General +########################################################################### + +# Enable UTF-8 +setw -g utf8 on +set-option -g status-utf8 on + +# Scrollback/History limit +set -g history-limit 2048 + +# Index Start +set -g base-index 1 + +# Mouse +set-option -g mouse-select-pane on + +# Force reload of config file +unbind r +bind r source-file ~/.tmux.conf + + +### Keybinds +########################################################################### + +# Unbind C-b as the default prefix +unbind C-b + +# Set new default prefix +set-option -g prefix ` + +# Return to previous window when prefix is pressed twice +bind C-a last-window +bind ` last-window + +# Allow swapping C-a and ` using F11/F12 +bind F11 set-option -g prefix C-a +bind F12 set-option -g prefix ` + +# Keybind preference +setw -g mode-keys vi +set-option -g status-keys vi + +# Moving between panes with vim movement keys +bind h select-pane -L +bind j select-pane -D +bind k select-pane -U +bind l select-pane -R + +# Window Cycle/Swap +bind e previous-window +bind f next-window +bind E swap-window -t -1 +bind F swap-window -t +1 + +# Easy split pane commands +bind = split-window -h +bind - split-window -v +unbind '"' +unbind % + +# Activate inner-most session (when nesting tmux) to send commands +bind a send-prefix + + +### Theme +########################################################################### + +# Statusbar Color Palatte +set-option -g status-justify left +set-option -g status-bg black +set-option -g status-fg white +set-option -g status-left-length 40 +set-option -g status-right-length 80 + +# Pane Border Color Palette +set-option -g pane-active-border-fg green +set-option -g pane-active-border-bg black +set-option -g pane-border-fg white +set-option -g pane-border-bg black + +# Message Color Palette +set-option -g message-fg black +set-option -g message-bg green + +# Window Status Color Palette +setw -g window-status-bg black +setw -g window-status-current-fg green +setw -g window-status-bell-attr default +setw -g window-status-bell-fg red +setw -g window-status-content-attr default +setw -g window-status-content-fg yellow +setw -g window-status-activity-attr default +setw -g window-status-activity-fg yellow + + +### UI +########################################################################### + +# Notification +setw -g monitor-activity on +set -g visual-activity on +set-option -g bell-action any +set-option -g visual-bell off + +# Automatically set window titles +set-option -g set-titles on +set-option -g set-titles-string '#H:#S.#I.#P #W #T' # window number,program name,active (or not) + +# Statusbar Adjustments +set -g status-left "#[fg=red] #H#[fg=green]:#[fg=white]#S#[fg=green] |#[default]" + +# Show performance counters in statusbar +# Requires https://github.com/thewtex/tmux-mem-cpu-load/ +set -g status-interval 4 +set -g status-right "#[fg=green] | #[fg=white]#(tmux-mem-cpu-load)#[fg=green] | #[fg=cyan]%H:%M #[default]" + +``` + + +### Šaltiniai + +[Tmux | Home](http://tmux.sourceforge.net) + +[Tmux Manual page](http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man1/tmux.1?query=tmux) + +[Gentoo Wiki](http://wiki.gentoo.org/wiki/Tmux) + +[Archlinux Wiki](https://wiki.archlinux.org/index.php/Tmux) + +[Display CPU/MEM % in statusbar](https://stackoverflow.com/questions/11558907/is-there-a-better-way-to-display-cpu-usage-in-tmux) + +[tmuxinator - Manage complex tmux sessions](https://github.com/tmuxinator/tmuxinator) -- cgit v1.2.3 From d8a3184a73cfbb3be3ab99e7d7e3ebc577d06494 Mon Sep 17 00:00:00 2001 From: Yu Zhang <583181285@qq.com> Date: Fri, 10 Feb 2017 01:54:31 -0600 Subject: [standard-ml/en-en] Format fixing and some APIs (#2645) * [standard-ml/en-en] Format fixing * [standard-ml/en-en] Add descriptions for `map` and `foldl` * [standard-ml/en-en] Add myself as a contributor * review --- standard-ml.html.markdown | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/standard-ml.html.markdown b/standard-ml.html.markdown index 133e4f54..c9eb2a2e 100644 --- a/standard-ml.html.markdown +++ b/standard-ml.html.markdown @@ -235,17 +235,18 @@ val hmm = answer "What is the meaning of life, the universe and everything?" (* Functions can take several arguments by taking one tuples as argument: *) fun solve2 (a : real, b : real, c : real) = - ( (~b + Math.sqrt(b * b - 4.0*a*c)) / (2.0 * a), - (~b - Math.sqrt(b * b - 4.0*a*c)) / (2.0 * a) ) + ((~b + Math.sqrt(b * b - 4.0 * a * c)) / (2.0 * a), + (~b - Math.sqrt(b * b - 4.0 * a * c)) / (2.0 * a)) (* Sometimes, the same computation is carried out several times. It makes sense to save and re-use the result the first time. We can use "let-bindings": *) fun solve2 (a : real, b : real, c : real) = - let val discr = b * b - 4.0*a*c + let val discr = b * b - 4.0 * a * c val sqr = Math.sqrt discr val denom = 2.0 * a in ((~b + sqr) / denom, - (~b - sqr) / denom) end + (~b - sqr) / denom) + end (* Pattern matching is a funky part of functional programming. It is an @@ -292,6 +293,9 @@ val thermometer = val some_result = (fn x => thermometer (x - 5) ^ thermometer (x + 5)) 37 (* Here is a higher-order function that works on lists (a list combinator) *) +(* map f l + applies f to each element of l from left to right, + returning the list of results. *) val readings = [ 34, 39, 37, 38, 35, 36, 37, 37, 37 ] (* first an int list *) val opinions = List.map thermometer readings (* gives [ "Cold", "Warm", ... ] *) @@ -324,7 +328,11 @@ val n = op + (5, 5) (* n is now 10 *) (* 'op' is useful when combined with high order functions because they expect functions and not operators as arguments. Most operators are really just infix functions. *) -val sum_of_numbers = foldl op+ 0 [1,2,3,4,5] +(* foldl f init [x1, x2, ..., xn] + returns + f(xn, ...f(x2, f(x1, init))...) + or init if the list is empty. *) +val sum_of_numbers = foldl op+ 0 [1, 2, 3, 4, 5] (* Datatypes are useful for creating both simple and complex structures *) @@ -407,7 +415,8 @@ fun writePoem(filename) = let val file = TextIO.openOut(filename) val _ = TextIO.output(file, "Roses are red,\nViolets are blue.\n") val _ = TextIO.output(file, "I have a gun.\nGet in the van.\n") - in TextIO.closeOut(file) end + in TextIO.closeOut(file) + end (* Read a nice poem from a file into a list of strings *) fun readPoem(filename) = -- cgit v1.2.3 From 870e2fbf6dccfe9d769bf3d6ccae402d698322df Mon Sep 17 00:00:00 2001 From: Adrian Sieber Date: Fri, 10 Feb 2017 07:58:10 +0000 Subject: Fix omitting end / beginning in ranges (#2649) --- python3.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python3.html.markdown b/python3.html.markdown index 02745117..596b53e6 100644 --- a/python3.html.markdown +++ b/python3.html.markdown @@ -208,9 +208,9 @@ li[4] # Raises an IndexError # You can look at ranges with slice syntax. # (It's a closed/open range for you mathy types.) li[1:3] # => [2, 4] -# Omit the beginning -li[2:] # => [4, 3] # Omit the end +li[2:] # => [4, 3] +# Omit the beginning li[:3] # => [1, 2, 4] # Select every second entry li[::2] # =>[1, 4] -- cgit v1.2.3 From dbecb473cecfeb0914cb104ff4d680f9fef2b31d Mon Sep 17 00:00:00 2001 From: Paulo Moura Date: Sat, 11 Feb 2017 16:48:10 +0000 Subject: Fixes and improvements to the Logtalk tutorial (#2651) --- logtalk.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logtalk.html.markdown b/logtalk.html.markdown index d4010f8b..bff52cae 100644 --- a/logtalk.html.markdown +++ b/logtalk.html.markdown @@ -106,7 +106,7 @@ Error = error( yes ``` -A subtle point is that predicate scope directives specify predicate _calling_ semantics, not _definitions_ semantics. For example, if an object playing the role of a class declares a predicate private, the predicate can be defined in subclasses and instances *but* can only be called in its instances _from_ the class. +A subtle point is that predicate scope directives specify predicate _calling_ semantics, not _definition_ semantics. For example, if an object playing the role of a class declares a predicate private, the predicate can be defined in subclasses and instances *but* can only be called in its instances _from_ the class. # Defining and implementing a protocol -- cgit v1.2.3 From f30a5376b48ed1aa8932f5cbfb7e1067787e6619 Mon Sep 17 00:00:00 2001 From: Paulo Moura Date: Sat, 11 Feb 2017 23:40:15 +0000 Subject: [logtalk/it-it] Add Italian translation of the Logtalk tutorial] (#2652) * [logtalk/it-it] Add Italian translation of the Logtalk tutorial] * Add `en` tag to link to the official website in the Italian translation for the Logtalk tutorial --- it-it/logtalk-it.html.markdown | 551 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 551 insertions(+) create mode 100644 it-it/logtalk-it.html.markdown diff --git a/it-it/logtalk-it.html.markdown b/it-it/logtalk-it.html.markdown new file mode 100644 index 00000000..0b9b7d2e --- /dev/null +++ b/it-it/logtalk-it.html.markdown @@ -0,0 +1,551 @@ +--- +language: Logtalk +filename: learnlogtalk-it.lgt +contributors: + - ["Paulo Moura", "http://github.com/pmoura"] +translators: + - ["Ugo Chirico", "https://github.com/ugochirico"] +lang: it-it +--- + +Logtalk è un linguaggio di programmazione logica orientata agli oggetti che estende il linguaggio Prolog con le moderne tecniche di Object-Oriented Programming quali incapsulamento, ereditarietà e riutilizzo del codice, senza compromettere le caratteristiche di programmazione dichiarativa del Prolog. Logtalk è implementato in codice altamente portabile e utilizza i più moderni standard di conformità del Prolog rispetto al compilatore back-end. + +Per mantenere una dimensione ragionevole, questo tutorial presuppone necessariamente che il lettore abbia una conoscenza del linguaggio Prolog ed è inoltre focalizzato esclusivamente sulla descrizione delle caratteristiche object-oriented di Logtalk. + +# Sintassi + +Logtalk utilizza la sintassi standard del linguaggio Prolog con l'aggiunta di un paio di operatori e di alcune direttive per una curva di apprendimento morbida e per assicurare ampia portabilità. Una conseguenza importante è che il codice Prolog può essere facilmente incapsulato in oggetti con poche o nessuna modifica. Inoltre, Logtalk può interpretare come oggetti Logtalk, in modo trasparente, la maggior parte dei moduli Prolog già esistenti. + +I principali operatori sono: + +* `::/2` - per inviare un messaggio ad un oggetto +* `::/1` - per inviare un messaggio a se stesso _self_ (cioè all'oggetto che riceverà il messaggio) +* `^^/1` - _super_ per chiamare un predicato ereditato o importato + +Alcune delle più importanti entità e direttive saranno introdotte nelle sezioni successive. + +# Entità e Ruoli + +Logtalk tratta gli oggetti, i protocolli e le categorie come entità di prima classe. I rapporti tra le entità definiscono i _patterns of code reuse_ ossia i modelli di riutilizzo del codice e i _roles_ ossia i ruoli svolti da tali entità. Ad esempio, quando un oggetto istanzia un altro oggetto, il primo oggetto assume il ruolo di istanza e il secondo oggetto assume il ruolo di classe. Una relazione di tipo _extends_ tra due oggetti implica che entrambi gli oggetti svolgano il ruolo di prototipi, in cui uno di loro estende l'altro, che diventa quindi suo prototipo padre. + +# Definizione di un oggetto + +Un oggetto incapsula le dichiarazioni e le definizioni dei predicati. Gli oggetti possono essere creati in modo dinamico, ma di solito sono dichiarati come statici e definiti nel codice sorgente. Un singolo file sorgente può contenere un qualsiasi numero di definizioni di entità. Ecco un semplice oggetto `list` che definisce un membro pubblico `member/2`: + +``` +:- object(list). + + :- public(member/2). + member(Head, [Head| _]). + member(Head, [_| Tail]) :- + member(Head, Tail). + +:- end_object. +``` + +# Compilazione dei file sorgenti + +Supponendo che il codice di cui sopra per l'oggetto `list` venga salvato in un file` list.lgt`, esso può essere compilato e caricato utilizzando il predicato predefiniti `logtalk_load/1` o la sua abbreviazione `{}/1`, con il percorso del file come argomento (l'estensione può essere omessa): + +``` +?- {list}. +yes +``` + +# Inviare un messaggio ad un oggetto + +L'operatore infisso `::/2` è usato per inviare messaggi ad un oggetto. Analogamente al Prolog, è possibile fare backtracking per le soluzioni alternative: + +``` +?- list::member(X, [1,2,3]). +X = 1 ; +X = 2 ; +X = 3 +yes +``` + +Analogamente alla programmazione object-oriented, logtalk consente anche l'Incapsulamento. +Un predicato può essere dichiarata pubblico, protetto o privato. Può anche essere _local_ quando non esiste una direttiva specifica per esso all'interno dello scope. Per esempio: + + +``` +:- object(scopes). + + :- private(bar/0). + bar. + + local. + +:- end_object. +``` + +Assumendo che l'oggetto è salvato nel file `scopes.lgt`: + +``` +?- {scopes}. +yes + +?- catch(scopes::bar, Error, true). +Error = error( + permission_error(access, private_predicate, bar/0), + logtalk(scopes::bar, user) +) +yes + +?- catch(scopes::local, Error, true). +Error = error( + existence_error(predicate_declaration, local/0), + logtalk(scopes::local, user) +) +yes +``` + +Quando il predicato in un messaggio non è noto per l'oggetto (il ruolo dell'oggetto determina le procedure di ricerca), si ha un errore. +Per esempio: + +``` +?- catch(scopes::unknown, Error, true). +Error = error( + existence_error(predicate_declaration, unknown/0), + logtalk(scopes::unknown, user) +) +yes +``` + +Un punto fondamentale da capire è che le direttive che specificano il predicato nello scope specificano la semantica di chiamata (_calling_) del predicato, e non la semantica di definizione (_definition_). Ad esempio, se un oggetto ha il ruolo di una classe e dichiara un predicato privato, tale predicato può essere definito nelle sue sottoclassi e nelle istanze * ma * può essere chiamato solo nelle sue istanza (_from_) dalla classe. + +# Definizione e implementazione di un protocollo + +Un Protocollo contiene le dichiarazioni dei predicati che possono essere implementati da un qualsivoglia numero di oggetti e categorie: + +``` +:- protocol(listp). + + :- public(member/2). + +:- end_protocol. + +:- object(list, + implements(listp)). + + member(Head, [Head| _]). + member(Head, [_| Tail]) :- + member(Head, Tail). + +:- end_object. +``` + +Lo scope dei predicati di un protocollo può essere ristretto usando implementazioni protected e private. Ad esempio: + +``` +:- object(stack, + implements(private::listp)). + +:- end_object. +``` + +Difatti, tutte le relazioni tra entità (nella direttiva di apertura di un entità) possono essere definite come public (default), protected, o private. + +# Prototipi + +Un oggetto senza una istanza o senza una relazione di specializzazione con un altro oggetto interpreta il ruolo di prototipo. Un prototipo può estendere un altro oggetto, il suo prototipo genitore. + +``` +% clyde, our prototypical elephant +:- object(clyde). + + :- public(color/1). + color(grey). + + :- public(number_of_legs/1). + number_of_legs(4). + +:- end_object. + +% fred, another elephant, is like clyde, except that he's white +:- object(fred, + extends(clyde)). + + color(white). + +:- end_object. +``` + +Per rispondere ad un messaggio inviato ad un oggetto che ha il ruolo di prototipo, si cerca prima una risposta nel prototipo stesso e se il prototipo non sa rispondere si passa all'eventuale prototipo genitore (se esiste): + +``` +?- fred::number_of_legs(N). +N = 4 +yes + +?- fred::color(C). +C = white +yes +``` + +Un messaggio è valido se il relativo predicato è dichiarato in un oggetto (e se il mittente è nel campo di applicazione), ma fallirà, piuttosto che lanciare un errore, se il predicato non è definito. Questa è chiamata la _closed-world assumption_. Ad esempio, si consideri il seguente oggetto, salvato in un file `foo.lgt`: + +``` +:- object(foo). + + :- public(bar). + +:- end_object. +``` + +Caricando il file e cercando di chiamare il predicato `bar/0` questo fallisce come previsto. Si noti che ciò è diverso dal chiamare un predicato sconosciuto _unknown_, che invece genera un errore: + +``` +?- {foo}. +yes + +?- foo::bar. +no + +?- catch(foo::baz, Error, true). +Error = error( + existence_error(predicate_declaration, baz/0), + logtalk(foo::baz, user) +) +yes +``` + +# Classi e istanze + +Per definire gli oggetti nei ruoli di classi e/o istanze, un oggetto deve avere almeno un istanziazione o una relazione di specializzazione con un altro oggetto. Gli oggetti che hanno il ruolo di meta-classi possono essere utilizzati quando abbiamo bisogno di usare una classe come se fosse un'istanza. Il seguente esempio mostra come creare dinamicamente nuovi oggetti in fase di esecuzione: + +``` +% a simple, generic, metaclass defining a new/2 predicate for its instances +:- object(metaclass, + instantiates(metaclass)). + + :- public(new/2). + new(Instance, Clauses) :- + self(Class), + create_object(Instance, [instantiates(Class)], [], Clauses). + +:- end_object. + +% a simple class defining age/1 and name/1 predicate for its instances +:- object(person, + instantiates(metaclass)). + + :- public([ + age/1, name/1 + ]). + + % a default value for age/1 + age(42). + +:- end_object. + +% a static instance of the class person +:- object(john, + instantiates(person)). + + name(john). + age(12). + +:- end_object. +``` + +Nel rispondere ad un messaggio inviato ad un oggetto ha assunto il ruolo di istanza, tal messaggio viene convalidato partendo dalla sua classe e andando a ritroso nella gerarchia, se necessario, fino alle sue superclassi. Supponendo che il messaggio sia valido, allora si cerca una risposta a partire dall'istanza stessa: + +``` +?- person::new(Instance, [name(paulo)]). +Instance = o1 +yes + +?- o1::name(Name). +Name = paulo +yes + +?- o1::age(Age). +Age = 42 +yes + +?- john::age(Age). +Age = 12 +yes +``` + +# Categorie + +Una categoria è un'unità atomica di codice riutilizzabile. Una categoria è usata per incapsulare una insieme coesivo (_cohesive_) di dichiarazioni e di definizioni di predicato ed è atta ad implementare una singola (_single_) funzionalità che può essere importata in qualsiasi oggetto. Una categoria può quindi essere concepita come il concetto duale di protocollo. Nel seguente esempio, si definiscono prima le categorie che rappresentano i motori di auto e poi si importano tali categorie negli oggetti auto: + +``` +% a protocol describing engine characteristics +:- protocol(carenginep). + + :- public([ + reference/1, + capacity/1, + cylinders/1, + horsepower_rpm/2, + bore_stroke/2, + fuel/1 + ]). + +:- end_protocol. + +% a typical engine defined as a category +:- category(classic, + implements(carenginep)). + + reference('M180.940'). + capacity(2195). + cylinders(6). + horsepower_rpm(94, 4800). + bore_stroke(80, 72.8). + fuel(gasoline). + +:- end_category. + +% a souped up version of the previous engine +:- category(sport, + extends(classic)). + + reference('M180.941'). + horsepower_rpm(HP, RPM) :- + ^^horsepower_rpm(ClassicHP, ClassicRPM), % "super" call + HP is truncate(ClassicHP*1.23), + RPM is truncate(ClassicRPM*0.762). + +:- end_category. + +% with engines (and other components), we may start "assembling" some cars +:- object(sedan, + imports(classic)). + +:- end_object. + +:- object(coupe, + imports(sport)). + +:- end_object. +``` + +Le Categorie sono compilate in modo indipendente e, quindi, consentono l'importazione di oggetti da aggiornare mediante il semplice aggiornamento delle categorie importate, senza richiedere pertanto la ricompilazione dell'oggetto. Le Categorie forniscono anche la _runtime transparency_, cioè il protocollo della categoria si aggiunge al protocollo degli oggetti che importano tale categoria: + +``` +?- sedan::current_predicate(Predicate). +Predicate = reference/1 ; +Predicate = capacity/1 ; +Predicate = cylinders/1 ; +Predicate = horsepower_rpm/2 ; +Predicate = bore_stroke/2 ; +Predicate = fuel/1 +yes +``` + +# Hot patching + +Le categorie possono essere anche usate per modificare gli oggetti al volo (_hot-patch_). Una categoria può aggiungere nuovi predicati ad un oggetto e/o sostituire le definizioni dei predicati dell'oggetto. Ad esempio, si consideri il seguente oggetto: + +``` +:- object(buggy). + + :- public(p/0). + p :- write(foo). + +:- end_object. +``` + +Si supponga che l'oggetto stampi la stringa sbagliata quando riceve il messaggio `p/0`: + +``` +?- {buggy}. +yes + +?- buggy::p. +foo +yes +``` + +Se il codice sorgente dell'oggetto non è disponibile e bisogna correggere l'applicazione che sta eseguendo il codice dell'oggetto, si può semplicemente definire una categoria che corregge il predicato non corretto: + +``` +:- category(patch, + complements(buggy)). + + % fixed p/0 def + p :- write(bar). + +:- end_category. +``` + +Dopo la compilazione e il caricamento della categoria nell'applicazione in esecuzione si ottiene: + +``` +?- {patch}. +yes + +?- buggy::p. +bar +yes +``` + +Poiché l'hot-patching pregiudica forzatamente l'incapsulamento, un apposito flag di compilazione `complementary` può essere impostato (a livello globale o per un singolo oggetto) per consentire, limitare o prevenire l'hot-patching. + +# Oggetti Parametrici e Categorie + +Gli oggetti e le categorie possono essere parametrizzati utilizzando come identificativo un compound-term al posto di un atomo. Oggetti e parametri di una categoria sono variabili logiche _logical variables_ condivise con tutti i predicati incapsulati. Ecco un esempio con cerchi geometrici: + +``` +:- object(circle(_Radius, _Color)). + + :- public([ + area/1, perimeter/1 + ]). + + area(Area) :- + parameter(1, Radius), + Area is pi*Radius*Radius. + + perimeter(Perimeter) :- + parameter(1, Radius), + Perimeter is 2*pi*Radius. + +:- end_object. +``` + +Oggetti parametrici possono essere utilizzati come qualsiasi altro oggetto e di solito forniscono i valori da assegnare ai parametri quando si invia un messaggio: + +``` +?- circle(1.23, blue)::area(Area). +Area = 4.75291 +yes +``` + +Gli oggetti parametrici forniscono anche un modo semplice per associare un insieme di predicati con un semplice predicato Prolog. Fatti Prolog possono essere interpretati come oggetti proxy parametrici ( _parametric object proxies_) quando hanno lo stesso funtore e arietà degli identificatori di oggetti parametrici. Per lavorare con i proxy viene fornita una sintassi maneggevole. Per esempio, si prendano le seguenti clausole per il predicato `circle/2`: + +``` +circle(1.23, blue). +circle(3.71, yellow). +circle(0.39, green). +circle(5.74, black). +circle(8.32, cyan). +``` + +Con queste clausole, si può facilmente calcolare, ad esempio, un elenco con le aree di tutti i cerchi: + +``` +?- findall(Area, {circle(_, _)}::area(Area), Areas). +Areas = [4.75291, 43.2412, 0.477836, 103.508, 217.468] +yes +``` + +In pratica, il costrutto `{Goal}::Message` prova il goal `Goal`, instanziando le variabili interne e inviando un messaggio `Message` al termine risultante. + +# Eventi and monitor + +Logtalk supporta l'_event-driven programming_ mediante la definizione di eventi e di monitor. Un evento è semplicemente l'invio di un messaggio ad un oggetto. Un monitor è un gestore di un evento. L'evento (con l'invio di un messaggio) è un'attività atomica, ed è preceduta da un evento _before_ e da un evento _after_. Il monitor gestisce tali eventi mediante i predicati, `before/3` e `after/3`, che sono chiamati rispettivamente prima e dopo il verificarsi dell'evento. Un monitor può inoltre interrogare, registrare e cancellare un evento nel registro eventi a livello di sistema il quale che associa gli eventi con i monitor. Ad esempio, un semplice tracer per ogni messaggio inviato utilizzando il costrutto `::/2` può essere definito come: + +``` +:- object(tracer, + implements(monitoring)). % built-in protocol for event handlers + + :- initialization(define_events(_, _, _, _, tracer)). + + before(Object, Message, Sender) :- + write('call: '), writeq(Object), write(' <-- '), writeq(Message), + write(' from '), writeq(Sender), nl. + + after(Object, Message, Sender) :- + write('exit: '), writeq(Object), write(' <-- '), writeq(Message), + write(' from '), writeq(Sender), nl. + +:- end_object. +``` + +Supponendo che l'oggetto `tracer` e l'oggetto `list` definito in precedenza siano stati già compilati e caricati, si possono osservare i gestori di eventi in azione durante l'invio di un messaggio: + +``` +?- list::member(X, [1,2,3]). + +call: list <-- member(X, [1,2,3]) from user +exit: list <-- member(1, [1,2,3]) from user +X = 1 ; +exit: list <-- member(2, [1,2,3]) from user +X = 2 ; +exit: list <-- member(3, [1,2,3]) from user +X = 3 +yes +``` + +Gli eventi possono essere impostati e cancellati dinamicamente in fase di esecuzione chiamando i predicati predefiniti `define_events/5` e` abolish_events/5` . + +La programmazione event-driven può essere vista come una forma di _computational reflection_. Si noti però che gli eventi sono generati solo quando si utilizza il costrutto di controllo per l'invio di messaggi `::/2`. + +# Espressioni lambda + +Logtalk supporta anche le espressioni lambda. I parametri della espressioni lambda sono rappresentati mediante una lista con l'operatore infisso `(>>)/2` che collega i parametri alla relativa lambda espressione. Ecco alcuni semplici esempi di che usano i meta-predicati. + + +``` +?- {library(metapredicates_loader)}. +yes + +?- meta::map([X,Y]>>(Y is 2*X), [1,2,3], Ys). +Ys = [2,4,6] +yes +``` + +Logtalk supporta anche il Currying: + +``` +?- meta::map([X]>>([Y]>>(Y is 2*X)), [1,2,3], Ys). +Ys = [2,4,6] +yes +``` + +Infine, le variabili libere Lambda possono essere espresso usando la sintassi estesa `{Free1, ...}/[Parameter1, ...]>>Lambda`. + +# Macro + +I Termini e goal nel file sorgente possono essere _estesi_ al momento della compilazione specificando una hook ad un oggetto (_hook object_) che definisce le regole di riscrittura dei termini e riscrittura dei quesiti. Ad esempio, si consideri il seguente oggetto semplice, salvato nel file `source.lgt`: + +``` +:- object(source). + + :- public(bar/1). + bar(X) :- foo(X). + + foo(a). foo(b). foo(c). + +:- end_object. +``` + +Si supponga il seguente hook all'oggetto, salvato nel file `my_macros.lgt`, che estende le clausole e chiama il predicato locale `foo/1`: + +``` +:- object(my_macros, + implements(expanding)). % built-in protocol for expanding predicates + + term_expansion(foo(Char), baz(Code)) :- + char_code(Char, Code). % standard built-in predicate + + goal_expansion(foo(X), baz(X)). + +:- end_object. +``` + +Dopo aver caricato il file contenente la macro, si può espandere il nostro file sorgente usando il flag del compilatore `hook`: + +``` +?- logtalk_load(my_macros), logtalk_load(source, [hook(my_macros)]). +yes + +?- source::bar(X). +X = 97 ; +X = 98 ; +X = 99 +true +``` + +La libreria Logtalk fornisce infine il supporto per combinare hook agli oggetti utilizzando diversi modi (ad esempio, definendo una pipeline di espansioni). + + +# Maggiori informazioni + +Visita il [Sito web di Logtalk (en)](http://logtalk.org) per maggiori informazioni. -- cgit v1.2.3 From 66c635ddac676b5f1050ac848ddcfd32c7f09dc0 Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Sat, 11 Feb 2017 21:46:45 -0800 Subject: Get the fuck out with your plagarism --- meteor.html.markdown | 567 --------------------------------------------------- 1 file changed, 567 deletions(-) delete mode 100644 meteor.html.markdown diff --git a/meteor.html.markdown b/meteor.html.markdown deleted file mode 100644 index 1685e0be..00000000 --- a/meteor.html.markdown +++ /dev/null @@ -1,567 +0,0 @@ ---- -category: tool -tool: meteor.js -Filename: meteor.html.markdown -contributors: - - ["Mohammed Rafy", "https://github.com/IamRafy/"] ---- - - - -Meteor is an ultra-simple environment for building modern websites. What once took weeks, even with the best tools, now takes hours with Meteor. - -The web was originally designed to work in the same way that mainframes worked in the 70s. The application server rendered a screen and sent it over the network to a dumb terminal. Whenever the user did anything, that server rerendered a whole new screen. This model served the Web well for over a decade. It gave rise to LAMP, Rails, Django, PHP. - -But the best teams, with the biggest budgets and the longest schedules, now build applications in JavaScript that run on the client. These apps have stellar interfaces. They don't reload pages. They are reactive: changes from any client immediately appear on everyone's screen. - -They've built them the hard way. Meteor makes it an order of magnitude simpler, and a lot more fun. You can build a complete application in a weekend, or a sufficiently caffeinated hackathon. No longer do you need to provision server resources, or deploy API endpoints in the cloud, or manage a database, or wrangle an ORM layer, or swap back and forth between JavaScript and Ruby, or broadcast data invalidations to clients. -Meteor Supports OS X, Windows, and Linux. // https://github.com/meteor/meteor/wiki/Supported-Platforms -On Windows? https://install.meteor.com/windows -On OS X or Linux? Install the latest official Meteor release from your terminal: -$ curl https://install.meteor.com/ | sh -The Windows installer supports Windows 7, Windows 8.1, Windows Server 2008, and Windows Server 2012. The command line installer supports Mac OS X 10.7 (Lion) and above, and Linux on x86 and x86_64 architectures. - -Once you've installed Meteor, create a project: -meteor create myapp -Run it locally: - -cd myapp -meteor -# Meteor server running on: http://localhost:3000/ - -Then, open a new terminal tab and unleash it on the world (on a free server we provide): - -meteor deploy myapp.meteor.com - -Principles of Meteor - -* Data on the Wire. Meteor doesn't send HTML over the network. The server sends data and lets the client render it. - -* One Language. Meteor lets you write both the client and the server parts of your application in JavaScript. - -* Database Everywhere. You can use the same methods to access your database from the client or the server. - -* Latency Compensation. On the client, Meteor prefetches data and simulates models to make it look like server method calls return instantly. - -* Full Stack Reactivity. In Meteor, realtime is the default. All layers, from database to template, update themselves automatically when necessary. - -* Embrace the Ecosystem. Meteor is open source and integrates with existing open source tools and frameworks. - -* Simplicity Equals Productivity. The best way to make something seem simple is to have it actually be simple. Meteor's main functionality has clean, classically beautiful APIs. - -Developer Resources -------------------- - -If anything in Meteor catches your interest, we hope you'll get involved with the project! - -TUTORIAL -Get started fast with the official Meteor tutorial! https://www.meteor.com/install - -STACK OVERFLOW -The best place to ask (and answer!) technical questions is on Stack Overflow. Be sure to add the meteor tag to your question. -http://stackoverflow.com/questions/tagged/meteor - -FORUMS -Visit the Meteor discussion forumsto announce projects, get help, talk about the community, or discuss changes to core. -https://forums.meteor.com/ - -GITHUB -The core code is on GitHub. If you're able to write code or file issues, we'd love to have your help. Please read Contributing to Meteor for how to get started. https://github.com/meteor/meteor - -THE METEOR MANUAL -In-depth articles about the core components of Meteor can be found on the Meteor Manual. The first article is about Tracker, our transparent reactivity framework. More articles (covering topics like Blaze, Unibuild, and DDP) are coming soon! http://manual.meteor.com/ - -What is Meteor? ---------------- - -Meteor is two things: - -A library of packages: pre-written, self-contained modules that you might need in your app. - -There are about a dozen core Meteor packages that most any app will use. Two examples: webapp, which handles incoming HTTP connections, and templating, which lets you make HTML templates that automatically update live as data changes. Then there are optional packages like email, which lets your app send emails, or the Meteor Accounts series (accounts-password, accounts-facebook, accounts-ui, and others) which provide a full-featured user account system that you can drop right into your app. In addition to these "core" packages, there are thousands of community-written packages in Atmosphere, one of which might do just what you need. - -A command-line tool called meteor. - -meteor is a build tool analogous to make, rake, or the non-visual parts of Visual Studio. It gathers up all of the source files and assets in your application, carries out any necessary build steps (such as compiling CoffeeScript, minifying CSS, building npm modules, or generating source maps), fetches the packages used by your app, and outputs a standalone, ready-to-run application bundle. In development mode it can do all of this interactively, so that whenever you change a file you immediately see the changes in your browser. It's super easy to use out of the box, but it's also extensible: you can add support for new languages and compilers by adding build plugin packages to your app. - -The key idea in the Meteor package system is that everything should work identically in the browser and on the server (wherever it makes sense, of course: browsers can't send email and servers can't capture mouse events). Our whole ecosystem has been built from the ground up to support this. - -Structuring your application ----------------------------- - -A Meteor application is a mix of client-side JavaScript that runs inside a web browser or PhoneGap mobile app, server-side JavaScript that runs on the Meteor server inside a Node.js container, and all the supporting HTML templates, CSS rules, and static assets. Meteor automates the packaging and transmission of these different components, and it is quite flexible about how you choose to structure those components in your file tree. - -Special Directories -------------------- - -By default, any JavaScript files in your Meteor folder are bundled and sent to the client and the server. However, the names of the files and directories inside your project can affect their load order, where they are loaded, and some other characteristics. Here is a list of file and directory names that are treated specially by Meteor: - -client - -Any directory named client is not loaded on the server. Similar to wrapping your code in if (Meteor.isClient) { ... }. All files loaded on the client are automatically concatenated and minified when in production mode. In development mode, JavaScript and CSS files are not minified, to make debugging easier. (CSS files are still combined into a single file for consistency between production and development, because changing the CSS file's URL affects how URLs in it are processed.) - -HTML files in a Meteor application are treated quite a bit differently from a server-side framework. Meteor scans all the HTML files in your directory for three top-level elements: , , and