MathGroup Archive 1998

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

Search the Archive

keys in a hash table (aka, all assigned indices in an array): awful hack


suppose I make some assignments like this:
  fruits[apple]= crunchy
  fruits[lemon]= sour

I'm treating fruits like a hash table and now I would like a list of all
the keys.  In this case {apple,lemon}.

It seems like there should be an easy way to do this. All I came up with
was the following hack:

keys[hash_]:= 
  DownValues[hash] /. {RuleDelayed->(#&), hash->(#&)} //ReleaseHold


the hash values will be simple; we can just do fruits/@keys[fruits]

Thanks,
Daniel

--
Daniel Reeves  dreeves at umich.edu  http://interlabs.bradley.edu/~daniel

"Computer Science is no more about computers than astronomy is about
telescopes."  -- E W Dijkstra



  • Prev by Date: differences between math and mathematica
  • Next by Date: Re: 3DGraphics color problem
  • Previous by thread: Re: differences between math and mathematica
  • Next by thread: Re: keys in a hash table (aka, all assigned indices in an array): awful hack