From 22716a2cc76624dfc8a254c64361e51feeeedcf8 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Thu, 2 Jan 2025 18:37:07 +0100 Subject: [PATCH] Make symbol assignments global in ginsh. 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 . 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ginsh/ginsh_parser.ypp b/ginsh/ginsh_parser.ypp index 36fc38e7..7710ce13 100644 --- a/ginsh/ginsh_parser.ypp +++ b/ginsh/ginsh_parser.ypp @@ -40,7 +40,6 @@ #include #include #endif - #include #include "ginsh.h" @@ -262,7 +261,14 @@ exp : T_NUMBER {$$ = $1;} } } | T_DIGITS '=' T_NUMBER {$$ = $3; Digits = ex_to($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;} -- 2.49.0