

Introduction to Lisp: Heron's method - johnaspden
http://learnclojure.blogspot.com/2010/01/clojure-dojo-method-of-heron-of.html

======
bleair
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.

------
anonjon
"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.

~~~
johnaspden
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.

~~~
anonjon
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. x _x+y_ y 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?)

