Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2008

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

Search the Archive

Matching HoldPattern explicitly

  • To: mathgroup at
  • Subject: [mg85779] Matching HoldPattern explicitly
  • From: Yaroslav Bulatov <yaroslavvb at>
  • Date: Fri, 22 Feb 2008 04:59:20 -0500 (EST)

I'm trying to use Mathematica symbols as dictionaries. In particular
if I have (kk[1, 2] = 3; kk[3, 4] = 4;), I'd like a function "keys"
that would accept kk, and return {{1,2},{3,4}}.

A recipie on
suggests to do

keys[dict_] := Map[#[[1]] /. {HoldPattern[dict[x_]] -> x} &,

However, this doesn't quite work (p:HoldPattern[x] doesn't match
"HoldPattern[x]"). Verbatim[HoldPattern[dict... doesn't work because I
need to do a substitution for local dict variable. So my question is

1. What's the best way to match HoldPattern explicitly, while allowing
for local variable substitutions inside "HoldPattern" pattern
2. What is the best way of implementing Python like dictionaries in

  • Prev by Date: Re: Extracting the value from Solve
  • Next by Date: Re: Extracting the value from Solve
  • Previous by thread: Re: NDSolve[] and Differential Equations: Problem solving two
  • Next by thread: Re: Matching HoldPattern explicitly