Tak-Shing Chan said:
Chris said:
[...]
In other words -- and this is a general principle -- the important
thing is not the syntax, but the required semantics.
Syntax is important, too, because a helpful syntax can
enhance readability (and writeability).
x1 = div(sub(neg(b),sqrt(sub(pow(b,2),mul(mul(4,a),c)))),mul(2,a));
[OT] LISP programmers might disagree (with this particular
example).
[OT] LISP programmers go into debt trying to buy enough
parentheses to get through the day. Been there, done that
(professionally), still hearing from collection agencies. ;-)
Seriously, one just doesn't find Lisp programmers writing
single-expression forms as complex as those C and FORTRAN folks
dash off as a matter of course. The expression above, in LISP,
would most likely be split into two if not three parts, with
one or perhaps two temporary variables just to hold intermediate
results:
(setq d (- (pow b 2) (* 4 a c)))
(setq n (- (- b) (sqrt d)))
(setq x1 (/ n (mul 2 a)))
In principle, of course, this could be written
(setq x1 (/ (- (- b) (sqrt (- (pow b 2) (* 4 a c)))) (mul 2 a)))
.... but that hardly ever happens. When it does, it's as hard
to read as ... well, just *look* at it. (And note that this
example takes advantage of LISP's "variadic" functions in a way
not available to C; the C equivalent, above, is even worse.)
With practice one becomes more adept at reading this kind
of verbose linearized tree (as I said: been there), but it's
never going to be as readable as the C/FORTRAN/ALGOL syntax
that enjoys the benefit of a close resemblance to the standard
mathematical notation we've all been reading since grade school.
Real-life example: Here, in all its ugliness, is an actual
expression from one of my actual C programs:
quadratic (&t1, &t2,
SQUARE(xvj - xvk) + SQUARE(yvj - yvk),
2.0 * ((xcj - xck) * (xvj - xvk)
+ (ycj - yck) * (yvj - yvk)),
SQUARE(xcj - xck) + SQUARE(ycj - yck)
- SQUARE(rj + ball[k].r));
Even with the benefits of C's looks-like-mathematics syntax,
this thing is sufficiently difficult to read that I went to
a little extra work chopping it into multiple lines and adding
suggestive indentation. Still, it remains comprehensible, if
just barely so. Challenge: Translate this into LISP (or another
syntax using functional forms for operators) and make it no less
readable than the above. I'll even allow you to leave out the
first two arguments, as they're artifacts of the way C does things.
I'll bet you a dollar^H^H^H^H^H^H^H denarius^H^H^H^H^H^H^H^H^H^H^H
ten electrons you can't do it.