Re: [stack] Generators (was: Concatenative Hardware)

Don Groves <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
Sorry for not changing the subject line earlier...

On Nov 2, 2007, at 19:26 , William Tanksley, Jr wrote:

> Don Groves <[email protected]> wrote:
>> A generator is a persistent function. When activated, it pushes a
>> copy of
>> itself on the stack. The copy performs the generative function and
>> remains
>> on the stack until specifically dropped. Each time it comes to the
>> top of the stack it generates a value according to its definition.
>
> "Comes to the top of the stack" is unclear. It would make more sense
> to say that every time GENERATE is called on it, it produces the next
> value. (You could also overload UNCONS to work that way... but that
> seems dangerous.)

Good point! I could just use the I or DIP combinator to execute a  
generator.
This would make it more generally useful.


>> Example: [1 2 ...] defgen Z+
>> Z+ is now a generator a copy of which will generate positive  
>> integers as
>> long as it remains active (until dropped from the stack).
>
> As long as you're defining new syntax, why not have "[x ...]" be
> defined in the language as a "generator quotation", so you don't need
> 'defgen'? Just use 'const' or whatever.

That was my original design and I'll return to that, thanks!


>> stack:
>> => Z+
>> yields -
>> stack:[2 3 ...] 1
>> =>
>
>> The next time it comes to the top of the stack, it will generate a 2,
>> thusly -
>> stack:[3 4 ...] 2
>> =>
>
> Specifically, does this mean that:
>
> => Z+ SWAP SWAP
> yields -
> stack:1 2 [4 5 ...] 3
>
> ?
>
> If so, is there any way to drop a generator from the stack?

I was thinking of having a dropY instruction, but then that couldn't be
defined as swap drop could it?  This problem is also solved by using
a combinator to execute a generator.


>> This behaviour continues until the user/program decides to stop it.
>
> How?
>
>> Thus,
>> the ellipsis generator, ..., can mimic an infinite list. Z+ is
>> included in the
>> ACL standard library.
>
> Obviously the ellipsis generator is either very clever with lots of
> special cases, or it can only handle additive sequences.

That depends on the definition. [0 -1 ...] would generate negative
sequences, for example. I could also include an operator in the  
definition
and make it more group-like. Nothing in ACL is cast in concrete yet  
which
is one reason I appreciate your (and other's) comments and suggestions
so much!


>> ... and so on until 99 is produced, at which point the generator copy
>> self-destructs.
>
> Without being dropped? How will client code know that their stack's
> been changed?

One thing I forgot to mention is that a finite generator acts like an  
empty
list after generating its last value so a null value will be  
generated when
the client code asks for the next value. I suppose I could require  
the client
code to drop the generator at that point...
--
Don


>
>> Don Groves
>
> -Billy
>
>
>
> Yahoo! Groups Links
>
>
>
>
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.