2016 Update

This commit is contained in:
Tina Müller 2016-12-05 22:15:40 +01:00
parent 948b86eafa
commit dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions

View file

@ -10,3 +10,4 @@ Create a function which takes in a number of arguments which are specified by na
* [[Varargs]]
* [[Optional parameters]]
* [[wp:Named parameter|Wikipedia: Named parameter]]
<br><br>

View file

@ -0,0 +1,3 @@
def fun(bar: bar, baz: baz), do: IO.puts "#{bar}, #{baz}."
fun(bar: "bar", baz: "baz")

View file

@ -0,0 +1,10 @@
f := proc(a, {b:= 1, c:= 1})
print (a*(c+b));
end proc:
#a is a mandatory positional parameter, b and c are optional named parameters
f(1);#you must have a value for a for the procedure to work
2
f(1, c = 1, b = 2);
3
f(2, b = 5, c = 3);#b and c can be put in any order
16

View file

@ -1,4 +1,4 @@
sub funkshun ($a, $b?, $c = 15, :$d, *@e, *%f) {
sub funkshun ($a, $b?, :$c = 15, :$d, *@e, *%f) {
say "$a $b $c $d";
say join ' ', @e;
say join ' ', keys %f;

View file

@ -0,0 +1,3 @@
fun dosomething (a, b, c) = print ("a = " ^ a ^ "\nb = " ^ Real.toString b ^ "\nc = " ^ Int.toString c ^ "\n")
fun example {a, b, c} = dosomething (a, b, c)

View file

@ -0,0 +1 @@
example {a="Hello World!", b=3.14, c=42}

View file

@ -0,0 +1,12 @@
datatype param = A of string | B of real | C of int
fun args xs =
let
(* Default values *)
val a = ref "hello world"
val b = ref 3.14
val c = ref 42
in
map (fn (A x) => a := x | (B x) => b := x | (C x) => c := x) xs;
(!a, !b, !c)
end

View file

@ -0,0 +1 @@
dosomething (args [A "tam", B 42.0]);