Re: [stack] sweetening concatenative syntax
Manfred Von Thun <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <C406C2CF.F83%[email protected]> |
On 11/3/08 6:58 PM, "Manfred Von Thun" <[email protected]> wrote: > > On 5/3/08 8:04 PM, "John Nowak" <[email protected] > <mailto:john%40johnnowak.com> wrote > > ... >> > 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. > Here it is, copied to paper, ported by car, sent as mail: A, B, C are the three input variables, R is the rest of the stack. P and Q are the output variables, the positive and negative roots. Every datum on the stack is typed as shown. Two local variables are used: Diff and Root. quad turns [C:num, B:num, A:num | R] into [[P:num,N:num] list | R] :- > Diff is B*B -$*A*C, > ( Diff < 0.0, > -> write(quadratic: cannot take root of negative argument¹) > ; Root is sqrt(Diff), > P is (0-B+Root)/(2*A), > N is (0-B-Root)/(2*A) > ). > Looks a lot more intelligible this way with local variables than when written in [urely concatenative style. > > - Manfred > [Non-text portions of this message have been removed]