Re: [stack] syntax preference question

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
For the sake of completeness, Slava offered this definition for the  
quadratic formula:

   : monic ( c b a -- c' b' ) tuck [ / ] 2bi@ ;
   : discriminant ( c b -- b d ) tuck sq 4 / swap - sqrt ;
   : critical ( b d -- -b/2 d ) [ -2 / ] dip ;
   : +- ( x y -- x+y x-y ) [ + ] [ - ] 2bi ;
   : quadratic ( c b a -- alpha beta ) monic discriminant critical +- ;

This is quite a bit better than the version given here:
http://www.latrobe.edu.au/philosophy/phimvt/joy/jp-quadratic.html

Using the rather terse syntax in the last email, along with 't' for  
'tuck' and 'x' for 'swap', Slava's version could hence be written as  
such:

   t 2@[/] t sq 4 / x - sqrt `[-2 /] 2[+,-]

If the cleave combinators were type-aware (which is almost certainly a  
bad idea), we could do away with the arity notations. Further hell  
could result from making ',' infix and using brackets to disambiguate  
only when necessary:

   t @/ t sq 4 / x - sqrt `[-2 /] +,-

Alright, enough perversity for now.

- John
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.