Changeset 9976 for docs/Perl6/FAQ
- Timestamp:
- 04/17/06 07:28:36 (3 years ago)
- Files:
-
- 1 modified
-
docs/Perl6/FAQ/Capture.pod (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/Perl6/FAQ/Capture.pod
r9966 r9976 120 120 121 121 However, regardless of single- or multi- dispatch, the argument list (Capture) 122 can never have more than one invocant s. Typically, the presence of an invocant122 can never have more than one invocant. Typically, the presence of an invocant 123 123 indicates a method-call (which may fall back to a subroutine-call); the lack of 124 124 invocant means a subroutine-call. 125 125 126 1.foo(2); # Int.foo with 1 as "self"; if not found, fallback to foo(1, 2) 126 1.foo(2); # Int.foo with 1 as "self"; if not 127 # found, fallback to foo(1, 2) 127 128 foo(1: 2); # same as above 128 129 129 bar(1, 2); # never looks at Int.foo; calls &foo in lexical/package scope 130 bar(1, 2); # never looks at Int.bar; calls &bar 131 # in lexical/package scope 130 132 131 133 Method/subroutine calls are determined by the presence of an invocant at the … … 266 268 267 269 sub foo (@y is rw) { ... } 268 foo(1, 2, 3); # error: three arguments passed where one is expected270 foo(1, 2, 3); # FAIL: three arguments passed where one is expected 269 271 270 272 However, these forms are valid: … … 282 284 modify the container itself, so this won't work: 283 285 284 @y.push(4); # error: cannot find method: List.push286 @y.push(4); # FAIL: cannot find method: List.push 285 287 286 288 On the other hand, because variables are initialized by their sigils, … … 300 302 Array container bound to C<@y>: 301 303 302 $x.push(0); # error: cannot find method: List.push304 $x.push(0); # FAIL: cannot find method: List.push 303 305 @y.push(0); # works just fine 304 306 … … 327 329 However, they differ when you try to assign something into them: 328 330 329 $x = 42; # fails- Array doesn't handle scalar assignment331 $x = 42; # FAIL - Array doesn't handle scalar assignment 330 332 @y = 42; # works - @y.elems is now 1 331 333 … … 340 342 341 343 $x := 41; 342 $x = 42; # fails- Int doesn't handle scalar assignment either344 $x = 42; # FAIL - Int doesn't handle scalar assignment either 343 345 344 346 =head2 Why
