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

> I had a lab full of students today to whom
> I am introducing Common Lisp. Everything started out
> well. I taught this class last year and never
> had a problem (used version 18c then, using 18d now).
> I introduced defun, and proceeded to show them
> a simple example and then...
> 
> $ lisp
> CMU Common Lisp 18d, running on cs01.vancouver.wsu.edu 
>  Send questions to [EMAIL PROTECTED] and bug reports to [EMAIL PROTECTED] 
>  Loaded subsystems: 
>  �� �Python 1.0, target Intel x86 
>  �� �CLOS based on PCL version: �September 16 92 PCL (f) 
>  * (defun max (a b) (if (> a b) a b)) 
>   
>  MAX 
>  * (max 3 5) 
>  [GC completed with 5,957,176 bytes retained and -9,440 bytes freed.] 
>  [GC will next occur when at least 7,957,176 bytes are in use.] 
>  [GC threshold exceeded with 7,961,480 bytes in use. �Commencing GC.] 
> <etc>
> 
> Uh... how could max throw the gc into a frenzy?

As Marco has already said, the problem is that you aren't just
defining a function called MAX, you are redefining the Common Lisp
function CL:MAX.  The compiler internals are permitted to assume
certain things about functions defined by the standard; for instance,
their signature: in Common Lisp, MAX works on an arbitrary number of
arguments, not just two.  Also, the compiler is entitled to assume
things about where the function is stored, and so on; by redefining
it, you are probably breaking a compiler invariant somewhere.  Bad
things happen if you do that :-)
 
> It did actually work in a few instances, but then things
> quickly went down hill. Any theories?

It would be nice if the system were slightly more tolerant of this
kind of thing (I got bit by trying to profile calls to LENGTH
yesterday, with the same kind of results); but redefining CL
operators, either explicitly or implicitly, is a nono.  If you were
wedded to showing them MAX, you could do

(defpackage "SCRATCH"
  (:use))

(defun scratch::max (a b)
  (if (> a b) a b))

(scratch::max 1 2)

or else use a different, unreserved name (e.g. MAXIMUM-OF-TWO :-)

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