Re: [stack] sweetening concatenative syntax
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Mar 6, 2008, at 6:56 PM, William Tanksley, Jr wrote:
>> What 'unlist' does is take three arguments. The first is a list. The
>> second is a function that says what to do if that list is null. The
>> the third is a function that acts on the list after is has been
>> unconsed if it is not null. The 'unlist' function is called a sum
>> deconstructor as lists are sum types (they're either a "null" or a
>> "cons").
>
> Cool! So 'unlist' does exactly what FunForth does (well, it's
> typesafe, unlike FunForth).
>
> I suppose I don't get why lambdas help with that, then. I assumed you
> were talking about pattern matching, since lambdas there could fit
> into the pattern, therefore helping you notate what is being
> extracted. But if you're only disassembling the parts of a structure,
> I don't see why you have to give the parts names.
Ah, sorry if I've confused you. Lambdas don't have anything to do with
it; they just let you write it in a way that makes it look more like
pattern matching. You can write it without variables if you prefer.
You can even write it with just one variable which is actually nicer:
f map = []
[xs -> f i xs f map cons]
unlist
Since we're not binding the element below 'xs' the element is simply
left on the stack.
- John