MathGroup Archive 2006

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

Search the Archive

Is it possible for me to implement associative arrays this way?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg66178] Is it possible for me to implement associative arrays this way?
  • From: Don Taylor <dont at agora.rdrop.com>
  • Date: Wed, 3 May 2006 02:44:49 -0400 (EDT)
  • Reply-to: dont at agora.rdrop.com
  • Sender: owner-wri-mathgroup at wolfram.com

I've tried searching the net to see if I could find an answer before
I bothered folks with this.

I wrote a little bit of code to help someone out.  It would have
been very convenient and clear if I could have used short lists as
subscripts, something similar to AWK's associative arrays, not what
Mathematica usually does with lists as subscripts.

With experimenting I think I see how Mathematica uses
   {1, 2, 3, 4, 5, 6}[[2]];
   {1, 2, 3, 4, 5, 6}[[{2,3,4}]];
   x={1, 2, 3, 4, 5, 6};
   x[[2]];
   x[[2]]=4;
   x[[{2, 3, 4}]] = 5
   x[[{2, 3, 4}]] = {5, 4, 3}
and even a bit oddly
   x[[{2, 3, 4}]] = {5, 4, 3, 2, 1}
But the the syntax
   {1, 2, 3, 4, 5, 6}[[{{2,3,4}}]]
is not currently used by Mathematica.  In other words when a Part
specification is not an integer or list of integers this isn't used.

So, is there some way I could unprotect some bit of Mathematica,
insert a tiny bit of code such that if a Part specification was a
list of a list that it would create a table to implement the
associative array, and then reprotect Mathematica, for use both on
the left and right side of '='?

This would be really convenient and not seem to subvert the
principles too much that Mathematica tries to use.

Thank you


  • Prev by Date: Re: Function of function analytic definition
  • Next by Date: Re: Periodic Rebirth of Hyperbolic Functions by ODE in Mathematica
  • Previous by thread: Re: How to find expected value?
  • Next by thread: Re: Is it possible for me to implement associative arrays this way?