Why aren't we all speaking LISP now?

Steven D. Majewski sdm7g at Virginia.EDU
Sat May 12 16:36:21 EDT 2001


On Sat, 12 May 2001, Courageous wrote:

> 
> >> Even simple things like iterating over a sequence of objects is done
> >> in a completely different way: in Lisp you do something to the first
> >> item then recurse.  In Python, you use "for x in list".
> 
> I missed this comment earlier. It's incorrect. Amongst professional
> Common Lisp programmers, there are two common forms used for
> iterating over items in a list. They are (dolist), which is identical in
> function to Python's for: form, and (map) which is identical in function
> to Python's map/lambda (which was borrowed directly from Lisp)
> and very similar in function to Python's list comprehension.

I mostly agree with Courageous here.

  Most Lisp (as opposed to Scheme) programmers use recursion mostly
where recursion is actually needed -- which would be for the same
sorts of things C or Python programmers would use recursion: 
 traversing complicated tree or list structures -- dealing with
recursively defined data structures, etc. 

  AI programs, for example, tend to use recursion because of the
nature of the problem, not the nature of the language. non-stackless
Python uses recursion in it's ceval.c interpreter loop. 

 Things that can be done in loops are usually done in loops, or else
some variant of map is used. Too many nested maps are discouraged 
if they would produce excess CONSing (The python equiv. would be 
creating too many temporary intermediate lists). In those cases, 
programmers will use iteration for performance sake (although maybe
a first prototype would use nested maps) or else use functional 
composition: instead of useing several simple functions in nested
map expressions, build up a more complicated function using lambda
and other functional expressions and apply that function in one 
pass. ( There is also a mapinto function, that maps back into place,
which is useful for vector-math type constructions to avoid creating
a bunch of temporary lists or vectors. ) 

-- Steve Majewski






More information about the Python-list mailing list