[svn:perl6-synopsis] r14547 - doc/trunk/design/syn

2008-06-11 Thread larry
Author: larry
Date: Wed Jun 11 14:09:40 2008
New Revision: 14547

Modified:
   doc/trunk/design/syn/S03.pod

Log:
change most left-associative short-circuit ops to list-associative
x and xx are now left associative
define what associativity means for unary ops


Modified: doc/trunk/design/syn/S03.pod
==
--- doc/trunk/design/syn/S03.pod(original)
+++ doc/trunk/design/syn/S03.podWed Jun 11 14:09:40 2008
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall [EMAIL PROTECTED]
   Date: 8 Mar 2004
-  Last Modified: 2 Apr 2008
+  Last Modified: 11 Jun 2008
   Number: 3
-  Version: 135
+  Version: 136
 
 =head1 Overview
 
@@ -36,36 +36,46 @@
 L  Symbolic unary! + - ~ ? | +^ ~^ ?^ \ ^ =
 L  Multiplicative* / % + + + ~ ~ ~ ? div mod
 L  Additive  + - +| +^ ~| ~^ ?| ?^
-N  Replication   x xx
-L  Concatenation ~
+L  Replication   x xx
+X  Concatenation ~
 X  Junctive and  
 X  Junctive or   | ^
 L  Named unary   sleep abs sin
 N  Nonchaining infix but does = leg cmp .. ..^ ^.. ^..^
 C  Chaining infix!= ==  =  = eq ne lt le gt ge ~~ === eqv !eqv
-L  Tight and 
-L  Tight or  || ^^ // min max
+X  Tight and 
+X  Tight or  || ^^ // min max
 L  Conditional   ?? !! ff fff
 R  Item assignment   = := ::= = += -= **= xx= .=
 L  Loose unary   true not
 X  Comma operator, p5=
 X  List infixZ minmax X X~X X*X XeqvX
 R  List prefix   : print push say die map substr ... [+] [*] any $ @
-L  Loose and and andthen
-L  Loose or  or xor orelse
+X  Loose and and andthen
+X  Loose or  or xor orelse
 N  Terminator; ==, ==, ==, ==, {...}, unless, extra ), ], }
 
-The associativities specified above are:
+Using two C! symbols below generically to represent any pair of operators
+that have the same precedence, the associativities specified above
+for binary operators are interpreted as follows:
 
-Assoc Meaning of $a op $b op $c
+Assoc Meaning of $a ! $b ! $c
 = =
-L   left  ($a op $b) op $c
-R   right $a op ($b op $c)
+L   left  ($a ! $b) ! $c
+R   right $a ! ($b ! $c)
 N   non   ILLEGAL
-C   chain ($a op $b) and ($b op $c)
-X   list  op($a, $b, $c) or op($a; $b; $c)
+C   chain ($a ! $b) and ($b ! $c)
+X   list  infix:!($a; $b; $c)
 
-Note that list associativity only works between identical operators.
+For unaries this is interpreted as:
+
+Assoc Meaning of !$a!
+= =
+L   left  (!$a)!
+R   right !($a!)
+N   non   ILLEGAL
+
+Note that list associativity (X) only works between identical operators.
 If two different list-associative operators have the same precedence,
 they are assumed to be left-associative with respect to each other.
 For example, the CX cross operator and the CZ zip operator both
@@ -77,6 +87,9 @@
 
 (@a X @b) Z @c
 
+Similarly, if the only implementation of a list-associative operator
+is binary, it will be treated as left associative.
+
 If you don't see your favorite operator above, the following
 sections cover all the operators in precedence order.  Basic operator
 descriptions are here; special topics are covered afterwards.
@@ -659,7 +672,7 @@
 
 ^$limit
 
-Constructs a range of C0..^$limit or locates a metaclass as a shortcut
+Constructs a range of C0 ..^ $limit or locates a metaclass as a shortcut
 for C$limit.HOW.  See L/Range semantics.
 
 =item *
@@ -932,7 +945,7 @@
 
 C infix: , all() operator
 
-$x  $y
+$a  $b  $c ...
 
 =back
 
@@ -944,13 +957,13 @@
 
 C infix:| , any() operator
 
-$x | $y
+$a | $b | $c ...
 
 =item *
 
 C infix:^ , one() operator
 
-$x ^ $y
+$a ^ $b ^ $c ...
 
 =back
 
@@ -1042,6 +1055,11 @@
 Constructs Range objects, optionally excluding one or both endpoints.
 See L/Range semantics.
 
+Note that these differ:
+
+$min ..^ $max  $ min .. $max-1
+$min .. ^$max  # $min .. (0..$max-1)
+
 =back
 
 =head2 Chaining binary precedence
@@ -1145,10 +1163,10 @@
 
 C infix: , short-circuit and
 
-$condition  $whentrue
+$a  $b  $c ...
 
-Returns the left argument if the left argument is false, otherwise
-evaluates and returns the right argument.  In list context forces
+Returns the first argument that evaluates to false, otherwise
+returns the result of the last argument.  In list context forces
 a false return to mean C().  See Cand below for low-precedence
 version.
 
@@ -1160,13 +1178,14 @@
 
 =item *
 
-C infix:|| , short-circuiting inclusive-or
+C infix:|| , short-circuit inclusive-or
 
-$condition || $whenfalse
+$a || $b || $c ...
 
-Returns the left argument if it's true, otherwise evaluates and 

Re: [svn:perl6-synopsis] r14547 - doc/trunk/design/syn

2008-06-11 Thread Ryan Richter
On Wed, Jun 11, 2008 at 02:09:41PM -0700, [EMAIL PROTECTED] wrote:
 +Note that these differ:
 +
 +$min ..^ $max$ min .. $max-1
 +$min .. ^$max# $min .. (0..$max-1)

The punctuation looks a little funny on the first line.  Also, are
$min ..^ $max and $min .. $max-1 really the same range?

I'm a little curious about the second line, is that even legal?  It
seems to me a Range should only allow itself to be constructed from
endpoints with a well-defined ordering, so a Range of Ranges should be
illegal.  Or does the .. end up pulling a num out of the ^$max range
iterator for its endpoint somehow via MMD?

-ryan


S12 Patch for metacalls, Representation API (Was: Re: Foo.HOW.metamethod vs Foo.^metamethod)

2008-06-11 Thread Daniel Ruoso
Seg, 2008-06-09 às 17:51 -0700, Larry Wall escreveu:
 On Sat, Jun 07, 2008 at 09:49:03PM +0100, Daniel Ruoso wrote:
 : 2) Assume the capture-translation and define that
 : $foo.HOW.can($foo,'bar') keeps the $how as the invocant and must receive
 : the referring object as first argument.
 I prefer this approach, I think.

I took the liberty to write a patch to S12 with this new context. The
extended format $foo.HOW.methods($foo) becomes a little awkward,
specially for Class based OO. Maybe there should be a more extended
modification to promote the .^methods syntax, since $foo.HOW is then
more usefull for prototype-based OO, where $foo.HOW might be, for
instance, Prototype::Delegation::C3 or Prototype::Concatenation.

This actually brings me to another issue, which is how much do we expect
for this prototype-based meta implementations to be exchangeable between
Perl 6 implementations?

The point is that they *must* be representation independent, so that you
can use it with whatever low-level object metainstance (in the Moose
jargon) you like, and for that to be possible, we need a representation
API. SMOP is already pointing in that direction, take a look at:

  * http://www.perlfoundation.org/perl6/index.cgi?smop_oo_api
  * http://svn.pugscode.org/pugs/v6/smop/src-s1p/P6Meta.pm

daniel

__DATA__

Index: S12.pod
===
--- S12.pod (revision 14546)
+++ S12.pod (working copy)
@@ -123,11 +123,15 @@
 CHOW method.  A class object is just considered an empty
 instance in Perl 6, more properly called a prototype object, or just
 protoobject.
-The actual class object is the metaclass object pointed to by the
-CHOW syntax.  So when you say CDog, you're referring to both a
-package and a protoobject, that latter of which points to the
-actual object representing the class via CHOW.  The protoobject
-differs from an instance object not by having a different
+
+In a class-based OO implementation, the actual class object is the
+metaclass object pointed to by the CHOW syntax.  So when you say
+CDog, you're referring to both a package and a protoobject, that
+latter of which points to the actual object representing the class via
+CHOW. In a prototype-based OO implementation, on the other hand, the
+metaclass object is probably going to be shared by several types and
+the methods are most likely going to be stored in the prototypes.  The
+protoobject differs from an instance object not by having a different
 type but rather in the extent to which it is defined.  Some objects
 may tell you that they are defined, while others may tell you that
 they are undefined.  That's up to the object, and depends on how the
@@ -1892,23 +1896,29 @@
 $x === $y
 $obj.bless(%args)
 
-Every class has a CHOW function/method that lets you get at the
-class's metaobject, which lets you get at all the metadata properties
-for the class (or other metaobject protocol) implementing the objects
-of the class:
+Every object, defined or not, has a CHOW function/method that lets
+you get at the metaobject, which lets you get at all the metadata
+properties for the type (or other metaobject protocol) implementing
+the objects of the type:
 
-MyClass.methods()   # call MyClass's .methods method (error?)
-MyClass.HOW.methods()   # get the method list of MyClass
+MyClass.methods()# call MyClass's .methods method (error?)
+MyClass.HOW.methods(MyClass) # get the method list of MyClass
 
 The C^ metasyntax is equivalent to C.HOW:
 
-MyClass.HOW.methods()   # get the method list of MyClass
-^MyClass.methods()  # get the method list of MyClass
-MyClass.^methods()  # get the method list of MyClass
+MyClass.HOW.methods(MyClass) # get the method list of MyClass
+^MyClass.methods(MyClass)
 
-Each object of the class also has a C.HOW or C.^ method:
+When using the C^ metasyntax in the method invocation, it also
+implies a translation in the capture, passing the invocant as first
+argument:
 
-$obj.HOW.methods();
+MyClass.HOW.methods(MyClass) # get the method list of MyClass
+MyClass.^methods()   # equivalent shorter syntax
+
+Each object of the type also has a C.HOW or C.^ method:
+
+$obj.HOW.methods($obj);
 $obj.^methods();
 
 Class traits may include:
@@ -1964,9 +1974,9 @@
 Strictly speaking, metamethods like C.isa(), C.does(), and C.can()
 should be called through the meta object:
 
-$obj.HOW.can(bark)
-$obj.HOW.does(Dog)
-$obj.HOW.isa(Mammal)
+$obj.HOW.can($obj, bark)
+$obj.HOW.does($obj, Dog)
+$obj.HOW.isa($obj, Mammal)
 
 or
 
@@ -1992,7 +2002,7 @@
 
 actually calls:
 
-$obj.HOW.does(Dog)
+$obj.HOW.does($obj, Dog)
 
 which is true if C$obj either does or isa CDog (or isa
 something that does CDog).  If CDog is a subset, any additional




[svn:perl6-synopsis] r14548 - doc/trunk/design/syn

2008-06-11 Thread larry
Author: larry
Date: Wed Jun 11 16:26:27 2008
New Revision: 14548

Modified:
   doc/trunk/design/syn/S03.pod

Log:
clarification of reduced short-circuit ops


Modified: doc/trunk/design/syn/S03.pod
==
--- doc/trunk/design/syn/S03.pod(original)
+++ doc/trunk/design/syn/S03.podWed Jun 11 16:26:27 2008
@@ -1203,8 +1203,15 @@
 is true.  In list context forces a false return to mean C().
 See Cxor below for low-precedence version.
 
-Similar to the C[^^] reduce operator, but short-circuits in the sense
-that it does not evaluate any arguments after a 2nd true result.
+This operator short-circuits in the sense that it does not evaluate
+any arguments after a 2nd true result.  Closely related is the reduce
+operator:
+
+[^^] a(), b(), c() ...
+
+but note that reduce operators are not macros but ordinary list
+operators, so c() is always called before the reduce is done.
+
 
 =item *
 
@@ -1704,7 +1711,7 @@
 
 [+] [*] [] [\+] [\*] etc.
 
-See LReduction operators.
+See LReduction operators below.
 
 =item *
 
@@ -3486,7 +3493,7 @@
 [-] 4, 3, 2;  # 4-3-2 = (4-3)-2 = -1
 [**] 4, 3, 2; # 4**3**2 = 4**(3**2) = 262144
 
-For list-associating operators (like C  ), all arguments are taken
+For chain-associative operators (like C  ), all arguments are taken
 together, just as if you had written it out explicitly:
 
 [] 1, 3, 5;  # 1  3  5
@@ -3635,6 +3642,15 @@
 (And, in fact, the latter are already easy to express anyway,
 and more obviously nonsensical.)
 
+Similarly, list-associative operators that have the thunk-izing 
characteristics of
+macros (such as short-circuit operators) lose those macro-like characteristics.
+You can say
+
+[||] a(), b(), c(), d()
+
+to return the first true result, but the evaluation of the list is controlled
+by the semantics of the list, not the semantics of C||.
+
 Most reduce operators return a simple scalar value, and hence do not care
 whether they are evaluated in item or list context.  However, as with
 other list operators and functions, a reduce operator may return a list


[svn:perl6-synopsis] r14549 - doc/trunk/design/syn

2008-06-11 Thread larry
Author: larry
Date: Wed Jun 11 16:49:17 2008
New Revision: 14549

Modified:
   doc/trunk/design/syn/S03.pod

Log:
Fixes suggested by Ryan++


Modified: doc/trunk/design/syn/S03.pod
==
--- doc/trunk/design/syn/S03.pod(original)
+++ doc/trunk/design/syn/S03.podWed Jun 11 16:49:17 2008
@@ -1057,8 +1057,11 @@
 
 Note that these differ:
 
-$min ..^ $max  $ min .. $max-1
-$min .. ^$max  # $min .. (0..$max-1)
+0 ..^ 10   # 0 .. 9
+0 .. ^10   # 0 .. (0..9)
+
+(It's not yet clear what the second one should mean, but whether it
+succeeds or fails, it won't do what you want.)
 
 =back
 


Re: [svn:perl6-synopsis] r14549 - doc/trunk/design/syn

2008-06-11 Thread Ryan Richter
On Wed, Jun 11, 2008 at 04:49:18PM -0700, [EMAIL PROTECTED] wrote:
 -$min ..^ $max$ min .. $max-1
 -$min .. ^$max# $min .. (0..$max-1)
 +0 ..^ 10 # 0 .. 9
 +0 .. ^10 # 0 .. (0..9)

Ah, I should have been more specific - I meant that, since ~~ treats
Ranges as continuous intervals, 0 ..^ 10 isn't the same as 0 .. 9.
Although I guess there's no way to unabbreviate 0 ..^ 10...

-ryan


Re: [svn:perl6-synopsis] r14549 - doc/trunk/design/syn

2008-06-11 Thread Larry Wall
On Wed, Jun 11, 2008 at 08:20:41PM -0400, Ryan Richter wrote:
: On Wed, Jun 11, 2008 at 04:49:18PM -0700, [EMAIL PROTECTED] wrote:
:  -$min ..^ $max  $ min .. $max-1
:  -$min .. ^$max  # $min .. (0..$max-1)
:  +0 ..^ 10   # 0 .. 9
:  +0 .. ^10   # 0 .. (0..9)
: 
: Ah, I should have been more specific - I meant that, since ~~ treats
: Ranges as continuous intervals, 0 ..^ 10 isn't the same as 0 .. 9.
: Although I guess there's no way to unabbreviate 0 ..^ 10...

Well, maybe 0 .. 10-ε or some such.

Larry


[svn:perl6-synopsis] r14551 - doc/trunk/design/syn

2008-06-11 Thread larry
Author: larry
Date: Wed Jun 11 17:53:27 2008
New Revision: 14551

Modified:
   doc/trunk/design/syn/S05.pod

Log:
added ... et al. as suggested by ruoso++


Modified: doc/trunk/design/syn/S05.pod
==
--- doc/trunk/design/syn/S05.pod(original)
+++ doc/trunk/design/syn/S05.podWed Jun 11 17:53:27 2008
@@ -16,7 +16,7 @@
Date: 24 Jun 2002
Last Modified: 11 Jun 2008
Number: 5
-   Version: 80
+   Version: 81
 
 This document summarizes Apocalypse 5, which is about the new regex
 syntax.  We now try to call them Iregex rather than regular
@@ -1410,6 +1410,15 @@
 
 =item *
 
+The C ... , C ??? , and C !!!  special tokens
+have the same not-defined-yet meanings within regexes that the bare
+elipses have in ordinary code.  (However, by the recursive rules above,
+C !!  is equivalent to C ? , which matches the null string.
+Likewise C !!before x  is just like C ?before x , except
+that it is ignored by the longest-token matcher.)
+
+=item *
+
 A leading C* indicates that the following pattern allows a
 partial match.  It always succeeds after matching as many characters
 as possible.  (It is not zero-width unless 0 characters match.)