Here's a macro example. It's to prevent multiple evaluation when writing other macros. Each variable is rebound to a gensym that will then hold the value.

The effect is that each value is evaluated only once, up-front in the binding thus introduced (hence the alternate name once-only). An implementation is:

(defmacro rebinding ((&rest variables) &body body) (loop for var in variables as name = (symbol-name var) as temp = (gensym name) collect ``(,',temp ,,var) into temps collect `(,var ',temp) into renames finally (return ``(let (,,.temps) ,(let (,.renames) ,@body)))))

In use:

(rebinding (x y z) `(quux (+ ,x ,y) (* ,x ,z)))

Applying macroexpand-1 to this expression gives (prettied-up):

`(LET ((#:X10716 ,X) (#:Y10717 ,Y) (#:Z10718 ,Z)) ,(LET ((X '#:X10716) (Y '#:Y10717) (Z '#:Z10718)) `(QUUX (+ ,X ,Y) (* ,X ,Z))))

Evaluating the inner, comma-fronted LET reduces this to:

`(LET ((#:X10716 ,X) (#:Y10717 ,Y) (#:Z10718 ,Z)) (QUUX (+ #:X10716 #:Y10717) (* #:X10716 #:Z10718)))

In the above output, keep in mind that READing the same gensym twice would produce two different (uninterned) symbols. In the REPL:

? (eq '#:X10716 '#:X10716)

The *print-circle* option controls whether the printer will detect shared components.

An Exercise for the Reader

There's a variant where the body is "spliced" into the expansion. This would allow—intentionally or otherwise—for (say) declarations:

(rebinding (x y) `(declare (fixnum ,x ,y)) `(do-fixnum-stuff ,x ,y))

This won't work with the definition of rebinding given above, because the body is an implicit progn—only the last form is kept.