newLISP Fan Club

Forum => newLISP in the real world => Topic started by: Fritz on October 31, 2009, 01:52:05 PM

Title: (amb 'list)
Post by: Fritz on October 31, 2009, 01:52:05 PM
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?
Title: Re: (amb 'list)
Post by: m i c h a e l on October 31, 2009, 02:29:47 PM
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
Title: Re: (amb 'list)
Post by: cormullion on October 31, 2009, 02:32:39 PM
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
Title: Re: (amb 'list)
Post by: Fritz on October 31, 2009, 03:00:33 PM
Oh, thanx!