1 ;;;; tests for the code walker
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; This software is derived from software originally released by Xerox
7 ;;;; Corporation. Copyright and release statements follow. Later modifications
8 ;;;; to the software are in the public domain and are provided with
9 ;;;; absolutely no warranty. See the COPYING and CREDITS files for more
12 ;;;; copyright information from original PCL sources:
14 ;;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
15 ;;;; All rights reserved.
17 ;;;; Use and copying of this software and preparation of derivative works based
18 ;;;; upon this software are permitted. Any distribution of this software or
19 ;;;; derivative works must comply with all applicable United States export
22 ;;;; This software is made available AS IS, and Xerox Corporation makes no
23 ;;;; warranty about the software, its performance or its conformity to any
26 (in-package :sb-walker)
28 ;;;; stuff based on the tests at the end of the original CMU CL
29 ;;;; pcl/walk.lisp file
31 (defmacro take-it-out-for-a-test-walk (form)
32 `(take-it-out-for-a-test-walk-1 ',form))
34 (defun take-it-out-for-a-test-walk-1 (form)
35 (let ((copy-of-form (copy-tree form))
36 (result (walk-form form nil
38 (format t "~&Form: ~S ~3T Context: ~A" x y)
40 (let ((lexical (variable-lexical-p x env))
41 (special (variable-special-p x env)))
44 (format t "lexically bound"))
47 (format t "declared special"))
50 (format t "bound: ~S " (eval x)))))
52 (cond ((not (equal result copy-of-form))
53 (format t "~%Warning: Result not EQUAL to copy of start."))
54 ((not (eq result form))
55 (format t "~%Warning: Result not EQ to copy of start.")))
59 (defmacro foo (&rest ignore)
60 (declare (ignore ignore))
63 (defmacro bar (&rest ignore)
64 (declare (ignore ignore))
68 (with-output-to-string (*standard-output*)
69 (take-it-out-for-a-test-walk (list arg1 arg2 arg3)))
70 "Form: (LIST ARG1 ARG2 ARG3) Context: EVAL
71 Form: ARG1 Context: EVAL
72 Form: ARG2 Context: EVAL
73 Form: ARG3 Context: EVAL
74 (LIST ARG1 ARG2 ARG3)"))
77 (with-output-to-string (*standard-output*)
78 (take-it-out-for-a-test-walk (list (cons 1 2) (list 3 4 5))))
79 "Form: (LIST (CONS 1 2) (LIST 3 4 5)) Context: EVAL
80 Form: (CONS 1 2) Context: EVAL
83 Form: (LIST 3 4 5) Context: EVAL
87 (LIST (CONS 1 2) (LIST 3 4 5))"))
90 (with-output-to-string (*standard-output*)
91 (take-it-out-for-a-test-walk (progn (foo) (bar 1))))
92 "Form: (PROGN (FOO) (BAR 1)) Context: EVAL
93 Form: (FOO) Context: EVAL
94 Form: 'GLOBAL-FOO Context: EVAL
95 Form: (BAR 1) Context: EVAL
96 Form: 'GLOBAL-BAR Context: EVAL
97 (PROGN (FOO) (BAR 1))"))
100 (with-output-to-string (*standard-output*)
101 (take-it-out-for-a-test-walk (block block-name a b c)))
102 "Form: (BLOCK BLOCK-NAME A B C) Context: EVAL
103 Form: A Context: EVAL
104 Form: B Context: EVAL
105 Form: C Context: EVAL
106 (BLOCK BLOCK-NAME A B C)"))
109 (with-output-to-string (*standard-output*)
110 (take-it-out-for-a-test-walk (block block-name (list a) b c)))
111 "Form: (BLOCK BLOCK-NAME (LIST A) B C) Context: EVAL
112 Form: (LIST A) Context: EVAL
113 Form: A Context: EVAL
114 Form: B Context: EVAL
115 Form: C Context: EVAL
116 (BLOCK BLOCK-NAME (LIST A) B C)"))
119 (with-output-to-string (*standard-output*)
120 (take-it-out-for-a-test-walk (catch catch-tag (list a) b c)))
121 "Form: (CATCH CATCH-TAG (LIST A) B C) Context: EVAL
122 Form: CATCH-TAG Context: EVAL
123 Form: (LIST A) Context: EVAL
124 Form: A Context: EVAL
125 Form: B Context: EVAL
126 Form: C Context: EVAL
127 (CATCH CATCH-TAG (LIST A) B C)"))
129 ;;; This is a fairly simple MACROLET case. While walking the body of the
130 ;;; macro, X should be lexically bound. In the body of the MACROLET form
131 ;;; itself, X should not be bound.
133 (with-output-to-string (*standard-output*)
134 (take-it-out-for-a-test-walk
135 (macrolet ((foo (x) (list x) ''inner))
138 "Form: (MACROLET ((FOO (X)
142 (FOO 1)) Context: EVAL
143 Form: (LIST X) Context: EVAL
144 Form: X Context: EVAL; lexically bound
145 Form: ''INNER Context: EVAL
146 Form: X Context: EVAL
147 Form: (FOO 1) Context: EVAL
148 Form: 'INNER Context: EVAL
156 ;;; A slightly more complex MACROLET case. In the body of the macro X
157 ;;; should not be lexically bound. In the body of the macrolet form itself
158 ;;; X should be bound. Note that THIS CASE WILL CAUSE AN ERROR when it
159 ;;; tries to macroexpand the call to FOO.
161 (multiple-value-bind (res cond)
163 (take-it-out-for-a-test-walk
165 (macrolet ((foo () (list x) ''inner))
168 (assert (and (null res) cond)))
171 (with-output-to-string (*standard-output*)
172 (take-it-out-for-a-test-walk
173 (flet ((foo (x) (list x y))
174 (bar (x) (list x y)))
176 "Form: (FLET ((FOO (X)
180 (FOO 1)) Context: EVAL
181 Form: (LIST X Y) Context: EVAL
182 Form: X Context: EVAL; lexically bound
183 Form: Y Context: EVAL
184 Form: (LIST X Y) Context: EVAL
185 Form: X Context: EVAL; lexically bound
186 Form: Y Context: EVAL
187 Form: (FOO 1) Context: EVAL
188 Form: 1 Context: EVAL
196 (with-output-to-string (*standard-output*)
197 (take-it-out-for-a-test-walk
199 (flet ((foo (x) (list x y))
200 (bar (x) (list x y)))
207 (FOO 1))) Context: EVAL
208 Form: 2 Context: EVAL
209 Form: (FLET ((FOO (X)
213 (FOO 1)) Context: EVAL
214 Form: (LIST X Y) Context: EVAL
215 Form: X Context: EVAL; lexically bound
216 Form: Y Context: EVAL; lexically bound
217 Form: (LIST X Y) Context: EVAL
218 Form: X Context: EVAL; lexically bound
219 Form: Y Context: EVAL; lexically bound
220 Form: (FOO 1) Context: EVAL
221 Form: 1 Context: EVAL
230 (with-output-to-string (*standard-output*)
231 (take-it-out-for-a-test-walk
232 (labels ((foo (x) (bar x))
235 "Form: (LABELS ((FOO (X)
239 (FOO 1)) Context: EVAL
240 Form: (BAR X) Context: EVAL
241 Form: X Context: EVAL; lexically bound
242 Form: (FOO X) Context: EVAL
243 Form: X Context: EVAL; lexically bound
244 Form: (FOO 1) Context: EVAL
245 Form: 1 Context: EVAL
253 (with-output-to-string (*standard-output*)
254 (take-it-out-for-a-test-walk
255 (flet ((foo (x) (foo x)))
257 "Form: (FLET ((FOO (X)
259 (FOO 1)) Context: EVAL
260 Form: (FOO X) Context: EVAL
261 Form: 'GLOBAL-FOO Context: EVAL
262 Form: (FOO 1) Context: EVAL
263 Form: 1 Context: EVAL
269 (with-output-to-string (*standard-output*)
270 (take-it-out-for-a-test-walk
271 (flet ((foo (x) (foo x)))
272 (flet ((bar (x) (foo x)))
274 "Form: (FLET ((FOO (X)
278 (BAR 1))) Context: EVAL
279 Form: (FOO X) Context: EVAL
280 Form: 'GLOBAL-FOO Context: EVAL
281 Form: (FLET ((BAR (X)
283 (BAR 1)) Context: EVAL
284 Form: (FOO X) Context: EVAL
285 Form: X Context: EVAL; lexically bound
286 Form: (BAR 1) Context: EVAL
287 Form: 1 Context: EVAL
295 (with-output-to-string (*standard-output*)
296 (take-it-out-for-a-test-walk (prog () (declare (special a b)))))
297 "Form: (PROG () (DECLARE (SPECIAL A B))) Context: EVAL
300 (DECLARE (SPECIAL A B))
301 (TAGBODY))) Context: EVAL
303 (DECLARE (SPECIAL A B))
304 (TAGBODY)) Context: EVAL
305 Form: (TAGBODY) Context: EVAL
306 (PROG () (DECLARE (SPECIAL A B)))"))
309 (with-output-to-string (*standard-output*)
310 (take-it-out-for-a-test-walk (let (a b c)
311 (declare (special a b))
314 (DECLARE (SPECIAL A B))
318 Form: (FOO A) Context: EVAL
319 Form: 'GLOBAL-FOO Context: EVAL
320 Form: B Context: EVAL; lexically bound
321 Form: C Context: EVAL; lexically bound
323 (DECLARE (SPECIAL A B))
329 (with-output-to-string (*standard-output*)
330 (take-it-out-for-a-test-walk (let (a b c)
331 (declare (special a) (special b))
334 (DECLARE (SPECIAL A) (SPECIAL B))
338 Form: (FOO A) Context: EVAL
339 Form: 'GLOBAL-FOO Context: EVAL
340 Form: B Context: EVAL; lexically bound; declared special
341 Form: C Context: EVAL; lexically bound
343 (DECLARE (SPECIAL A) (SPECIAL B))
349 (with-output-to-string (*standard-output*)
350 (take-it-out-for-a-test-walk (let (a b c)
351 (declare (special a))
352 (declare (special b))
355 (DECLARE (SPECIAL A))
356 (DECLARE (SPECIAL B))
360 Form: (FOO A) Context: EVAL
361 Form: 'GLOBAL-FOO Context: EVAL
362 Form: B Context: EVAL; lexically bound; declared special
363 Form: C Context: EVAL; lexically bound
365 (DECLARE (SPECIAL A))
366 (DECLARE (SPECIAL B))
372 (with-output-to-string (*standard-output*)
373 (take-it-out-for-a-test-walk (let (a b c)
374 (declare (special a))
375 (declare (special b))
379 (DECLARE (SPECIAL A))
380 (DECLARE (SPECIAL B))
389 Form: 1 Context: EVAL
390 Form: (FOO A) Context: EVAL
391 Form: 'GLOBAL-FOO Context: EVAL
392 Form: B Context: EVAL; lexically bound; declared special
393 Form: C Context: EVAL; lexically bound
395 (DECLARE (SPECIAL A))
396 (DECLARE (SPECIAL B))
403 (with-output-to-string (*standard-output*)
404 (take-it-out-for-a-test-walk (eval-when ()
407 "Form: (EVAL-WHEN NIL A (FOO A)) Context: EVAL
408 Form: A Context: EVAL
409 Form: (FOO A) Context: EVAL
410 Form: 'GLOBAL-FOO Context: EVAL
411 (EVAL-WHEN NIL A (FOO A))"))
414 (with-output-to-string (*standard-output*)
415 (take-it-out-for-a-test-walk
416 (eval-when (:execute :compile-toplevel :load-toplevel)
419 "Form: (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A)) Context: EVAL
420 Form: A Context: EVAL
421 Form: (FOO A) Context: EVAL
422 Form: 'GLOBAL-FOO Context: EVAL
423 (EVAL-WHEN (:EXECUTE :COMPILE-TOPLEVEL :LOAD-TOPLEVEL) A (FOO A))"))
426 (with-output-to-string (*standard-output*)
427 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
428 (foo a b) (list a b))))
429 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B)) Context: EVAL
430 Form: (FOO A B) Context: EVAL
431 Form: 'GLOBAL-FOO Context: EVAL
432 Form: (LIST A B) Context: EVAL
433 Form: A Context: EVAL; lexically bound
434 Form: B Context: EVAL; lexically bound
435 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (LIST A B))"))
438 (with-output-to-string (*standard-output*)
439 (take-it-out-for-a-test-walk (multiple-value-bind (a b)
441 (declare (special a))
443 "Form: (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
444 Form: (FOO A B) Context: EVAL
445 Form: 'GLOBAL-FOO Context: EVAL
446 Form: (LIST A B) Context: EVAL
447 Form: A Context: EVAL; lexically bound
448 Form: B Context: EVAL; lexically bound
449 (MULTIPLE-VALUE-BIND (A B) (FOO A B) (DECLARE (SPECIAL A)) (LIST A B))"))
452 (with-output-to-string (*standard-output*)
453 (take-it-out-for-a-test-walk (progn (function foo))))
454 "Form: (PROGN #'FOO) Context: EVAL
455 Form: #'FOO Context: EVAL
459 (with-output-to-string (*standard-output*)
460 (take-it-out-for-a-test-walk (progn a b (go a))))
461 "Form: (PROGN A B (GO A)) Context: EVAL
462 Form: A Context: EVAL
463 Form: B Context: EVAL
464 Form: (GO A) Context: EVAL
465 (PROGN A B (GO A))"))
468 (with-output-to-string (*standard-output*)
469 (take-it-out-for-a-test-walk (if a b c)))
470 "Form: (IF A B C) Context: EVAL
471 Form: A Context: EVAL
472 Form: B Context: EVAL
473 Form: C Context: EVAL
477 (with-output-to-string (*standard-output*)
478 (take-it-out-for-a-test-walk (if a b)))
479 "Form: (IF A B) Context: EVAL
480 Form: A Context: EVAL
481 Form: B Context: EVAL
482 Form: NIL Context: EVAL; bound: NIL
486 (with-output-to-string (*standard-output*)
487 (take-it-out-for-a-test-walk ((lambda (a b) (list a b)) 1 2)))
488 "Form: ((LAMBDA (A B) (LIST A B)) 1 2) Context: EVAL
489 Form: (LAMBDA (A B) (LIST A B)) Context: EVAL
490 Form: (LIST A B) Context: EVAL
491 Form: A Context: EVAL; lexically bound
492 Form: B Context: EVAL; lexically bound
493 Form: 1 Context: EVAL
494 Form: 2 Context: EVAL
495 ((LAMBDA (A B) (LIST A B)) 1 2)"))
498 (with-output-to-string (*standard-output*)
499 (take-it-out-for-a-test-walk ((lambda (a b)
500 (declare (special a))
503 "Form: ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2) Context: EVAL
504 Form: (LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) Context: EVAL
505 Form: (LIST A B) Context: EVAL
506 Form: A Context: EVAL; lexically bound; declared special
507 Form: B Context: EVAL; lexically bound
508 Form: 1 Context: EVAL
509 Form: 2 Context: EVAL
510 ((LAMBDA (A B) (DECLARE (SPECIAL A)) (LIST A B)) 1 2)"))
513 (with-output-to-string (*standard-output*)
514 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
516 "Form: (LET ((A A) (B A) (C B))
517 (LIST A B C)) Context: EVAL
518 Form: A Context: EVAL
519 Form: A Context: EVAL
520 Form: B Context: EVAL
521 Form: (LIST A B C) Context: EVAL
522 Form: A Context: EVAL; lexically bound
523 Form: B Context: EVAL; lexically bound
524 Form: C Context: EVAL; lexically bound
525 (LET ((A A) (B A) (C B))
529 (with-output-to-string (*standard-output*)
530 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b)) (list a b c))))
531 "Form: (LET* ((A A) (B A) (C B))
532 (LIST A B C)) Context: EVAL
533 Form: A Context: EVAL
534 Form: A Context: EVAL; lexically bound
535 Form: B Context: EVAL; lexically bound
536 Form: (LIST A B C) Context: EVAL
537 Form: A Context: EVAL; lexically bound
538 Form: B Context: EVAL; lexically bound
539 Form: C Context: EVAL; lexically bound
540 (LET* ((A A) (B A) (C B))
544 (with-output-to-string (*standard-output*)
545 (take-it-out-for-a-test-walk (let ((a a) (b a) (c b))
546 (declare (special a b))
548 "Form: (LET ((A A) (B A) (C B))
549 (DECLARE (SPECIAL A B))
550 (LIST A B C)) Context: EVAL
551 Form: A Context: EVAL
552 Form: A Context: EVAL
553 Form: B Context: EVAL
554 Form: (LIST A B C) Context: EVAL
555 Form: A Context: EVAL; lexically bound; declared special
556 Form: B Context: EVAL; lexically bound
557 Form: C Context: EVAL; lexically bound
558 (LET ((A A) (B A) (C B))
559 (DECLARE (SPECIAL A B))
563 (with-output-to-string (*standard-output*)
564 (take-it-out-for-a-test-walk (let* ((a a) (b a) (c b))
565 (declare (special a b))
567 "Form: (LET* ((A A) (B A) (C B))
568 (DECLARE (SPECIAL A B))
569 (LIST A B C)) Context: EVAL
570 Form: A Context: EVAL
571 Form: A Context: EVAL; lexically bound
572 Form: B Context: EVAL; lexically bound
573 Form: (LIST A B C) Context: EVAL
574 Form: A Context: EVAL; lexically bound; declared special
575 Form: B Context: EVAL; lexically bound
576 Form: C Context: EVAL; lexically bound
577 (LET* ((A A) (B A) (C B))
578 (DECLARE (SPECIAL A B))
582 (with-output-to-string (*standard-output*)
583 (take-it-out-for-a-test-walk (let ((a 1) (b 2))
586 (declare (special a))
588 "Form: (LET ((A 1) (B 2))
591 (DECLARE (SPECIAL A))
592 (FOO A B))) Context: EVAL
593 Form: 1 Context: EVAL
594 Form: 2 Context: EVAL
595 Form: (FOO BAR) Context: EVAL
596 Form: 'GLOBAL-FOO Context: EVAL
598 (DECLARE (SPECIAL A))
599 (FOO A B)) Context: EVAL
600 Form: (FOO A B) Context: EVAL
601 Form: 'GLOBAL-FOO Context: EVAL
605 (DECLARE (SPECIAL A))
609 (with-output-to-string (*standard-output*)
610 (take-it-out-for-a-test-walk (multiple-value-call #'foo a b c)))
611 "Form: (MULTIPLE-VALUE-CALL #'FOO A B C) Context: EVAL
612 Form: #'FOO Context: EVAL
613 Form: A Context: EVAL
614 Form: B Context: EVAL
615 Form: C Context: EVAL
616 (MULTIPLE-VALUE-CALL #'FOO A B C)"))
619 (with-output-to-string (*standard-output*)
620 (take-it-out-for-a-test-walk (multiple-value-prog1 a b c)))
621 "Form: (MULTIPLE-VALUE-PROG1 A B C) Context: EVAL
622 Form: A Context: EVAL
623 Form: B Context: EVAL
624 Form: C Context: EVAL
625 (MULTIPLE-VALUE-PROG1 A B C)"))
628 (with-output-to-string (*standard-output*)
629 (take-it-out-for-a-test-walk (progn a b c)))
630 "Form: (PROGN A B C) Context: EVAL
631 Form: A Context: EVAL
632 Form: B Context: EVAL
633 Form: C Context: EVAL
637 (with-output-to-string (*standard-output*)
638 (take-it-out-for-a-test-walk (progv vars vals a b c)))
639 "Form: (PROGV VARS VALS A B C) Context: EVAL
640 Form: VARS Context: EVAL
641 Form: VALS Context: EVAL
642 Form: A Context: EVAL
643 Form: B Context: EVAL
644 Form: C Context: EVAL
645 (PROGV VARS VALS A B C)"))
648 (with-output-to-string (*standard-output*)
649 (take-it-out-for-a-test-walk (quote a)))
650 "Form: 'A Context: EVAL
654 (with-output-to-string (*standard-output*)
655 (take-it-out-for-a-test-walk (return-from block-name a b c)))
656 "Form: (RETURN-FROM BLOCK-NAME A B C) Context: EVAL
657 Form: A Context: EVAL
658 Form: B Context: EVAL
659 Form: C Context: EVAL
660 (RETURN-FROM BLOCK-NAME A B C)"))
663 (with-output-to-string (*standard-output*)
664 (take-it-out-for-a-test-walk (setq a 1)))
665 "Form: (SETQ A 1) Context: EVAL
667 Form: 1 Context: EVAL
672 (with-output-to-string (*standard-output*)
673 (take-it-out-for-a-test-walk (setq a (foo 1) b (bar 2) c 3)))
674 "Form: (SETQ A (FOO 1) B (BAR 2) C 3) Context: EVAL
675 Form: (SETQ A (FOO 1)) Context: EVAL
677 Form: (FOO 1) Context: EVAL
678 Form: 'GLOBAL-FOO Context: EVAL
679 Form: (SETQ B (BAR 2)) Context: EVAL
681 Form: (BAR 2) Context: EVAL
682 Form: 'GLOBAL-BAR Context: EVAL
683 Form: (SETQ C 3) Context: EVAL
685 Form: 3 Context: EVAL
686 (SETQ A (FOO 1) B (BAR 2) C 3)"))
692 (with-output-to-string (*standard-output*)
693 (take-it-out-for-a-test-walk (tagbody a b c (go a))))
694 "Form: (TAGBODY A B C (GO A)) Context: EVAL
695 Form: A Context: QUOTE
696 Form: B Context: QUOTE
697 Form: C Context: QUOTE
698 Form: (GO A) Context: EVAL
699 (TAGBODY A B C (GO A))"))
702 (with-output-to-string (*standard-output*)
703 (take-it-out-for-a-test-walk (the foo (foo-form a b c))))
704 "Form: (THE FOO (FOO-FORM A B C)) Context: EVAL
705 Form: (FOO-FORM A B C) Context: EVAL
706 Form: A Context: EVAL
707 Form: B Context: EVAL
708 Form: C Context: EVAL
709 (THE FOO (FOO-FORM A B C))"))
712 (with-output-to-string (*standard-output*)
713 (take-it-out-for-a-test-walk (throw tag-form a)))
714 "Form: (THROW TAG-FORM A) Context: EVAL
715 Form: TAG-FORM Context: EVAL
716 Form: A Context: EVAL
717 (THROW TAG-FORM A)"))
720 (with-output-to-string (*standard-output*)
721 (take-it-out-for-a-test-walk (unwind-protect (foo a b) d e f)))
722 "Form: (UNWIND-PROTECT (FOO A B) D E F) Context: EVAL
723 Form: (FOO A B) Context: EVAL
724 Form: 'GLOBAL-FOO Context: EVAL
725 Form: D Context: EVAL
726 Form: E Context: EVAL
727 Form: F Context: EVAL
728 (UNWIND-PROTECT (FOO A B) D E F)"))
730 (defmacro flet-1 (a b)
731 (declare (ignore a b))
734 (defmacro labels-1 (a b)
735 (declare (ignore a b))
739 (with-output-to-string (*standard-output*)
740 (take-it-out-for-a-test-walk
741 (flet ((flet-1 (a b) () (flet-1 a b) (list a b)))
744 "Form: (FLET ((FLET-1 (A B)
749 (FOO 1 2)) Context: EVAL
750 Form: NIL Context: EVAL; bound: NIL
751 Form: (FLET-1 A B) Context: EVAL
752 Form: 'OUTER Context: EVAL
753 Form: (LIST A B) Context: EVAL
754 Form: A Context: EVAL; lexically bound
755 Form: B Context: EVAL; lexically bound
756 Form: (FLET-1 1 2) Context: EVAL
757 Form: 1 Context: EVAL
758 Form: 2 Context: EVAL
759 Form: (FOO 1 2) Context: EVAL
760 Form: 'GLOBAL-FOO Context: EVAL
769 (with-output-to-string (*standard-output*)
770 (take-it-out-for-a-test-walk
771 (labels ((label-1 (a b) () (label-1 a b)(list a b)))
774 "Form: (LABELS ((LABEL-1 (A B)
779 (FOO 1 2)) Context: EVAL
780 Form: NIL Context: EVAL; bound: NIL
781 Form: (LABEL-1 A B) Context: EVAL
782 Form: A Context: EVAL; lexically bound
783 Form: B Context: EVAL; lexically bound
784 Form: (LIST A B) Context: EVAL
785 Form: A Context: EVAL; lexically bound
786 Form: B Context: EVAL; lexically bound
787 Form: (LABEL-1 1 2) Context: EVAL
788 Form: 1 Context: EVAL
789 Form: 2 Context: EVAL
790 Form: (FOO 1 2) Context: EVAL
791 Form: 'GLOBAL-FOO Context: EVAL
792 (LABELS ((LABEL-1 (A B)
800 (with-output-to-string (*standard-output*)
801 (take-it-out-for-a-test-walk (macrolet ((macrolet-1 (a b) (list a b)))
804 "Form: (MACROLET ((MACROLET-1 (A B)
807 (FOO 1 2)) Context: EVAL
808 Form: (LIST A B) Context: EVAL
809 Form: A Context: EVAL; lexically bound
810 Form: B Context: EVAL; lexically bound
811 Form: (MACROLET-1 A B) Context: EVAL
812 Form: (A B) Context: EVAL
813 Form: B Context: EVAL
814 Form: (FOO 1 2) Context: EVAL
815 Form: 'GLOBAL-FOO Context: EVAL
816 (MACROLET ((MACROLET-1 (A B)
822 (with-output-to-string (*standard-output*)
823 (take-it-out-for-a-test-walk (macrolet ((foo (a) `(inner-foo-expanded ,a)))
825 "Form: (MACROLET ((FOO (A)
826 `(INNER-FOO-EXPANDED ,A)))
827 (FOO 1)) Context: EVAL
828 Form: `(INNER-FOO-EXPANDED ,A) Context: EVAL
829 Form: 'INNER-FOO-EXPANDED Context: EVAL
830 Form: A Context: EVAL; lexically bound
831 Form: (FOO 1) Context: EVAL
832 Form: (INNER-FOO-EXPANDED 1) Context: EVAL
833 Form: 1 Context: EVAL
835 `(INNER-FOO-EXPANDED ,A)))
839 (with-output-to-string (*standard-output*)
840 (take-it-out-for-a-test-walk (progn (bar 1)
842 `(inner-bar-expanded ,a)))
847 `(INNER-BAR-EXPANDED ,A)))
848 (BAR 2))) Context: EVAL
849 Form: (BAR 1) Context: EVAL
850 Form: 'GLOBAL-BAR Context: EVAL
851 Form: (MACROLET ((BAR (A)
852 `(INNER-BAR-EXPANDED ,A)))
853 (BAR 2)) Context: EVAL
854 Form: `(INNER-BAR-EXPANDED ,A) Context: EVAL
855 Form: 'INNER-BAR-EXPANDED Context: EVAL
856 Form: A Context: EVAL; lexically bound
857 Form: (BAR 2) Context: EVAL
858 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
859 Form: 2 Context: EVAL
863 `(INNER-BAR-EXPANDED ,A)))
867 (with-output-to-string (*standard-output*)
868 (take-it-out-for-a-test-walk (progn (bar 1)
871 `(inner-bar-expanded ,s)))
877 `(INNER-BAR-EXPANDED ,S)))
878 (BAR 2))) Context: EVAL
879 Form: (BAR 1) Context: EVAL
880 Form: 'GLOBAL-BAR Context: EVAL
881 Form: (MACROLET ((BAR (S)
883 `(INNER-BAR-EXPANDED ,S)))
884 (BAR 2)) Context: EVAL
885 Form: (BAR S) Context: EVAL
886 Form: 'GLOBAL-BAR Context: EVAL
887 Form: `(INNER-BAR-EXPANDED ,S) Context: EVAL
888 Form: 'INNER-BAR-EXPANDED Context: EVAL
889 Form: S Context: EVAL; lexically bound
890 Form: (BAR 2) Context: EVAL
891 Form: (INNER-BAR-EXPANDED 2) Context: EVAL
892 Form: 2 Context: EVAL
897 `(INNER-BAR-EXPANDED ,S)))
901 (with-output-to-string (*standard-output*)
902 (take-it-out-for-a-test-walk (cond (a b)
903 ((foo bar) a (foo a)))))
904 "Form: (COND (A B) ((FOO BAR) A (FOO A))) Context: EVAL
905 Form: (IF A (PROGN B) (COND ((FOO BAR) A (FOO A)))) Context: EVAL
906 Form: A Context: EVAL
907 Form: (PROGN B) Context: EVAL
908 Form: B Context: EVAL
909 Form: (COND ((FOO BAR) A (FOO A))) Context: EVAL
910 Form: (IF (FOO BAR) (PROGN A (FOO A)) (COND)) Context: EVAL
911 Form: (FOO BAR) Context: EVAL
912 Form: 'GLOBAL-FOO Context: EVAL
913 Form: (PROGN A (FOO A)) Context: EVAL
914 Form: A Context: EVAL
915 Form: (FOO A) Context: EVAL
916 Form: 'GLOBAL-FOO Context: EVAL
917 Form: (COND) Context: EVAL
918 Form: NIL Context: EVAL; bound: NIL
919 (COND (A B) ((FOO BAR) A (FOO A)))"))
922 (with-output-to-string (*standard-output*)
923 (let ((the-lexical-variables ()))
924 (walk-form '(let ((a 1) (b 2))
925 #'(lambda (x) (list a b x y)))
927 #'(lambda (form context env)
928 (declare (ignore context))
929 (when (and (symbolp form)
930 (variable-lexical-p form env))
931 (push form the-lexical-variables))
933 (or (and (= (length the-lexical-variables) 3)
934 (member 'a the-lexical-variables)
935 (member 'b the-lexical-variables)
936 (member 'x the-lexical-variables))
937 (error "Walker didn't do lexical variables of a closure properly."))))
940 (quit :unix-status 104)