Skip to content

iteration

Pannous edited this page Sep 22, 2021 · 4 revisions

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]

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 {start it}// or 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:

print all characters in "hello"
print characters in "hello"

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:

nums=[1,2,3,4]
print nums that are even

This works in the python implementation of Angle but might need some time to be part of the Wasp implementation.

The keywords, functions or functors each any and all are reserved but currently not in used.

Question when and why would for for each for any and for all ever differ?

On the other hand we can have each any and all acting similar or identical to for:

each [1,2,3]: print it
all [1,2,3]: print it
all numbers > 2: print it

The last example may seem difficult, but it is just the > operator acting on the whole set via broadcasting

open questions

Home

Philosophy

data & code blocks

features

inventions

evaluation

keywords

iteration

tasks

examples

todo : bad ideas and open questions

⚠️ specification and progress are out of sync

Clone this wiki locally