In Mathematica 9, I used to be able to do

rules = Dispatch[{'a' -> 1, 'b' -> 2}]

to extract the rules from Dispatchwrapped list of rules. In Mathematica 10 the following error is raised:

Part::partd: Part specification Dispatch[...][[1]] is longer than depth of object. >>

Is this a bug? I am using only the trial version currently. I got aware of it because it breaks the AutomaticUnits package.


No, this is not a bug. Dispatch tables are now atomic:

Dispatch[{"a" -> 1, "b" -> 2, "c" -> 3}] // AtomQ

As noted by user 18w here we can use Normal to recover the rules.

Dispatch[{"a" -> 1, "b" -> 2, "c" -> 3}] // Normal
{"a" -> 1, "b" -> 2, "c" -> 3}
  • 1
    $\begingroup$ And (they became atoms) for good reason, Dispatch tables with symbols in them were hard to use properly. See Performance of Dispatch and lists of Rules. Maybe I should see if I can simplify my answer to your "Why is there no PositionFunction in Mathematica?" Q&A. There was another issue with performance I think. $\endgroup$ – Jacob Akkerboom Jul 14 '14 at 13:37
  • 2
    $\begingroup$ Sweet, Dispatch now works with Verbatim! The example in my answer (below "This may be because Dispatch just does not work well with Verbatim. Example:") now works! $\endgroup$ – Jacob Akkerboom Jul 14 '14 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.