Re: [stack] sweetening concatenative syntax
"Christopher Diggins" <[email protected]>
| Newsgroups | gmane.comp.lang.concatenative |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Mar 18, 2008 at 10:17 PM, Manfred Von Thun <[email protected]> wrote: > > 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. I agree. I think it is worth mentioning that Slava made some interesting points on the subject of quadratics in a concatenative style: http://factor-language.blogspot.com/2007/03/evaluating-quadratic-polynomial.html When you see ">r ... r>" in Factor I believe you can just replace it with "[...] dip". - Christopher ------------------------------------ Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/concatenative/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/concatenative/join (Yahoo! ID required) <*> To change settings via email: mailto:[email protected] mailto:[email protected] <*> To unsubscribe from this group, send an email to: [email protected] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/