Using @ For Iterators

Originally I mentioned the concept of natives taking variables as an optimization.

But how bad is it, really, to say:

>> iter: [a b c]

>> @iter
== a

>> next $iter  ; <-- using the "pass in the variable to update" trick
== [b c]

>> @iter: <magic>
== <magic>

>> head of iter
== [a <magic> c]

I think my biggest objection is that NEXT is a common variable name, and I've been trying to move away from it being in global namespace, preferring NEXT OF. (If you're doing a lot of NEXTs in your code, you could always say next: next-of/)

So with ADVANCE:

advance $iter

advance the iter ; if you don't like the $ sign

advance:2 $iter  ; dialected call with how much to advance y

advance:by num $iter  ; refinement form (potential "positional" refinement)

It "hides" the mutation (in the sense that there's no SET-WORD). But it would mean that BLOCK! could act as a light iterator, and be compatible with the object-like iterators which implemented ADVANCE as a mutating function.

1 Like