« first day (3492 days earlier)      last day (288 days later) » 

7:35 AM
@HostileForksaysdonttrustSE The "curse of knowledge". Nicely put and very apropos.
 
 
5 hours later…
12:45 PM
Intrestingly, JavaScript has generators in the ES6 version, via something called function*. I'd not heard of that. But their approach is less pleasant, you have to go through a two-step process to make a function* that makes a parameterized generator object, then get the value with gen.next().value:
function* generator(i) {
  yield i;
  yield i + 10;
}

const gen = generator(10);

console.log(gen.next().value);
// expected output: 10

console.log(gen.next().value);
// expected output: 20
GENERATOR is a component you can use directly in my view:
>> array/initial 10 generator [while [true] [yield 1 yield 2 yield 3]]
== [1 2 3 1 2 3 1 2 3 1]
If you want a function that makes a generator with some static parameterization, you make that function:
gmaker: function [i] [
    return generator [
        yield i
        yield i + 10
    ]
]

gen: gmaker 10

print [gen]
; expected output: 10

print [gen]
; expected output: 20
They have a feature of deferring to another generator with "yield*". But with my rules, YIELD of NULL is a no-op, hence the generator will return NULL only when the body completes. And YIELD's stock behavior is to return what it yielded when the generator is continued. So to defer to another generator, all you need to do is until [null? yield gen2]. :-)
With the ability to quote arbitrary values, if you want to take issue with not being able to make a generator that yields null then guess what?
n-generator: func [body [block!]] [
    let g: generator compose [
        yield: enclose 'yield func [f] [
            f/value: quote :f/value
            return dequote do f
        ]
        (as group! body)
    ]
    return chain [:g | :dequote]
]
Just change the yield to quote what it gets, and dequote in both the yield's return and the generator's return. Then you can YIELD nulls, if you want to be a bad sport and not follow the protocol that I came up with for a reason...
 

« first day (3492 days earlier)      last day (288 days later) »