diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-11-02 19:34:04 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-11-02 19:34:04 -0800 |
commit | f53fea8d4d8428e81a048cab5ac323d3a3979b00 (patch) | |
tree | 6f78adbc3391164937f106b0122b754a0713ba3d /tests/012/cont.tl | |
parent | 3ac0654ecebb31ebaaf553446244408fcf0f79fc (diff) | |
download | txr-f53fea8d4d8428e81a048cab5ac323d3a3979b00.tar.gz txr-f53fea8d4d8428e81a048cab5ac323d3a3979b00.tar.bz2 txr-f53fea8d4d8428e81a048cab5ac323d3a3979b00.zip |
Add amb test case for continuations.
* tests/012/cont.tl (amb-scope): New macro.
(amb): New function.
New test case using amb.
Diffstat (limited to 'tests/012/cont.tl')
-rw-r--r-- | tests/012/cont.tl | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/012/cont.tl b/tests/012/cont.tl index 6bdfa14c..0a728ff9 100644 --- a/tests/012/cont.tl +++ b/tests/012/cont.tl @@ -17,3 +17,23 @@ (test (let ((f (obtain (yflatten '(a b (c . d) (e (f (g)))))))) (gun [f])) (a b c d e f g)) + +(defmacro amb-scope (. forms) + ^(block amb-scope ,*forms)) + +(defun amb (. args) + (suspend amb-scope cont + (each ((a args)) + (when (and a (call cont a)) + (return-from amb a))))) + +(test (amb-scope + (let ((w1 (amb "the" "that" "a")) + (w2 (amb "frog" "elephant" "thing")) + (w3 (amb "walked" "treaded" "grows")) + (w4 (amb "slowly" "quickly"))) + (amb (and (eql [w1 -1] [w2 0]) + (eql [w2 -1] [w3 0]) + (eql [w3 -1] [w4 0]))) + (list w1 w2 w3 w4))) + ("that" "thing" "grows" "slowly")) |