[svn:perl6-synopsis] r13499 - doc/trunk/design/syn
Author: larry Date: Sat Dec 23 02:10:28 2006 New Revision: 13499 Modified: doc/trunk/design/syn/S03.pod Log: Ruminations on defining the limits of what are considered metatokens. Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSat Dec 23 02:10:28 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 22 Dec 2006 + Last Modified: 23 Dec 2006 Number: 3 - Version: 79 + Version: 80 =head1 Changes to Perl 5 operators @@ -1256,6 +1256,38 @@ Multidimensional lists should be handled properly. +=head1 Nesting of metaoperators + +In order to match operators by the longest-token rule, the +compiler pregenerates various metaforms based on existing operators. +Unfortunately, with nesting metaoperators there are an infinite number +of metaforms, so we arbitrarily say that no metacircumfix form is +pregenerated that uses the same grammatical category more than once. +Therefore forms like C<[+=]> and C<»!===«> and C are generated, +but not forms like C<»X*X«> or C. You do get C<[X*X]>, +though, because reduction is prefix_circumfix_meta_operator while +cross operators are infix_circumfix_meta_operator. + +This use-each-category-once limitation is not a great hardship since +you can define your own infix operators. Suppose you say + +&infix: ::= &infix:; + +After this you can use C, C<[xp]>, and C<[«xp»=]«> as if C +were a built-in. Not that any of those necessarily make sense... + +The compiler is not actually required to pregenerate the metaform +tokens as long as it can guarantee the same semantics, that is, +that it follows the longest-token rule across all syntax categories +active at that spot in the parse. This could be achieved by use +of a DFA parser (or exhaustive NFA matcher) to guarantee longest +match of the generatable forms, for instance, followed by a check +to make sure it is not trumped by an even longer "hardwired" token. +Suppose the user were to define, say, C<< infix:<[EMAIL PROTECTED]> >> or +C<< statement_modifier: >>; those hardwired forms must take +precedence over the C operator even if the metaform DFA only +knows how to recognize the C part. + =head1 Junctive operators C<|>, C<&>, and C<^> are no longer bitwise operators (see
[svn:perl6-synopsis] r13500 - doc/trunk/design/syn
Author: larry Date: Sat Dec 23 12:10:42 2006 New Revision: 13500 Modified: doc/trunk/design/syn/S03.pod Log: Clarification on which forms of infix:<~~> are provided dynamically if compile-time recognition fails over to multiple dispatch. Clarification on limits to metaoperator size. Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSat Dec 23 12:10:42 2006 @@ -14,7 +14,7 @@ Date: 8 Mar 2004 Last Modified: 23 Dec 2006 Number: 3 - Version: 80 + Version: 81 =head1 Changes to Perl 5 operators @@ -705,8 +705,18 @@ to the table above, any existing C<< infix:<~~> >> routines are completely ignored. If the types cannot be matched at compile time, one attempt is made to multiply dispatch to all C<< infix:<~~> >> -infix definitions. If this fails, the most generic multi definition -of C<< infix:<~~> >> calls C<===> to match the two variables exactly +infix definitions. The standard C<< infix:<~~> >> definitions are +intended to reproduce as closely as possible the compile-time table above, +but it can do this based only on the run-time types of the arguments. +Therefore only the entries above that indicate a type on both sides +can be dispatched that way. (You can tell those because both sides +start with a capital letter. So multiple dispatch ignores the +".method", "boolean", "undef", and "*" entries, which are recognized +syntactically, not by type.) + +If there is no appropriate signature match under the rules of multiple +dispatch, the most generic multi definition of C<< infix:<~~> >> +defaults to calling C<===> to match the two variables exactly according to their type. In general you should just rely on this and not attempt to define your own C<< infix:<~~> >> operators, because complexifying the run-time semantics of C<~~> is not doing @@ -1264,7 +1274,8 @@ of metaforms, so we arbitrarily say that no metacircumfix form is pregenerated that uses the same grammatical category more than once. Therefore forms like C<[+=]> and C<»!===«> and C are generated, -but not forms like C<»X*X«> or C. You do get C<[X*X]>, +but not forms like C<»X*X«> or C or C<<< <<+=>>= >>>. +You do get C<[X*X]>, though, because reduction is prefix_circumfix_meta_operator while cross operators are infix_circumfix_meta_operator. @@ -1288,6 +1299,13 @@ precedence over the C operator even if the metaform DFA only knows how to recognize the C part. +Note that the maximum possible token length is bounded by the sum +of the maximum lengths of each metacategory, so an enumerated solution +is always possible, though perhaps not practical. It's also the case +that no metaform is allowed to contain whitespace, so a solution +that starts at the length of the current "word" and works down is also +possible. + =head1 Junctive operators C<|>, C<&>, and C<^> are no longer bitwise operators (see
[svn:perl6-synopsis] r13501 - doc/trunk/design/syn
Author: larry Date: Sat Dec 23 12:50:23 2006 New Revision: 13501 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S06.pod Log: Housekeeping move of basic types section from S06 to S02, no other changes. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podSat Dec 23 12:50:23 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 16 Dec 2006 + Last Modified: 23 Dec 2006 Number: 2 - Version: 81 + Version: 82 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -656,6 +656,344 @@ =back +=head2 Native types + +Values with these types autobox to their uppercase counterparts when +you treat them as objects: + +bit single native bit +int native signed integer +uintnative unsigned integer (autoboxes to Int) +buf native buffer (finite seq of native ints or uints, no Unicode) +num native floating point +complex native complex number +boolnative boolean + +=head2 Undefined types + +These can behave as values or objects of any class, except that +C always returns false. One can create them with the +built-in C and C functions. (See S02 for how failures +are handled.) + +Undef Undefined (can serve as a prototype object of any class) +WhateverWildcard (like undef, but subject to do-what-I-mean via MMD) +Failure Failure (throws an exception if not handled properly) + +=head2 Immutable types + +Objects with these types behave like values, i.e. C<$x === $y> is true +if and only if their types and contents are identical (that is, if +C<$x.WHICH> eqv C<$y.WHICH>). + +Bit Perl single bit (allows traits, aliasing, undef, etc.) +Int Perl integer (allows Inf/NaN, arbitrary precision, etc.) +Str Perl string (finite sequence of Unicode characters) +Num Perl number +Complex Perl complex number +BoolPerl boolean +Exception Perl exception +CodeBase class for all executable objects +Block Executable objects that have lexical scopes +ListLazy Perl list (composed of Seq and Range parts) +Seq Completely evaluated (hence immutable) sequence +Range A pair of Ordered endpoints; gens lazy Seq in list context +Set Unordered Seq that allows no duplicates (does KeyHash, but ro) +Bag Unordered Seq that allows duplicates (does KeyHash, but ro) +JunctionSets with additional behaviours +PairSeq of two elements that serves as a one-element Mapping +Mapping Pairs with no duplicate keys +Signature Function parameters (left-hand side of a binding) +Capture Function call arguments (right-hand side of a binding) +BlobAn undifferentiated mass of bits + +=head2 Mutable types + +Objects with these types have distinct C<.WHICH> values that do not change +even if the object's contents change. + +Scalar Perl scalar +Array Perl array +HashPerl hash +KeyHash Perl hash that autodeletes values matching default +KeySet KeyHash of Bool (does Set in list/array context) +KeyBag KeyHash of UInt (does Bag in list/array context) +Buf Perl buffer (a stringish array of memory locations) +IO Perl filehandle +Routine Base class for all wrappable executable objects +Sub Perl subroutine +Method Perl method +Submethod Perl subroutine acting like a method +Macro Perl compile-time subroutine +Regex Perl pattern +Match Perl match, usually produced by applying a pattern +Package Perl 5 compatible namespace +Module Perl 6 standard namespace +Class Perl 6 standard class namespace +RolePerl 6 standard generic interface/implementation +Object Perl 6 object +Grammar Perl 6 pattern matching namespace + +A C differs from a normal C in how it handles default +values. If the value of a C element is set to the default +value for the C, the element is deleted. If undeclared, +the default default for a C is 0 for numeric types, C +for boolean types, and the null string for string and buffer types. +A C of a C type defaults to the undefined prototype +for that type. More generally, the default default is whatever defined +value an C would convert to for that value type. A C +of C deletes elements that go to either 0 or the null string. +A C also autodeletes keys for normal undef values (that is, +those undefined values that do not contain an unthrown exception). + +A C is a C of booleans with a default of C. +If you use the C interface and increment an elemen
[svn:perl6-synopsis] r13502 - doc/trunk/design/syn
Author: larry Date: Sat Dec 23 18:37:23 2006 New Revision: 13502 Modified: doc/trunk/design/syn/S03.pod Log: More attempts to make smartmatch semantics consistent with multiple dispatch. Regex matching now does not "autogrep" an Array since we're trying to extend Regex matching to sequences of other than just Str. Defined cat() in scalar context to fake up a lazy string implementation type. (Still basically a no-op in list context, since lists are already lazy.) Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podSat Dec 23 18:37:23 2006 @@ -14,7 +14,7 @@ Date: 8 Mar 2004 Last Modified: 23 Dec 2006 Number: 3 - Version: 81 + Version: 82 =head1 Changes to Perl 5 operators @@ -608,52 +608,58 @@ .{Any} . .[number] .method Class Subset Enum Role Type Subst Regex -Buf CharStr +Buf Char LazyStrStr Int UInt etc. Num Note that all types are scalarized. Both C<~~> and C/C provide scalar contexts to their arguments. (You can always hyperize C<~~> explicitly, though.) So both C<$_> and C<$x> here -are potentially container objects. The first possible match in this -table is used. By definition all normal arguments can be matched to -at least one of these entries. +are potentially container objects. The first section contains +privileged syntax; if a match can be done via one of those entries, +it will be. Otherwise the rest of the table is used, and the match +will be dispatched according to the normal rules of multiple dispatch; +however, the optimizer is allowed to assume that no C<< infix:<~~> >> +operators are added at run time, so if the argument types are evident +at compile time, the jump table can be optimized. By definition all +normal arguments can be matched to at least one of the entries below. -$_ $xType of Match ImpliedMatching Code +$_ $xType of Match ImpliedMatch if == = == -Any Code:($) scalar sub truth match if $x($_) -Any .method method truth*match if $_.method - -HashHash hash keys identical sets match if $_.keys === $x.keys -HashArray hash value slice truth match if $_{any(@$x)} -HashJunction hash key slice existence match if $_.exists($x) -HashRegex hash key grepmatch if any($_.keys) === /$x/ - -Array Array arrays are comparablematch if $_ »===« $x -Array Junction list intersectionmatch if any(@$_) === $x -Array Regex array grep match if any(@$_) === /$x/ -Array Num array contains numbermatch if any($_) == $x -Array Str array contains stringmatch if any($_) eqv $x -Array Buf array equivalent to buf match if $_ eqv Array($x) -Array Set array equivalent to set match if Set($_) === $x - -Num NumRange in numeric range match if $min <= $_ <= $max - -CodeSignature signature compatibility* match if $_ is a subset of $x - Signature Signature signature compatibility match if $_ is a subset of $x - -HashAny hash entry existence match if exists $_{$x} -Array Any array contains item* match if any($_) === $x -Any Signature parameter bindingmatch if $_ can bind to $x -Any Range in range match if [!after] $x.min,$_,$x.max -Any Type type membership match if $_.does($x) -Any Regex pattern matchmatch if $_ ~~ /$x/ -Any Num numeric equality match if $_ == $x -Any Str string equality match if $_ eqv $x -Any Code:() simple closure truth*match if $x() (ignoring $_) -Any boolean simple expression truth* match if $x.true given $_ -Any undef undefinedmatch unless defined $_ -Any * default match anything -Any Any run-time dispatchmatch if infix:<~~>($_, $x) +Any Code:($) scalar sub truth $x($_) +Any .method method truth*$_.method +Any boolean simple expression truth* $x.true given $_ +Any undef undefinednot defined $_ +Any * default True + +Num Num numeric equality $_ == $x +Num Junction numeric equality $_ == $x +Str Str string equality $_ eqv $x +Str Junction string equality $_ eqv $x + +HashHash hash keys identical sets $_.keys === $x.keys +HashArray hash value slice truth $_{any(@$x)} +HashJunction hash key
[svn:perl6-synopsis] r13503 - doc/trunk/design/syn
Author: larry Date: Sat Dec 23 18:57:20 2006 New Revision: 13503 Modified: doc/trunk/design/syn/S05.pod Log: removed "is from" in favor of ":= cat" which composes better. Modified: doc/trunk/design/syn/S05.pod == --- doc/trunk/design/syn/S05.pod(original) +++ doc/trunk/design/syn/S05.podSat Dec 23 18:57:20 2006 @@ -14,9 +14,9 @@ Maintainer: Patrick Michaud <[EMAIL PROTECTED]> and Larry Wall <[EMAIL PROTECTED]> Date: 24 Jun 2002 - Last Modified: 18 Oct 2006 + Last Modified: 23 Dec 2006 Number: 5 - Version: 40 + Version: 41 This document summarizes Apocalypse 5, which is about the new regex syntax. We now try to call them I rather than "regular @@ -3024,7 +3024,7 @@ Anything that can be tied to a string can be matched against a regex. This feature is particularly useful with input streams: - my $stream is from($fh); # tie scalar to filehandle + my $stream := cat =$fh; # tie scalar to filehandle # and later...