[Date Index] [Thread Index] [Author Index]
Re: How to call 'Clear' from within a function?
I thank all the responders for helping me to clarify my thoughts on this issue. The reason I was using Strings, not Symbols, is too complicated and too uninteresting to detail here. To answer Albert Retey's question, what I was trying to do: I was planning to investigate how precision affected certain computations. It was my intention to set (and reset) various variables by calling a single function which would repeatedly call a function such as this one: ClearAll [ f, x, watt, meter ]; SetAttributes [ f, HoldFirst ]; f [ var_, expr_, precision_, units_: 1 ] := ( ClearAll [ var ]; var = If [ precision == 0, expr, SetPrecision [ expr, precision ] ] units ); (* examine f: *) f [ x, 5., 0 ] f [ x, 5., 8 ] f [ x, 5., 12, watt meter ^ -2 ] As usual, an urge to increase precision turned moot with a more clever algorithm.