MathGroup Archive 2008

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

Search the Archive

Re: help with new symbols (or pointers)

  • To: mathgroup at
  • Subject: [mg92426] Re: help with new symbols (or pointers)
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at>
  • Date: Tue, 30 Sep 2008 21:50:43 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gbt2t4$lfo$>

ag wrote:
> Hi,
> I want to create new symbols inside a module & assign them values=85
> e.g. something like: Symbol[=93x=94<>"num"] = 5
> It is not working=85
> The problem is that I dont know how many symbols I would need (it
> could be 5, 50 or 5000)... So I cannot do something like:
> Symbol["x"<>"1"];
> x1=5;
> Is there anything in Mathematica which is like pointers in C
> (something which would assign a value to a given location in memory)?
> Any help would be appreciated!

The following should help:

     Do[Set[Evaluate[Symbol["var" <> ToString[num]]], 2 num], {num, 3}]
     Do[Print[Symbol["var" <> ToString[num]]], {num, 3}]




Note that the assignment operator '=' is written in fullform Set and it 
has the attribute *HoldFirst* that prevents the immediate evaluation of 
its first argument (so we force it thanks to the function *Evaluate*). 
Also, *ToString* transforms an expression (a number in our case) into a 
string of characters.

-- Jean-Marc

  • Prev by Date: Re: ClearAll error message
  • Next by Date: Re: Is there any simplier way to plot in a specific style?
  • Previous by thread: Re: help with new symbols (or pointers)
  • Next by thread: AuthorTools bug in Export v5.2