Re: Extra Data and Data structures

• To: mathgroup at smc.vnet.net
• Subject: [mg107235] Re: [mg107203] Extra Data and Data structures
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Sat, 6 Feb 2010 03:24:37 -0500 (EST)

```Clear[f, extraData]

f = extraData[{1, 2, 3, 4}, "cool"];

x*f

x*f == f*x

True

f/x

"cool"]

f/x == (1/x) f

True

x + f

x + f == f + x

True

x - f

x - f == -f + x

True

getExtra[f]

cool

g = 3*f

getExtra[g]

cool

Bob Hanlon

---- Uayeb <uayebswinburne at gmail.com> wrote:

=============
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
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:

3*f
{3,6,9,12}

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

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: Weird vanishing syntax coloring
• Next by Date: Re: Re: Combining InterpolatingFunctions
• Previous by thread: Extra Data and Data structures
• Next by thread: Re: Extra Data and Data structures