-
-
Notifications
You must be signed in to change notification settings - Fork 4
broadcasting
All functions are automatically broadcasting on lists and pair values:
square number=number*number
square [1 2 3] == [1 4 9]
square [a:1 b:2 c:3] == [a:1 b:4 c:9]
delete file = run `rm $file.name`
delete all files in ls / # 🧐
Even though the map functor is part of angle, in 99% situations it should be superfluous via all/iteration as seen above.
Broadcasting reduces the amount of cases where function pointers are necessary.
Just use square [1 2 3] == [1 4 9]
instead of map &square [1 2 3] == [1 4 9]
An interesting special case might be if functions take more than one argument:
int sum(int a, int b) { return a + b; }
sum [ 1 , 2 , 3 ]
MIGHT be treated as sum(1,sum(2,3))
// depending on the associativity or the operator left or right folding or it doesn't matter
Broadcasting applies to functions but not to basic operators:
[1,2,3]+4 == [1,2,3,4]
[1,2,3]>>1 == [2, 3]
[1,2,3]++ == [2, 3]
In these cases one does have to use the keywords [[map]] or [[each]] or wrap the operator into it a [[closure]]:
map [1,2,3] {it+1} each [1,2,3] {it+1} [1,2,3] {++} // dodgy
MAYBE we adopt ruby style symbols for function pointers too:
map [1,2,3] :++