Revision 27882

Date:
2009/08/06 13:14:15
Author:
lwall
Revision Log:
[S02] Note that coercion to Nil provides "loop else" functionality
Define what we mean by the Parcel type.
Files:

Legend:

 
Added
 
Removed
 
Modified
  • docs/Perl6/Spec/S02-bits.pod

     
    13 13
    14 14 Created: 10 Aug 2004
    15 15
    16 Last Modified: 17 Jun 2009
    17 Version: 171
    16 Last Modified: 6 Aug 2009
    17 Version: 172
    18 18
    19 19 This document summarizes Apocalypse 2, which covers small-scale
    20 20 lexical items and typological issues. (These Synopses also contain
     
    980 980 as a null list into list context, and an empty capture into slice
    981 981 context. A C<Nil> object may also carry failure information,
    982 982 but if so, the object behaves as a failure only in item context.
    983 Use C<Failure>/C<undef> when you want to return a hard failure that
    984 will not evaporate in list context.
    983 Use C<Failure> when you want to return a hard failure that
    984 will not evaporate in list context. Casting to C<Nil> is one
    985 way of evaluating an expression and throwing the result away:
    985 986
    987 @inclist = map { $_ + 1 }, @list || Nil( warn 'Empty @list!' );
    988
    989 @inclist = do for @list || Nil( warn 'Empty @list!' ) {
    990 $_ + 1;
    991 }
    992
    993 Or if you want to test the how many results you got back from
    994 the C<map> or C<for>:
    995
    996 @inclist = map { $_ + 1 }, @list or Nil( warn 'Empty @list!' );
    997
    998 @inclist = do for @list {
    999 $_ + 1;
    1000 } or Nil( warn 'Empty @list!' )
    1001
    986 1002 =head2 Immutable types
    987 1003
    988 1004 Objects with these types behave like values, i.e. C<$x === $y> is true
     
    1399 1415
    1400 1416 C<@x> may be bound to an object of the C<Array> class, but it may also
    1401 1417 be bound to any object that does the C<Positional> role, such as a
    1402 C<List>, C<Seq>, C<Range>, C<Buf>, or C<Capture>. The C<Positional>
    1418 C<List>, C<Seq>, C<Range>, C<Buf>, C<Parcel>, or C<Capture>. The C<Positional>
    1403 1419 role implies the ability to support C<< postcircumfix:<[ ]> >>.
    1404 1420
    1405 1421 Likewise, C<%x> may be bound to any object that does the C<Associative>
     
    1571 1587
    1572 1588 =item *
    1573 1589
    1590 A list of one or more objects may be grouped together by parentheses
    1591 into a "parenthesis cell", or C<Parcel>. This kind of list should
    1592 not be confused with the flattening list context. Instead, this is
    1593 a raw syntactic list; no interpretation is made of the list without
    1594 knowing what context it will be evaluated in. For example, when
    1595 you say:
    1596
    1597 (1,2,3,:mice<blind>)
    1598
    1599 the result is a C<Parcel> object containing three C<Int> objects
    1600 and a C<Pair> object, that is, four positional objects. When, however,
    1601 you say something like:
    1602
    1603 rhyme(1,2,3,:mice<blind>)
    1604
    1605 the C<Parcel> is translated (at compile time, in this case)
    1606 into a C<Capture> with 3 positionals and one named argument
    1607 in preparation for binding.
    1608
    1609 =item *
    1610
    1574 1611 An argument list may be captured into an object with backslashed parens:
    1575 1612
    1576 1613 $args = \(1,2,3,:mice<blind>)