This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fib(0) -> 0; | |
| fib(1) -> 1; | |
| fib(N) when N > 0 -> fib(N - 1) + fib(N - 2). | |
| lists:foreach(fun(N) -> io:format("n=~p => ~p~n", [N, fib(N)]) end, lists:seq(0, 39)). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec fib n = | |
| match n with | |
| |0|1 -> n | |
| |x when x > 0 -> fib(x - 1) + fib(x - 2) | |
| for x in 0..39 do | |
| printfn "fib(%d) = %d" x (fib x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type BinaryTree = | |
| |Node of obj * BinaryTree * BinaryTree | |
| |Empty | |
| member tree.Traverse f = | |
| match tree with | |
| |Node(data, l, r) -> | |
| f data | |
| l.Traverse f | |
| r.Traverse f | |
| |Empty -> () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib(n) | |
| { | |
| |0|1 => n | |
| |_ => fib(n - 1) + fib(n - 2) | |
| } | |
| foreach (i in $[0..39]) | |
| WriteLine("fib({0}) = {1}", i, fib(i)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public macro not_null(obj) | |
| syntax ("not_null", obj) | |
| { | |
| def var_name = $"$obj"; | |
| <[ | |
| when ($obj == null) | |
| throw System.ArgumentNullException($var_name); | |
| $obj; | |
| ]> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public macro not_null(obj) | |
| syntax ("not_null", obj) | |
| { | |
| def var_name = $"$obj"; | |
| <[ | |
| when ($obj == null) | |
| throw System.ArgumentNullException($var_name); | |
| $obj; | |
| ]> | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| { | |
| public Name: string; | |
| public this(name: string) | |
| requires name != null | |
| { | |
| Name = name; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| { | |
| public Name: string; | |
| public Age: int; | |
| public this(requires (name != null && name.Length > 0) name: string, | |
| requires (age > 0) age: int) | |
| { | |
| Name = name; | |
| Age = age; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person | |
| { | |
| public Name: string; | |
| public this([NotNull] name: string) | |
| { | |
| Name = name; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defn fib [n] | |
| (if (< n 2) | |
| n | |
| (+ (fib (- n 1)) | |
| (fib (- n 2))))) | |
| (time | |
| (doseq [n (range 40)] | |
| (prn (str "Fib(" n ") = " (fib n))))) |