Re: [stack] Fwd: [Factor-talk] cleave, 2cleave, and spread
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Apr 4, 2008, at 12:10 AM, William Tanksley, Jr wrote:
> I'm not sure that it's impossible to type, by the way;
> it seems like it should be possible if the arrays are typed.
I'll cover this in my next email (responding to Daniel).
>> That's not to say cleave isn't convenient, but for
>> convenience alone you can always offer it as a macro that
>> translates a
>> statically-known list of functions to the same thing in terms of some
>> simpler core set.
>
> What would such a thing look like -- either the macro or the "simpler
> core set"? (Just curious.)
The translation looks something like this:
{[foo] [bar] [baz]} cleave ==> [foo] keep [bar] keep [baz] i
In other words, you just insert 'keep' between the functions and add
'i' at the end (as you don't want to keep the value around that last
time). For 2cleave, use 2keep, etc. Accordingly, you have an easy way
to implement 'cleave' as a macro in a typed language.
Of course, since it is a macro, you do have to know the list at
compile time (i.e. it has to be provided as a literal). According to a
discussion earlier tonight with Slava, this seems to be the most
common use case by far.
- John