Page 1 of 1

(amb 'list)

Posted: Sat Oct 31, 2009 8:52 pm
by Fritz
Trying to select a random value from the list.

Code: Select all

(set 'mylist '((0 0) '(0 1) '(0 2)))
(amb mylist)
Result: ((0 0) (0 1) (0 2))

Different combinations of expand, eval, map and apply wont work in my hands. Only working method I have found is the monstercode with eval-string:

Code: Select all

(eval-string (append "(amb '" (join (map string mylist) " '") ")"))
But there should be some simple solution, right?

Re: (amb 'list)

Posted: Sat Oct 31, 2009 9:29 pm
by m i c h a e l
Hi Fritz,

Try this:

Code: Select all

> (set 'mylist '((0 0) (0 1) (0 2)))
((0 0) (0 1) (0 2))
> (apply amb mylist)
(0 2)
> (apply amb mylist)
(0 0)
> (apply amb mylist)
(0 2)
> _
Also notice that only one quote is necessary in creating the list. Hope that helps!

m i c h a e l

Re: (amb 'list)

Posted: Sat Oct 31, 2009 9:32 pm
by cormullion
m i c h a e l beat me to it...

amb doesn't take a list, just a series of expressions, so:

Code: Select all

apply amb my-list
is what you want

Re: (amb 'list)

Posted: Sat Oct 31, 2009 10:00 pm
by Fritz
Oh, thanx!