MathGroup Archive 2000

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

Search the Archive

RE: Subscripted local variables in Module



> -----Original Message-----
> From: skker [mailto:skker at skker.com]
To: mathgroup at smc.vnet.net

> 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.
>

The first argument in a Module must be a list of symbols; x[1] is not a
symbol but an expression. It is easy enough:

Module[{x},
   x[1] = 1;
   x[2] = 2;
   x[1] + x[2]
   ]
3

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



  • Prev by Date: Re: Subscripted local variables in Module
  • Next by Date: how much graphics RAM?
  • Previous by thread: Re: Subscripted local variables in Module
  • Next by thread: Re: Subscripted local variables in Module