From: Robert D. <rob...@gm...> - 2024-10-13 20:16:05
|
I don't understand what's going on in all the examples, but specifically about the one mentioned in the subject line. [a:b,b:c,c:d]; ev('[a,b,c],'a=42); yielding [42, c, d]. I think I can explain this. Note that ev handles the trailing equations differently depending on whether the left hand side is an atom or not. If the left hand side is an atom, then MSET (assignment operator ":") is called to temporarily assign the right hand side (after evaluation of the right hand side) to the left hand side (without evaluating the left hand side). Otherwise, MAXIMA-SUBSTITUTE (internal substitution function, also called by subst) is called to substitute the right hand side (after evaluation of the right hand side) for the left hand side (after evaluation of the left hand side). 'a is a nonatomic expression ((MQUOTE) $A), so MAXIMA-SUBSTITUTE is called to substitute 42 for the result of evaluating 'a, which is a, into [a, b, c], and then [42, b, c], is evaluated, yielding [42, c, d]. Tracing MEVAL, MSET, and MAXIMA-SUBSTITUTE sheds some light on all that, although it doesn't show the whole picture; I suspect there are various details which are obscured by ev or maybe MEVAL. I think it's been said before, but it bears repeating. ev is a conglomeration of convenience features, which are not altogether consistent, and so predicting what's going to happen in any specific case can't be conclusively decided by any process shorter than reading the entire function. Given that, what almost everyone does is to stick to special cases of ev for which the results are predictable. FWIW Robert |