merits of Lisp vs Python

Paddy paddy3118 at netscape.net
Tue Dec 12 21:13:26 EST 2006


John Thingstad wrote:

> 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
I can't quite figure out the meaning of your sentence above.

> 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..
Not even close.

In my example above:
 for a in y:
   dosomethingwith(a)
y could be a lot of built-in types such as an array, list, tuple, dict,
file, or set.
 
- Paddy.




More information about the Python-list mailing list