[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's wrong here?

> Given these two definitions:
> (defstruct flugblog
>  (color 'blue)
>  (size 'huge))
> (defun foo ()
> ;;
> ;; Returns the color of a newly-constructed, temporary flugblog
> ;;
>  (let ((x (make-flugblog)))
>   (eval '(flugblog-color x))))
> CLISP chokes on (foo).  It complains that x has no value.  I've
> through this problem, and it seems to have something to do with the
> to EVAL.  Any clues?

Yes, "x" is not declared special.

Quoting CLtL 2:

"eval form                                       [Function]

The form is evaluated in the current dynamic environment and a null
lexical environment."

- You can eigther use a local or a global special declaration:

Modify foo;

 (let ((x (make-flugblog)))
     (declare (special x))
  (eval '(flugblog-color x))))

Or evaluate "(defvar x)" before running (or compiling) foo.

-- Bernt

 Bernt Nilsson, Systems Manager     | Internet: BKN@IDA.LIU.SE
 IDA, LiTH (CS Dept. Linkoping U)   | uucp:     ...!sunic!liuida!bkn
 S-581 83 Linkoping, Sweden         | Bitnet:   BKN@SELIUIDA
 Phone +46 13 281975