MathGroup Archive 2009

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

Search the Archive

Re: On ~= (simulating a C structure) in Mathematica....

  • To: mathgroup at
  • Subject: [mg103941] Re: On ~= (simulating a C structure) in Mathematica....
  • From: Dan <dflatin at>
  • Date: Tue, 13 Oct 2009 23:18:18 -0400 (EDT)
  • References: <hb1nse$sob$>

On Oct 13, 7:21 am, Jason Ledbetter <jasonbr... at> wrote:


> In[262]:= test[data_] := Module[{}, {data[0] = "zero", data[1] = "one"}];
> bar = test[foo];
> DownValues[bar]
> Out[262]= {}
> I'm expecting... {HoldPattern[bar[0]]:> zero...}
> Thoughts? I realize I'm probably doing this The Hard Way and welcome other
> alternatives... my end goal is to be able to have a single variable that
> describes the entire dataset/individually-imported-layers that can be passed
> to other functions so I can more readily work with multiple datasets
> -jbl

When you modify down values for a parameter passed to a function in
Mathematica, the parameter passed acquires the down values. This is
similar to passing by reference in C. Also note that in your example,
your function was returning a list. You might want to try:

test[data_] := Module[{}, data[0] = "zero"; data[1] = "one";];

You can also consider using strings as field names, as in

test[data_] := Module[{}, data@"zvalue" = "zero"; data@"ovalue" "one";];

This will give you the freedom to make your "structure" more self

-- Daniel

  • Prev by Date: Import[] - limited from a pipe?
  • Next by Date: Re: Convert Graphics3D to Graphics2D. Is it possible?
  • Previous by thread: Re: On ~= (simulating a C structure) in Mathematica....
  • Next by thread: Better Way of Testing and Replacing List Elements?