Re: [stack] language hierarchy
Manfred Von Thun <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <C3B3F779.DDB%[email protected]> |
On 12/12/07 2:44 AM, "John Cowan" <[email protected]> wrote: William Tanksley, Jr scripsit How about "self" as a call to its enclosing context? >> > It won't work for dynamic definitions, because there's no distinct concept >> of >> > "enclosing context". All you know is that you're inside a quotation that's >> > inside another quotation; you can't look ahead to see which enclosure is >> the >> > one being defined and/or executed. There are several solutions: [snippage] >> 4. >> > Fall back on the Y combinator, or its eager equivalent Z. >> > Two things: First, the Z combinator is actually pretty much the same as the x combinator in Joy, definable as: x == dup i, which can do everything that the y combinator can (and it is also more efficient). Second, the problem of using a defined function before it has been defined also occurs in quite conventional definitions when there is mutual recursion of functions. Most languages use the format A definition consists of a head followed(!) by a body A head consists of a name and the names and types of the parameters and the type of the value returned. The body consists of a statement (for procedures) or an expression (for functions) or a combination of these. Since the head precedes the body, there is no problem about recursive calls in the body, not even in a single pass compiler. If the order were reversed, as in the style currently being discussed, then a single pass compiler would have to do some backpatching, and it all gets messy. But even if the head always precedes the body, there will be a problem about mutual recursion. In Pascal (parsing-) functions can be nested, so the usual mutual recursion of expression -> term -> factor -> expression can be handled by nesting. But that will not work in some cases, most famously for factor -> function-call -> actual parameters -> expression The problem arises because some statements are procedure calls which also need actual parameters. The (very simple) solution is to give a so-called forward declaration. In C there is no nesting of definitions, so all cases of mutual recursion need one (or more) forward declarations, called prototypes in C. The same trick of using forward declarations could also be used if one really wants to have definitions to have first the body and then the name (presumably no explicit parameters in a concatenative language). Then a simply recursive definition would look like this: [] def foo (* the forward declaration with dummy body*) [.. foo.. foo..] def foo (* the full definition with recursive calls *) But I still do not see any advantage in reversing the normal <name body> order for ordinary and self-recursive definitions. I think that for languages with explicit parameters (most languages) it makes sense to give forward/prototypes for all functions, as one is encouraged to do in large C programs. But that is another matter. - Manfred [Non-text portions of this message have been removed]