Hello,

of course I have to use  amb-collect.

Maybe I didnt describe my problem properly.

My intention is to pass the arguments to choose from in a list.

The teaching material I got from university gives the following exanple for the 
usage
of amb-collect:

***************************************************************************************

;;get all pairs of values von a and b,
;;which have sum 7

(amb-collect)
( let ( ( a (amb 1 2 3 4 5 6 7 ) )
          (b (amb 2 4 6 8 ) ) )
( amb-assert (= (+ a b) 7 ) )
( cons a b ) ) )


-------->( ( 1 . 6) (3 . 4) (5 . 2 ) )

***************************************************************************************

I'm looking for a way to use two lists instead to provide these values: (1 2 3 
4 5 6 7) and (2 4 6 8)


Thanks,
Stefan




Am 14.09.2010 17:50, schrieb Thomas Chust:
2010/9/14 Stefan Busch<stefan_bus...@arcor.de>:
[...]
Your solution looked convincing to me,
but when I try e.g.

(amb list (list 1 2 3 4))

it's not evaluated to the desired

1 2 3 4,

but to

1.
[...]
Hello,

I assume you meant to say (amb-list ...) instead of (amb list ...). Of course
this expression evaluates to the first item in the list. This is the whole
point of amb: To return the result *one* of its arguments evaluates to, but to
provide the possibility of backtracking and choosing another argument.

If you want a list of all possible return values of an expression, you *must*
wrap it in an amb-collect. The implementation of amb provided by
(planet murphy/amb:1:1/amb) will even signal an error if the dynamic context
of an ambiguous expression is not enclosed by something equivalent to amb-find
or amb-collect.

Ciao,
Thomas



_________________________________________________
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users

Reply via email to