[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ensuring modifiable references within a backquoted template
Date: Mon, 23 Apr 90 16:58 EDT
To: lgm%ihlpf.att.com@vax.cam.nist.gov, slug%AI.SRI.COM@vax.cam.nist.gov
In-Reply-To: The message of 10 Apr 90 23:18 EDT from lgm@ihlpf.att.com
Message-ID: <19900423205816.2.MILLER@ARTEMIS.cam.nist.gov>
Date: Tue, 10-Apr-90 23:18:54-EDT
Date: Mon, 23 Apr 90 15:11 CDT
I want to initialize multiple variables with a complex list
structure template. The template is mostly constant but has a few
modifiable references. These latter may start out as a constant
value such as NIL but will be changed later (e.g., via PUSH) on a
variable-by-variable basis. The question is how to *ensure* the
proper modifiability, especially in a portable manner. If I
simply quote or backquote the template - e.g.,
'(A (B NIL))
or
`(A (B NIL))
every variable then refers to the same identical template, which
is not what I want. Even "evaluating" (via a comma) the constant
NIL
`(A (B ,NIL))
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 know, of course, that I can use nested LISTs, instead of the
backquote, to obtain the desired effect; but for sufficiently
complex list structure, that alternative is markedly inferior to
the backquote notation.
Lawrence G. Mayka
AT&T Bell Laboratories
lgm@ihlpf.att.com
Standard disclaimer.
Why not just use plain old quote and wrap a copy-tree around the whole?
It (should be) guaranteed safe and transportable, although it copies the
whole thing instead of just the specific parts you want copied.
Otherwise, just write your own analogue to backquote! If your pattern is
initially all constants it might be easier than you think...
bruce
miller@cam.nist.gov