On Fri, 13 Dec 2002, [iso-8859-1] Fr�d�ric Dumont wrote:

> 
> According to CLHS, 
> "~W provides automatic support for the detection of circularity and
> sharing. If the value of *print-circle* is not nil and ~W is applied
> to an argument that is a circular (or shared) reference, an
> appropriate #n# marker is inserted in the output instead of printing
> the argument."
> 
> If I try the following
> (let ((a '(1 2 3)) (*print-circle* t)) (format t "~w ~w" a a))
> =>
> (1 2 3) (1 2 3)
> 
> I think this is wrong.  The argument is shared, and should be handled
> as such.

This is proper behavior.  ~W is equivalent to a call to WRITE, but
FORMAT itself is not.  What you have here is two top-level calls to WRITE,
and they shouldn't share circularity information.  I assume you think that
the output should be #1=(1 2 3) #1#, but that can't be processed by READ
correctly.

Now, if "~W" is encountered recursively, say within a print-object method
or a pretty printing method, I'd hope that the shared structure stuff
would work properly, but I can't check that at the moment.

Tim

> 
> Now, with 
> (let ((a '(1 2 3)) (*print-circle* t)) (format t "~w" (list a a)))
> =>
> (#1=(1 2 3) #1#)
> 
> Obviously, this is better, when the argument has shared subcomponents.
> 
> So the question is, is the first result wrong?  If this is not the
> case, then ignore the following.
> 
> Some random investigations of the code led me to OUTPUT-OBJECT, called
> twice in the first example (once for each arguments), and each time
> calling CHECK-FOR-CIRCULARITY in a "clean" state (a context with no
> circularity detection yet).  The later function's docstring refers to
> some WITH-CIRCULARITY-DETECTION, which I can't find in the code, but
> sounds like it should have been used in FORMAT body, so that all
> arguments would have been processed within a single circularity
> detection context.  Now, I admit I got lost in the recursive CHECK-IT
> calls (otherwise, I would have tried to write such a macro), so I
> could be deeply wrong.
> 
> Regards
> -- 
>     Frederic Dumont           / /  (_)__  __ ____  __
> [EMAIL PROTECTED]   / /__/ / _ \/ // /\ \/ /
>     PGP key 0711F125        /____/_/_//_/____/ /_/\_\  forever!!!!!!!
> Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread!
> 


Reply via email to