Re: [stack] Combining Combinators
Manfred Von Thun <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <C2AAE4AB.A53%[email protected]> |
On 20/6/07 6:47 PM, "Christopher Diggins" <[email protected]> wrote: > On 6/19/07, Manfred Von Thun <[email protected]> wrote: >> On 19/6/07 1:05 AM, "William Tanksley, Jr" <[email protected]> wrote: >> >>> Manfred Von Thun <[email protected]> wrote: [..] >> At level one there are functions which take zero level entities >> as arguments. > > In Cat this would be the set of functions with types matching: ('A 'b -> 'C) But also binary operators such as +, <, cons and so on, also ternary operators such as + +, ..., also operators returning several items: + + dup, which consumes three and yields two. I don¹t know the upper/lower case conventions of your type notation to say whether these cases are already included in (A b -> C). (I don¹t dare to put in the single quotes, knowing the mess that incompatible mailers create.) [..] > Is: > > DEFINE f = [[dip] cons] dip. > > A level-3 combinator in Joy? Let us see. f is of the form [..] dip, with quotation [..] on top. Because of the dip, what is below the [..] will first be saved away temporarily, and after [..] has been executed the saved part will be restored. Suppose the saved part is 999. So the top of the stack is 999 [..], the 999 will be saved, [..] executed, then 999 restored. When [..] executes, it will push [dip] and then cons something, X, which has to be on the stack, in front of the quotation [dip], giving [X dip]. So we know that for f == [[dip] cons] dip to operate, the top of the stack has to be 999, and below that X. X 999 f X 999 [[dip] cons] dip X [[dip] cons] i 999 X [dip] cons 999 [X dip] 999 This is all we know so far from the specification of f. But presumably the intention is that [X dip] is going to be executed by some unspecified combinator. In that case it will push X and then call dip. So X will have to be a quotation, say X = [Q]. Redoing the above derivation: [Q] 999 f [Q] 999 [[dip] cons] dip [Q] [[dip] cons] i 999 [Q] [dip] cons 999 [[Q] dip] 999 So f has the effect of changing [Q], the second element of the stack into [[Q] dip], leaving the top element 999 unchanged. So f changes one quotation [Q] into another [[Q] dip], but it does not execute the result. So it is a higher order function in the sense of yielding a function, a perfectly respectable and frequently used sense of higher order. Such things are sometimes called functionals. But they are not the sort I was concerned with, since the resulting quotation [[Q] dip] is not executed. I should mention that a simpler function g == [[dip] cons] i == [dip] cons would serve equally well as an example of a program transformer. The 999 and the outer dip in your f don¹t serve any purpose. [..] > If you are concerned about eliminating any possibility of level-3 > combinators in Joy, can't you rewrite the definitions of the level-2 > primitives so that they accept combinators or non-combinators? I don't > see the reason that "dip" can't accept straight values like "5" on the > top of the stack, if "i" can accept them. Correction: Joy does not allow any of the following: 5 i 5 dip 5 map 2 3 + i 2 3 + dip ... [..] > I believe it is either good to go all the way one direction or the > other: either non-combinator values can be "evaluated" or they can't. > As far as I can see (and I could be mistaken) Joy is somewhat > ambiguous about what exactly can and can't be evaluated. can or can¹t where is the ambiguity in Joy? In Joy the combinators always expect one or more quotations: [Q] i [Q] dip [Q] map [Q1] [Q2] concat i [Q1] [Q2] concat dip ... The older combinators always expect the quotation on top of the stack. Some of the newer convenience combinators that I have been toying with expect a numeric parameter above the quotation: [Q] 3 dips would be used like this 2 3 777 888 999 [+] 3 dips == 2 3 [+] i 777 888 999 == 2 3 + 777 888 999 5 777 888 999 But old and new all expect a quotation [..] - Manfred [Non-text portions of this message have been removed]