MathGroup Archive 2008

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

Search the Archive

Re: help with new symbols (or pointers)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92410] Re: help with new symbols (or pointers)
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Tue, 30 Sep 2008 21:47:46 -0400 (EDT)
  • Organization: University of Bergen
  • References: <gbt2t4$lfo$1@smc.vnet.net>

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

Try Evaluate[Symbol["x" <> "1"]] = 5.  This will only work if you can 
make sure that x1 does not already have a value.  But do consider using 
x[1], x[2], etc. instead of x1, x2, ...

If there is really no way to avoid building symbol names from strings, 
then you can use the following function to assign values to symbols 
which might already have a value:

assignToName[name_, value_] :=
  ToExpression[name, InputForm,
   Function[symbol, symbol = value, {HoldFirst}]]

assignToName["x"<>"1", 5]

> 
> 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)?
> 

No, Mathematica does not have pointers.


  • Prev by Date: Re: New definition of the Plot preference
  • Next by Date: Re: Font size in plot coordinates?
  • Previous by thread: Re: help with new symbols (or pointers)
  • Next by thread: Re: help with new symbols (or pointers)