All pastes #796072 Raw Edit

blackdog

public text v1 · immutable
#796072 ·published 2007-11-24 19:13 UTC
rendered paste body
(defun cons-function (arg)
  (cons arg '()))

(defmacro bad-macro (arg)
  (list (cons-function arg)))

(defmacro good-macro (arg)
  (list 'cons-function arg))

(defmacro good-macro-with-backquote (arg)
  `(cons-function ,arg))

;; These forms are the equivalent to what will be happening during macro expansion
;; The result of each form - the expansion - will itself be evaluated
(apply (lambda (arg) (list (cons-function arg))) (list 3)) ; bad-macro
(apply (lambda (arg) (list 'cons-function arg)) (list 3)) ; good-macro
(apply (lambda (arg) `(cons-function ,arg)) (list 3))     ; good-macro-with-backquote

(cons-function 3) ; consing 3 and '() => the list (3)

(bad-macro 3)
                
(good-macro 3)

(good-macro-with-backquote 3)