merits of Lisp vs Python

Ken Tilton kentilton at gmail.com
Sat Dec 9 11:07:41 EST 2006



Steven D'Aprano wrote:
> On Fri, 08 Dec 2006 22:02:59 +0200, Alex Mizrahi wrote:
> 
> 
>>you have an expression 3 + 4 which yields 7.
>>you have an expression 4 * 1 which yields 4.
>>if you paste 3 + 4 in place of 1, you'll have 4 * 3 + 4 = 16. as we know, * 
>>is commutative, but 3 + 4 * 4 = 19.
>>so result depends on implicit operator precendence rules.
>>
>>in lisp, if you paste (+ 3 4) in (* 4 1), you'll have (* 4 (+ 3 4)), and it 
>>does not depend on order of operands, (* (+ 3 4) 4) yields same results. you 
>>do not have to remember precendence rules 
> 
> 
> Speaking as somebody who programmed in FORTH for a while, that doesn't
> impress me much. Prefix/postfix notation is, generally speaking, more of a
> pain in the rear end than it is worth, even if it saves you a tiny bit of
> thought when pasting code.
> 
> Except, of course, it doesn't really save you any thought. You can't just
> expect to paste an expression randomly into another expression and have it
> do the right thing.

Tell that to the unlimited number of monkeys I have over hear generating 
my next application. You might also read what I wrote earlier in this 
thread about how I leveraged the parens thing to edit code in logical 
chunks instead of chunks of text. If you think about it, that is exactly 
how code should be edited.

But I am fascinated: Python text can be edited randomly because it uses 
infix? Or did you just throw in randomly because your point sounded so 
weak without it? :)

> Oh, it will compile all right. But it won't do the
> right thing! Since you -- not the compiler -- have to understand the
> semantics of what you are pasting where, and paste the right expression
> into the right place, the effort saved by not using infix notation is less
> than the effort needed to mentally translate between prefix and infix.

Has it ever occurred to you that you might be the one translating? 
Because you are, you just do not know it. The only time I translate is 
when I have to express a multi-operator math formula in Lisp:

    (eql y (+ (* m (expt x 2)) b))

I threw an exponent into the slope-intercept form of a line for the heck 
of it. Gotta tell you, I do not have to code a lot of math formulas in 
Lisp, and I would definitely download and infix-eating macro if I did.

Aside from that, you are the one translating. Prefix is terribly natural 
to the mind. Think about it. Add it all up. Add the tax and price and 
tip. Those are imperative, this one functional: the sum of the parts. 
The only time one hears infix in speech is when one is reading math 
notation. So... put two and two together.

> 
> If you are one of those people who actually think in prefix notation, then
> I raise my hat to you while backing away slowly.

Be careful backing away from yourself. :) I remember talking to a Welsh 
chap who had experienced the transition to a decimal system for money 
from the good old days of shillings, etc. He said he still had to 
translate pennies to shillings, even though the decimal system was less 
ornate. What mattered was the habit, not the clarity of representation.

The good news is in my earlier point: you already are using prefix. Even 
in programming. What does a functionall look like? fn(p1,p2,p3) Lisp 
just moved the left parenthesis in front of the fn so the logical chunk 
(function+parameters) is also a textual chunk neatly packaged and 
editable between matching parens.

> 
> (And actually, I'll give you one point: I've been hitting my head against
> a brick wall over a particular problem, and I think your email just gave
> me a clue how to solve it. Sometimes prefix/postfix notation is the right
> tool for the job. See, I can learn from Lisp.)

I think that was A Message From God(tm).

:)

ken

-- 
Algebra: http://www.tilton-technology.com/LispNycAlgebra1.htm

"Well, I've wrestled with reality for thirty-five
years, Doctor, and I'm happy to state I finally
won out over it." -- Elwood P. Dowd

"I'll say I'm losing my grip, and it feels terrific."
    -- Smiling husband to scowling wife, New Yorker cartoon



More information about the Python-list mailing list