Remix.run Logo
bloaf a day ago

> Rye also has left to right flow so it adds left-set-word. In Rye all assigned words with set-words are constants and they are used by default. So we also need a "mod-word", that is the double colon that you noticed, and left-mod-word

So I would assume that the :i is actually constant within the loop body scope. That is, the loop function is doing something like this:

; i is not assigned in this scope

evaluate {1 :i, prns i}

evaluate {2 :i, prns i}

evaluate {3 :i, prns i}

; i is still not assigned in this scope

But it sounds like you're telling me that :i would actually escape the scope of the loop body and so it needs to be modifiable or else the loop will break.

middayc a day ago | parent [-]

Yes, Rye follows REBOL in this case. Plain block invocation doesn't create it's own scope / context. That holds for do, if, either, loop, for, map, etc.

It would be costly to have this on by default. If you want separation there are many ways to achieve it. Rye has many functions related to contexts / scopes. For creating contexts in multiple ways and evaluating code inside contexts or with context as parent or isolated context, etc.

And a lot of builtins directly accept anonymous functions in place of blocks of code.

For example for loop also accepts function if you want separation and don't mind the cost.

    for { 1 2 3 } fn { x } { print x }
    ; which can also be written with fn1
    for { 1 2 3 } fn1 { .print }
    ; or latest experiment where we have syntax for 3 injected blocks 
    ; .() - same as "with"
    ; .[] - same as "reduce/with"
    ; .{} - same as "fn1"
    ; where it's already decided department from REBOL: 
    ; () is "do"
    ; [] is "vals"
    ; {} is literal block 
    for { 1 2 3 } .{ .print }