What can you do in LISP that you can't do in Python

James_Althoff at i2.com James_Althoff at i2.com
Tue May 22 16:30:13 EDT 2001


Hannah wrote:
>Facit: Smalltalk's blocks, Lisp's and Python's lambdas are just the same:
>unevaluated (but possibly compiled!) code, optionally with formal
>parameters.
>
>Kind regards,
>
>Hannah.

Although I agree with the basic concept above, I think "just the same"
pushes things a bit too far when comparing Smalltalk's blocks with Python's
lambdas (less so when comparing Smalltalk's and Lisp's).  I would suggest a
couple of key differences:

o Python differentiates between statements and expressions.  A lambda block
in Python is restricted such that it can only contain an expression and not
a statement (nor a sequence of statements).  A block in Smalltalk does not
have this restriction.

o Because of the above, you need to use a function def in Python if you
want a general purpose block (as contrasted with a Python lambda).  Such a
function must be named and must be defined before (ahead of) the code that
uses it -- as opposed to being "nameless" and defined "in place" (as is
possible for Python's lambdas).  Smalltalk does not have this restriction.
A "fully general" block in Smalltalk can be "nameless" and can be defined
"in place".

o We (the Smalltalk-80 group at Xerox PARC) designed the syntax and
semantics of Smalltalk-80 from the very beginning to allow "nameless,
in-place" code blocks to serve a *very* prominent role in the language --
namely, to implement *all* control structures.  In fact, we designed the
syntax and semantics of Smalltalk-80 specifically so as to make it
unnecessary to define *any* builtin control structure into the language
proper (aside from method invocation). (The goal was to design the language
such that essentially every construct -- including every control structure
-- could be considered to be a "parameterized message sent to an object).
Python (like most languages), on the other hand, was designed to have
special syntax and semantics to support each of its builtin control
structures.  In this sense, lambdas do not serve the same fundamental role
in Python that blocks do in Smalltalk.


Jim






More information about the Python-list mailing list