Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8446
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: How to call 'Clear' from within a function? |
| Date | 2012-02-10 10:52 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jh2ssv$jl$1@smc.vnet.net> (permalink) |
| References | <201202091038.FAA18317@smc.vnet.net> |
Clear[x]; x x = 2 Clear[x] (* you clear symbols not strings *) x x 2 x ClearAll[f]; SetAttributes[f, HoldFirst]; f[arg_] := (Print[Unevaluated[arg]]; Clear[arg]); x = 2 f[x] x 2 x x Bob Hanlon On Thu, Feb 9, 2012 at 5:38 AM, James Stein <mathgroup@stein.org> wrote: > Before trying to encapsulate 'Clear' in a function, I try this: > > Clear [ x ] ; > x > x = 2 > Clear [ ToString [ Unevaluated [ x ] ] ] ; > x > > And I expect to get three lines of output: x, 2, and x > But instead I get these three lines output: x, 2 and 2. > > What do I misunderstand, or need to know? > > I observe that a function CAN obtain the name of a symbol passed to it: > > ClearAll [ f ] ; > SetAttributes [ f, HoldFirst ] ; > f [ arg_ ] := ( Print [ Unevaluated [ arg ] ] ; > Clear [ ToString [ Unevaluated [ arg ] ] ] ) ; > x = 2; (* assign a value to 'x' *) > f [ x ] ; (* 'f' can print the symbol 'x' ! *) > x (* but 'x' still has value '2' ; the 'Clear' had no effect !? *) > > Similar problems with trying to call 'Set' from within a function....
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: How to call 'Clear' from within a function? Bob Hanlon <hanlonr357@gmail.com> - 2012-02-10 10:52 +0000
csiph-web