"When we write lisp, we have magic powers, and the reason is that our code is in a form that is easy to manipulate programmatically."
Yet there isn't a single macro or piece of code writing code implemented in this example. Also, it isn't magic, it is list construction. For the last time LISP IS NOT MAGIC.
"This is clearly seriously annoying, and like monads in Haskell, it's the first thing you hit when you learn lisp, but I promise that after a month or so of using it you stop noticing it, and although it's never quite as good for actual arithmetic, it's actually much nicer as a notation for a generalized function call."
No, it is seriously clearer than having implicit rules for order of operations that you have to memorize. Not annoying, and much better for arithmetic.
Also, there are a boatload of built in functions in clojure-contrib related to math. USE THEM. There is no need to waste time reimplementing absolute value when it is in clojure-contrib already.
There's a second half being written which will do symbolic differentiation, and maybe a few small macros. This is supposed to be a gentle introduction for non-lispers and I seriously think this will be enough for two hours.
But I'm writing something more devious just in case.
Any sufficiently advanced technology is indistinguishable from magic. I do know how it works. I've done my meta-circular interpreters.
I also know there's an abs function. There's a sqrt function too. That's not really the point of the thing.
And I am never going to believe that (+ (* x x) (* y y))
is clearer than xx + yy, even though I do realise that that's only because those rules were drummed into me at school.
More exotic examples of operator precedence, yes, I agree.
I'm glad you will be doing something more interesting for the second half.
I understand that the sqrt function is done for teaching purposes, but there is no point in showing people how to write an abs function, all it does is give the impression that Clojure doesn't have an absolute value function.
It would be a better use of time to take the opportunity to show people how to import a function from an external library (like clojure.contrib), than it would be to re-implement a relatively mundane function. Using libraries is important and something that should be covered in an introduction to a language.
My point about operator precedence is that it is clearer because it is explicit. When you add exponentiation into infix math notation, it gets very easy to screw stuff up by missing a paren.
xx+yy is ambiguous with x(x+y)y, in lisp it would be (+ (* x x) (* y y)) vs. (* x y (+ x y)).
(The point being that they have vastly different structure).
(Is it ironic that I'm arguing that missing a paren is more annoying in infix than it is in prefix?)
Clarke's Law, "Any sufficiently advanced technology is indistinguishable from magic". If you are used to java, clojure - or any lisp - is sufficiently advanced to be considered magic.
That is true presupposing that the technology behind lisp is sufficiently inscrutable to make it magic-like.
Fortunately for us, lisp is probably the exact opposite of a magic-like programming language. All you are doing is composing lists of symbols into trees of symbols and then executing them. It is stupidly simple.
Saying that lisp is magic serves the sole purpose of scaring newbies and spreading the fud that using lisp is a complex, complicated, and difficult. (it is not).
I totally agree that lisp isn't magic once you have seen past the alien notation and a couple of new paradigms (pervasive meta programming, fp, symbolic manipulation, laziness). But I consider it foolish to discount that barrier for a programmer who has never ventured outside the baroque temple of the curly brace. Perception is significant as reality.
I liked this example. Like Blue's Clues it progressed and built nicely. Unlike so many other lisp blog posts and some of the comments right here, this post was missing the pompous, elitest attitude about how LISP is superior to all other programming languages.
8 comments
[ 2.9 ms ] story [ 33.0 ms ] threadYet there isn't a single macro or piece of code writing code implemented in this example. Also, it isn't magic, it is list construction. For the last time LISP IS NOT MAGIC.
"This is clearly seriously annoying, and like monads in Haskell, it's the first thing you hit when you learn lisp, but I promise that after a month or so of using it you stop noticing it, and although it's never quite as good for actual arithmetic, it's actually much nicer as a notation for a generalized function call."
No, it is seriously clearer than having implicit rules for order of operations that you have to memorize. Not annoying, and much better for arithmetic.
Also, there are a boatload of built in functions in clojure-contrib related to math. USE THEM. There is no need to waste time reimplementing absolute value when it is in clojure-contrib already.
But I'm writing something more devious just in case.
Any sufficiently advanced technology is indistinguishable from magic. I do know how it works. I've done my meta-circular interpreters.
I also know there's an abs function. There's a sqrt function too. That's not really the point of the thing.
And I am never going to believe that (+ (* x x) (* y y)) is clearer than xx + yy, even though I do realise that that's only because those rules were drummed into me at school.
More exotic examples of operator precedence, yes, I agree.
I understand that the sqrt function is done for teaching purposes, but there is no point in showing people how to write an abs function, all it does is give the impression that Clojure doesn't have an absolute value function.
It would be a better use of time to take the opportunity to show people how to import a function from an external library (like clojure.contrib), than it would be to re-implement a relatively mundane function. Using libraries is important and something that should be covered in an introduction to a language.
My point about operator precedence is that it is clearer because it is explicit. When you add exponentiation into infix math notation, it gets very easy to screw stuff up by missing a paren. xx+yy is ambiguous with x(x+y)y, in lisp it would be (+ (* x x) (* y y)) vs. (* x y (+ x y)). (The point being that they have vastly different structure).
(Is it ironic that I'm arguing that missing a paren is more annoying in infix than it is in prefix?)
Also, reimplementing functions that are already there is a perfectly acceptable way to learn a language.
Clarke's Law, "Any sufficiently advanced technology is indistinguishable from magic". If you are used to java, clojure - or any lisp - is sufficiently advanced to be considered magic.
Edit: possessive apostrophe
Fortunately for us, lisp is probably the exact opposite of a magic-like programming language. All you are doing is composing lists of symbols into trees of symbols and then executing them. It is stupidly simple.
Saying that lisp is magic serves the sole purpose of scaring newbies and spreading the fud that using lisp is a complex, complicated, and difficult. (it is not).