numere-org / NumeRe

Framework for numerical computations, data analysis and visualisation
https://www.numere.org
GNU General Public License v3.0
20 stars 7 forks source link

Enable 'clear var' in terminal #25

Closed numeredev closed 1 year ago

numeredev commented 1 year ago

DESCRIPTION

What does your feature request improve on? Please describe. The list of available variables in global scope is growing on and on. There's no possibility to reduce the number of variables after they are created with exception of restarting the application. Enabling something like clear var in terminal (only in terminal) will improve on this situation.

Describe the solution you'd like Create or enable the command clear var in terminal (only there) to remove all user-created variables from global scope. It is discussable, whether clear var shall imply clear -memory. The command shall not remove auto-created variables.

Additional context Add any other context or screenshots about the feature request here.

(Do not write below this line)


DEVS' SECTION

ANALYSIS

To implement things like that, we need to distinct between internal and external variables. So, create a function for clearing numerical and string variables. Deleting string variables should not be too difficult. Simply add a method to the StringVarFactory to clear all public vars (which do not start with _~ or so). Do a similar thing for the ParserBase, however, do not delete the default variables x, y, z, t, nrows, ncols, nlen (and nlines for legacy reasons).

Evaluate, whether we shall separate between clear -memory and clear -var or whether clear -var shall automatically call clear -memory or whether clear -memory should be in fact the most general one calling also clear -var.

IMPLEMENTATION STEPS

(see also our Wiki for implementation guidelines)

DOCUMENTATION STEPS

(see also our Wiki for further information)

PULL REQUEST

numeredev commented 1 year ago

Implementation should start within static CommandReturnValues cmd_clear(string& sCmd) (located in commandfunctions.hpp). There's already the example for clear -memory. There's already some basic interface for obtaining the list of vars and deleting them within the ParserBase (ParserBase::GetVar() and ParserBase::RemoveVar()), so one can use that.

To ensure that this command is only executed within its legal scope, you can check for the stack trace size of the debugger (e.g. via NumeReKernel::getInstance()->getDebugger().getStackSize()), which should be zero in combination with NumeReKernel::getInstance()->getProcedureInterpreter().GetCurrentLine(), which also should be zero.