merits of Lisp vs Python

Pascal Bourguignon pjb at informatimago.com
Sun Dec 10 13:36:20 EST 2006


Bill Atkins <atkinw at rpi.edu> writes:
>> Yes. But you can't redefine 1+2 in Python, at least not without hacking
>> the interpreter. Can you redefine (+ 1 2) in Lisp? 
>
> Yes.  Can't you redefine standard functions in Python?
>
> Frank Buss correctly points out that you can shadow the + symbol and
> make it whatever you'd like it to be.  

Well, there is no "THE + symbol", there are a lot of different symbols
named "+".  The one you get when you read the characters of "(+ 1 2)"
depends on the dynamic binding of the COMMON-LISP:*PACKAGE* symbol.


> This is true, but now someone
> has to intentionally and specifically import the package containing
> that shadowed + into their own package.  You are never unwittingly
> using a different + than the standard CL one, although you really seem
> to want this to be the case.

The Common Lisp standard has no provision to and indeed forbid to
modify the function binding of the COMMON-LISP:+  symbol.

On the other hand, implementations may allow, sometimes with the help
of an implementation specific WITHOUT-PACKAGE-LOCK operator, to change
the function binding of the COMMON-LISP:+ symbol.

So, while the standard preserves itself, and wants you to explicitely
say you're using a symbol named "+" from a different package than
COMMON-LISP, rather than modifying CL:+, the implementations may still
allow you to actually modify the COMMON-LISP package, but of course,
this may not be Common Lisp anymore, if you don't follow the
specifications of Common Lisp (and if you do, why are you trying to
modify CL:+ that already implements Common Lisp!?).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This universe shipped by weight, not volume.  Some expansion may have
occurred during shipment.



More information about the Python-list mailing list