From: Michel T. <ta...@lp...> - 2023-10-24 08:46:25
|
What is the problem with the simpler: (%i1) map(lambda([x],x+a),[2,3,4]); (%o1) [a + 2, a + 3, a + 4] (%i2) x:5; (%o2) 5 (%i3) map(lambda([x],x+a),[2,3,4]); (%o3) [a + 2, a + 3, a + 4] (%i4) a:3; (%o4) 3 (%i5) map(lambda([x],x+a),[2,3,4]); (%o5) [5, 6, 7] Le 24/10/2023 à 01:24, Eduardo Ochs a écrit : > 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 > > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss -- Michel Talon |