I was wondering if there was any way to call a function on a variable containing a list without having to use a foreach/while loop. (apply + 1 2 3) obviously works, but (apply + (create$ 1 2 3)) doesn't, so that doesn't help me. This sort of problem comes up a lot, and I usually handle it by implode$-ing the list, str-cat-ing the function and parentheses, and then build-ing it as follows:
(bind ?list (create$ 1 2 3)) (apply + ?bind) ;ERROR, as mentioned above (build (str-cat "(+ " (implode$ ?list) ")) ;SUCCESS However, this time, I'm dealing with a list of fact-ids, and this method doesn't work because Jess doesn't parse "<Fact-2>" to a fact-id from the implode$-ed string. I thought maybe I could create$ a new list with the function at the beginning, but there is no way that I could find to evaluate a list, only a string. E.g.: (bind ?list (create$ 1 2 3)) (bind ?flist (create$ + ?list)) ;?flist is (+ 1 2 3), but can't evaluate So, I guess I'm looking for three possible solutions: 1) calling a function on a list 2) getting Jess to correctly parse a fact-id from a string 3) getting Jess to evaluate a list as a function Any ideas? Or should I just give up and resort to iterative measures? -- View this message in context: http://www.nabble.com/Calling-a-function-on-all-elements-in-a-list-tp15921074p15921074.html Sent from the Jess mailing list archive at Nabble.com. -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------