[Edu-sig] Re: Python Programming: An Introduction to Computer
urnerk at qwest.net
Sun Dec 14 13:16:52 EST 2003
> > For example, I think the reason it's often compared to LISP is you
> > have all these hooks into the syntax itself, such that you can
> > program at the meta level. Changing the meaning of the arithmetic
> > operators is just the beginning.
> Um, this is not a "hook into the syntax", and operator overloading
> isn't very Lispish; I think the concept actually came from Algol-68
> and was popularized by C++.
By "hook into the syntax" I meant the ability to change the behavior of
obj() via __call__, or obj.a via __getattr__ or __getattribute__. Or we
might change the behavior of obj[a] (__getitem__).
I see overloading of arithmetic operators as just the beginning.
> Lisp's hooks into the syntax are a lot more direct: its syntax
> actually translates to a data structure that is directly manipulable
> from inside the program, which is not how Python works. The available
> "representations" of program code are either trivial (strings),
> immutable (code objects) or extremely hard to handle (parse trees).
> And there is no way to change the *syntax*.
This is a sort of perverse example, but is what I was trying to get at re
>>> class P:
self.value = value
return P(self.value + other.value)
return "P: value = %s" % self.value
>>> p1 = P(3)
>>> p2 = P(5)
P: value = 8
P: value = 25
Many other languages wouldn't let you mess with the behavior of square
brackets like this. Not that we'd want to in just this way of course.
True, the syntax is still legal Python. What's changing is behavior.
> About the main topic of this weekend's thread, I am happy to hear
> Python's role in the CS curriculum clarified (thanks to John Zelle's
> book as a conversation-starter), and I am seeing some posts from Arthur
> that I can actually understand.
> --Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Edu-sig