1 ;;;; various tests of EVAL with side effects
3 ;;;; This software is part of the SBCL system. See the README file for
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
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 ;;;; Note: this stuff gets loaded in (by LOAD) and is therefore
15 ;;;; evaluated by EVAL, rather than compiled and then loaded; this is
16 ;;;; why this idiom (a sequence of top-level forms) works as a test of
19 (cl:in-package :cl-user)
21 ;;; Until sbcl-0.7.9.x, EVAL was not correctly treating LOCALLY,
22 ;;; MACROLET and SYMBOL-MACROLET, which should preserve top-levelness
23 ;;; of their body forms:
26 (locally (defstruct locally-struct a (b t)))
28 (let ((x (make-locally-struct :a 1)))
29 (assert (eql (locally-struct-a x) 1))
30 (assert (eql (locally-struct-b x) t)))
33 (defmacro locally-macro (x) `(+ ,x 1))
34 (assert (= (locally-macro 3) 4)))
36 (locally (declare (special x))
37 (defun locally-special-test ()
39 (defun locally-special-test-aux ()
42 (locally-special-test)))
43 (assert (= (locally-special-test-aux) 1)))
47 (defstruct macrolet-struct a (b t)))
49 (let ((x (make-macrolet-struct :a 1)))
50 (assert (eql (macrolet-struct-a x) 1))
51 (assert (eql (macrolet-struct-b x) t)))
54 (defmacro macrolet-macro (x) `(+ ,x 1))
55 (assert (= (macrolet-macro 3) 4)))
57 (locally (declare (special x))
58 (defun macrolet-special-test ()
60 (defun macrolet-special-test-aux ()
63 (macrolet-special-test)))
64 (assert (= (macrolet-special-test-aux) 1)))
66 (macrolet ((foo (x) `(macrolet-bar ,x)))
67 (defmacro macrolet-bar (x) `(+ ,x 1))
68 (assert (= (foo 1) 2)))
72 (defstruct symbol-macrolet-struct a (b t)))
74 (let ((x (make-symbol-macrolet-struct :a 1)))
75 (assert (eql (symbol-macrolet-struct-a x) 1))
76 (assert (eql (symbol-macrolet-struct-b x) t)))
79 (defmacro symbol-macrolet-macro (x) `(+ ,x 1))
80 (assert (= (symbol-macrolet-macro 3) 4)))
82 (locally (declare (special x))
83 (defun symbol-macrolet-special-test ()
85 (defun symbol-macrolet-special-test-aux ()
88 (symbol-macrolet-special-test)))
89 (assert (= (symbol-macrolet-special-test-aux) 1)))
91 (symbol-macrolet ((foo (symbol-macrolet-bar 1)))
92 (defmacro symbol-macrolet-bar (x) `(+ ,x 1))
95 ;;; Bug reported by Paul Dietz: CONSTANTP on a self-evaluating object
98 (assert (constantp (find-class 'symbol)))
99 (assert (constantp #p""))
101 ;;; DEFPARAMETER must assign a dynamic variable
102 (let ((var (gensym)))
103 (assert (equal (eval `(list (let ((,var 1))
104 (defparameter ,var 2)
111 (sb-ext:quit :unix-status 104)