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

Parameter and trait questions - just how 'only' _is_ 'read-only'?

Thread Next
Chip Salzenberg
March 26, 2005 01:47
Parameter and trait questions - just how 'only' _is_ 'read-only'?
Message ID:
I'm working on enhancing Perl6::Subs[*] to support more parameter
traits than just C<is required>.  I have some questions about
parameters and traits.  (These questions all apply to pure Perl 6,
which I know I won't be able to translate completely, but I want to
know which target I'm missing.)

 * Given a parameter C<Array @a>, it's obvious I'm not allowed to
   C<push @a,1>, because I didn't say C<is rw>.  But am I allowed to
   C<@a[0]++>?  How about C<@a[0][0]++>?  How deep is read-only-ness?

 * Similarly, how deep is the copy implied by C<is copy>?

 * Do traits attach syntactically to the variable name, or to the
   declaration as a whole?

     variable:     @a is rw of Array
                   Array @a is rw

     declaration:  @a of Array is rw
                   Array @a is rw

 * As far as I can tell, the choice of spelling an array parameter
   C<Array @a> or C<Array $a> is entirely cosmetic: both @a and
   $a are capable of holding an Array reference.  Is there actually
   a difference, e.g. in how they handle an undefined value?

[*] Shameless Plug:  Perl6::Subs is a source filter that lets you use
    much of the Perl 6 parameter syntax in your Perl 5 programs; and
    it enforces many constraints for you.  You can even add your own
    constraints with C<where BLOCK> subtyping.  Amaze your enemies!
    Confound your friends!  Use Perl6::Subs today!

Chip Salzenberg            - a.k.a. -            <>
         Open Source is not an excuse to write fun code
            then leave the actual work to others.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About