From: Eduardo O. <edu...@gm...> - 2023-10-23 23:24:57
|
Hi list, what is the right/recommended way to define something like Lisp's "map" in Maxima? I tried this, to_lisp(); (defun foo (x) (* x 10)) (map 'list 'foo '(2 3 5 8)) ;;-> (20 30 50 80) (to-maxima) map_list(f, as) := makelist(apply(f, [a]), a, as); map_list(lambda([x], 10*x), [2, 3, 5, 8]); /* [20, 30, 50, 80] */ map_list(lambda([x], x+b), [2, 3, 5, 8]); /* [b+2, b+3, b+5, b+8] */ map_list(lambda([x], x+a), [2, 3, 5, 8]); /* [4, 6, 10, 16] */ but it doesn't work well in cases like the last one, in which f mentions a global variable with the same name as the variable used in the makelist... Thanks in advance! Cheers =), Eduardo Ochs |