iteration - pannous/warp GitHub Wiki
Iteration is often implicit since all functions are automatically broadcasted 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]
Bare multi-argument application broadcasts: square 1 2 3 is square [1 2 3].
# not yet: shell / path broadcasting (card shell-backtick-run)
delete file = run `rm $file.name`
delete files in ls /
The all keyword takes a block on the left or right making it a functor similar to map:
delete all files
all files {delete it}
all processes start // here start is uncharged code, identical to
all processes {it.start}
mathematical signature:
all :: block `all` iteratable | `all` iteratable block
each :: action `each` iteratable | `each` iteratable action
Todo: what if the block retuns an iteratable? Ambiguity?
Again broadcasting should make the all keyword superfluous in many situations. The print walks print characters in "hello" and print all characters in "hello" were dropped (decision rust-cleanup-drops); the loop says it:
for c in "hello": print c
Other Iteration see for keyword:
for 1..10 : print it
for chars in text: print it
for friend in [foe1, friend1, foe2, friend2]: print it
Interesting: string Iteration Interesting: (structurally) matching for condition
Here we see overlap with the that keyword (not yet in warp — worked in the python Angle implementation):
nums=[1,2,3,4]
print nums that are even
The keywords, functions or functors each any and all are reserved. On lists, each / all as for-like forms run today; English set filters do not yet:
each [1,2,3]: print it
all [1,2,3]: print it
# not yet: `all numbers > 2` as a filtered iteration (card all-filter-iteration)
all numbers > 2: print it
The last example may seem difficult, but it is just the > operator acting on the whole set via broadcasting
Question when and why would for for each for any and for all ever differ?
open questions