[plt-scheme] problem with backtracking order of nested ambs

From: keydana at gmx.de (keydana at gmx.de)
Date: Tue Oct 6 16:02:09 EDT 2009

Hi Thomas,

thanks very much - this is it!
I'll use your second version with the thunk, and from there call the  
specific selection function - and as I have no performance  
considerations here, I can safely call the procedure several times  
from the "top-level" amb :-)

Thanks again for the quick help (I'm really in quite a pressure to get  
this working),
Sigrid



Am 06.10.2009 um 15:47 schrieb Thomas Chust:

> 2009/10/5 keydana at gmx.de <keydana at gmx.de>:
>> [...]
>> (let ((x (amb 3 5 4)))
>>  (let ((result (amb (begin (assert (even? x)) x) 77)))
>>    result))
>>
>> I would need amb to first try all of '(3 5 4) and only after that,  
>> take 77
>> as last possible way out.
>> [...]
>
> Hello Sigrid,
>
> since the evaluation order of amb itself cannot be modified easily,
> you have to reverse the dynamic nesting order of the two ambivalent
> expressions. This can for example be done by "physically" moving the
> inner out outward:
>
>  (let ((result
>           (amb
>             (let ((x (amb 3 5 4)))
>               (assert (even? x))
>               x)
>             77)))
>    result)
>
> or by wrapping the outer one in a procedure:
>
>  (let ((x (lambda () (amb 3 5 4))))
>    (let ((result (amb (let ((x (x))) (assert (even? x)) x) 77)))
>      result))
>
> Ciao,
> Thomas
>
>
> -- 
> All these theories, diverse as they are, have two things in common:  
> They
> explain the observed facts, and they are completely and utterly wrong.
>                               -- Terry Pratchett, "The Light  
> Fantastic"



Posted on the users mailing list.