[svn:perl6-synopsis] r14413 - doc/trunk/design/syn
Author: larry Date: Sat Jun 2 12:42:11 2007 New Revision: 14413 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S04.pod doc/trunk/design/syn/S06.pod doc/trunk/design/syn/S09.pod doc/trunk/design/syn/S13.pod Log: Dropped : from all listop contextualizers, whether sigil and typename. The @@ contextualizer is now also named "slice". Consistent with that, we have regularized slice nomenclature: * A "slice" now always refers to the whole multidimensional subscript, or the list of lists corresponding to that. * We now try to avoid calling the individual sublists "slices". * The parameter to a subscript is *@@slice, not *@@slices. * The term "multislice" is now deemed redundant. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podSat Jun 2 12:42:11 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 29 May 2007 + Last Modified: 2 Jun 2007 Number: 2 - Version: 108 + Version: 109 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -446,8 +446,11 @@ $spot.defined; # False say $spot; # "Dog" -Any class name used as a value by itself is an undefined instance of that -class's prototype. See S12 for more on that. +Any class name used as a value by itself is an undefined instance of +that class's prototype, or I. See S12 for more on that. +(Any type name in rvalue context is parsed as a list operator +indicating a typecast, but an argumentless one of these degenerates +to a typecast of undef, producing the protoobject.) To get a real C object, call a constructor method such as C: @@ -1059,7 +1062,7 @@ % unordered hash (associative array) & code/rule/token/regex :: package/module/class/role/subset/enum/type/grammar -@@ multislice view of @ +@@ slice view of @ Within a declaration, the C<&> sigil also declares the visibility of the subroutine name without the sigil within the scope of the declaration: @@ -1324,9 +1327,9 @@ =item * -Slicing syntax is covered in S09. Multidimensional -slices will be done with semicolons between individual slice subscripts. -Each such slice is evaluated lazily. +Slicing syntax is covered in S09. A multidimensional +slice will be done with semicolons between individual slice sublists. +Each such slice sublist is evaluated lazily. =item * @@ -1422,9 +1425,17 @@ than a punctuational variable. This allows you to use sigils as coercion operators: -print $( foo() ) +print $( foo() )# foo called in item context +print @@( foo() ) # foo called in slice context -It also allows the use of bare sigils as placeholders for anonymous variables: +The bare sigil is parsed as a list operator in rvalue context, so +these mean the same thing: + +print $ foo() # foo called in item context +print @@ foo() # foo called in slice context + +In declarative contexts bare sigils may be used as placeholders for +anonymous variables: my ($a, $, $c) = 1..3; print unless (state $)++; Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSat Jun 2 12:42:11 2007 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 29 May 2007 + Last Modified: 2 Jun 2007 Number: 3 - Version: 115 + Version: 116 =head1 Overview @@ -729,16 +729,6 @@ Note that, unlike in Perl 5, you must use the C<.meth> forms to default to C<$_> in Perl 6. -=item * - -The C contextualizer - -item - -The new name for Perl 5's C contextualizer. Equivalent to C<$()>. -We still call the values scalars, and talk about "scalar operators", but -scalar operators are those that put their arguments into item context. - =back =head2 Nonchaining binary precedence @@ -1297,40 +1287,80 @@ Sigils as contextualizer listops -$: -@: -%: -&: -@@: +Sigil Alpha variant +- - +$ item +@ list +@@ slice +% hash As listops, these look like terms from the left, but raise their precedence on the right sufficiently to govern list infix operators: - $: 1,2 Z 3,4 # [[1,3],[2,4]] - @: 1,2 Z 3,4 # 1,3,2,4 -@@: 1,2 Z 3,4 # [1,3],[2,4] - %: 1,2 Z 3,4 # { 1 => 3, 2 => 4 } - - $: 1,2 X 3,4 # [[1,3],[1,4],[2,3],[2,4]] - @: 1,2 X 3,4 # 1,3,1,4,2,3,2,4 -@@: 1,2 X 3,4 # [1,3],[1,4],[2,3],[2,4] + $ 1,2 Z 3,4 # [\(1,3),\(2,4)] + @ 1,2 Z 3,4 # 1,3,2,4 +@@ 1,
[svn:perl6-synopsis] r14414 - doc/trunk/design/syn
Author: larry Date: Sat Jun 2 14:45:43 2007 New Revision: 14414 Modified: doc/trunk/design/syn/S03.pod Log: First installment of filling out descriptions of operator semantics. Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSat Jun 2 14:45:43 2007 @@ -97,21 +97,40 @@ =item * +Heredoc + +qq:to/END/ +Dear $recipient: +Thanks! +Sincerely, +$me +END + +=item * + Array composer [1,2,3] +Provides list context inside. + =item * Hash composer { a => 42 } +Inside must be a list of pairs, otherwise you must use C +or C<%()> instead. + =item * Closure -{...} +{ ... } + +When found where a statement is expected, executes immediately. Othewise +always defers evaluation of the inside scope. =item * @@ -119,6 +138,8 @@ \(@a,$b,%c) +An abstraction representing an argument list that doesn't yet know its context. + =item * Sigiled variables @@ -128,7 +149,7 @@ %z $^a $?FILE -@@multidim +@@slice &func &div:(Int, Int --> Int) @@ -247,6 +268,9 @@ $obj.::Class::meth $obj.Class::meth# same thing, assuming Class is predeclared +As in Perl 5, tells the dispatcher which class to start searching from, +not the exact method to call. + =item * Mutating method call @@ -286,7 +310,7 @@ Dotted postfix form of any other prefix operator -$x.'++' # prefix:<++>($x), fallback to postfix:<++> +$x.:<++> # prefix:<++>($x) =back @@ -396,79 +420,109 @@ prefix:, boolean context -? +?$x +Evaluates the expression as a boolean and returns C if expression +is true or C otherwise. See "true" below for a low-precedence alternative. =item * prefix:, boolean negation -! +!$x +Returns the opposite of what C would. See "not" below for a low-precedence alternative. =item * prefix:<+>, numeric context -+ ++$x + +Unlike in Perl 5, where C<+> is a no-op, this operator coerces +to numeric context in Perl 6. (It coerces only the value, not the +original variable.) The narrowest appropriate type of C, C, +or C will be returned. A string containing two integers +separated by a C will be returned as a C. Exponential notation +and radix notations are recognized. =item * prefix:<->, numeric negation -- +-$x + +Coerces to numeric and returns the negation of the resulting number. =item * prefix:<~>, string context -~ +~$x + +Coerces the value to a string. (It only coerces the value, not the +original variable.) =item * prefix:<|>, flatten object into arglist -| +| $capture + +Interpolates the contents of the C (or C-like) value +into the current argument list as if they had been specified literally. =item * prefix:<+^>, numeric bitwise negation -+^ ++^$x + +Coerces to numeric and then does bitwise negation on the number. =item * prefix:<~^>, string bitwise negation -~^ +~^$x +Coerces to string buffer and then does bitwise negation on each element. =item * prefix:, boolean bitwise negation -?^ +?^$x + +Coerces to boolean and then flips the bit. (Same as C.) =item * prefix:<\>, Capture constructor -\ +\$x +[EMAIL PROTECTED] +\%x +\($invocant: $pos1, $pos2, :named($arg)) + +Defers the contextualization of its argument or arguments till it is +bound into some other context. =item * prefix:<^>, upto operator -^ +^$limit -Constructs a range or locates a metaclass. See L. +Constructs a range of C<0..^$limit> or locates a metaclass as a shortcut +for C<$limit.HOW>. See L. =item * prefix:<=>, iterate iterator -= +=$iterator Unary C<=> reads lines from a filehandle or filename, or iterates an iterator, or in general causes a scalar to explode its guts @@ -491,7 +545,9 @@ infix:<*> -* +$x*$y + +Multiplication, resulting in wider type of the two. =item * @@ -499,7 +555,8 @@ $numerator / $denominator -Converts both operands to C and does division returning C. +If either operand is of C type, +converts both operands to C and does division returning C. If the denominator is zero, returns either C<+Inf>, C, or C<-Inf> as the numerator is positive, zero, or negative. (This is construed as the best default in light of the operator's possible use within @@ -507,6 +564,11 @@ on an individual scalar division, you can always check the denominator yourself.) +If both operands are of integer type, you still get a C, but the +C type is allowed to do the division lazily; internally it may +store a C until the time a value is called for. If converted +to C directly no division ever need be done. + =item * infix:, generic division @@ -529,7 +591,7 @@ infix:<%>, modulus -% +$x
'x' vs. 'xx'
Is there any reason why we can't simply define '$a x $n' as being shorthand for 'cat($a xx $n)'? In what way does the former differ from the latter, other than the use of a Whatever in place of $n? -- Jonathan "Dataweaver" Lang
Re: 'x' vs. 'xx'
On 6/2/07, Jonathan Lang <[EMAIL PROTECTED]> wrote: Is there any reason why we can't simply define '$a x $n' as being shorthand for 'cat($a xx $n)'? In what way does the former differ from the latter, other than the use of a Whatever in place of $n? -- Jonathan "Dataweaver" Lang "$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt description of its behavior. "cat($a xx *)" is an attempt to provide an infinite string since 'a' x Inf would result in memory overflow (but the cat trick works since lists are evaluated lazily).
Re: 'x' vs. 'xx'
Chas Owens wrote: Jonathan Lang wrote: > Is there any reason why we can't simply define '$a x $n' as being > shorthand for 'cat($a xx $n)'? In what way does the former differ > from the latter, other than the use of a Whatever in place of $n? "$a x $n" is equivalent to "join '', $a xx $n", but that isn't an apt description of its behavior. "cat($a xx *)" is an attempt to provide an infinite string since 'a' x Inf would result in memory overflow (but the cat trick works since lists are evaluated lazily). Then it looks to me like 'cat($a xx $n)' is more flexible than "join '', $a xx $n", and would work better as the baseline definition for '$a x $n'. Is there any reason to prefer a join-based definition to a cat-based one? AFAICT, the only thing that 'join' can do that 'cat' can't is to provide a delimiter when stitching the component strings together; in the case of 'x', this feature is (rightfully) not being used. -- Jonathan "Dataweaver" Lang