Interpreter fails on Association with mixed type Values:

<|"a" -> 1, "b" -> "99%"|> // Map[Interpreter["Number" | "Percent"]]

MapThread::mptd: "Object !(InterpreterPackageScopeparserSemantic[...

(long list of warnings)

<|"a" -> Replace[
     Interpreter`DependentTypes`PackagePrivate`a_] :> 
    Interpreter`DependentTypes`PackagePrivate`a, {0, \[Infinity]}], 
 "b" -> Quantity[99, "Percent"]|>

man pages say Alternative forms are tried in sequence. Without that sequence, of course the percent will not be parsed, but the 1 is.

<|"a" -> 1, "b" -> "99%"|> // Map[Interpreter["Number"]]

<|"a" -> 1, "b" ->Failure[...enter a valid number...]] |>

  • 2
    $\begingroup$ Is there a question here? If you want a place to simply post issues you encounter, I suspect that Wolfram's Community site would be the more appropriate place. $\endgroup$ – chuy Jun 8 '15 at 20:25
  • 1
    $\begingroup$ @chuy, Prepend["Why does "] $\endgroup$ – alancalvitti Jun 8 '15 at 21:48

This has nothing to do with Association.

{1, "99%"} // Map[Interpreter["Number" | "Percent"]] 

fails as well.

Originally, I thought the answer could be found (more or less) in the documentation where the first line of the Details and Option section says:

Interpreter[...][input] applies the interpreter to a particular input, which is typically a string.

That "typically a string" suggests that the input might be something different than a string, but I don't believe that there is one example among the multitude of examples that is is using anything other than a string. And indeed, if you change your 1 to a "1" your problem goes away:

<|"a" -> "1", "b" -> "99%"|> //Map[Interpreter["Number" | "Percent"]]
(* <|"a" -> 1, "b" -> Quantity[99, "Percent"]|> *)

So, documentation error? Well, no. This is not the end of the story, as both

(* 1 *)


(* Quantity[1, "Percent"] *)

do work without error messages. So, non-string input is altogether possible.

It is the combination with Alternatives that doesn't work.

Interpreter["Number" | "Percent"][1]

gives the voluminous set of error messages again, with the string version working OK:

Interpreter["Number" | "Percent"]["1"]
(* 1 *)

For now, I'd call it a bug. A workaround would be to apply ToString where necessary.

  • $\begingroup$ As you say, Alternatives within Interpreter indeed seems to be the root cause. Note that <|"a" -> 1, "b" -> "99%"|> // Map[Interpreter["SemanticExpression"]] works just fine to return: <|"a" -> 1, "b" -> Quantity[99, "Percent"]|>. (+1) $\endgroup$ – MarcoB Jun 8 '15 at 21:32

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.