With my work on "99 Problems", I find that "is copy" is getting annoying to type over and over again. Many of the problems are much simpler with "is copy", so the question is, "when is 'is copy' not necessary"? In fact, I'd like a shortcut for it, but Larry says (on #perl6) that slurpy *@some_array might default to "is copy" in the future. That would be at least a small win for stuff like this:
# P19 (**) Rotate a list N places to the left. # Examples: # * (rotate '(a b c d e f g h) 3) # (D E F G H A B C) # * (rotate '(a b c d e f g h) -2) # (G H A B C D E F) sub rotate (int $times is copy, *@list is copy) returns Array { if $times < 0 { $times += @list.elems; } @list.push: @list.shift for 1 .. $times; return @list; } rotate(3, ).perl.say; rotate(-2, ).perl.say;
@foo.rotate($x).perl.say
Is there, within every Perl programmer, a Ruby/Smalltalk lover waiting to get out?
Re:Why?
chromatic on 2006-12-19T03:11:45
Why is it backwards?
Re:Why?
educated_foo on 2006-12-19T03:35:29
Well, I usually say "Cheney yourself" rather than "self Cheney";). More seriously, it encourages single dispatch by privileging the first argument, while I believe multiple dispatch is a better way to program. Re:Why?
Aristotle on 2006-12-20T15:20:25
In Perl 5, people almost always do either this:
sub foo {
my $param = shift;
#...
}or this:
sub foo {
my ( $param ) = @_;
#...
}In both cases, you work on a copy. Almost never do people work directly with the values in
@_
. And that works out very well, because you almost never want to pass parameters by reference, almost always by value.But the Perl 6 setup defaults to giving you named aliases (as opposed to the array of aliases you get with Perl 5), which you’re then expected to work on directly. If you want Perl 5 style effective behaviour, it’s actually easier to write it exactly the same way as in Perl 5, ie.
my ( $foo, $bar, $baz ) = @_;
, than to do it the Perl 6 way by parrottingis copy
after each parameter:( $foo is copy, $bar is copy, $baz is copy )
.So the default is definitely wrong.
Re:Why?
chromatic on 2006-12-20T19:42:01
I actually meant "Why do you say that chained method calls are backwards?" I try to stay out of the perpetual pass by value/pass by reference wars. (I need some sort of self-discipline somewhere.)
Re:Why?
Ovid on 2006-12-20T20:13:36
While I knew what you were referring to, I do agree with Aristotle. In trying to work out the "99 Problems", I'm finding "is copy" is getting very annoying. I would be nice to have a simple syntax which would allow this, when it's appropriate.
Now if only I knew someone on the Perl 6 design team to explain that too
... :)