From 8bb8739fb9f641f39481c12c9ea9bc96762bbae4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 3 Feb 2022 14:23:17 -0800 Subject: doc: fix in amb macro. * txr.1: when the amb macro detects that the continuation has succeeded, it should return that successful value from the amb-scope, rather than returning the local successful argument a from the amb function. Although it works both ways, it is inefficient when it returns from the function. The reason is that each call to amb executes the successful future twice: once via (call cont a) and then again by returning the a value. This then causes an exponential cascade in calls: each successive amb call sthe successful future twice, so for instance if the solution has a sequence of 8 amb calls, the successful case is reached 256 times. --- txr.1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/txr.1 b/txr.1 index fcf6ce6b..68582448 100644 --- a/txr.1 +++ b/txr.1 @@ -52008,8 +52008,9 @@ and (defun amb (. args) (suspend amb-scope cont (each ((a args)) - (when (and a (call cont a)) - (return-from amb a))))) + (if a + (iflet ((r (call cont a))) + (return-from amb-scope r)))))) .brev Use -- cgit v1.2.3