Author: audreyt Date: Thu Aug 10 09:40:48 2006 New Revision: 10783 Modified: doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S06.pod
Log: * S03: Signature ~~ Signature now tests for compatibility, i.e. whether if anything that can bind to LHS can also bind to RHS. * S06: The "want" function now returns a Signature object, instead of a "Context" object with vaguely defined pseudo-class methods. This also unifies the calling convention with the returning convention. Modified: doc/trunk/design/syn/S03.pod ============================================================================== --- doc/trunk/design/syn/S03.pod (original) +++ doc/trunk/design/syn/S03.pod Thu Aug 10 09:40:48 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 9 Aug 2006 + Last Modified: 11 Aug 2006 Number: 3 - Version: 54 + Version: 55 =head1 Changes to Perl 5 operators @@ -562,7 +562,9 @@ Num NumRange in numeric range match if $min <= $_ <= $max Str StrRange in string range match if $min le $_ le $max Capture Signature parameter binding match if $cap can bind to $sig - Any Code:() simple closure truth* match if $x() (ignoring $_) + Code Signature signature compatibility* match if $_ is a subset of $x + Signature Signature signature compatibility match if $_ is a subset of $x + Any Code:() simple closure truth* match if $x() (ignoring $_) Any Class class membership match if $_.does($x) Any Role role playing match if $_.does($x) Any Num numeric equality match if $_ == $x Modified: doc/trunk/design/syn/S06.pod ============================================================================== --- doc/trunk/design/syn/S06.pod (original) +++ doc/trunk/design/syn/S06.pod Thu Aug 10 09:40:48 2006 @@ -1763,6 +1763,10 @@ Specifies that the parameter cannot be modified (e.g. assigned to, incremented). It is the default for parameters. +$x = 5; + +sub f ($x) {} + =item C<is rw> Specifies that the parameter can be modified (assigned to, incremented, @@ -1880,35 +1884,35 @@ =head2 The C<want> function -The C<want> function returns an object that contains information about -the context in which the current block, closure, or subroutine was +The C<want> function returns a C<Signature> object that contains information +about the context in which the current block, closure, or subroutine was called. -The returned context object is typically tested with a smart match (C<~~>) -or a C<when>: +As with normal function signatures, you can test the result of C<want> with a +smart match (C<~~>) or a C<when>: given want { - when Scalar {...} # called in scalar context - when List {...} # called in list context - when Lvalue {...} # expected to return an lvalue - when 2 {...} # expected to return two values + when :($) {...} # called in scalar context + when :(*@) {...} # called in list context + when :($ is rw) {...} # expected to return an lvalue + when :($,$) {...} # expected to return two values ... } -or has the corresponding methods called on it: +You can also use the postfix signature syntax to test for compatibility: + + if want:($) {...} # called in scalar context + elsif want:(*@) {...} # called in list context + elsif want:($ is rw) {...} # expected to return an lvalue + elsif want:($,$) {...} # expected to return two values + +The C<.arity> method also works here: - if (want.Scalar) {...} # called in scalar context - elsif (want.List) {...} # called in list context - elsif (want.rw) {...} # expected to return an lvalue - elsif (want.count > 2) {...} # expected to return more than two values - -Note these are pseudo type associations. There's no such thing as an -Lvalue object, and a List is really an unbound argument list object, -parts of which may in fact be eventually bound into scalar context. + if want.arity > 2 {...} # expected to return more than two values =head2 The C<leave> function -A C<return> statement causes the innermost surrounding subroutine, +A C<return> call causes the innermost surrounding subroutine, method, rule, token, regex (as a keyword), macro, or multimethod to return. Only declarations with an explicit keyword such as "sub" may be returned from. You may not return from a quotelike operator such