Subject: [clisp-list] bound symbols at compile-time?

From: Pascal Bourguignon <[email-masked]>
Date: Wed Jan 29 16:28:05 2003

Here is an extract of aima code:
(http://www.cs.berkeley.edu/~russell/code/doc/install.html)
whose purpose is to avoid redefining existing functions or macros:

------------------------------(bug-1.lisp)------------------------------

(defmacro define-if-undefined (&rest definitions)
  "Use this to conditionally define functions, variables, or macros that
  may or may not be pre-defined in this Lisp.  This can be used to provide
  CLtL2 compatibility for older Lisps."
  `(progn
     ,@(mapcar #'(lambda (def)
                   (let ((name (second def)))
                     `(unless (or (boundp ',name)
                                  (fboundp ',name)
                                  (special-form-p ',name)
                                  (macro-function ',name))
                        ,def)))
               definitions)))

(define-if-undefined
           
(defmacro with-simple-restart (restart &rest body)
  "Like PROGN, except provides control over restarts if there is an error."
  (declare (ignore restart))
  `(progn ,@body))

)

------------------------------------------------------------------------

[pascal@thalassa pascal]$ clisp
;; Loading file /home/pascal/.clisprc.lisp ...
;; Loaded file /home/pascal/.clisprc.lisp
[1]> (load "bug-1")
T
[2]> (compile-file "bug-1")

Compiling file /home/pascal/src/common/lisp/clisp/bug-1.lisp ...
** - Continuable Error
DEFUN/DEFMACRO(WITH-SIMPLE-RESTART): #<PACKAGE COMMON-LISP> is locked
If you continue (by typing 'continue'): Ignore the lock and proceed
1. Break [3]> 

I can't understand  why when loading or evaluating  directly the macro
define-if-undefined, it detects  correctly that WITH-SIMPLE-RESTART is
FBOUNDP (in COMMON-LISP package), but that when compiling, it does not
and tries to redefine it.

I've tried to insert some (eval-when (compile load eval) ...)  at
various places, or even to use [the undocumented!  even in the
implementation notes] (ext:without-package-lock '("COMMON-LISP")...). 

I always get this:
DEFUN/DEFMACRO(WITH-SIMPLE-RESTART): #<PACKAGE COMMON-LISP> is locked
error.

So please, how can one compile a source avoiding to redefine functions
or macro already defined in COMMON-LISP under CLISP?

-- 
__Pascal_Bourguignon__                   http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie

---

From: Sam Steingold <[email-masked]>
Date: Wed Jan 29 17:17:16 2003

> * In message <[email-masked]>
> * On the subject of "[clisp-list] bound symbols at compile-time?"
> * Sent on Thu, 30 Jan 2003 01:26:14 +0100 (CET)
> * Honorable Pascal Bourguignon <[email-masked]> writes:
>

compiling the expression

        (when foo
          (bar))

requires compiling both FOO and BAR even if during evaluation FOO will
turn out to be false and so (BAR) will never be called.

> implementation notes] (ext:without-package-lock '("COMMON-LISP")...). 

<http://clisp.cons.org/impnotes.html#pack-lock>

> or macro already defined in COMMON-LISP under CLISP?

(eval-when (compile load eval)
  (unless (defined-p 'FOO)
    (push :need-own-foo *features*)))

#+:need-own-foo
(defmacro foo ...)

or just use #+ansi-cl :-)

-- 
Sam Steingold (http://www.podval.org/~sds) running RedHat8 GNU/Linux
<http://www.camera.org> <http://www.iris.org.il> <http://www.memri.org/>
<http://www.mideasttruth.com/> <http://www.palestine-central.com/links.html>
Why do we want intelligent terminals when there are so many stupid users?

---

From: Pascal Bourguignon <[email-masked]>
Date: Wed Jan 29 21:00:02 2003

> <http://clisp.cons.org/impnotes.html#pack-lock>

Thanks. I looked to an old version :-(

> or just use #+ansi-cl :-)

You're right.  I just avoided loading that file with a #-CLISP and all
is fine now.