argument - pannous/warp GitHub Wiki
arguments are parameters to functions and closures
In angle they can be symbolic and subject to structural matching
They take the same semantics of optional, required, constant and mutable as other variables:
to call person{name?, phone text, email?, mutable status} do
telephone.dial person.phone
person.status = called
unused optional fields can be omitted. Fields which are required in the callers object can be optional in the callees parameter and vice versa: an object of the following class can still be passed to the above call function:
class person{
name,
phone?
}
since the name is always provided it is OK to fill the optional name? parameter of the call function however it is required to fill the phone parameter to call the function:
person john:{name:"Jonathan" phone:"899-573-5842"}
call john// ok
call person {name:"Dick"} // compile error: missing argument field phone
default values are allowed on all parameters, quantities too: f(t = 1s) := t * 2; f() is 2s.
Angle seeks to encourage point-free (“argument-less”) tacit programming, especially by automatic broadcasting but also by (inverse) function composition via and & pipe.
Named arguments (warp, decision P37)
A call may name its arguments, in any order; a name may also set a free variable of the function's body:
f(a, b) := a - b
f(b=1, a=10)
f y := y*y + v
f(y=2, v=3)
A parameter written after a preposition is passed by that word, as Swift labels its arguments. In a call the label
always takes a colon: play(tone, for duration) is called play 440Hz for: 0.5s (also play(440Hz, for: 0.5s)),
move(x, from a, to b) is called move 1 from: 10 to: 3, in any order. as labels one too: save(made, as file)
is called save sound as: "song.wav".
to move piece from a to b: piece + a - b
move 1 from: 10 to: 3 // 8
Without its colon the word keeps its own meaning, 1 to 5 a range, for x in xs a loop; move 1 from 10 to 3 says
"from labels an argument of move with a colon".
A missing argument stays an error: a local variable of the same name is not taken implicitly (see gap-filling).