Re: [stack] Generators revisited

Don Groves <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
On Nov 13, 2007, at 19:20 , William Tanksley, Jr wrote:

> Don Groves <[email protected]> wrote:
>> In rethinking the design of generators, it occurred to me that a
>> generator is in fact a closure. I'm not familiar enough with the
>> literature yet to know if closures already have an accepted
>> methodology in this group, so please enlighten me if this is so.
>
> Sure is! Actually, I kinda assumed that was going to be how you'd
> implement them :-).

I may be slow at times but I eventually catch up ;-)


>> A generator might look like [[f] a b ..] where f is the generation
>> function and a, b, etc, are its static data.  A new combinator,
>> generate (as suggested by Billy), would be needed which would
>> disassemble the generator; apply f to the the list [a b ..];
>> reassemble the generator; and push the new value on the stack.
>
> Yup. It's a simple enough function to define.
>
> The hard part is building all of the 'f's you might need. It's
> impossible to build them all; in general you have to let programmers
> build 'em for you. Icon takes one route (by making expressions be
> capable of repeating themselves); anyone know any others?

Sure, a few simple ones could be built in (Z for example) but others
would be up to users to define as needed. I'm implementing a
Fibonacci generator in ACL at the moment to serve as an example.
--
Don


>> Don Groves
>
> -Billy
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.