[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Ensuring modifiable references within a backquoted template
Date: Mon, 7 May 90 15:10 EDT
From: Kent M Pitman <KMP@stony-brook.scrc.symbolics.com>
Date: Mon, 7 May 90 14:16 EDT
From: RWK@FUJI.ILA.Dialnet.Symbolics.COM (Robert W. Kerns)
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))
Actually, I (partially) stand by my code. This is equivalent to
`(A ,(COPY-TREE '(B NIL))). Since you can rely on backquote to
copy structure ABOVE any computed unoptimizable structure, you can
move the COPY-TREE down.
I don't see why you want to force people to "solve" this problem by
avoiding backquote for some (apparently arbitrarily chosen) portion
of the structure. Indeed, you could write (LIST 'A (LIST 'B NIL)),
but why would you want to? I think `(A (B ,(copy-tree nil))) is a
*LOT* more readable, especially when dealing with larger examples
where the mishmash resulting from "de-backquotifying" would be
worse.
Indeed, in this particular case, I would write
(COPY-TREE '(A (B NIL)))
instead, since most of it is a constant, but I was illustrating the
more general technique, since the example I was presented with also
used the same technique in a less robust/obvious way.
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.
I have a real problem with "solutions" that destroy readability for
the sake of philosophy. I've got nothing against philosophy; I'm just
not willing to give up readability.
Actually, you don't address what I think is the real issue with my
approach: it's a bigger hammer than may be needed; it may copy
more than is desired.
How about this instead:
;;; Discourage even the most hyper compiler.
(proclaim '(notinline copy-to-here))
(DEFUN COPY-TO-HERE (frob)
frob)
`(A (B ,(COPY-TO-HERE NIL)))
or
`(A ,(COPY-TO-HERE `(B NIL)))
depending on just how much needs to be copied?
Then both the COPY-TREE and COPY-TO-HERE are appropriate in their
places; COPY-TREE is useful when you want to be sure that it's ALL
copied (including possible subforms introduced by evaluation).
What do you think. Does this give us politically correct style,
perspicuousnous ("clarity", for those of us who like clarity in
writing), while retaining the readability of the template style?