Author: larry Date: Sun Aug 27 22:52:36 2006 New Revision: 11504 Modified: doc/trunk/design/syn/S02.pod
Log: Clarification on syntactic mapping of <a b> and <c> to ('a','b') and ('c'). Modified: doc/trunk/design/syn/S02.pod ============================================================================== --- doc/trunk/design/syn/S02.pod (original) +++ doc/trunk/design/syn/S02.pod Sun Aug 27 22:52:36 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 15 Aug 2006 + Last Modified: 27 Aug 2006 Number: 2 - Version: 65 + Version: 66 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1394,6 +1394,43 @@ The C<qw/foo bar/> quote operator now has a bracketed form: C<< <foo bar> >>. When used as a subscript it performs a slice equivalent to C<{'foo','bar'}>. +Elsewhere it is equivalent to a parenthesisized list of strings: +C<< ('foo','bar') >>. Since parentheses are generally reserved just for +precedence grouping, they merely autointepolate in list context. Therefore + + @a = 1, < 2 3 >, 4; + +is equivalent to + + @a = 1, 2, 3, 4; + +In scalar context, though, the implied parentheses are not removed, so + + $a = < a b >; + +is equivalent to: + + $a = ('a','b'); + +which, because the list is in scalar context, is autopromoted an Array object: + + $a = ['a','b']; + +Likewise, if bound to a scalar parameter, C<< <a b> >> will be +treated as a single list object, but if bound to a slurpy parameter, +it will auto-flatten. + +But note that under the parenthesis-rewrite rule, a single value will +still act like a scalar value. These are all the same: + + $a = < a >; + $a = ('a'); + $a = 'a'; + +And if bound to a scalar parameter, no list is constructed. +To force a single value to become a list object in scalar context, +you should use C<< ['a'] >> for clarity as well as correctness. + Much like the relationship between single quotes and double quotes, single angles do not interpolate while double angles do. The double angles may be written either with French quotes, C<«$foo @bar[]»>, or