From: Eduardo O. <edu...@gm...> - 2023-10-24 14:45:59
|
Hi all, esp. Barton, ouch, it seems that my mental model of how "map" worked was wrong... some of the strange recursions that I was complaining about are due to listarith:true, not to map! And I lost the code in which I was trying to use map for some complex list jugglings and something didn't work... Anyway, thanks a lot, and sorry for the noise! Cheers, Eduardo On Tue, 24 Oct 2023 at 10:42, Barton Willis <wi...@un...> wrote: > > If you have found a bug in map, please report it. Also, try doing* listarith > : false *and rerunning your examples. > > --Barton > ------------------------------ > *From:* Eduardo Ochs <edu...@gm...> > *Sent:* Tuesday, October 24, 2023 08:30 > *To:* Michel Talon <ta...@lp...> > *Cc:* max...@li... < > max...@li...> > *Subject:* Re: [Maxima-discuss] How do I translate "(map 'list f as)" to > Maxima? > > Non-NU Email > ------------------------------ > Hi Michel, > map sometimes recurses on trees, not on lists: > > f : lambda([x], x+10); > g : lambda([ab], 10*ab[1]+ab[2]); > f([3,4]); > map(f, [[1,2],[3,4],[5,6]]); /* [[11, 12], [13, 14], [15, 16]] */ > map(g, [[1,2],[3,4],[5,6]]); /* [12, 34, 56] */ > map(f, [[1,2],[3,4],5]); /* [[11, 12], [13, 14], 15] */ > map(g, [[1,2],[3,4],5]); /* error */ > > It tries to do the right thing and it usually does, but there are some > cases in which its dtrt-iness is not what I expected... so I thought > that it would be nice to also have some functions with a simpler > logic. > Cheers, > Eduardo > > > On Tue, 24 Oct 2023 at 05:48, Michel Talon <ta...@lp...> wrote: > > 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 lis...@li...https://lists.sourceforge.net/lists/listinfo/maxima-discuss <https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!CF7OnbdkTSf-tofhEy1XexZwzM1O66mv06yRhhdJ18I5kjMHfTRRHxQK3cud2CC5VyZ2FgnSeznP93MRADM$> > > -- > Michel Talon > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > <https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!CF7OnbdkTSf-tofhEy1XexZwzM1O66mv06yRhhdJ18I5kjMHfTRRHxQK3cud2CC5VyZ2FgnSeznP93MRADM$> > > |