Author: lwall Date: 2010-01-30 20:40:20 +0100 (Sat, 30 Jan 2010) New Revision: 29602
Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S03-operators.pod Log: [S02,S03] start detangling sigils from other contexts No longer use .list to mean force-flat semantics "List" now always means lazily contextual. Use .flat or .slice to be specific about that @@ is starting to go away (don't have sig relief for slices yet) @ no longer means .flat @($x) and @$x defined to be identical Foo($x) and $x.Foo defined to be identical for any known Foo type Args to coercions always passed as parcels, not flat lists Modified: docs/Perl6/Spec/S02-bits.pod =================================================================== --- docs/Perl6/Spec/S02-bits.pod 2010-01-30 18:02:06 UTC (rev 29601) +++ docs/Perl6/Spec/S02-bits.pod 2010-01-30 19:40:20 UTC (rev 29602) @@ -13,8 +13,8 @@ Created: 10 Aug 2004 - Last Modified: 23 Jan 2009 - Version: 196 + Last Modified: 30 Jan 2009 + Version: 197 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1191,6 +1191,7 @@ Bool Boolean Exception Failure Block Callable + Seq Iterable Range Iterable Set Associative[Bool] Bag Associative[UInt] @@ -1230,7 +1231,8 @@ because they can be wrapped in place.) Iterator Perl list - Seq Partially or completely reified list + SeqIter Iterator over a Seq + RangeIter Iterator over a Range Scalar Perl scalar Array Perl array Hash Perl hash @@ -1294,9 +1296,8 @@ The following roles are supported: Iterator List - Seq Iterable Scalar - Array Positional + Array Positional Iterable Hash Associative KeySet KeyHash[Bool] KeyBag KeyHash[UInt] @@ -1315,12 +1316,10 @@ Stash Associative SoftRoutine Routine -Types that do the C<List> role are generally hidden from casual view, -since iteration is typically triggered by context rather than by -explicit call to the iterator's C<.get> method. Filehandles are a -notable exception. C<Seq> is mutable insofar as it it generated -lazily, but the portion of the list that is already reified is -considered immutable. +Types that do the C<List> role are generally hidden from casual +view, since iteration is typically triggered by context rather than +by explicit call to the iterator's C<.get> method. Filehandles are +a notable exception. See L<S06/"Wrapping"> for a discussion of soft vs. hard routines. @@ -3980,6 +3979,9 @@ (Once determined, the values are readonly, however. To create an anonymous mutable array, use explicit square brackets around the list.) +To force explicit flattening or slicing (anti-flattening), use either the C<flat> +or C<slice> contextualizers. + To force a non-flattening item context, use the "C<item>" operator. =item * Modified: docs/Perl6/Spec/S03-operators.pod =================================================================== --- docs/Perl6/Spec/S03-operators.pod 2010-01-30 18:02:06 UTC (rev 29601) +++ docs/Perl6/Spec/S03-operators.pod 2010-01-30 19:40:20 UTC (rev 29602) @@ -15,8 +15,8 @@ Created: 8 Mar 2004 - Last Modified: 29 Jan 2010 - Version: 187 + Last Modified: 30 Jan 2010 + Version: 188 =head1 Overview @@ -681,7 +681,7 @@ ^$limit Constructs a range of C<0 ..^ +$limit> or locates a metaclass as a shortcut -for C<$limit.HOW>. See L</Range and RangeIterator semantics>. +for C<$limit.HOW>. See L</Range and RangeIter semantics>. =back @@ -1094,7 +1094,7 @@ $min ^..^ $max Constructs C<Range> objects, optionally excluding one or both endpoints. -See L</Range and RangeIterator semantics>. +See L</Range and RangeIter semantics>. =back @@ -2132,41 +2132,35 @@ =item * -Sigils as contextualizer listops +Sigils as coercions to roles Sigil Alpha variant ----- ------------- - $ item - @ list - @@ slice - % hash + $ Scalar + @ Positional (or Iterable?) + % Associative + & Callable -These may only be used as functions with explicit parens: +Note that, since these are coercions to roles, they are allowed +to return any actual type that does the role in question. - $(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 } +Unless applied directly to a scalar variable, as in C<@$a>, these +may only be applied with explicit parens around an argument that +is processed as a bare C<Parcel> object, not a flattening list: - $(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) # Scalar((1,3),(2,4)) + @(1,2 Z 3,4) # ((1,3),(2,4)) + %(1,2 Z 3,4) # PairSeq(1 => 3, 2 => 4) -These can also influence the result of functions that returns lists of captures: + $(1,2 X 3,4) # Scalar((1,3),(1,4),(2,3),(2,4)) + @(1,2 X 3,4) # ((1,3),(1,4),(2,3),(2,4)) - $(map { $_, $_*2 }, ^4) # [\(0,0),\(1,2),\(2,4),\(3,6)] - @(map { $_, $_*2 }, ^4) # 0,0,1,2,2,4,3,6 - @@(map { $_, $_*2 }, ^4) # [0,0],[1,2],[2,4],[3,6] - %(map { $_, $_*2 }, ^4) # { 0 => 0, 1 => 2, 2 => 4, 3 => 6 } +(Note, internal parens indicate nested C<Parcel> structure here, +since there is no flattening.) -The parens may not be omitted on the sigiled forms, but the alpha variants may -be used as normal listops: +Since a C<Parcel> with one argument is transparent, there can be no +difference between the meaning of C<@($a)> and C<@$a>. - item map { $_, $_*2 }, ^4 # [\(0,0),\(1,2),\(2,4),\(3,6)] - list map { $_, $_*2 }, ^4 # 0,0,1,2,2,4,3,6 - slice map { $_, $_*2 }, ^4 # [0,0],[1,2],[2,4],[3,6] - hash map { $_, $_*2 }, ^4 # { 0 => 0, 1 => 2, 2 => 4, 3 => 6 } - =item * The C<item> contextualizer @@ -2178,14 +2172,17 @@ We still call the values scalars, and talk about "scalar operators", but scalar operators are those that put their arguments into item context. -If given a list, this function makes a C<Capture> object from it. The function -is agnostic about any C<Captures> embedded in such a capture. (Use C<@> or C<@@> -below to force that one way or the other). +If given a list, this function makes a C<Seq> object from it. The function +is agnostic about any C<Parcel> embedded in such a sequence, and any contextual +decisions will be deferred until subsequent use of the contents. -Note that this is a list operator, not a unary prefix operator, -since you'd generally want it for converting a list to an item. -Single items don't need to be converted to items. +Note that this parses as a list operator, not a unary prefix operator, +since you'd generally want it for converting a list to a sequence object. +(Single items don't need to be converted to items.) Note, however, that +it does no flattening of its list items: + @x = slice(item (1,2),(3,4)) # @x eqv [[1,2],[3,4]] + =item * The C<list> contextualizer @@ -2193,21 +2190,29 @@ list foo() Forces the subsequent expression to be evaluated in list context. -A list of C<Capture>s will be transformed into a flat list. -Equivalent to C<@(...)> (except that empty C<@()> means C<@($/)>, while -empty C<list()> means an empty list). +Any flattening happens lazily. =item * +The C<flat> contextualizer + + flat foo() + +Forces the subsequent expression to be evaluated in a flattening +list context. The result will be recursively flattened, i.e., +contain no embedded C<Parcel> objects. + +=item * + The C<slice> contextualizer slice foo() Forces the subsequent expression to be evaluated in slice context. (Slices are considered to be potentially multidimensional in PerlĀ 6.) -A list of C<Capture>s will be transformed into a list of lists. -Equivalent to C<@@(...)> (except that empty C<@@()> means C<@@($/)>, while -empty C<slice()> means a null slice). +A list of C<Parcel>s will be transformed into a list of C<Seq>s. +(C<Seq> objects do not autoflatten themselves in a list unless +explicitly dereferenced.) =item * @@ -2216,7 +2221,7 @@ hash foo() Forces the subsequent expression to be evaluated in hash context. -The expression is evaluated in list context (flattening any C<Capture>s), +The expression is evaluated in list context (flattening any C<Parcel>s), then a hash will be created from the list, taken as a list of C<Pair>s. (Any element in the list that is not a C<Pair> will pretend to be a key and grab the next value in the list as its value.) Equivalent to @@ -3111,7 +3116,7 @@ =back -=head1 Range and RangeIterator semantics +=head1 Range and RangeIter semantics The C<..> range operator has variants with C<^> on either end to indicate exclusion of that endpoint from the range. It always @@ -3154,7 +3159,7 @@ C<< infix:<cmp> >> or equivalent), a range is constructed in that type. If C<T> also defines C<.succ>, then the range may be iterated. (Otherwise the range may only be used as an interval, and will return -failure if asked for a C<RangeIterator>.) Note that it is not necessary +failure if asked for a C<RangeIter>.) Note that it is not necessary to define a range multimethod in type C<T>, since the generic routine can usually auto-generate the range for you.