From: SourceForge.net <no...@so...> - 2007-06-15 20:48:35
|
Bugs item #1735401, was opened at 2007-06-11 16:27 Message generated for change (Comment added) made by woollett You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1735401&group_id=4933 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Lisp Core Group: None Status: Closed Resolution: Wont Fix Priority: 5 Private: No Submitted By: Ted Woollett (woollett) Assigned to: Nobody/Anonymous (nobody) Summary: makelist( ) inside function definition Initial Comment: Attempts to use makelist function inside a user defined function: Maxima 5.12.0 http://maxima.sourceforge.net Using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (aka GCL) /* 1 */ (%i1) table1(expr, n, n1, n2) := ( z : makelist(expr, n, n1,n2 ), print(" z = ", z) )$ (%i2) table1(n^2, n, 1, 3)$ 2 2 2 z = [n , n , n ] /* 2 */ (%i3) table2(expr,n,n1,n2) := ( print(" expr = ",expr," n = ",n," n1 = ",n1," n2 = ",n2), z : makelist(expr,n,n1,n2), print(" z = ", z) )$ (%i4) table2(n^2,n,1,3)$ 2 expr = n n = n n1 = 1 n2 = 3 2 2 2 z = [n , n , n ] /* 3 */ (%i5) table3(expr,n,n1,n2) := block([z], print(" expr = ",expr," n = ",n," n1 = ",n1," n2 = ",n2), z : makelist(expr,n,n1,n2), print(" z = ", z) )$ (%i6) table3(n^2,n,1,3)$ 2 expr = n n = n n1 = 1 n2 = 3 2 2 2 z = [n , n , n ] /* 4 */ (%i7) table4(expr,n,n1,n2) := block([z,m1:n1, m2:n2], print(" expr = ",expr," n = ",n," m1 = ",m1," m2 = ",m2 ), z : makelist(expr, n, m1, m2), print(" z = ", z) )$ (%i8) table4(n^2, n, 1, 3)$ 2 expr = n n = n m1 = 1 m2 = 3 2 2 2 z = [n , n , n ] I am assuming "expr" is not a reserved word in Maxima. Perhaps I am not using corrent passage of arguments?? ---------------------------------------------------------------------- Comment By: Ted Woollett (woollett) Date: 2007-06-15 13:48 Message: Logged In: YES user_id=1806103 Originator: YES Can we add a comment after a thread is "closed"?? Thanks for the explanation of forcing evaluation with ev(). I clearly need to pay closer attention to R. Dodier's "Minimal Maxima" discussion of these issues. Was initially trying to make something like Mathematica's Table function. The following works but retains brackets if expr is [n, n^2]. (%i7) mytable(expr,n, [nval] ) := map( disp, ( if length(nval) = 2 then makelist( ev(expr),n, nval[1], nval[2] ) else makelist( ev(expr) , n, nval[1] ) ) ) ; ---------------------------------------------------------------------- Comment By: Robert Dodier (robert_dodier) Date: 2007-06-14 18:24 Message: Logged In: YES user_id=501686 Originator: NO It turns out that the observed behavior is to be expected. Maxima does not try as much as it can to evaluate expressions; variables in expressions are evaluated just once. This policy makes it easier to predict results, at the cost of some surprise. makelist evaluates its first argument, expr, for each value of n between n1 and n2. What is the value of expr? It is n^2 in each case. That is not evaluated further, so the result is [n^2, n^2, n^2]. There are various ways to cause expr to be evaluated more. Here is one. my_table (expr, n, n1, n2) := makelist (ev (expr), n, n1, n2); my_table (n^2, n, 1, 3); => [1, 4, 9] Although Maxima's evaluation rules are complex and often confusing, I'm closing this report as "won't fix". Hope this helps. Robert Dodier ---------------------------------------------------------------------- Comment By: Ted Woollett (woollett) Date: 2007-06-11 16:37 Message: Logged In: YES user_id=1806103 Originator: YES my computer system: Maxima version: 5.12.0 Maxima build date: 19:33 5/3/2007 host type: i686-pc-mingw32 lisp-implementation-type: GNU Common Lisp (GCL) lisp-implementation-version: GCL 2.6.8 ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=104933&aid=1735401&group_id=4933 |