On Tue, May 29, 2007 at 02:21:37PM -0400, Mark J. Reed wrote:
: My expectation before reading the delta was that negative counts
: would do a reversal:
:
: "123" x -1 = "321"
:
: ('a', 'b', 'c') xx -3 = ('c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a');
:
: I don't know why I think that makes sense, but it was honestly my
: first thought. Does it make sense to anyone else? Is there a
: compelling reason I'm missing for having negative values behave as if
: they were zero rather than adding some other potentially useful
: functionality?
The main rationale for going with null return is that the biggest use of
replication has generally been something like:
say $foo, ' ' x (20 - $foo.width), $bar
and it would be counterproductive to degrade to "negative" spaces in
such a case. (This is also the rationale for not returning failure
on negative counts.)
Note, however, that these are just multimethods, so if you defined a
variant that accepted a count of type "Int where *..-1, it would come
earlier in the candidate list than the normal count of type "Int".
So you could give it different semantics if you like.
Arguably, in Perl 6 people might instead write
say $foo.fmt("%20s"), $bar
but just because people can write it that way doesn't mean they will.
(Plus that approach doesn't work if you want to count tabs.)
And generally, I think
@list xx -1
is less readable than
@list.reverse
so I don't feel inclined to include it as another Way To Do It.
Larry