From f22d21584b60d643e1c91d262a81af0cfb8ae9ed Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 30 Jul 2021 07:53:11 -0700 Subject: 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. --- tests/012/cont.tl | 4 ++-- 1 file 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")) -- cgit v1.2.3