Re: [stack] Concatenative Hardware
"William Tanksley, Jr" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
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.) > 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. > 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? > 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. > ... 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? > Don Groves -Billy