Re: Subscripted local variables in Module

• To: mathgroup at smc.vnet.net
• Subject: [mg24013] Re: Subscripted local variables in Module
• From: hwolf at debis.com
• Date: Tue, 20 Jun 2000 03:07:30 -0400 (EDT)
• Organization: debis Systemhaus
• References: <8ikdfu\$qkm@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```skker schrieb:
>
> Why can't I use subscripted local variables in a Module?
>
> Module[{x[1], x[2]},
>    x[1] = 1;
>    x[2] = 2;
>    x[1] + x[2]
>    ]
> doesn't work. I could fix this code by replacing x[1] by x and x[2] by
> y. But there is a more serious problem when I want a non-fixed number of
> local variables.

Within Module you introduce local _symbols_, not variables (neither as
downvalues "x[1]" nor subcripted "Subscript[x, 1]".

let's define globals:

In[4]:= x[1] = "what's that?";

In[5]:= \!\(x\_1 = "\<and that?\>"\);

So either ...

In[6]:= Module[{x}, x[1] = 1; x[2] = 2;
x[1] + x[2]]
Out[6]= 3

In[7]:= x[1]
Out[7]= "what's that?"

...or ...

In[8]:=
\!\(Module[{x}, x\_1 = 1; x\_2 = 2; \[IndentingNewLine]x\_1 + x\_2]\)
Out[8]= 3

In[9]:= \!\(x\_1\)
Out[9]= "and that?"

...will do. (I intentially used the boxed forms here, so you can paste them
into a notebook)

Hartmut Wolf

```

• Prev by Date: Re: Getting peak value from a Graph in Plot command - pls help
• Next by Date: Re: And, Or, Intersection, Union - no Orderless attribute
• Previous by thread: RE: Subscripted local variables in Module
• Next by thread: how much graphics RAM?