For Syntax - Spicery/Nutmeg GitHub Wiki
In Nutmeg the long-term goal is to see for-loops as a way of finding solutions to a logic query. For each solution it iterates over a set of statements with the bindings for each solution in turn. At the time of writing the type of query available is:
-
variable in expression
, which binds the given variable to each value produced by streaming from a snapshot of the given expression.
For example:
### Equivalent to map( f, [ 0 ..< 10 ] )
[ for i in [ 0 ..< 10 ] do f( i ) endfor ]
The idea is to unify bindings, if-statements, and for-loops into a single vision of solving logic queries where:
- Bindings require at least one solution or they throw an error
- If-statements find the first solution and run the
then
part with the binding or they execute theelse
branch - For-statements find all the solutions and execute the statements repeatedly with each binding in turn.