1 ;;; A little backquote implementation without optimizations of any
2 ;;; kind for lispstrack.
4 (defun backquote-expand-1 (form)
10 ((eq (car form) 'unquote)
12 ((eq (car form) 'backquote)
13 (backquote-expand-1 (backquote-expand-1 (cadr form))))
18 ((and (listp s) (eq (car s) 'unquote))
19 (list 'list (cadr s)))
20 ((and (listp s) (eq (car s) 'unquote-splicing))
23 (list 'list (backquote-expand-1 s)))))
26 (defun backquote-expand (form)
27 (if (and (listp form) (eq (car form) 'backquote))
28 (backquote-expand-1 (cadr form))
31 (defmacro backquote (form)
32 (backquote-expand-1 form))
34 ;;; Tests. Compare backquote agains the backquote of the host Lisp.
35 (macrolet ((test (form1 form2)
36 `(assert (equal ,form1 ,form2))))
37 (test (backquote (1 2 3 4))
39 (test (backquote (1 2 (+ 3 4)))
41 (test (backquote (1 2 (unquote (+ 3 4))))
43 (test (backquote (1 2 (unquote-splicing '(3 4))))
45 (test (backquote (backquote x))
49 (backquote (quote (unquote x)))))
52 (eval (backquote (backquote ((unquote (unquote x)))))))))