develooper Front page | perl.perl6.language | Postings from July 2005

Slurpy "is rw" arrays (*@args is rw)

Thread Next
From:
Ingo Blechschmidt
Date:
July 29, 2005 03:22
Subject:
Slurpy "is rw" arrays (*@args is rw)
Message ID:
dccvvt$gei$1@sea.gmane.org
Hi,

are the following assumptions correct?

    sub foo (*@args)       { push @args, 42 }
    sub bar (*@args is rw) { push @args, 42 }

    foo @some_array;   # dies ("Can't modify constant array...")

    bar @some_array;
    # works, but does not change @some_array, as the * causes &bar to
    # receive a *new* array (which happens to contain @some_array's
    # elements), right?
    # @args is only an array constructed by the parameter binding code;
    # @args =:= @some_array is false (consider bar(@some_array, 42)).

    bar 1,2,3;         # works too

Or is @args always readonly and the declaration (*@args is rw) is an
error?


--Ingo

-- 
Linux, the choice of a GNU | Perfection is reached, not when there is no
generation on a dual AMD   | longer anything to add, but when there is
Athlon!                    | no longer anything to take away.


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