[stack] syntax preference question

John Nowak <[email protected]>
Newsgroups gmane.comp.lang.concatenative
Message-ID <[email protected]>
Everyone likes debating matters of syntax, right?

Here's a (rather monolithic) way of writing the quadratic formula in  
Factor:

   [ rot 4 * * [ [ neg ] [ sq ] bi ] dip - sqrt [ + ] [ - ] 2bi ] keep
   2 * tuck [ / ] 2bi@

Here's the same formula in Fifth using c-expressions. This is the  
syntax I've been using for my examples recently:

   keep(rot 4 * * dip(bi(neg, sq)) - sqrt 2bi(+, -)) 2 * tuck 2bi@(/)

Here's the same thing using s-expressions. Note that because  
whitespace can't be used as composition in all cases, we need an  
explicit composition combining form (called 'o'):

   (o (keep (o rot 4 * * (dip (bi neg sq)) - sqrt (2bi + -)) 2 * tuck  
(2bi@ /))

This could be improved somewhat by making [a b c] special syntax for  
(o a b c):

   [(keep [rot 4 * * (dip (bi neg sq)) - sqrt (2bi + -)] 2 * tuck  
(2bi@ /)]

Anyway, I'm unsure which of the two approaches, c-expressions or s- 
expressions, is preferable. C-expressions look a fair bit cleaner (as  
concatenation always represents composition), but they're less regular  
(code is no longer just a simple tree). There may also be some  
advantages to making composition explicit of which I'm not yet aware.

Yet another thought was to have a more "special" syntax with square  
brackets used for the cleave combinator (with a number prefixed for  
keeping more than one value per quotation) and things like `foo(a) as  
syntactic sugar for dip(foo(a)):

  [rot 4 * * `[neg, sq] - sqrt 2[+, -], 2 * tuck 2@[/]]

Of course, this approach could be made more severe.

Any thoughts?

- 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.