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

backquote



    Date: Thu, 10 Nov 88 11:55:40 PST
    From: Don Cohen <donc@vaxa.isi.edu>

    (defmacro protected-+ (x y)
      `(let ((x ,x) (y ,y)) (and (numberp x) (numberp y) (+ x y))))

I prefer this definition:

(defmacro protected-+ (x y &environment env)
  (once-only (x y &environment env)
    `(and (numberp ,x) (numberp ,y) (+ ,x ,y))))

Using this definition, I then defined the macro for defining protected
forms like this.

(defmacro define-protected (function &rest args)
  (let ((name (make-protected-name function))
	(let-list (build-let-list args))
	(function-call (build-function-call function args)))
    `(defmacro ,name
	       ,(mapcar #'cadr args)
       (once-only (,@let-list &environment env)
	 `(and ,,@args ,,function-call)))))

Basically, I simply nested commas within one another.  When writing the
outer backquote form, I think of the inner backquote form as if it were
in it's expanded form.  Doing this, all you have to do is to make sure
that you're out of a quoted form before you put your other comma in.
this might require typing something like ",'".  The only tricky thing is
that I can never remember if I want ",,@" or ",@," and I seem to pick
the wrong one every time.