MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Simple question about named variables.


Perhaps I'm missing your intention, but the following very simple
interaction appears to achieve your goal:

In[1]:= x = 5

Out[1]= 5

In[2]:= ClearI[y_] := Clear[x]

In[3]:= ClearI[x]

In[4]:= x

Out[4]= x




-----Original Message-----
From: Pianiel [mailto:pdpdel at gmail.com] 
Sent: Friday, June 26, 2009 06:51
To: mathgroup at smc.vnet.net
Subject: [mg101245] [mg101187] Simple question about named variables.

Dear Mathematica users,

I would like to write a function which clears many variables called:

Test1,Test2,...

So I write the function:

ClearI[i_] := Clear@ToExpression@StringJoin["Test", ToString@i]

Test1 = 1;
Test2 = 2;


ClearI[1] does not work because the expression is evaluated. What
mathematica does is Clear@1. How could I ask Mathematica to do
Clear@Test1, Clear@Test2, ... automatically?

I am sure that the solution is simple... but I could not find it.

Thank you in advance

Pianiel




  • Prev by Date: Re: Eigenvalue bug in Mathematica 7.0.0
  • Next by Date: Re: The Principle "Everything is an expression"
  • Previous by thread: Simple question about named variables.
  • Next by thread: Re: Simple question about named variables.