"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Monday, December 29, 2008


(1984 Edition: Blogger Destroys Ignorance)

Before leaving on a short holiday adventure following the Northwest Snowpocalypse of 2008, I'd set out to email my blog a short love note to Lisp. After a few helpful comments, blogger destroying same, and Twitter destroying my patience for revising blog posts, I'll try rewriting with previous comments in mind...

Something I really like about Lisp and Smalltalk is the very small number of rules and the very large bang for the buck. Ioke and io fall into that same realm:

Although nothing beats Lisp for me. Consider doubling the fraction 3/2.

In ioke the following expression evaluates to the integer 3:

3/2 + 3/2

Although Smalltalk has fractions (and if it didn't you could add them), the same expression evaluates to the fraction 9/4. Why? Because Smalltalk evaluates binary messages from left to right. There are no "mathematical operators", no "operator precedence", and no syntax for literal fractions. The Smalltalk equivalent to the ioke expression above is:

(3/2) + (3/2)

Or less generally:

3/2 * 2

Smalltalk's fewer rules than the common Algol derivatives are a good thing. As Nat Pryce commented earlier, the mathematical operator precedence rules we learn in grade school are far from universal across all of mathematics anyway. Why cling to them in programming languages?

Now we get to Lisp:

(+ 3/2 3/2)

Fractions can be expressed truly as literal numbers. This evaluates to 3 and there's never any question about "operator precedence". The fewest rules of all: function application is function application. Absolutely uniform. Absolutely lovely.


Steve Dekorte said...

"by Io as well"? Was that meant as a joke-via-understatement? :-)

Nat Pryce said...

Strictly speaking, operator precedence is not one of the rules of maths. It is a convention that one learns in primary school. There are plenty of areas of math that do without the common operator precedence rules. Lambda calculus for example. Considering the immense benefits a programming language gets by following a simpler convention, it's time us programmers moved beyond the maths we first learned at school.

mccoma said...

I guess I got a beginner's question then, on your first example (3/2 + 3/2) it seems there are no spaces between the number and the /. I thought Smalltalk did fractions and treated that as an "entity" and not a divide. So, I guess I would have thought Smalltalk would get the same result since your are adding two fractions.

Gordon Weakliem said...

That's a good point about simple syntax, but are the examples really the same thing? In Lisp, 3/2 isn't really an operator, is it? Lisp has a notation for fractions which isn't really invoking a function, it's just a notation for a constant.

Patrick Logan said...

Hey, blogger saved the comments after all.

Steve - thanks, yes, ioke should be described as most directly influenced by io.

Nat - thanks, yes, operator precedence is not ubiquitous, so you're right. All the more reason to abandon it when programming.

McComa and Gordon - thanks, yes. Smalltalk and Lisp have fractions. But Smalltalk has no literal for fractions and so binary message parsing rules may surprise you.

Most Lisps for 25 years or so have had literal fractions. And they still have no operators and only one syntactical form for applying functions. The simplest of all.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.