On ~= (simulating a C structure) in Mathematica....
- To: mathgroup at smc.vnet.net
- Subject: [mg103922] On ~= (simulating a C structure) in Mathematica....
- From: Jason Ledbetter <jasonbrent at gmail.com>
- Date: Tue, 13 Oct 2009 07:17:21 -0400 (EDT)
Folk, I'm importing data into mathematica from a web service using some perl middleware (the lack of XPath functionality in mathematica coupled with my very junior comprehension of mathematica patterns forced this for now). The perl middleware returns datasets by "layers" that I'm (somewhat successfully) manipulating within mathematica. For each dataset, I end up with a few large pieces of data that are roughly analogous to "layers". Right now, I am mentally keeping track of the variable names for each layer but I would like to expand this to be more programatic so I can work with comparisons between datasets (which would each contain a number of "layers"). Initially I was just naming variables like... datasetId=3728; layer1ImportString = "!importprogram..."<> ToString[datasetId]"; layer1=Import[layer1ImportString....]; .... This would let me have a single identifiable dataset with named layers. I've been pondering abusing DownValues to store this data at a known-to-me "index". e.g., dataset1[0]=3278; dataset1[1]=Import[layer1ImportString...]; I believe this approach will work, but what I'm trying to do now is encapsulate all of the initial dataset/layer importing into one function which leads to my question. How can I do: dataset1=importById[3728]; and get dataset1[0], dataset1[1], etc populated? For example: 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 concurrently. Thanks, -jbl
- Follow-Ups:
- Re: On ~= (simulating a C structure) in Mathematica....
- From: Jason Ledbetter <jasonbrent@gmail.com>
- Re: On ~= (simulating a C structure) in Mathematica....