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

> I've cut and pasted together what seems
> to be the concensus answer:
> 
> > MAX is predefined in Common Lisp. 
> 
> > MAX is a builtin function.
> 
> > your problem comes from redefining a standard Common Lisp function.
> 
> There were also a couple of suggestions to place max in a different
> namespace or give it another name, and of course I could do
> that. The students also suggested the aforementioned namespace
> collision with a builtin.  My response way "bah" -- Lisp allows you
> to redefine functions -- even the builtin ones (although this is not
> generally a good idea). 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."

To be a /real/ language lawyer, you have to quote the HyperSpec:

# 11.1.2.1.2 Constraints on the COMMON-LISP Package for Conforming
#            Programs
#
# Except where explicitly allowed, the consequences are undefined if
# any of the following actions are performed on an external symbol of
# the COMMON-LISP package:
# ...
# 2. Defining, undefining, or binding it as a function.(Some
#    exceptions are noted below.)

(none of the exceptions apply).

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

That's right.

> 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?!?

You have been told how to protect yourself in CMUCL.  Other
implementations have their own ways.  In LispWorks, check the variable
*PACKAGES-FOR-WARN-ON-REDEFINITION*, for instance.

> > YOU created an infinite regress. 
>   
> Assuming what I did was wrong,

It was.

> 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?
> 
> In any case, I wouldn't call this a "feature."

Well, it may do anything it likes... such are the joys of undefined
behavior.

> Any more thoughts? Thanks for your time.

Do you know /why/ it is undefined behavior?  Think a bit about it
(hint: macros...)!

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0



Reply via email to