|
From: Stavros M. <mac...@gm...> - 2024-10-13 21:24:26
|
To elaborate a bit on what Robert said, I strongly discourage you from
using *ev *programmatically if there is some other way to accomplish what
you want.
For your example:
subst('['a=42], '[a,b,c]); /* [a,b,c] */
This is looking for the expression *'a* in *[a,b,c]* and not finding it.
Contrast:
subst('['a=42], '['a,b,c]) => [42, b, c]
By the way, I would strongly recommend that you write:
[a:'b,b:'c,c:'d];
so that it has the same effect if you re-evaluate it. Otherwise:
[a:b, b:c, c:d] => [b, c, d]
[a:b, b:c, c:d] => [c, d, d]
-s
On Sun, Oct 13, 2024 at 4:16 PM Robert Dodier <rob...@gm...>
wrote:
> 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
>
>
> _______________________________________________
> Maxima-discuss mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
|