Changeset 13610 for docs/Perl6/FAQ

Show
Ignore:
Timestamp:
09/25/06 13:04:55 (2 years ago)
Author:
audreyt
Message:

* Perl6::FAQ::Capture: Use |$x not [,]=$x.

Files:
1 modified

Legend:

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

    r11830 r13610  
    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<[,]> operator casts objects into Captures, and merges them 
     163=head3 What do |$x, |@x and |%x mean? 
     164 
     165The prefix C<|> operator casts objects into Captures, and merges them 
    166166t 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) 
     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) 
    178178 
    179179It also works with C<@> and C<%> variables: 
    180180 
    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) 
     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,