Backquote at Macro-expansion Time



Hi everyone,

For one of my projects, I would like to be able to make a macro which
wraps an expression in a backquote. In an imaginary implementation,
the macro (called wrap) would work as follows:

(defvar x 'a)
(wrap x)
X
(wrap ,x)
A

In Arc (which is currently implemented in Scheme), I would write the
above macro as such:

arc> (= x 'a)
b
arc> (mac wrap (expr) (list 'quasiquote expr))
#3(tagged mac #<procedure>)
arc> (wrap x)
x
arc> (wrap ,x)
a

But since there is no standard English name for backquote in CL, I
can't make backquote an argument to list. To an extent, I can get
around this is some implementations, which provide an internal
backquote macro which seems to do what I want. For example, in CLISP,
I can

[2]> (defvar x 'a)
X
[3]> (defmacro wrap (expr) (list 'system::backquote expr))
WRAP
[4]> (wrap x)
X
[5]> (wrap (system::unquote x))
A

But watch what happens when I try to use the comma syntax for unquote:

[8]> (wrap ,x)
*** - READ: comma is illegal outside of backquote

It seems that even CLISP, which provides backquote and unquote macros,
attempts (and in the above case fails) to resolve backquote and comma
syntax at read-time.

I have not done a thorough examination of other implementations but my
understanding is that the situation is more or less the same (at least
with respect to read-time expansion of backquote).

This is rather annoying since I don't want to type system::unquote
inside calls to my macro. I also would rather not leave the expression
unquoted and force myself to type quotes all over the place. I suppose
I could attempt to redefine comma as a read-macro expanding to a
system::unquote, but I don't know if CL would allow me to redefine a
basic part of the language like the comma, or if it would be safe to
do so even if it were possible.

So then, is it possible to accomplish what I want in CL? (Is it
possible to do it portably, or failing that, do with read-time
conditionals such that the user of my macro wouldn't notice the
difference? And which implementations would this be doable under?) If
it is possible, what is the best method to accomplish this? If not,
why not?

If anyone could provide suggestions, insights, or other information
about working with backquote, I would really appreciate it.
.



Relevant Pages

  • Re: Backquote at Macro-expansion Time
    ... wraps an expression in a backquote. ... A comma with no matching backquote is an error in CL. ... The behavior of the above WRAP can be obtained simply by using the ... transliterated into a macro call very similar to Scheme quasiquote. ...
    (comp.lang.lisp)
  • Re: Backquote at Macro-expansion Time
    ... a backquote form as some kind of ordinary expression. ... implementations provide a macro which could be used to force backquote ... So WRAP is not particularly useful. ... Does the check necessarily need to be a read-time check? ...
    (comp.lang.lisp)
  • Re: backquote and splice operators in ordinary namespace: hygine issue?
    ... syntax for the backquote, preferably the exact same one as Scheme, ... [which is almost certainly a macro ]. ... requiring the initial backquote reader macro. ...
    (comp.lang.lisp)
  • Re: Could someone explain this?
    ... The macro could be defined like this: ... The parameter lists (a.k.a "lambda lists") of macros can be nested to ... This list will be spliced into the backquote template. ...
    (comp.lang.lisp)
  • Re: EDT question: SET ENTITY WORD
    ... DEFINE MACRO DELIMITERS_TRUNCATE_PROGRAMMING ... DEFINE KEY GOLD CONTROL D AS "EXT DELIMITERS_WORD_PROCESSING ... INSERT; SET WRAP 78 ... Weaver Consulting Services Inc. Canadian VAR for CHARON-VAX ...
    (comp.os.vms)