0.7.11.10:
[sbcl/lichteblau.git] / tests / eval.impure.lisp
blobf7803ffa521ee1a1ebcd2bd6574e5990be255c4b
1 ;;;; various tests of EVAL with 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 ;;;; 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
17 ;;;; EVAL.
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:
25 ;;; LOCALLY
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)))
32 (locally
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 ()
40 (let ((x 1))
41 (declare (special x))
42 (locally-special-test)))
43 (assert (= (locally-special-test-aux) 1)))
45 ;;; MACROLET
46 (macrolet ()
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)))
53 (macrolet ()
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 ()
61 (let ((x 1))
62 (declare (special x))
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)))
70 ;;; SYMBOL-MACROLET
71 (symbol-macrolet ()
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)))
78 (symbol-macrolet ()
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 ()
86 (let ((x 1))
87 (declare (special x))
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))
93 (assert (= foo 2)))
95 ;;; Bug reported by Paul Dietz: CONSTANTP on a self-evaluating object
96 ;;; must return T
98 (assert (constantp (find-class 'symbol)))
99 (assert (constantp #p""))
101 ;;; success
102 (sb-ext:quit :unix-status 104)