Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
r14595 - doc/trunk/design/syn
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
la...@cvs.perl.org  
View profile  
 More options Oct 14 2008, 8:14 pm
Newsgroups: perl.perl6.language
From: la...@cvs.perl.org
Date: Tue, 14 Oct 2008 17:14:19 -0700 (PDT)
Local: Tues, Oct 14 2008 8:14 pm
Subject: [svn:perl6-synopsis] r14595 - doc/trunk/design/syn
Author: larry
Date: Tue Oct 14 17:14:18 2008
New Revision: 14595

Modified:
   doc/trunk/design/syn/S02.pod
   doc/trunk/design/syn/S04.pod
   doc/trunk/design/syn/S06.pod
   doc/trunk/design/syn/S09.pod
   doc/trunk/design/syn/S12.pod

Log:
delete ambiguous use of {...} for hash unpacking, just use sigs for that
  (list unpacking may still be done with [...] for clarity)
simplify parsing of expressions in conditionals to dwim on map/grep blocks
  (you now need to parenthesize only on listops called with 0 args, like caller)
define .pick on enumerable types, e.g. Day.pick
clean out old instances of rand ARG, esp. where used as example of 0-or-1-ary
revamp obsolete usages of exists

Modified: doc/trunk/design/syn/S02.pod
=========================================================================== ===
--- doc/trunk/design/syn/S02.pod        (original)
+++ doc/trunk/design/syn/S02.pod        Tue Oct 14 17:14:18 2008
@@ -12,9 +12,9 @@

   Maintainer: Larry Wall <la...@wall.org>
   Date: 10 Aug 2004
-  Last Modified: 9 Oct 2008
+  Last Modified: 14 Oct 2008
   Number: 2
-  Version: 138
+  Version: 139

 This document summarizes Apocalypse 2, which covers small-scale
 lexical items and typological issues.  (These Synopses also contain
@@ -1096,8 +1096,8 @@

     # Anything assigned to the variable $mitsy must conform
     # to the type Fish and either the Cat or Dog type...
-    my Cat|Dog Fish $mitsy = new Fish but { int rand 2 ?? .does Cat
-                                                       !! .does Dog };
+    my Cat|Dog Fish $mitsy = new Fish but { Bool.pick ?? .does Cat
+                                                      !! .does Dog };

 =head2 Parameter types

Modified: doc/trunk/design/syn/S04.pod
=========================================================================== ===
--- doc/trunk/design/syn/S04.pod        (original)
+++ doc/trunk/design/syn/S04.pod        Tue Oct 14 17:14:18 2008
@@ -12,9 +12,9 @@

   Maintainer: Larry Wall <la...@wall.org>
   Date: 19 Aug 2004
-  Last Modified: 1 Sep 2008
+  Last Modified: 14 Oct 2008
   Number: 4
-  Version: 69
+  Version: 70

 This document summarizes Apocalypse 4, which covers the block and
 statement syntax of Perl.
@@ -1080,11 +1080,11 @@
     }

 parentheses aren't necessary around C<EXPR> because the whitespace
-between C<EXPR> and the block forces the block to be considered a
-block rather than a subscript.  This works for all control structures,
-not just the new ones in Perl 6.  A top-level bare block
-is always considered a statement block if there's space
-before it:
+between C<EXPR> and the block forces the block to be considered a block
+rather than a subscript, provided the block occurs where an infix
+operator would be expected.  This works for all control structures,
+not just the new ones in Perl 6.  A top-level bare block is always
+considered a statement block if there's a term and a space before it:

     if $foo { ... }
     elsif $bar { ... }
@@ -1094,30 +1094,24 @@

 You can still parenthesize the expression argument for old times'
 sake, as long as there's a space between the closing paren and the
-opening brace.  You I<must> parenthesize the expression if there is
-a bare block or pointy block that would be misinterpreted as the statement's
-block.  This is regardless of whether a term or operator is expected where
-the block occurs.  (A block inside brackets, or used as a
-postcircumfix is fine, though.)  Any block with whitespace
-in front of it will be taken as terminating the conditional, even if
-the conditional expression could take another argument.  Therefore
-
-    if rand { say "exists" } { extra() }
-    if rand -> $x { say "exists" } { extra() }
-
-is always parsed as
-
-    if (rand) { say "exists" }; { extra() }
-    if (rand) -> $x { say "exists" }; { extra() }
-
-rather than
-
-    if (rand { say "exists" }) { extra() }
-    if (rand (-> $x { say "exists" })) { extra() }
-
-Apart from that, it is illegal to use a bare closure where an
-operator is expected.  (Remove the whitespace if you wish it to be
-a postcircumfix.)
+opening brace.  (Otherwise it will be parsed as a hash subscript.)
+
+Note that the parser cannot intuit how many arguments a list operator
+is taking, so if you mean 0 arguments, you must parenthesize the
+argument list to force the block to appear after a term:
+
+    if caller {...}    # WRONG, parsed as caller({...})
+    if caller() {...}  # okay
+    if (caller) {...}  # okay
+
+Note that common idioms work as expected though:
+
+    for map { $^a + 1 }, @list { .say }
+
+Unless you are parsing a statement that expects a block argument,
+it is illegal to use a bare closure where an operator is expected
+because it will be considered to be two terms in row.
+(Remove the whitespace if you wish it to be a postcircumfix.)

 Anywhere a term is expected, a block is taken to be a closure definition
 (an anonymous subroutine).  If the closure is empty, or appears to contain

Modified: doc/trunk/design/syn/S06.pod
=========================================================================== ===
--- doc/trunk/design/syn/S06.pod        (original)
+++ doc/trunk/design/syn/S06.pod        Tue Oct 14 17:14:18 2008
@@ -13,9 +13,9 @@

   Maintainer: Larry Wall <la...@wall.org>
   Date: 21 Mar 2003
-  Last Modified: 11 Oct 2008
+  Last Modified: 14 Oct 2008
   Number: 6
-  Version: 95
+  Version: 96

 This document summarizes Apocalypse 6, which covers subroutines and the
@@ -713,10 +713,8 @@
 undefined is not considered to be missing, and hence does not trigger
 the default.  Use C<//=> within the body for that.)

-(Conjectural: Within the body you may also use C<exists> on the
-parameter name to determine whether it was passed.  Maybe this will have to
-be restricted to the C<?> form, unless we're willing to admit that a parameter
-could be simultaneously defined and non-existent.)
+You may check whether an optional parameter was bound to anything
+by calling C<VAR($param).defined>.

 =head2 Named parameters

@@ -1356,39 +1354,9 @@

     sub quicksort (:$reverse, :$inplace, *$pivot, *@data)

-=head2 Unpacking hash parameters
-
-Likewise, a hash argument can be mapped to a hash of parameters, specified
-as named parameters within curlies.  Instead of saying:
-
-    sub register (%guest_data, $room_num) {
-        my $name := delete %guest_data<name>;
-        my $addr := delete %guest_data<addr>;
-        ...
-    }
-
-you can get the same effect with:
-
-    sub register ({:$name, :$addr, *%guest_data}, $room_num) {
-        ...
-    }
-
-Use of the curly form is not allowed where it might be confused with the
-following block's opening curly:
-
-    -> {:$name, :$addr, *%guest_data}, $room_num {  # WRONG
-
-However, as described in the next section, you can always use a
-sub-signature instead:
-
-    -> (:$name, :$addr, *%guest_data), $room_num {  # note ()'s
-
-In fact, the [...] and {...} forms are really just extra documentation
-about what you expect.
-
 =head2 Unpacking tree node parameters

-You can unpack tree nodes in various dwimmy ways by enclosing the bindings
+You can unpack hash values and tree nodes in various dwimmy ways by enclosing the bindings
 of child nodes and attributes in parentheses following the declaration of
 the node itself:

Modified: doc/trunk/design/syn/S09.pod
=========================================================================== ===
--- doc/trunk/design/syn/S09.pod        (original)
+++ doc/trunk/design/syn/S09.pod        Tue Oct 14 17:14:18 2008
@@ -12,9 +12,9 @@

   Maintainer: Larry Wall <la...@wall.org>
   Date: 13 Sep 2004
-  Last Modified: 17 July 2008
+  Last Modified: 14 Oct 2008
   Number: 9
-  Version: 28
+  Version: 29

 =head1 Overview

@@ -362,7 +362,7 @@
     @@x <==  %hash.keys.grep: {/^\d+$/};
     @@x <== =<>;
     @@x <== 1..*;
-    @@x <== gather { loop { take rand 100 } };
+    @@x <== gather { loop { take 100.rand } };

     @array{@@x}

@@ -374,7 +374,7 @@
     @x <==  %hash.keys.grep: {/^\d+$/};
     @x <== =<>;
     @x <== 1..*;
-    @x <== gather { loop { take rand 100 } };
+    @x <== gather { loop { take 100.rand } };

     @array{@@x}  # multidimensional
     @array{@x}   # flattened
@@ -1206,7 +1206,7 @@
 In Perl 6 these read-only operations are indeed non-destructive:

     my %hash;
-    exists %hash<foo><bar>; # %hash is still empty
+    %hash<foo><bar> :exists; # %hash is still empty

 But these bindings I<do> autovivify:

Modified: doc/trunk/design/syn/S12.pod
=========================================================================== ===
--- doc/trunk/design/syn/S12.pod        (original)
+++ doc/trunk/design/syn/S12.pod        Tue Oct 14 17:14:18 2008
@@ -12,9 +12,9 @@

   Maintainer: Larry Wall <la...@wall.org>
   Date: 27 Oct 2004
-  Last Modified: 21 Aug 2008
+  Last Modified: 14 Oct 2008
   Number: 12
-  Version: 63
+  Version: 64

 =head1 Overview

@@ -1787,6 +1787,26 @@
 type C<bit>.  Never compare a value to "C<true>", or even "C<True>".
 Just use it in a boolean context.

+Enum types (and perhaps certain other finite, enumerable types such
+as finite ranges) define a C<.pick> method on the protoobject of
+that type.  Hence:
+
+    my enum CoinFace <Heads Tails>;
+    CoinFace.pick
+
+returns C<Heads> or C<Tails> with equal probability, and
+
+    Month.pick(*)
+
+will return the months in random order.  Presumably
+
+    StandardPlayingCards.pick(5)
+
+might return a Royal Flush, but a Full House is much
+more likely.  It can never return Five Aces, since the pick
+is done without replacement.  (If it I<does> return Five Aces,
+it's time to walk away.)
+
 =head1 Open vs Closed Classes

 By default, all classes in Perl are non-final, which means


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »