1.0.12.14: sequence optimizations: COPY-SEQ
[sbcl.git] / tests / macroexpand.impure.lisp
blob8a139357d9af43fae81ad8c2d93a6fe83a0d0dd3
1 ;;;; This file is for macroexpander tests which have side effects
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 ;;; From Matthew Swank on cll 2005-10-06
16 (defmacro defglobal (name &optional value)
17 (let ((internal (gensym)))
18 `(progn
19 (defparameter ,internal ,value)
20 (define-symbol-macro ,name ,internal))))
22 (defglobal glob)
24 (assert (= (let ((glob 4)) glob)))
25 (assert (null glob))
26 (assert (equal (let ((glob nil)) (setf glob (cons 'foo glob)) glob) '(foo)))
27 (assert (null glob))
28 (assert (equal (let ((glob nil)) (push 'foo glob) glob) '(foo)))
29 (assert (null glob))
33 ;;; CLHS 3.1.2.1.1 specifies that symbol macro expansion must also
34 ;;; go through *MACROEXPAND-HOOK*. (2007-09-22, -TCR.)
36 (define-symbol-macro .foo. 'foobar)
38 (let* ((expanded-p nil)
39 (*macroexpand-hook* #'(lambda (fn form env)
40 (when (eq form '.foo.)
41 (setq expanded-p t))
42 (funcall fn form env))))
43 (multiple-value-bind (expansion flag) (macroexpand '.foo.)
44 (assert (equal expansion '(quote foobar)))
45 (assert flag)
46 (assert expanded-p)))
48 (let ((sb-ext::*evaluator-mode* :interpret))
49 (let* ((expanded-p nil)
50 (*macroexpand-hook* #'(lambda (fn form env)
51 (when (eq form '.foo.)
52 (setq expanded-p t))
53 (funcall fn form env))))
54 (eval '.foo.)
55 (assert expanded-p)))
57 (let* ((expanded-p nil)
58 (*macroexpand-hook* #'(lambda (fn form env)
59 (when (eq form '/foo/)
60 (setq expanded-p t))
61 (funcall fn form env))))
62 (compile nil '(lambda ()
63 (symbol-macrolet ((/foo/ 'foobar))
64 (macrolet ((expand (symbol &environment env)
65 (macroexpand symbol env)))
66 (expand /foo/)))))
67 (assert expanded-p))