merits of Lisp vs Python

Ken Tilton kentilton at gmail.com
Fri Dec 15 10:47:51 EST 2006



xscottg at gmail.com wrote:
> Ken Tilton wrote:
> 
>>Andrew Reilly wrote:
>>
>>
>>> That all looks like data.
>>
>>No, not reverse, the part you did not understand. I do not mean what the
>>code was doing, I meant that it was code.
>>
> 
> 
> Code is data is code 

I was hoping no one would make that mistake. :) macros are all about 
code is data, but code is not data in Python* so the two words code and 
data serve to differentiate them for Pythonistas.

*  Taking questions after a keynote to ILC200? where he reiterated that 
Python was the same as Lisp for all intents and purposes:

Norvig: "Yes, John?"
McCarthy: "Is code also data in Python?"
Norvig: "No."

End of exchange. :)

>- even in Python:

This could be tougher than I thought.

> 
> skills_table = [
>   {
>   "title": "Absolute Value",
>   "annotations": ["Bleah bleah", "ho hum", "etc..."],
>   "hints": ["and so on", "etc..."],
>   "reverse" : (lambda x: whatever(x))

That does not demonstrate that code is data, that demonstrates that a 
lambda is a first-class object (and, yes, Python's lambda is lame).

You will know you have code as data when you can write Python code that 
takes apart "whatever(x)" and produces "oh-now-I-get-it(y)". As part of 
the language, such that Python applies your transforming code for you 
whenever it sees whatever. (Hell, even C has a preprocessor.)

>   },
>   {
>   "title": "Square Root",
>   "annotations": ["Bleah bleah", "ho hum", "etc..."],
>   "hints": ["and so on", "etc..."],
>   "reverse" : (lambda x: someother(x))
>   },
>   # etc...
> ]
> 
> Of course those lambdas are crippled in Python (and not really
> necessary in this bogus example)...  But that's without trying to be
> clever:
> 
> class AbsoluteValue:
>    title="Absolute Value"
>    annotations=["Some list", "goes here"]
>    @classmethod
>    def reverse(cls, *args):
>      # I didn't understand what your code was doing

yeah, and god forbid you should ask. :) this is the crux of the matter!

Actually, it is kinda cool that you and Greg are semi-identifying the 
crux by saying "this is the only bit I do not get, I'll skip this, move 
on, nothing to see here".

>      pass
> defskill(AbsoluteValue)
> 
> That would be a reasonable place for a "pie decorator" on a class, but
> I guess that's not allowed. 

Hmmm. Actually, that is the whole point, all of Python is allowed. 
decorators were used in PyCells, but I never got much of an idea what 
they did. Is there a moral equivalent of a macroexpansion for decorators 
so you can show the before and after?


> I doubt this second example would be
> considered "Pythonic" in any case...

exactly what we are looking for in this cultural exchange: how would 
Python handle what I am doing with macros in the reverse functions? Make 
it as slick and programmer-friendly (cuz I may get to a hundred of these 
before I am done with Algebra I) as possible. When all the Pythonistas 
proclaim it optimal, then we compare and contrast.

This, btw, is the Tilton Test for language comparison: Not measurements 
of programmer effort, rather examination of perfect equivalent code. 
PyCells vs Cells would be an amazing case, because that is some hairy 
functionality.

>>Not the code. In reverse.
>>
> Why not?

Is, too! (ie, I am kinda looking for a specific question that conveys 
understanding of the use case.)

> Python has plenty of other flaws that I can't happily work around, and
> I do think Lisp is more flexible.  However, I think your example is
> readable enough with a data driven algorithm in most any popular
> language.  All of the data is visible to the reverse(...) method.
> Maybe I missed something in your example, but I think you aren't trying
> hard enough.  :-)

Precisely. I am not trying at all. I am coding between visits to Usenet. 
This use case just popped up and was pretty simple (at first, before I 
got to the reverse function) so I dropped it off. This is a wild macro, 
not farm-bred, deliberately crafted to embarrass macro. A real live 
natural comes up all the time working wouldn't want to code without it 
macro. I could have searched my code base to find more brutal cases, but 
this is short and sweet and unforced and uncontrived and wheres my 
thesaurus?


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