|
5 | 5 | (test-begin "Continuations") |
6 | 6 |
|
7 | 7 | (test-assert "continuation? (call/cc)" |
8 | | - (continuation? (call/cc (lambda (k) k)))) |
| 8 | + (continuation? (call/cc values))) |
9 | 9 | (test-assert "continuation? (call/comp)" |
10 | | - (continuation? |
11 | | - (call/prompt |
12 | | - (lambda () |
13 | | - (call/comp (lambda (k) k)))))) |
| 10 | + (continuation? (call/prompt (lambda () (call/comp values))))) |
14 | 11 | (test-assert "continuation? (call/delimited-cc)" |
15 | | - (continuation? |
16 | | - (call/prompt |
17 | | - (lambda () |
18 | | - (call/delim-cc (lambda (k) k)))))) |
| 12 | + (continuation? (call/prompt (lambda () (call/delim-cc values))))) |
19 | 13 |
|
20 | 14 | (test-assert "continuation? (symbol)" (not (continuation? 'a))) |
21 | 15 | (test-assert "continuation? (symbol)" (not (continuation? (lambda args args)))) |
22 | 16 |
|
| 17 | +(test-assert (not (composable-continuation? (call/cc values)))) |
| 18 | +(test-assert (not (composable-continuation? |
| 19 | + (call/prompt (lambda () (call/delim-cc values)))))) |
| 20 | + |
| 21 | +(test-assert (composable-continuation? |
| 22 | + (call/prompt (lambda () (call/comp values))))) |
| 23 | + |
23 | 24 | (test-assert (continuation-prompt-tag? (default-continuation-prompt-tag))) |
24 | 25 | (test-assert (continuation-prompt-tag? (make-continuation-prompt-tag))) |
25 | 26 |
|
|
158 | 159 | (test-equal "(post mid pre)" (e)) |
159 | 160 | (test-equal '(mid pre post mid pre) v))) |
160 | 161 |
|
| 162 | +;; From SRFI-226 |
| 163 | + |
| 164 | +(test-equal 4 (+ 1 (reset 3))) |
| 165 | +(test-equal 5 (+ 1 (reset (* 2 (shift k 4))))) |
| 166 | +(test-equal 9 (+ 1 (reset (* 2 (shift k (k 4)))))) |
| 167 | +(test-equal 17 (+ 1 (reset (* 2 (shift k (k (k 4))))))) |
| 168 | +(test-equal 25 (+ 1 (reset (* 2 (shift k1 (* 3 (shift k2 (k1 (k2 4))))))))) |
| 169 | + |
| 170 | +(let () |
| 171 | + (define call-with-non-composable-continuation call/delim-cc) |
| 172 | + (test-equal 990 |
| 173 | + (let ([tag (make-continuation-prompt-tag)]) |
| 174 | + (* 2 |
| 175 | + (call-with-continuation-prompt |
| 176 | + (lambda () |
| 177 | + (* 3 |
| 178 | + (call-with-non-composable-continuation |
| 179 | + (lambda (k) |
| 180 | + (* 5 |
| 181 | + (call-with-continuation-prompt |
| 182 | + (lambda () |
| 183 | + (* 7 (k 11))) |
| 184 | + tag))) |
| 185 | + tag))) |
| 186 | + tag))))) |
| 187 | + |
| 188 | +(test-equal 6930 |
| 189 | + (let ([tag (make-continuation-prompt-tag)]) |
| 190 | + (* 2 |
| 191 | + (call-with-continuation-prompt |
| 192 | + (lambda () |
| 193 | + (* 3 |
| 194 | + (call-with-composable-continuation |
| 195 | + (lambda (k) |
| 196 | + (* 5 |
| 197 | + (call-with-continuation-prompt |
| 198 | + (lambda () |
| 199 | + (* 7 (k 11))) |
| 200 | + tag))) |
| 201 | + tag))) |
| 202 | + tag)))) |
| 203 | + |
| 204 | +(test-equal 7 (prompt (+ 2 (control k (k 5))))) |
| 205 | +(test-equal 5 (prompt (+ 2 (control k 5)))) |
| 206 | +(test-equal 12 (prompt (+ 5 (prompt (+ 2 (control k1 (+ 1 (control k2 (k2 6))))))))) |
| 207 | +(test-equal 8 (prompt (+ 5 (prompt (+ 2 (control k1 (+ 1 (control k2 (k1 6))))))))) |
| 208 | +(test-equal 18 (prompt |
| 209 | + (+ 12 (prompt (+ 5 (prompt (+ 2 (control k1 (control k2 (control k3 (k3 6))))))))))) |
| 210 | + |
| 211 | +(define-syntax let/prompt |
| 212 | + (syntax-rules () |
| 213 | + ((_ ((var val) ...) body ...) |
| 214 | + (let/prompt (default-continuation-prompt-tag) ((var val) ...) body ...)) |
| 215 | + ((_ tag ((var val) ...) body ...) |
| 216 | + (call-with-continuation-prompt |
| 217 | + (lambda () |
| 218 | + (let ((var val) ...) body ...)) |
| 219 | + tag)))) |
| 220 | + |
| 221 | +(let/prompt () |
| 222 | + (define call-with-non-composable-continuation call/delim-cc) |
| 223 | + (define tag (make-continuation-prompt-tag)) |
| 224 | + (call-with-continuation-prompt |
| 225 | + (lambda () |
| 226 | + (test-assert |
| 227 | + (continuation-prompt-available? tag |
| 228 | + (call-with-non-composable-continuation values)))) |
| 229 | + tag) |
| 230 | + (call-with-continuation-prompt |
| 231 | + (lambda () |
| 232 | + (test-assert |
| 233 | + (continuation-prompt-available? tag |
| 234 | + (call-with-non-composable-continuation values tag)))) |
| 235 | + tag) |
| 236 | + (call-with-continuation-prompt |
| 237 | + (lambda () |
| 238 | + (test-assert |
| 239 | + (not (continuation-prompt-available? tag |
| 240 | + (call-with-composable-continuation values tag))))) |
| 241 | + tag)) |
| 242 | + |
161 | 243 | (test-end) |
0 commit comments