(amb 'list)

Started by Fritz, October 31, 2009, 01:52:05 PM

Previous topic - Next topic

Fritz

Trying to select a random value from the list.


(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:


(eval-string (append "(amb '" (join (map string mylist) " '") ")"))

But there should be some simple solution, right?

m i c h a e l

#1
Hi Fritz,



Try this:


> (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

cormullion

#2
m i c h a e l beat me to it...



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


apply amb my-list is what you want

Fritz

#3
Oh, thanx!