Skip to main content

expression manipulation - How to Clear variables represented as a list of strings?


Say I have a string list called fullpara


fullpara={"width", "long", "line", "distance"}

And there are corresponding variables to each string, and I want to Clear these variables


Clear[width, long, line, distance]


How to do it in a way to manipulate fullpara as a whole?


Clear@@(ToExpression/@fullpara)

obviously won't work because ToExpression will evaluate the variable that already has a value.



Answer



According to the documentation of Clear or ClearAll it is possible to provide symbols in form of regular expression (limited), in particular as string with exact symbol name.


Clear @@ {"width", "long", "line", "distance"}




Let's say there is no possibility to do that, one way would be:


Map[Clear, 
ToExpression[{"width", "long", "line", "distance"}, InputForm, Hold],
{2}]; // ReleaseHold

Comments