chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Using the amb egg


From: Thomas Chust
Subject: Re: [Chicken-users] Using the amb egg
Date: Tue, 10 Aug 2010 17:04:25 +0200

2010/8/10 Jeronimo Pellegrini <address@hidden>:
> On Tue, Aug 10, 2010 at 02:40:15PM +0200, Thomas Chust wrote:
>> [...]
>> Unless you know exactly what you are doing, I would recommend to
>> enclose all applications of amb in amb-find or amb-collect forms. Your
>> example could be modified like this:
>
> Ah, it's clear now. So the LET form does not restrict amb to its
> scope.
> [...]

Hello Jeronimo,

since let is a core form of Scheme, it knows nothing about amb and
doesn't setup a context for amb. However, if you think that is
convenient, I suggest that you create your own macro combining let,
amb-find or amb-collect and maybe even the applications of amb
themselves. Take this definition for example:

  (define-syntax amb-let
    (syntax-rules ()
      [(amb-let ([var expr ...] ...) . body)
       (amb-collect
         (let ([var (amb expr ...)] ...) . body))]))

Your examples would then simply become:

  (amb-let ([a 1 2 3] [b -1 -2 -3])
    (amb-assert (= (+ a b) 0))
    (list a b))

and

  (amb-let ([a 1 2 3] [b -1 -2 -3])
    (amb-assert (= (+ a b) 10))
    (list a b))

Maybe that helps :-)

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]