develooper Front page | perl.perl5.porters | Postings from January 2011

RE: Changing variable to numeric without assignment (was: Using smart matching)

Thread Previous | Thread Next
From:
Jan Dubois
Date:
January 27, 2011 15:59
Subject:
RE: Changing variable to numeric without assignment (was: Using smart matching)
Message ID:
044b01cbbe7e$38af7250$aa0e56f0$@activestate.com
On Thu, 27 Jan 2011, Ed Avis wrote:
> 
> No, not at all.  I don't suggest any change to the existing semantics of +,
> except that it should become side-effect-free, that is, whether you evaluate
> ($b + 0) or do not evaluate that expression should have no effect on later uses
> of $b.  (Provided $b is just a plain scalar and not tied or an object, etc.)

I would agree with this (caching converted representations should not
be detectable at the language level).  Unfortunately some operations
are *documented* to behave otherwise:

|       The auto-increment operator has a little extra builtin magic to
|       it. If you increment a variable that is numeric, or that has
|       ever been used in a numeric context, you get a normal increment.
|       If, however, the variable has been used in only string contexts
|       since it was set, and has a value that is not the empty string
|       and matches the pattern "/^[a-zA-Z]*[0-9]*\z/", the increment is
|       done as a string, preserving each character within its range,
|       with carry:

(From perlop.pod; note the phrase "used in a numeric context")

Personally I consider these design mistakes, but I also don't think we
can undo them anymore either.  Just some of the warts we have to live
with.

Cheers,
-Jan


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About