Hi Marco,
Marco Maggi wrote:
I say: If it is in the position of a unary operator, it is
a unary operator. IMO the syntax "sin(b)" is ugly, I would
prefer:
| (infix '(a + sin b + cos c + tan (d + e)))
Sure, that works:
> (infix '(a + sin b + cos c + tan (d + e)))
(+ (+ (+ a (sin b)) (cos c)) (tan (+ d e)))
so that one can write also:
| (infix '(a + sin cos tan - (sin - 0.2)))
OK, so... I'm trying to keep the core algorithm really simple. When I
added unary '-' it seemed to make it quite a bit more complicated to
deal with this overloading. So for now, I keep it simple by using 'neg'
as the unary negate. So the above works:
> (infix '(a + sin cos tan neg (sin neg 0.2)))
(+ a (sin (cos (tan (neg (sin (neg 0.2)))))))
In that last example, I think you can just leave off the last set of
parenthesis. I get the same thing:
> (infix '(a + sin cos tan neg sin neg 0.2))
(+ a (sin (cos (tan (neg (sin (neg 0.2)))))))
It might also be nice to allow prefix notation to be
sprinkled in randomly. Perhaps another escape notation for
that? Abuse quasiquote for that feature?
You can define a "prefix" form that just expands to its
unchanged arguments.
Right, something like that would work.
The version that handles the above examples is at:
http://proteus.freeshell.org/_shunting-yard-unary-b.scm
Ed