|
From: Michel T. <ta...@lp...> - 2026-01-25 15:04:33
|
Le 25/01/2026 à 15:07, Barton Willis via Maxima-discuss a écrit : > About when 'local' is needed, maybe somebody else can help with this. > > The user documentation for 'local' waffles and says "|:=|, |array|, > |dependencies|, |atvalue|, |matchdeclare|, |atomgrad|, |constant|, > |nonscalar|, |assume|, and some others" (the "some others" being > waffle-like). > I think you have to contrast the documentation for block and the one for local. For block you have: If these variables are already bound 'block' saves the current values of the variables <v_1>, ..., <v_m> (if any) upon entry to the block, then unbinds the variables so that they evaluate to themselves; The local variables may be bound to arbitrary values within the block but when the block is exited the saved values are restored, and the values assigned within the block are lost. The important word here is *values*. So you see that in the declaration block([v],....) the symbol v is untouched but only the value associated to this symbol is manipulated. But for local you get: Saves the properties associated with the symbols <v_1>, ..., <v_n>, removes any properties before evaluating other expressions, and restores any saved properties on exit from the block or other compound expression in which 'local' appears. Here the important word is *properties*. Of course one needs to understand that a symbol has several things attached to it, particularly a value, a function slot and a property list. Here local manipulates the property list. The first example given is the one of lisp function definition, obtained by := Example: (%i1) f(x):=x^2; 2 (%o1) f(x) := x (%i2) :lisp(symbol-plist '$f) (MPROPS (NIL MEXPR ((LAMBDA) ((MLIST) $X) ((MEXPT) $X 2)))) As you can see the expression for the function f appears in the property-list of f, but not in the value or the function slot of f. If you compile f then the resulting function object appears in the function slot. (%i2) compile(f); (%o2) [f] (%i3) :lisp(symbol-function '$f) #<FUNCTION $F> Finally block([...] ...) isolates values inside the block, but not functions, while local() isolates maxima functions inside the block, but not compiled functions. All other declarations which occur through the property list behave the same as function definitions. I don't know the complete list of such situations, the doc above gives a partial list. Example: (%i4) matchdeclare(b,any); (%o4) done (%i5) :lisp(symbol-plist '$b) (MPROPS (NIL MATCHDECLARE ($ANY))) There are other "properties" however that are not included in the property list: (%i3) tellrat(a^2-2); 2 (%o3) [a - 2] (%i4) :lisp(symbol-plist '$a) NIL So one has to do some tests to be sure. -- Michel Talon |