Tue 30 May 2006
Left-to-Right Reader vs. Functional Programming
Posted by dkaz under Programming, Lisp/Scheme
Following Lisp/Scheme code has always felt a bit akward and unnatural to me.
I’ve thought long and hard about why that is and I might have the culprit (hint: it’s not the parentheses) - it’s the right-to-left/bottom-to-top reading style needed to follow the code.

August 5th, 2006 at 8:45 am
You lost me.
(defun foo (bar baz)
(let* ((a (+ bar 1))
(b (* a (/ baz 2))))
(do-something a b)
(with-open-file (s "out.txt")
(format s "Data: ~a ~a~%" a b))))
Why would you read that any other way than top/bottom, left/right?
public void foo(int bar, int baz) {
int a = bar + 1;
int b = a * (baz / 2);
doSomething(a, b);
File f = File.new("out.txt");
f.printf("Data: %d %d\n", a, b);
}
I guess I’m missing what you’re saying.
Dave
August 5th, 2006 at 8:46 am
(And wrapping my nicely-formatted code in code tags didn’t work
d
August 5th, 2006 at 11:09 am
English: a equals bar + 1
infix-stly: a = bar + 1
prefix-style: a (+ bar 1)
I feel like I have to backtrack to the “+” after reading “bar”.
August 7th, 2006 at 4:25 pm
Oh. I guess I can just remember longer.
I look at it as “Okay, I’m running +, and here are the arguments to it.”
When expressions get long the regular notation really helps clean things up, since functional programming is created by compositing functions. If you read from left -> right you end up drilling down into the functionality rather than having to deal with it all the time.