[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Date: Friday, 17 May 1985, 12:57-EDT
From: Guy Steele <gls%AQUINAS@THINK.ARPA>
Has anyone ever undertaken a study or catalog of backquote idioms?
Those of you who have used backquote at all seriously have probably come
', ,', ,, ,@, ,@', ,',',
Shades of back-quote TECO! I discourage people from nesting
things three deep, and never do in my code! It makes the
list of idioms too long.
Anyway, to contribute my own "idiom" and thoughts to your list:
You *NEVER* see ,',@. It's useful to recognize this one as
an error. (It helps to look at it as ,(QUOTE ,@X), and to
remember that QUOTE does not take a variable number of arguments.)
When I'm explaining backquote to people, I stick with the
following list, as the "most useful" and "easiest explained".
, ', ,', ,@',
And, of course, the error case above, which helps them remember
it's ,@', not ,',@.
Personally, I feel we would do well to include a list of idioms
in the next CLtL and recommend that people stick with the set of
idioms. It makes it a lot easier to read code if you only have
to contend with a fixed set of "tokens".
I think a little taxonomy of idioms is useful:
In most usage of nested back-quoting, the form produced is going to be
evaluated once per level.
Doing (SETQ ARGS '('A 'AA 'AAA))
(setq f '``(list ,@(list ,@ARGS)))
(eval f) ==> `(LIST A AA AAA)
(eval (eval f)) ==> (LIST A AA AAA)
In this case, we see that A, AA, and AAA, while originally quoted, are
about to be evaluated in the resulting form. This double evaluation
is a charactaristic of all of these idioms which have more than one
more comma than quote. I.e. ,, ,@, ,,@ and ,@(list ,@ARGS)
In general, it is rarely the right thing for something to be evaluated
multiple times. We rarely write A and expect the value of A's value.
I find this division of these idioms into "single-evaluation",
"multiple evaluation" and "complete error" to be quite helpful. I
consider any use of "multiple evaluation" idioms to be suspect when
I'm looking for bugs in code. Also, since I can never construct convincing
examples of when they're useful when I'm showing someone backquote, I
usually don't explain them at all the first time around.
However, it seems to me that ,@(LIST is the same as just plain comma.
I.e. the following also gives the same result.
(setq f1 '``(list ,,@args))
(eval f1) ==> `(LIST A AA AAA)
(eval (eval f1)) ==> (LIST A AA AAA)
Is there really a reason to add ,@(LIST ,@ to our lexicon?