Re: How to call 'Clear' from within a function?
- To: mathgroup at smc.vnet.net
- Subject: [mg124917] Re: How to call 'Clear' from within a function?
- From: James Stein <mathgroup at stein.org>
- Date: Sun, 12 Feb 2012 05:01:41 -0500 (EST)
- Delivered-to: firstname.lastname@example.org
- References: <201202091038.FAA18317@smc.vnet.net> <201202111139.GAA16453@smc.vnet.net>
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.