1
$\begingroup$

In the context of this question I tried setting up an interpreter that converts a string to a list of numbers, while converting "NA" to Indeterminate. My attempted solution works in general, but fails on the first iteration:

Exit[]   (* make sure to start with a fresh kernel *)

$Version
(*    "13.2.0 for Mac OS X ARM (64-bit) (November 18, 2022)"    *)

int = Interpreter[DelimitedSequence["Number" | {"NA" -> Indeterminate}, {"{", ",", "}"}]];

s = "{NA,NA,NA,2.05E-08,2.07E-06,3.45E-09,7.52E-07,NA,NA}";

int[s]
(*    Interpreter[DelimitedSequence["Number" | {"NA" -> Indeterminate}, {"{", ",", "}"}]][
          "{NA,NA,NA,2.05E-08,2.07E-06,3.45E-09,7.52E-07,NA,NA}"]    *)

int[s]
(*    {Indeterminate, Indeterminate, Indeterminate, 2.05*10^-8, 
       2.07*10^-6, 3.45*10^-9, 7.52*10^-7, Indeterminate, Indeterminate}    *)

int[s]
(*    {Indeterminate, Indeterminate, Indeterminate, 2.05*10^-8,
       2.07*10^-6, 3.45*10^-9, 7.52*10^-7, Indeterminate, Indeterminate}    *)

Is this a bug? Why else would an Interpreter fail on first use, then work fine for all subsequent uses?

update: a minimal example

Thanks to @BenIzd!

Exit[]   (*make sure to start with a fresh kernel*)

Interpreter["Number" | {"NA"}]["1"]
(*    Interpreter["Number" | {"NA"}]["1"]    *)

Interpreter["Number" | {"NA"}]["1"]
(*    1    *)
$\endgroup$
5
  • $\begingroup$ Works on the first and subsequent uses. I am running v12.2.0 on Win7-x64 . $\endgroup$
    – Syed
    May 4, 2023 at 7:43
  • $\begingroup$ Same for me; works the first and all subsequent uses (12.3.1 Win and 13.0.0 Win and 13.2.0. Wolfram Cloud). $\endgroup$
    – Domen
    May 4, 2023 at 8:02
  • $\begingroup$ Same for me. 13.2 on Windows 10 $\endgroup$ May 4, 2023 at 8:20
  • 1
    $\begingroup$ On my setup Windows 11, Mathematica 13.2.1, If I put int = ...; int["1"] in one cell it returns unevaluated but if they were separate it works fine. I think a better example would be the following Interpreter["Number" | {"NA"}]["1"] which returns unevaluated for the first time (fresh kernel) but works as expected on subsequent calls. $\endgroup$
    – Ben Izd
    May 5, 2023 at 8:33
  • $\begingroup$ Thanks @BenIzd, I've updated the minimal example. $\endgroup$
    – Roman
    May 5, 2023 at 11:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.