Changeset 9966 for docs/Perl6/FAQ

Show
Ignore:
Timestamp:
04/16/06 19:10:47 (3 years ago)
Author:
audreyt
Message:

* Capture.pod: postulate that

$arg = \($inv: $pos);
$obj.meth(*$arg)

means

$obj.meth($pos)

instead of an error.

Files:
1 modified

Legend:

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

    r9965 r9966  
    240240=head3 What about delegating a method? 
    241241 
    242 [hw; there's probably a golfier way] 
    243 Perl has a few other provisions for this (e.g., WRAP), but if you want 
    244 more control over invocation, you need to pass through the Capture but 
    245 replace the invocant: 
    246  
    247   method front_meth (\$args) { $:real_obj.back_meth( ??? ) } 
    248  
    249   # [ does $obj.meth($args) ignore a prebound invocant? ] 
     242Perl 6 has a few other provisions for this (e.g., .wrap), but if you want 
     243more control over invocation, you can take advantage of the default Signature 
     244for methods, which puts all positionals in C<@_> and named arguments in C<%_>: 
     245 
     246  method front_meth { 
     247    $!real_obj.back_meth( *@_, *%_ ); 
     248  } 
     249 
     250You can also take the argument list as a Capture object, and merge it with 
     251another method invocation: 
     252 
     253  method front_meth (\$args) { 
     254    $!real_obj_A.back_meth( *$args ); 
     255  } 
     256 
     257This works because when there is already an invocant present, further 
     258invocants in the constructing argument list will be ignored. 
    250259 
    251260=head3 How is @x = (1, 2, 3) different from @y := (1, 2, 3) ?