CACI-International / ergo

The ergo language and runtime.
MIT License
2 stars 2 forks source link

Provide some form of `for` #13

Open calebzulawski opened 1 year ago

calebzulawski commented 1 year ago

Without mutability, a for loop probably has limited use, but it can be confusing when it does come up:

^Array:from <| Iter:map (fn :dir -> fs:create-dir $dir) $dirs

would probably be easier to understand as something like

for :dir in $dirs { fs:create-dir $dir }

The scoping of :dir is a little bit unusual compared to the rest of the language, which might be a complication. Something like

for $dirs do (:dir -> fs:create-dir $dir)

is a little more in line with the rest of the language, but slightly more verbose and doesn't flow "grammatically".

afranchuk commented 1 year ago

Just a side note: the example you provided (creating directories) typically might be better to do in parallel rather than sequenced. But I get the underlying motivation of course!

for :dir in $dirs { fs:create-dir $dir }

This form would need to be dedicated syntax as things currently exist, though there were potential plans to allow arbitrary setters. Though the semantics of the scope to which dir pertains isn't easy to handle, the original intention was for the setters to correspond to the outer scope.

Otherwise there's a few ways I can think of that would handle this:

Obviously these all end up with fairly similar implementations. It might be appropriate to add more than one, too (for instance, Iter:do has argument ordering that is compatible with typical iterator piping).