Is Lisp just too hard?
reprog.wordpress.com
reprog.wordpress.com
I deal with the issue of arithmetic expressions the same way i deal with any other lisp code, i indent properly:
(+ (* 1.2
(- 2
1/3))
-8.7)
now just read it from the deepest level outwards.The problem, for me, is that it's not as easy to understand, read, or write. By this, I mean that most of the time that I'm reading an arithmetical expression, I don't really care what it means. I am only reading it because it's easier to just read it than to look for where it ends and continue. It's fluff. Not being as comfortable with prefix, and probably never being as comfortable with infix, it's not as friendly to the eyes.
When I need to understand it, I'm basically converting to infix-- I think in infix, not prefix. The parentheses in the infix expression are mental and implicit, and I think my mental notation is more than adequate. Prefix form gets in the way here.
And obviously, it's more of a pain to write fully parenthesized arithmetic than not.
(+ (* (- (/ 45 99) (* (+ 1 4) 3)) (* 4 (- 5 3))))
Which operator operates on the result of the 4*(5-3) sub-expression? You have to stop and THINK about that -- you can't just SEE the answer.
(+
(* (- (/ 45 99)
(* 3 (+ 1 4)))
(* 4 (- 5 3))))
Or perhaps add in even more indentation. In any case, now if you asked me what operates on the result of (* 4 (- 5 3)), I could tell you immediately that it's *.That said, I do agree that infix notation for mathematics can often be clearer and more concise. If I found myself doing a lot of arithmetic, I might be tempted to write a macro to allow me to write in infix.
However, as you start using LISP more and more frequently, the expression you gave could be evaluated within your head at sight. It's just to know where to start looking for a opening/closing paren.
... none of which is to say that Lisp Is Bad (which is certainly not the point I was trying to make in the original article) -- just that the good points are to some degree balanced by some bad ones, and Lisp evangelists don't ultimately help their cause by pretending that even the bad bits are good.
Something like this:
http://www.cliki.net/infixI wonder if intro-to-lisp books should shy away from arithmetic in the first few chapters to avoid this stumbling block. It seems odd to introduce the nature of lisp syntax by focusing on its weakest point. Shuffling lists of symbols around gives an introduction to the syntax and the more fundamental data types, and makes for an easier segue into macros.
[1] Variable assignment is the easiest to overcome, because you simply doesn't use variable assignment as much in Lisp, and in this sense the aversion is a good thing as working to avoid it helps produce more idiomatic code. Logical operators are also easier to overcome because in practice it's not common to have thorny expressions with high nesting levels like you can in arithmetic.
I wonder if it would be worthwhile to have a MATH special form in common lisp that that allows for special evaluation in its body, like how the LOOP form parses its arguments.
(OR (AND ...)
(AND ...)
...)
is cleaner (and shorter) than the corresponding one-liner in Python.http://reprog.wordpress.com/2010/04/14/the-long-overdue-seri...
(Common Lisp has mature FFI and wrappers around things like DBI and graphics libraries. Clojure gives you the JVM libraries for your sins, and I dare you to seriously argue that the JVM has no libraries to its name.)
Really.