MathGroup Archive 1998

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

Search the Archive

Re: keys in a hash table (aka, all assigned indices in an array): awf


Daniel,

An equivalent approach:

fruits[apple] = crunchy;
fruits[lemon] = sour;

keys[hash_Symbol] := 
	#[[1, 1, 1]]& /@ DownValues[hash];

keys[fruits]

{apple,lemon}

fruits/@keys[fruits]

{crunchy,sour}

Bob Hanlon

In a message dated 7/17/98 9:18:42 AM, dreeves at flip.eecs.umich.edu
wrote:

>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]


  • Prev by Date: Fit
  • Next by Date: Q: Graphics3D
  • Previous by thread: Re: Fit
  • Next by thread: Q: Graphics3D