diff options
-rw-r--r-- | cobol.html.markdown | 189 | ||||
-rw-r--r-- | dynamic-programming.html.markdown | 2 | ||||
-rw-r--r-- | es-es/ruby-es.html.markdown | 2 | ||||
-rw-r--r-- | ja-jp/python-jp.html.markdown | 32 | ||||
-rw-r--r-- | raku.html.markdown | 6 | ||||
-rw-r--r-- | wasm.html.markdown | 2 |
6 files changed, 211 insertions, 22 deletions
diff --git a/cobol.html.markdown b/cobol.html.markdown new file mode 100644 index 00000000..4452bd95 --- /dev/null +++ b/cobol.html.markdown @@ -0,0 +1,189 @@ +--- +language: COBOL +contributors: + - ["Hyphz", "http://github.com/hyphz/"] +filename: learn.COB +--- +COBOL is a business-oriented language revised multiple times since its original design in 1960. It is claimed to still be used in over 80% of +organizations. + +```cobol + *COBOL. Coding like it's 1985. + *Compiles with GnuCOBOL in OpenCobolIDE 4.7.6. + + *COBOL has significant differences between legacy (COBOL-85) + *and modern (COBOL-2002 and COBOL-2014) versions. + *Legacy versions require columns 1-6 to be blank (they are used + *to store the index number of the punched card..) + *A * in column 7 means a comment. + *In legacy COBOL, a comment can only be a full line. + *Modern COBOL doesn't require fixed columns and uses *> for + *a comment, which can appear in the middle of a line. + *Legacy COBOL also imposes a limit on maximum line length. + *Keywords have to be in capitals in legacy COBOL, + *but are case insensitive in modern. + + *First, we must give our program ID. + *Identification division can include other values too, + *but they are comments only. Program-id is mandatory. + identification division. + program-id. learn. + + *Let's declare some variables. + data division. + working-storage section. + + *Variables are specified by a "picture" - how they should be + *displayed, and variable type is inferred from this. + *The "01" value is the level number which is used for building + *data structures. + 01 myname picture xxxxxxxxxx. *> A 10 character string. + 01 age picture 999. *> A number up to 3 digits. + 01 valx picture 999. *> Another number up to 3 digits. + 01 inyear picture s9(7). *> S makes number signed. + *> Brackets indicate 7 repeats of 9, + *> ie a 6 digit number (not an array). + + *Now let's write some code. + procedure division. + + main-procedure. + *> COBOL is the language that uses DISPLAY instead of PRINT. + *> Note: no full stops after commands. Only after the LAST + *> command. + display "Hello. What's your name?" + + *> Let's input a string. + *> If input too long, later characters are trimmed. + accept myname + display "Hello " myname *> We can display several things. + display "How old are you?" + + *> Let's input a number. + *> If input too long, EARLIER characters are trimmed. + accept age + + display age *> Left-padded to three chracaters with zeroes, + *> because of the defined PICTURE for age. + + *> We have two ways of doing a FOR loop. + *> Old style way: doesn't give an index. + perform age times + display "*" with no advancing *> Ie, no newline at end + end-perform + display "." *> Output buffer isn't flushed until newline. + + *> New style way: with an index. + perform varying valx from 1 by 1 until valx > age + display valx "-" with no advancing + end-perform + display "." + + *> If tests are still good old if tests. + if myname = "Bob" then + display "I don't like Bob." + else + display "I don't know you." + end-if + + *> There are two ways of doing subprograms and calling + *> them. + *> The simplest way: a paragraph. + perform subparagraph + + *> The complex way, with parameters and stuff. + call "eratosthenes" using age returning valx + + display "There were " valx " primes." + + stop run. + + subparagraph. *> Marks the top of an internal subprogram. + *> Shares variable score with its caller. + + *> Read year from system timer. + *> Remember the whole "year 2000 crisis"? The yyyyddd + *> option was added in response to that. + accept inyear from day yyyyddd. + + *> We can do math step-by-step like this... + divide 1000 into inyear. + subtract age from inyear. + + display "You were born in " inyear "." + + *> Or we can just use expressions. + compute inyear = 1970 - inyear. + + if inyear >= 0 then + display "When you were " inyear ", " with no advancing + else + display inyear " years before you were born, " with no + advancing + end-if + + display "COBOL was the most popular language in the world." + . *> You can put the final . on a new line if it's clearer. + + + *If we want to use a subprogram, we use literally a subprogram. + *This is the entire program layout, repeated for the + *eratosthenes subroutine. + identification division. + program-id. eratosthenes. + + data division. + working-storage section. + *Declare an array. + *We can declare a variable to use as an index for it at the + *same time. + 01 sieve pic 9 occurs 999 times indexed by sa, sb. + *> Standard cobol doesn't have a boolean type. + 01 pstart pic 999. + 01 counter pic 999. + + *Our parameters have to be declared in the linkage section. + *Their pictures must match the values they're called with. + linkage section. + 01 maxvalue picture 999. + + *"using" declares our actual parameter variables. + *"returning" declares the variable value returned at end. + procedure division using maxvalue returning counter. + main-procedure. + + display "Here are all the primes up to " maxvalue "." + + perform varying sa from 1 by 1 until sa > maxvalue + move 1 to sieve (sa) + end-perform + + perform varying sa from 2 by 1 until sa > maxvalue + if sieve(sa) = 1 then + compute pstart = sa + sa + perform varying sb from pstart by sa until sb > + maxvalue + move 0 to sieve(sb) + end-perform + end-if + end-perform + + initialise counter *> To zero by default for a number. + + perform varying sa from 2 by 1 until sa > maxvalue + if sieve(sa) = 1 THEN + display sa + add 1 to counter + end-if + end-perform. + + end program eratosthenes. + + end program learn. + +``` + +##Ready For More? + +* [GnuCOBOL](https://sourceforge.net/projects/open-cobol/) + diff --git a/dynamic-programming.html.markdown b/dynamic-programming.html.markdown index 5d260206..3e3c0413 100644 --- a/dynamic-programming.html.markdown +++ b/dynamic-programming.html.markdown @@ -23,7 +23,7 @@ Always remember! ## Example of Dynamic Programming -The Longest Increasing Subsequence problem is to find the longest increasing subsequence of a given sequence. Given a sequence `S= {a1 , a2 , a3, a4, ............., an-1, an }` we have to find a longest subset such that for all `j` and `i`, `j<i` in the subset `aj<ai`. +The Longest Increasing Subsequence problem is to find the longest increasing subsequence of a given sequence. Given a sequence `S={ a1, a2, a3, a4, ............., an-1, an }` we have to find a longest subset such that for all `j` and `i`, `j<i` in the subset `aj<ai`. First of all we have to find the value of the longest subsequences(LSi) at every index i with last element of sequence being ai. Then largest LSi would be the longest subsequence in the given sequence. To begin LSi is assigned to be one since ai is element of the sequence(Last element). Then for all `j` such that `j<i` and `aj<ai`, we find Largest LSj and add it to LSi. Then algorithm take *O(n2)* time. Pseudo-code for finding the length of the longest increasing subsequence: diff --git a/es-es/ruby-es.html.markdown b/es-es/ruby-es.html.markdown index e3e43c18..63a47e89 100644 --- a/es-es/ruby-es.html.markdown +++ b/es-es/ruby-es.html.markdown @@ -139,7 +139,7 @@ status == :pendiente #=> true status == 'pendiente' #=> false -status == :aprovado #=> false +status == :aprobado #=> false # Arreglos diff --git a/ja-jp/python-jp.html.markdown b/ja-jp/python-jp.html.markdown index c80b4d4c..18e7d1b8 100644 --- a/ja-jp/python-jp.html.markdown +++ b/ja-jp/python-jp.html.markdown @@ -160,8 +160,8 @@ len("This is a string") # => 16 name = "Reiko" f"She said her name is {name}." # => "She said her name is Reiko" -# 基本的に、任意のPythonの文を中括弧に書くことができ、それは評価されて出力されます。 -f"{name} is {len(name)} characters long." +# 基本的に、任意のPythonの文を中括弧に書くことができ、それは文字列で出力されます。 +f"{name} is {len(name)} characters long." # => "Reiko is 5 characters long." # None はオブジェクトです(大文字からです!) None # => None @@ -191,7 +191,7 @@ print("I'm Python. Nice to meet you!") # => I'm Python. Nice to meet you! print("Hello, World", end="!") # => Hello, World! # コンソールから入力を得るための簡単な例 -input_string_var = input("Enter some data: ") # 入力を文字列として返します +input_string_var = input("Enter some data: ") # 入力を文字列として返します。 # Note: Python の初期のバージョンでは、 input() は raw_input() という名前で存在します。 # Pythonでは変数の宣言は存在せず、代入のみです。 @@ -201,7 +201,7 @@ some_var # => 5 # 代入されていない変数へのアクセスは例外を引き起こします。 # 例外の取り扱いについては、3章の制御の流れをご確認ください。 -some_unknown_var # NameError を送出します +some_unknown_var # NameError を送出します。 # ifは式として使用できます。 # C言語の「?:(三項演算子)」に対応する例: @@ -228,7 +228,7 @@ li[0] # => 1 li[-1] # => 3 # 範囲外の要素を参照すると IndexError になります。 -li[4] # IndexError が発生します +li[4] # IndexError が発生します。 # スライス構文により範囲を参照できます。 # 開始部分のインデックスに対応する部分は含まれますが、終了部分のインデックスに対応する部分は含まれません。 @@ -238,28 +238,28 @@ li[2:] # => [4, 3] # 末尾を取り除いたリスト li[:3] # => [1, 2, 4] # 1つ飛ばしで選択する -li[::2] # =>[1, 4] +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になる。 +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.remove(2) # 2 はリストの中に存在しないので、 ValueError が発生します。 # 要素を好きなところに挿入できます。 li.insert(1, 2) # li は [1, 2, 3] に戻りました。 # "index"で引数の要素が最初に出現する場所のインデックスを得られます。 li.index(2) # => 1 -li.index(4) # 4はリストの中に存在しないので、 ValueError が発生します。 +li.index(4) # 4 はリストの中に存在しないので、 ValueError が発生します。 # リスト同士を足すこともできます。 # Note: li と other_li の値は変更されません。 @@ -295,11 +295,11 @@ tup[:2] # => (1, 2) # タプルやリストから複数の変数に代入することができます。 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 になります。 +a, *b, c = (1, 2, 3, 4) # a は 1、 b は [2, 3]、c は 4 になります。 # 括弧を作成しなくてもデフォルトでタプルが作成されます。 d, e, f = 4, 5, 6 # 4、5、6がそれぞれd、 e、 fに代入されます。 # 2つの変数を交換するのがどれほど簡単か見てみましょう。 -e, d = d, e # d は 5 、 e は e になります。 +e, d = d, e # d は 5、 e は 4 になります。 # 辞書はマップ(キーと値の組み合わせ)を保存できます。 @@ -373,7 +373,7 @@ valid_set = {(1,), 1} filled_set = some_set filled_set.add(5) # filled_set は {1, 2, 3, 4, 5} になりました。 # 集合は重複した要素を持ちません。 -filled_set.add(5) # 以前の{1, 2, 3, 4, 5}のままです。 +filled_set.add(5) # 以前の {1, 2, 3, 4, 5} のままです。 # & により、集合同士の共通部分が得られます。 other_set = {3, 4, 5, 6} @@ -453,7 +453,7 @@ for i in range(4, 8): """ "range(lower, upper, step)" は、lower の数値から upper の数値までが、 -step 刻みで表現されるiterableを返します +step 刻みで表現されるiterableを返します。 step が与えられない場合、デフォルトは1になります。 出力: 4 @@ -552,7 +552,7 @@ varargs(1, 2, 3) # => (1, 2, 3) def keyword_args(**kwargs): return kwargs -# 何が起こるか、試してみましょう +# 何が起こるか、試してみましょう。 keyword_args(big="foot", loch="ness") # => {"big": "foot", "loch": "ness"} @@ -591,7 +591,7 @@ x = 5 def set_x(num): - # ローカル変数の x はグローバル変数の x とは異なります + # ローカル変数の x はグローバル変数の x とは異なります。 x = num # => 43 print(x) # => 43 @@ -783,7 +783,7 @@ if __name__ == '__main__': from human import Human -# 親クラスを子クラスのパラメータとして指定します +# 親クラスを子クラスのパラメータとして指定します。 class Superhero(Human): # もし子クラスが親クラスの全ての定義を変更なしで継承する場合、"pass"キーワードのみを書くだけで良いです。 diff --git a/raku.html.markdown b/raku.html.markdown index 4f397589..2460ac7e 100644 --- a/raku.html.markdown +++ b/raku.html.markdown @@ -284,8 +284,8 @@ else". You can have as many parameters *before* a slurpy one, but not *after*. sub as-many($head, *@rest) { @rest.join(' / ') ~ " !"; } -say as-many('Happy', 'Happy', 'Birthday'); # OUTPUT: «Happy / Birthday !» -say 'Happy', ['Happy', 'Birthday'], 'Day'; # OUTPUT: «Happy / Birthday / Day !» +say as-many('Happy', 'Happy', 'Birthday'); # OUTPUT: «Happy / Birthday !» +say as-many('Happy', ['Happy', 'Birthday'], 'Day'); # OUTPUT: «Happy / Birthday / Day !» # Note that the splat (the *) did not consume the parameter before it. @@ -769,7 +769,7 @@ sub unpack_array( @array [$fst, $snd] ) { # (^ remember the `[]` to interpolate the array) } unpack_array(@tail); -# OUTPUT: «My first is 3, my second is 3! All in all, I'm 2 3.» +# OUTPUT: «My first is 2, my second is 3! All in all, I'm 2 3.» # If you're not using the array itself, you can also keep it anonymous, # much like a scalar: diff --git a/wasm.html.markdown b/wasm.html.markdown index aba2084f..81344abe 100644 --- a/wasm.html.markdown +++ b/wasm.html.markdown @@ -61,7 +61,7 @@ contributors: ;; We have to use the right data type for each operation: ;; (local.set $mult_result (f32.mul (f32.const 2.0) (f32.const 4.0))) ;; WRONG! mult_result is f64! - (local.set $mult_result (f64.mul (f64.const 2.0) (f64.const 4.0))) ;; WRONG! mult_result is f64! + (local.set $mult_result (f64.mul (f64.const 2.0) (f64.const 4.0))) ;; WebAssembly has some builtin operations, like basic math and bitshifting. ;; Notably, it does not have built in trigonometric functions. |