 
 
 
 
 
 
Re: On ~= (simulating a C structure) in Mathematica....
- To: mathgroup at smc.vnet.net
- Subject: [mg103941] Re: On ~= (simulating a C structure) in Mathematica....
- From: Dan <dflatin at rcn.com>
- Date: Tue, 13 Oct 2009 23:18:18 -0400 (EDT)
- References: <hb1nse$sob$1@smc.vnet.net>
On Oct 13, 7:21 am, Jason Ledbetter <jasonbr... at gmail.com> wrote:
[snip]
> 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";];
test[bar];
DownValues[bar]
You can also consider using strings as field names, as in
test[data_] := Module[{}, data@"zvalue" = "zero"; data@"ovalue" "one";];
test[bar];
DownValues[bar]
This will give you the freedom to make your "structure" more self
documenting.
-- Daniel

