develooper Front page | perl.perl5.porters | Postings from July 2016

Unexpected acceptance of multiple alternating signs: Bug?

Thread Next
Glenn Golden
July 20, 2016 14:51
Unexpected acceptance of multiple alternating signs: Bug?
Message ID:
Not sure the following is really a bug, maybe just a well-known grammar
ambiguity that isn't worth diagnosing, but if it is considered a bug,
let me know, I'll file a ticket.

At compile time, perl 5.24.0 evidently accepts numeric values with arbitrary
pairs of alternating signs:

        $x = -+42;              # Value = -42
        $x = +-42;              # Value = -42
        $x = +-+-42;            # Value = +42

Although the above interpretations kinda-sorta make sense mathematically
(if you assume implicit parenthesis in the right place) it's nevertheless
somewhat unexpected (at least to me) that they are accepted as numeric values
without complaint, given that they are not accepted as valid numbers
by strtod() or by Scalar::Util::looks_like_number().

The above does not appear occur for runtime evaluation, only at compile-time:
At runtime, expressions like the above seem to be interpreted as non-numeric

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About