Why is Python popular, while Lisp and Scheme aren't?

Pascal Costanza costanza at web.de
Mon Nov 11 05:17:22 EST 2002


Carl Banks wrote:
> Pascal Costanza wrote:
> [snip]
> 
>>Now, let's go on - "funcall" takes a function and applies it to the 
>>remaining arguments.
>>
>>>(funcall '+ 1 1 1)
>>
>>3
>>
>>>(funcall '* 2 3)
>>
>>6
> 
> You mean (funcall #'+ 1 1 1) and (funcall #'* 2 3).

No, (funcall '+ 1 1 1) works as well (as defined by the ANSI specs).

>>...and so on. Now here is another nice macro.
>>
>>(defmacro apply-operators (op-list arg-list)
>>    `(loop for op in ',op-list
>>           do (format t " ~A: ~A~%" op (funcall op , at arg-list))))
> 
> 
> It is better to do this as a function.  As written, you cannot pass a
> in built-up list of operators or numbers, and for this reason, it is
> considered bad style.

Yes, you're right. I wanted to illustrate the usefulness of macros and 
the advantages of prefix notation at the same time. I should have kept 
that separate.

Here's the function version.

(defun apply-operators (op-list arg-list)
    (loop for op in op-list
          do (format t " ~A: ~A~%" op (apply op arg-list))))

The difference between funcall and apply is as follows.

 > (funcall '+ 5 6 7)
18

 > (apply '+ '(5 6 7))
18

apply takes the parameters as a list and furthermore requires a 
parameter list, whereas in funcall parameters are optional.

The call to apply-operators now looks as follows.

 > (apply-operators '(+ * min max) '(5 4 6 3 7))
  +: 25
  *: 2520
  min: 3
  max: 7

>>(loop for op in '(+ * min max)
>>      do (format t " ~A: ~A~%" op (funcall op 5 4 6 3 7)))
> 
> I really don't think this is the best example for an advantage of Lisp
> syntax, if that's what you were trying to do, since it's trivial in
> Python also.
> 
> def apply_operators(oplist,arglist)
>     for op in oplist:
>         print "%s: %s" % (op.__name__, reduce(op,arglist))
> 
> The only technical advantage of Lisp's syntax I can think of is that
> it matches the way the compiler sees it, which is why it's so
> convenient to write macros (which are more or less extensions of the
> compiler).

Yes, that's exactly the key point. Lisp's central feature is that code 
and data are the same, and Lisp's syntax, or better lack of syntax, lets 
you exploit this central feature in the most convenient way. That's why 
Lispers typically reject other more mainstream syntaxes. (But there are 
exceptions - see the loop syntax above. BTW, loop is a macro!)

However, please note that I am not advocating that Common Lisp is 
generally better than Python. I don't like language advocacy. (I am not 
giving these examples in order to convince you that Lisp is better.) If 
you don't need Lisp's expressive power then you are probably better off 
with Python. On the other hand, from what I've seen so far, Python is 
quite close to Lisp, so you have a big advantage in case you're 
interested in widening your horizon and actually taking a look at Lisp.


Pascal

-- 
Pascal Costanza               University of Bonn
mailto:costanza at web.de        Institute of Computer Science III
http://www.pascalcostanza.de  Römerstr. 164, D-53117 Bonn (Germany)




More information about the Python-list mailing list