algebra/prefix/infix (was: Python syntax in Lisp and Scheme)
Bruce Lewis
brlspam at yahoo.com
Wed Oct 8 09:23:34 EDT 2003
Pascal Bourguignon <spam at thalassa.informatimago.com> writes:
> Most probably, you would write a macro named WITH-INFIX and thus
> automatically scope the infix part:
>
> (with-infix 1 / x + 1 / ( x ^ 3 ) + 1 / ( x ^ 5 ) )
How about a with-algebraic macro? Someone mentioned that Python uses a
nice algebraic syntax. That would obviously be different from the infix
syntax you illustrated. With infix syntax, it takes some examination to
notice that the above expression is the sum of three fractions. You
have to think about operator precedence and everything. With algebraic
syntax you could see it at a glance:
1 1 1
----- + ----- + -----
3 5
x + 1 x x
Of course, prefix notation would also make it obvious at a glance that
you have the sum of three fractions:
(+ (/ 1 (+ x 1))
(/ 1 (expt x 3))
(/ 1 (expt x 5)))
You're already pretty close to algebraic syntax once you upgrade from
infix to prefix notation. But that actual algebraic syntax must be
really cool in Python. Isn't there some math tool out there that also
does it?
When Python programmers put algebraic formulas in their code, does it
mess up the indentation at all? I'm curious exactly how it works.
More information about the Python-list
mailing list