On Wed, Apr 23, 2008 at 04:03:01PM +0100, Smylers wrote:
: The algorithm for increment and decrement on strings sounds really good,
: however I'm concerned that dealing with all that has made the common
: case of integer decrement a little less intuitive where the integer
: happens to be stored in a string, for example in this case:
: 
:    perl -wle '$a = 10; $b = shift; $a--; $b--; print "$a $b"' 10
: 
: Perl 5 prints "9 9", but Perl 6 will print "9 09".

On the other hand, "09" has the advantage of still having the numeric
value 9.  But the converse is not true if the user was expecting a
string decrement, since decrementing "10" in Perl 5 to get 9 is also
counterintuitive if you were expecting "09".  So Perl 5 just punts,
which is the third option.  In any case, there's always something
to explain to a beginner.  But I think in Perl 6 we're leaning more
toward preserving information than Perl 5 did.

: I'm wondering if something similar should apply to C<-->; that string
: and numeric decrement are different, so should have different operators.

Well, you have to strike a balance somewhere.  On the one hand,
as you have pointed out, the exact semantics of "predecessor" are
slightly ambiguous in some cases, and type unions only sweep
the problem under the rug of multiple dispatch, and you still have
to teach the newbies.

On the other hand, there are already arguably enough non-meta operators
in standard Perl 6, and we shouldn't be looking for excuses to make
new ones for operations that will seldom make a difference in practice.

And Perl 6 thinks the difference between "09" and 9 is 0...  :)

Topping all that is that the "09" behavior can be lazily explained
after the fact, while a new operator would have to be explained
beforehand.

Larry

Reply via email to