summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-30 07:53:11 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-30 07:53:11 -0700
commit126c166e4e173db355e44e549b5c7f36b6edf741 (patch)
tree1866b0183da0345d36504ae09ed0598e6c127bfa
parent4dd724f26c6035ac6ec796a72377007c318a1d96 (diff)
downloadtxr-126c166e4e173db355e44e549b5c7f36b6edf741.tar.gz
txr-126c166e4e173db355e44e549b5c7f36b6edf741.tar.bz2
txr-126c166e4e173db355e44e549b5c7f36b6edf741.zip
tests: multiple evaluation issue in amb.
This issue doesn't affect the tests. This is for the benefit of someone who happens to be copy-and-pasting the amb implementation from here. * tests/012/cont.tl (amb): This function has an issue in that it calls the continuation (future calculation) and then if that succeeds, it normally returns the value. This means that the future is executed again. In the case of N amb expressions, the successful future is executed 2**N times. What amb must do is this: call the continuation and capture the value. If the value is successful, then that is the master return value; just return that from amb-scope, bypassing the second re-execution of the future.
-rw-r--r--tests/012/cont.tl4
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/012/cont.tl b/tests/012/cont.tl
index 1d79b37b..b89b1502 100644
--- a/tests/012/cont.tl
+++ b/tests/012/cont.tl
@@ -24,8 +24,8 @@
(defun amb (. args)
(suspend amb-scope cont
(each ((a args))
- (when (and a (call cont a))
- (return-from amb a)))))
+ (whenlet ((res (and a (call cont a))))
+ (return-from amb-scope res)))))
(test (amb-scope
(let ((w1 (amb "the" "that" "a"))