MathGroup Archive 2007

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

Search the Archive

Returning a local array

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84188] Returning a local array
  • From: Art <grenander at gmail.com>
  • Date: Thu, 13 Dec 2007 01:25:03 -0500 (EST)

I would like to return a local array. The below seems like the wrong
way to do it:

f[] := Module[{h}, h["a"] = 1; h["b"] = 2; h];
g = f[];

I would like g not to be associated with the local variable h, but
equivalent to defining it as follows:

g["a"] = 1; g["b"] = 2;

Is it better to work with rules instead? It can become awkward and I
would like to avoid it.

f[] := Module[{h}, h={"a" -> 1, "b" -> 2}; h];
g = f[];
"a" /. g

The specific problem is I am reading the header for a binary file that
has 20 or so parameters describing the binary file. I thought this
would be the analog of a structure in other languages and a good way
to put these parameters in a variable.

Thanks.


  • Prev by Date: Fill 1x6 grid with 1 over 6
  • Next by Date: Re: FullSimplify with Pi
  • Previous by thread: Re: Fill 1x6 grid with 1 over 6
  • Next by thread: Re: Returning a local array