Changeset 11830 for docs/Perl6/FAQ

Show
Ignore:
Timestamp:
07/31/06 05:59:09 (2 years ago)
Author:
audreyt
Message:

* Perl6::FAQ::Capture - remove prefix * and change it to prefix [,]

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/Perl6/FAQ/Capture.pod

    r10983 r11830  
    5353 
    5454  # passing the opaque Capture as actual function arguments   
    55   my $car = make_car(*$car_cap); 
     55  my $car = make_car([,]=$car_cap); 
    5656 
    5757  # extracting a specific positional argument 
     
    161161argument overrides the previous ones. 
    162162 
    163 =head3 What do *$x, *@x and *%x mean? 
    164  
    165 The prefix C<*> method casts an object into a Capture object, and merges 
    166 it into the Capture currently being constructed (e.g. an argument list): 
     163=head3 What do [,]$x, [,]@x and [,]%x mean? 
     164 
     165The prefix C<[,]> operator casts objects into Captures, and merges them 
     166t into the Capture currently being constructed (e.g. an argument list): 
    167167 
    168168    my $cap = \(1, 2, x=>42); 
    169     f(*$cap);   # f(1, 2, x=>42) 
     169    f([,] =$cap);   # f(1, 2, x=>42) 
    170170 
    171171Array, List, Hash and Pair objects cast into Capture objects in obvious 
    172172ways: 
    173173 
    174     my $a = [1, 2];     f(*$a);     # f(1, 2) 
    175     my $l = (1, 2);     f(*$l);     # f(1, 2) 
    176     my $h = {x => 42};  f(*$h);     # f(x => 42) 
    177     my $p = (x => 42);  f(*$p);     # f(x => 42) 
    178  
    179 It also works with the C<@> and C<%> sigils: 
    180  
    181     my @a = (1, 2);     f(*@a);     # f(1, 2) 
    182     my @a := [1, 2];    f(*@a);     # f(1, 2) 
    183     my %h = (x => 42);  f(*%a);     # f(x => 42) 
    184     my %h := {x => 42}; f(*%h);     # f(x => 42) 
     174    my $a = [1, 2];     f([,] @$a);     # f(1, 2) 
     175    my $l = (1, 2);     f([,] @$l);     # f(1, 2) 
     176    my $h = {x => 42};  f([,] %$h);     # f(x => 42) 
     177    my $p = (x => 42);  f([,] %$p);     # f(x => 42) 
     178 
     179It also works with C<@> and C<%> variables: 
     180 
     181    my @a = (1, 2);     f([,] @a);     # f(1, 2) 
     182    my @a := [1, 2];    f([,] @a);     # f(1, 2) 
     183    my %h = (x => 42);  f([,] %a);     # f(x => 42) 
     184    my %h := {x => 42}; f([,] %h);     # f(x => 42) 
    185185 
    186186 
     
    236236Yes, using the C<\$> signature: 
    237237 
    238     sub f (\$args) { g(*$args) } 
     238    sub f (\$args) { g([,] =$args) } 
    239239    f(1, 2, x => 42);   # same as g(1, 2, x => 42) 
    240240 
     
    248248 
    249249  method front_meth { 
    250     $!real_obj.back_meth( *@_, *%_ ); 
     250    $!real_obj.back_meth( [,] @_, %_ ); 
    251251  } 
    252252 
     
    255255 
    256256  method front_meth (\$args) { 
    257     $!real_obj_A.back_meth( *$args ); 
     257    $!real_obj_A.back_meth( [,] =$args ); 
    258258  } 
    259259 
     
    349349In the context of rules, Captures are superclasses of Match. So in the example of: 
    350350     
    351     my $rv = ("x-y-z-moose" ~~ /(.)-(.)-(.)-<animal> :{ return give_birth(*$/) }) 
     351    my $rv = ("x-y-z-moose" ~~ /(.)-(.)-(.)-<animal> :{ return give_birth([,] =$/) }) 
    352352 
    353353C<give_birth()> gets called with 'x', 'y', and 'z' as positional arguments,