Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Monday December 18, 2006
06:50 PM

Perl 6 "is copy"

[ #31958 ]

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, <a b c d e f g h>).perl.say;
rotate(-2, <a b c d e f g h>).perl.say;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • Man, that "is copy" is really annoying. Maybe it just takes some getting used to, but this strikes me as a default that's set wrong. Btw, why does everyone seem to enjoy writing everything backward-style in Perl 6? It seems like most of the code samples I see are of the form: @foo.rotate($x).perl.say Is there, within every Perl programmer, a Ruby/Smalltalk lover waiting to get out?
    • Why is it backwards?

      • 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.
      • 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

        • 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.)

          • 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 ... :)