$SELECT() stops evaluating tvexprs or exprs after the first true tvexpr is found
Final Release Note
$SELECT stops evaluating tvexprs or exprs once a true tvexpr is encountered even if evaluating later tvexprs or exprs would result in a NUMOFLOW or INVDLRCVAL errors. Previously a NUMOFLOW or INVDLRCVAL runtime error would be incorrectly issued (e.g., if $select(1:1,1:1E47)
). [#371 (closed)]
Description
According to the M standard at (courtesy http://71.174.62.16/Demo/AnnoStd), $select() should stop evaluation once a tvexpr that is true is found.
$S[ELECT]( L | tvexpr : expr | )
returns the value of the leftmost expr whose corresponding tvexpr is true. The process of evaluation consists of evaluating the tvexprs, one at a time in left-to-right order, until the first one is found whose value is true. The expr corresponding to this tvexpr (and no other) is evaluated and this value is made the value of $S. An error will occur if all tvexprs are false. Since only one expr is evaluated at any invocation of $S, that is the only expr which must have a defined value.
But below example proves otherwise.
> cat test.m
if $select(1:1,1:1E47) write "Hello "
write "World",!
> mumps test.m
if $select(1:1,1:1E47) write "Hello "
^-----
At column 18, line 1, source module test.m
%YDB-E-NUMOFLOW, Numeric overflow
It is okay to issue a NUMOFLOW error during compilation like above. But it is not okay to issue a run-time NUMOFLOW error like below. This is because the moment the 1:1 is evaluated, evaluating the remaining (i.e. 1:1E47) should not happen. But the NUMOFLOW error is issued because that is incorrectly evaluated even at runtime.
> mumps -run test
%YDB-E-NUMOFLOW, Numeric overflow
At M source location +1^test
Draft Release Note
$SELECT stops evaluating tvexprs or exprs once a true tvexpr is seen even in case later tvexprs or exprs contain a NUMOFLOW or INVDLRCVAL error. This conforms to the M standard. Previously a NUMOFLOW or INVDLRCVAL runtime error would be incorrectly issued (example M code "if $select(1:1,1:1E47)" OR "if select(1:1,1:
char(65535)" when in UTF-8 mode).