SLUG mail archive

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

Ensuring modifiable references within a backquoted template



    Date: Mon, 7 May 90 14:16 EDT
    From: RWK@FUJI.ILA.Dialnet.Symbolics.COM (Robert W. Kerns)

	Date: Mon, 23 Apr 90 15:11 CDT
	From: lgm@ihlpf.att.com
	always yields the identical list structure.  On the other hand,
	applying the comma to a function call such as

		`(A (B ,(IDENTITY NIL)))

	indeed results in multiple, safely modifiable list structures.
	Can I depend on this behavior portably, or could a Common Lisp
	implementation thwart my intent by "intelligently"
	constant-folding (IDENTITY NIL) into NIL anyway?  If I were to
	locally declare IDENTITY to be NOTINLINE, would I then be "safe"
	(though slightly slower)?

    I suggest using

    (locally (declare (notinline copy-tree))
      `(A (B ,(COPY-TREE NIL))))

    instead.  It's both less likely to be constant folding, and more
    indicative of your actual intent.

I think this is far from perspicuous and not philosophically correct.

I and others have been round and round with Bawden [one of several
architects of backquote] on this kind of thing and he insists that the
correct thing is:

 `(A ,(LIST 'B NIL))

This is the only thing that 1really0 says what you mean.  It says to do
template-style (i.e., possibly shared) construction of the outer list,
but that the inner list must be freshly allocated each time.

The problem I have with the use of COPY-TREE is that it is not copying
the cell which the user plans to modify.  If you had written:

 `(A ,(COPY-TREE '(B NIL)))

I would agree that you had actually made it safe to (SETF (CADADR result) ...).
But since you did not copy the cell which is the 1place0 in which the CADADR
value lives, then I don't agree that you made it safe.  Note also that
if you put the COPY-TREE in the semantically correct place, the NOTINLINE
declaration is no longer needed because it is clear from context that 
the call to COPY-TREE cannot be optimized out by any semantics-preserving
optimization.  And if the compiler does have a semantics-preserving optimization
to apply there (e.g., inline calls to CONS and LIST instead of an out of line
call to COPY-TREE), the last thing you would normally want is for that
optimization to be supressed by a spurious NOTINLINE declaration.

Follow-Ups: References:

Main Index | Thread Index