MathGroup Archive 2010

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

Search the Archive

Extra Data and Data structures

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107203] Extra Data and Data structures
  • From: Uayeb <uayebswinburne at gmail.com>
  • Date: Fri, 5 Feb 2010 03:23:57 -0500 (EST)

Oh wisdom of the Mathematica list,

I occassionally would have a use for being able to carry extra data
around with something like a large list or array. Thinking more
carefully about this, I realise what I'm really looking for is some
way I can create a data structure of sorts in a Mathematica object,
and then somehow be able to use it in standard Mathematica constructs
where it would assume a "default value."

My initial thought was to create some kind of wrapper function which
remains unevaluated but which as appropriate UpSets such that it
returns its default value when Mathematica trys to do something with
it.

I'd like to be able to do something like this:
f=extraData[{1,2,34},"cool"];

3*f
{3,6,9,12}
(or even "extraData[{3,6,9,12},"cool"])

getExtra[f]
"cool"

It would be particularly amazing if I could do something like this:

g=3*f;

getExtra[g]
"cool"

I envision some set of rules assigned to the wrapper function
extraData which somehow knows to pass most functions through to the
first argument, but which behaives specially to a few things, such as
Set, and the function to retrieve the extra data, getExtra.

The general case would then be something like
f_[extraData[data_,extra_]]^:=extraData[f[data],extra]

Unfortunately, the few times I've tried this, I very quickly end up
with too many special cases, which must be dealt with individually.
(For instance, the above suggestion won't deal with functions which
take multiple arguments, and functions which automatically thread over
lists are even more difficult.)

Any ideas? Is there an alternate (possibly less/more elegant)
solution?

Cheers,
Andy


  • Prev by Date: Re: intersecting surfaces
  • Next by Date: Re: Normality test
  • Previous by thread: Re: Sort of nested NIntegrate
  • Next by thread: Re: Extra Data and Data structures