Why is Python popular, while Lisp and Scheme aren't?
Pascal Costanza
costanza at web.de
Sat Nov 9 19:49:33 EST 2002
Syver Enstad wrote:
> On another note, I think the Smalltalk method call (keyword message send)
> syntax is fabulously readable, why haven't anybody picked that up?
> Code like this is marvelously more understandable than the usual
> position based argument list that one uses in Lisp and C.
>
> Ex:
>
> aCircle paintOn: aCanvas at: aPoint
>
> Where aCircle, aCanvas and aPoint are variable names, and what is
> happening is that one is calling the method paintOn: at: where aCircle
> is self. The alternative:
>
> aCircle.paint(aCanvas, aPoint)
>
> is okay for this example but the smalltalk way lets you convey much
> more. Python has a kind of middle ground with its keyword messages,
> which is good but not quite as nice as Smalltalk.
In Common Lisp, you can have:
(paint circle :on canvas :at point)
Given that you have defined paint as follows:
(defun paint (&key on at)
...)
You can also have default values.
(defun paint (&key (on default-canvas) (at '(0 0)))
...)
So you can have all of the following.
(paint circle :on canvas)
(paint circle :at '(5 5))
(paint circle)
If you define circle to be a class, you can have the usual overriding of
methods as follows:
(defmethod paint ((object circle)
&key (on default-canvas)
(at '(5 5)))
...)
(defmethod paint ((object rectangle)
&key (on default-canvas)
(at '(10 10))
...)
(paint (make-instance 'rectangle) :on my-canvas :at '(150 10))
...which is to show that you can mix positional and keyword parameters.
In the latter examples, circle and rectangle are classes defined as follows.
(defclass circle (graphical-object)
(radius))
(defclass rectangle (graphical-object)
(width height))
...where graphical-object is the common superclass, and radius, width
and height are slots (instance variables).
etc., etc. ;)
Pascal
--
Given any rule, however ‘fundamental’ or ‘necessary’ for science, there
are always circumstances when it is advisable not only to ignore the
rule, but to adopt its opposite. - Paul Feyerabend
More information about the Python-list
mailing list