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

Carl Banks imbosol at vt.edu
Sun Nov 10 19:02:35 EST 2002


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).


> ...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.


[snip]
> So here is an application.
> 
> > (apply-operators (+ * min max) (5 4 6 3 7))
>  +: 25
>  *: 2520
>  min: 3
>  max: 7
> 
> You can always take a look at the code a specific macro produces.
> 
> > (macroexpand-1 '(apply-operators (+ * min max) (5 4 6 3 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).


-- 
CARL BANKS




More information about the Python-list mailing list