merits of Lisp vs Python

John Thingstad john.thingstad at chello.no
Tue Dec 12 20:37:00 EST 2006


On Wed, 13 Dec 2006 01:54:58 +0100, Paddy <paddy3118 at netscape.net> wrote:

>
> Robert Uhl wrote:
>
>> Steven D'Aprano <steve at REMOVE.THIS.cybersource.com.au> writes:
>> >
>> > Speaking as somebody who programmed in FORTH for a while, that doesn't
>> > impress me much. Prefix/postfix notation is, generally speaking, more
>> > of a pain in the rear end than it is worth, even if it saves you a
>> > tiny bit of thought when pasting code.
>>
>> Of course, you use prefix notation all the time in Python:
>>
>>   for x in range(0,len(y)):
>>     dosomething(x)
>
> In Python, most containers are directly iterable so we are much more
> likely to arrange our program to use:
> for a in y:
>   dosomethingwith(a)
>
> -Paddy.
>

In lisp: (loop for a in y do (do-something a))

There is one difference.. There is no iterator so you have different  
pronouns for each sequence type:

list:  (loop for a in y ..
array: (loop for a across y ..
hash:  (loop for a over y ..

hardly ideal, but workable.

Still it is a lot simpler to change the declaration in the start of the  
loop
than having to changing the access to all references to a variable as you  
might have to
with recursion. Consider

(defun func-iter (list)
	(func (first list)))
	(when (not (endp list))
	  (func-iter (rest list)))

(You could write (mapc #'(lambda (e) (func e)) list) but that is beside  
the point.)

or something like that. What happens if you change the type to a array?  
Total rewrite..
 From a software engineering point of view iteration is preferable to  
recursion because
maintenance and aggregation is simpler. (Sorry about the digression.)

-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the Python-list mailing list