]> www.ginac.de Git - ginac.git/commitdiff
Make symbol assignments global in ginsh.
authorRichard Kreckel <kreckel@ginac.de>
Thu, 2 Jan 2025 17:37:07 +0000 (18:37 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Thu, 2 Jan 2025 22:00:29 +0000 (23:00 +0100)
When assigning an expression to a symbol, scan all previously assigned
symbols for that new symbol to occur in the expressions and replace
it with the new expression.

This has the effect of making symbols global in the scope of a ginsh
session.

See <https://www.ginac.de/pipermail/ginac-devel/2024-December/002655.html>.

The patch restores the behavior prior to GiNaC 1.4.4. It actually
even improves on it because the old version was based on assigned
symbols and that did not work with circular assignments whereas
substituion does.

ginsh/ginsh_parser.ypp

index 36fc38e7488391c7de587ddad83523adb2500017..7710ce1354290360e84e829fbe811f15e563bc27 100644 (file)
@@ -40,7 +40,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #endif
-
 #include <stdexcept>
 
 #include "ginsh.h"
@@ -262,7 +261,14 @@ exp        : T_NUMBER              {$$ = $1;}
                }
        }
        | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to<numeric>($3).to_int();}
-       | T_SYMBOL '=' exp      {$$ = $3; assigned_symbol_table[$1] = $3; }
+       | T_SYMBOL '=' exp      {
+               $$ = $3;
+               const exmap m{{$1, $3}};
+               for (auto & s : assigned_symbol_table) {
+                       s.second = s.second.subs(m);
+               }
+               assigned_symbol_table[$1] = $3;
+       }
        | exp T_EQUAL exp       {$$ = $1 == $3;}
        | exp T_NOTEQ exp       {$$ = $1 != $3;}
        | exp '<' exp           {$$ = $1 < $3;}