Re: [stack] sweetening concatenative syntax
Manfred Von Thun <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <C3FC86CE.F48%[email protected]> |
On 5/3/08 8:04 PM, "John Nowak" <[email protected]> wrote > > > I've had some thoughts recently on syntactic additions to > concatenative languages that seem potentially quite useful. > ... > I. Lambda Expressions > > Assuming functions have the syntax '[<body>]', it seems useful to > introduce the syntax '[<bindings> -> <body>], where bindings are > ordered with the top of the stack towards the right as is familiar. > For example, the following two functions are equivalent: > > foo :: -> [a b -> b a a] > foo = [swap dup] > foo = [a b -> b a a] > That is exactly the conclusion I came to when playing with a Joy in Prolog, PJoy Here are swap, +,your foo and stack in this notation (with help from Prolog¹s way of allowing simple modification of its native syntax: swap turns [A,B|R] into [B,A|R]. + turns [A,B|R] into [C|R] :- C is A+B. foo turns [B,A|R] into [A,A<B|R]. stack turns S into [S|S]. These are not documentation, but the implementation! R means the rest (of the Joy stack), the vertical bar is Prolog notation. The last one, for stack, is an example that would be difficult in the proposed lambda notations I have seen. > Pattern matching, which is one of Prolog¹s strengths, is also useful when defining new operators in terms of several others. The output stack from one operator has to match the input stack of the next operator, and in a crude compiler (from Joy to Prolog) which I write, Prolog did all the checking before I even noticed that it was doing that. > > > II. Local Function Variables > > If you permit lambdas, it makes sense to offer a simple syntax for > declaring functions with named variables. This is similar to how > Scheme offers '(define (foo <bindings>) <body>)' to mean '(define foo > (lambda (<bindings>) <body>))'. The declaration syntax proposed here > mimics use. In particular, the name of the function being defined > occurs *after* the arguments. > Indeed. They are useful when things get messy, such as the annoying quadratic formula. With ³local variables² in Pjoy it can be defined rather intelligibly. I¹ll have to bring the example from my home computer. - Manfred [Non-text portions of this message have been removed]