"Wayne O. Cochran" <[EMAIL PROTECTED]> writes:

> To be a language lawyer,
> here is a quote from Steel's "Common Lisp," sec 5.3.1, p.85.
> 
>   "It is permissible to use defun to redefine a function,  
>   to install a corrected version of an incorrect definition,
>   for example. It is permissible to redfine a macro as
>   a function."

It's generally not a good idea to be a language lawyer unless you're
quoting from the relevant standard, which in this case is the ANSI
standard for Common Lisp, or its close cousin, the CLHS.  I don't wish
to sound overly snooty, but suffice it to say that CMUCL's behaviour
is perfectly standard in this regard -- just as a C compiler is
justified in causing nasal demons to appear if you try to compile "i =
i++;".

> If one could not redefine the builtin functions then
> one would have to keep mental track of the very large
> set of functions, macros, etc... that are predefined
> in Lisp. 

Yes, or you could ask your environment:

* (symbol-package 'max)

#<PACKAGE "COMMON-LISP">

> Also, even if one could not redefine the builtin
> functions, the problem should manifest itself
> at definition time:
> 
> * (defun max (a b) (if (> a b) a b))
> MAX
> * #'max
> #<Interpreted Function MAX {4801E451}>
> 
> Everythings seems fine at this point. Shouldn't
> I have at least been issued a warning of some sort?!?

Yes, probably.  But here we are arguing about what is desireable, not
what is mandated.

> > You created an infinite regress. 
>   
> Assuming what I did was wrong, I am a little bit curious
> as to how this manifested itself. I have a hard time
> seeing how this could have triggered an "infinite regress."
> Either my max or the system's max should have been invoked.
> Can anyone explain how the system could have been
> confused into issuing multiple recursive calls?

Your MAX is called.  It is an interpreted function, so the interpreter
is invoked.  Let's say that, somewhere deep in the bowels of the
interpreter, CL:MAX is used.  Oops -- it's going to call _your_
version of MAX instead.  But that is an interpreted function, so the
interpreter is invoked.  Let's say that, somewhere deep in the bowels
of the interpreter, CL:MAX is used.  Oops -- it's going to call _your_
version of MAX instead.  But that is an interpreted function, so ...

> In any case, I wouldn't call this a "feature."

I think everyone is agreed on this -- death of the environment is
never a good thing.  Nonetheless, inside the interpreter and the
compiler there will be some things that you must not redefine unless
you really really know what you are doing.  Generally, these things
are hidden away in internal packages such as
KERNEL:COERCE-TO-FUNCTION, but nonetheless you can break your environment
in very amusing ways by redefining them.

"So don't do that".

Cheers,

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)

Reply via email to