Does CLOS do something weird with dynamic variables?
If I do the following...
(defclass a ()
())
(defmethod print-object ((a a) stream)
(print *print-pretty* stream))
....then evaluate
(let ((*print-pretty* nil))
(make-instance 'a))
T is printed.
How does that work?
On Nov 16, 12:52 pm, Andy Chambers <··············@googlemail.com>
wrote:
> Does CLOS do something weird with dynamic variables?
>
> If I do the following...
>
> (defclass a ()
> ())
>
> (defmethod print-object ((a a) stream)
> (print *print-pretty* stream))
>
> ....then evaluate
>
> (let ((*print-pretty* nil))
> (make-instance 'a))
>
> T is printed.
>
> How does that work?
Because (print-object) isn't called within the let, it's called to
print result of evaluating the entire expression. At that time, *print-
pretty* is back to its default of T. Nothing to do with CLOS.
- Peter
Andy Chambers <··············@googlemail.com> writes:
> Does CLOS do something weird with dynamic variables?
>
> If I do the following...
>
> (defclass a ()
> ())
>
> (defmethod print-object ((a a) stream)
> (print *print-pretty* stream))
>
> ....then evaluate
>
> (let ((*print-pretty* nil))
> (make-instance 'a))
>
> T is printed.
>
> How does that work?
You are seeing the REPL print the value returned by the LET form,
which is necessarily outside of the extent of the LET form
CL-USER> (let ((*print-pretty* nil))
(make-instance 'a))
T
If you stick in an explicit print, you force a call to
print-object with-in the extent of the let.
CL-USER> (let ((*print-pretty* nil))
(print (make-instance 'a)))
NIL
T
Alan Crowe
Edinburgh
Scotland
In article
<····································@41g2000hsh.googlegroups.com>,
Andy Chambers <··············@googlemail.com> wrote:
> Does CLOS do something weird with dynamic variables?
>
> If I do the following...
>
> (defclass a ()
> ())
>
> (defmethod print-object ((a a) stream)
> (print *print-pretty* stream))
>
> ....then evaluate
>
> (let ((*print-pretty* nil))
> (make-instance 'a))
>
> T is printed.
>
> How does that work?
Typical question: which Lisp are you using?
ACL?
In article <····························@news-europe.giganews.com>,
Rainer Joswig <······@lisp.de> wrote:
> In article
> <····································@41g2000hsh.googlegroups.com>,
> Andy Chambers <··············@googlemail.com> wrote:
>
> > Does CLOS do something weird with dynamic variables?
> >
> > If I do the following...
> >
> > (defclass a ()
> > ())
> >
> > (defmethod print-object ((a a) stream)
> > (print *print-pretty* stream))
> >
> > ....then evaluate
> >
> > (let ((*print-pretty* nil))
> > (make-instance 'a))
> >
> > T is printed.
> >
> > How does that work?
>
> Typical question: which Lisp are you using?
> ACL?
Ignore.
I was thinking of something else. Some Implementations have
different variables in the REPL.