Re: [stack] stackless fixed-arity concatenative languages
John Nowak <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On May 20, 2008, at 2:39 AM, Daniel Ehrenberg wrote: > This is a reasonable idea for some cases, but there's some generality > that's lost. Certainly. > Look at how reduce is defined in Factor: > > : reduce ( seq identity quot -- result ) > swapd each ; Aye. It makes sense as 'each' is a generalized version of 'fold' that allows you to access the stack and not just deal with two values. It's not clear to me though if something like 'each' is too powerful for its own good. It probably isn't. > When each runs, it has the stack underneath as an implicit > accumulator. That means that we can just use the code of each when > writing reduce, but only because the quotation can be not just 1/0 but > also 2/1. I suppose I just restated this above for no good reason. > Anyway, can't a type signature for each of something like ( A ( A x -- > A ) [x] -- A ) handle this adequately? Is it difficult to infer or > deal with such a type? The type for 'each' in Cat is exactly that and it works fine in practice. My main interest here is in allowing a direct and efficient translation to C. My guess is that the sacrifices necessary will be too severe, although it may possibly allow easier reasoning about program behavior that might make the loss of generality worth it. Given the lack of problems n-ary functions have presented though in terms of types and formalizing a term rewriting semantics, I'm skeptical of that being the case. - John