tagbody.lsp 1.59 KB
Newer Older
pfdietz's avatar
pfdietz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Oct 12 13:27:22 2002
;;;; Contains: Tests of TAGBODY

(in-package :cl-test)

(deftest tagbody.1
  (tagbody)
  nil)

(deftest tagbody.2
  (tagbody 'a)
  nil)

(deftest tagbody.3
  (tagbody (values))
  nil)

(deftest tagbody.4
  (tagbody (values 1 2 3 4 5))
  nil)

(deftest tagbody.5
  (let ((x 0))
    (values
     (tagbody
      (setq x 1)
      (go a)
      (setq x 2)
      a)
     x))
  nil 1)

(deftest tagbody.6
  (let ((x 0))
    (tagbody
     (setq x 1)
     (go a)
     b
     (setq x 2)
     (go c)
     a
     (setq x 3)
     (go b)
     c)
    x)
  2)

;;; Macroexpansion occurs after tag determination
(deftest tagbody.7
  (let ((x 0))
    (macrolet ((%m () 'a))
      (tagbody
       (tagbody
	(go a)
	(%m)
	(setq x 1))
       a ))
    x)
  0)

(deftest tagbody.8
  (let ((x 0))
    (tagbody
     (flet ((%f (y) (setq x y) (go a)))
       (%f 10))
     (setq x 1)
     a)
    x)
  10)

;;; Tag names are in their own name space
(deftest tagbody.9
  (let (result)
    (tagbody
     (flet ((a (x) x))
       (setq result (a 10))
       (go a))
     a)
    result)
  10)

(deftest tagbody.10
  (let (result)
    (tagbody
     (block a
       (setq result 10)
       (go a))
     (setq result 20)
     a)
    result)
  10)

(deftest tagbody.11
  (let (result)
    (tagbody
     (catch 'a
       (setq result 10)
       (go a))
     (setq result 20)
     a)
    result)
  10)

(deftest tagbody.12
  (let (result)
    (tagbody
     (block a
       (setq result 10)
       (return-from a nil))
     (setq result 20)
     a)
    result)
  20)