r29144 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 09:39:12 +0100 (Fri, 20 Nov 2009) New Revision: 29144 Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S03-operators.pod docs/Perl6/Spec/S04-control.pod Log: [Specs] more constant cleanups add 'anon' declarator in place of 'my'/'our' misuse Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-20 07:10:40 UTC (rev 29143) +++ docs/Perl6/Spec/S02-bits.pod2009-11-20 08:39:12 UTC (rev 29144) @@ -1492,14 +1492,11 @@ $lay = sub of Egg {...};# of type $lay = sub (--> Egg) {...}; # of type -but you can use a scope modifier to introduce an C prefix type: +but you can use the C scope declarator to introduce an C prefix type: -$lay = my Egg sub {...};# of type -$hat = my Rabbit sub {...}; # of type +$lay = anon Egg sub {...};# of type +$hat = anon Rabbit sub {...}; # of type -Because they are anonymous, you can change the C modifier to C -without affecting the meaning. - The return type may also be specified after a C<< --> >> token within the signature. This doesn't mean exactly the same thing as C. The C type is the "official" return type, and may therefore be Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 07:10:40 UTC (rev 29143) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 08:39:12 UTC (rev 29144) @@ -16,7 +16,7 @@ Created: 8 Mar 2004 Last Modified: 19 Nov 2009 -Version: 177 +Version: 178 =head1 Overview @@ -4273,7 +4273,6 @@ our $foo# lexically scoped alias to package variable has $foo# object attribute state $foo # persistent lexical (cloned with closures) -constant $foo # "our" scoped compile-time constant Variable declarators such as C now take a I as their argument. (The syntax of function signatures is described more fully in S06.) @@ -4282,11 +4281,20 @@ simple declaration that declares a single variable, along with its associated type, traits and the initializer: -constant Dog $foo is woof = 123;# okay: initializes $foo to 123 -constant (Dog $foo is woof = 123); # same thing (with explicit parens) -constant :(Dog $foo is woof = 123); # same thing (full Signature form) -constant (Dog $foo is woof) = 123; # wrong: constants cannot be assigned to +my Dog $foo is woof = 123;# okay: initializes $foo to 123 +my (Dog $foo is woof = 123); # same thing (with explicit parens) +my :(Dog $foo is woof = 123); # same thing (full Signature form) +The C declarator can declare either variables or names +as compile-time constants: + +constant $foo = 1; # compile-time constant variable +constant bar = 2; # compile-time constant symbol + +Because it can declare names in "type" space, the C +declarator may not declare using the signature, which would be +ambiguous. + Each declarator can take an initializer following an equals sign (which should not be confused with a normal assignment, because the timing of the initialization depends on the natural lifetime of the @@ -4315,17 +4323,17 @@ List-context pseudo-assignment is supported for simple declarations but not for signature defaults: -constant @foo = 1,2,3; # okay: initializes @foo to (1,2,3) -constant (@foo = 1,2,3);# wrong: 2 and 3 are not variable names +my @foo = 1,2,3; # okay: initializes @foo to (1,2,3) +my (@foo = 1,2,3);# wrong: 2 and 3 are not variable names When parentheses are omitted, you may use any infix assignment operator instead of C<=> as the initializer. In that case, the left hand side of the infix operator will be the variable's prototype object: -constant Dog $fido .= new; # okay: a constant Dog object -constant Dog $fido = Dog.new; # same thing -constant Dog $fido = $fido.new; # wrong: invalid self-reference -constant (Dog $fido .= new);# wrong: cannot use .= with parens +my Dog $fido .= new; # okay: a constant Dog object +my Dog $fido = Dog.new; # same thing +my Dog $fido = $fido.new; # wrong: invalid self-reference +my (Dog $fido .= new);# wrong: cannot use .= inside signature Note that very few mutating operators make sense on a type object, however, since type objects are a kind of undefined object. (Those operators with @@ -4396,6 +4404,8 @@ class Foo role Foo subset Foo +enum Foo +constant Foo and code declarators: @@ -4412,6 +4422,17 @@ These all have their uses and are explained in subsequent Synopses. +Note that since C is parsed as a type declarator (essentially +declaring a type with a single value), it can actually take a scope +declarator in front: + +my constant companion = '
Re: "deprecated" (was Re: r29143 ...)
On Thu, Nov 19, 2009 at 11:22:17PM -0800, Darren Duncan wrote: > pugs-comm...@feather.perl6.nl wrote: >> @@ -1020,22 +1018,17 @@ >> C<< prefix: >> >> -Coerces to type C. Floor semantics are used for fractional >> -values, including strings that appear to express fractional values. >> -That is, C must have the same result as C in all >> -cases. All implicit conversions to integer use the same semantics. >> +Deprecated, use the C coercion or the C function. > > Why would the Perl 6 spec contain anything deprecated rather than simply > not having it at all? Only because it was already implemented in earlier versions of Perl 6, and someone might look it up here. > Or do you mean "deprecated" as in the parser will explicitly recognize it > and die with a helpful error message, such as it does for Perl 5's "=~" > to catch brainos? Nope, that'll tend to either work anyway with int() or fail with two terms in a row for int $x. It might be worth a special message I suppose. > If you mean the latter, is there some central place (say in Synopsis 2) > that talks about this, such as in a "terminology" section? "When the > Perl 6 spec uses the word ... it means ..." You must think I'm writing a *real* spec. :) Larry
Re: "deprecated" (was Re: r29143 ...)
Larry Wall wrote: On Thu, Nov 19, 2009 at 11:22:17PM -0800, Darren Duncan wrote: pugs-comm...@feather.perl6.nl wrote: @@ -1020,22 +1018,17 @@ C<< prefix: >> -Coerces to type C. Floor semantics are used for fractional -values, including strings that appear to express fractional values. -That is, C must have the same result as C in all -cases. All implicit conversions to integer use the same semantics. +Deprecated, use the C coercion or the C function. Why would the Perl 6 spec contain anything deprecated rather than simply not having it at all? Only because it was already implemented in earlier versions of Perl 6, and someone might look it up here. Maybe it would be a good idea to add a file to the Perl 6 spec to collect things like this. The file would list features that the Perl 6 spec once had but no longer does *and* were supported by at least one Perl 6 implementation. Mention of these things can be omitted from all the other Perl 6 spec files. And so people still have somewhere to look for the question "where did that go?". Generally I'm a believer in having details relevant to the current version of a project be the only ones in the main files, and have details relevant only to past versions of the project that no longer exist be shunted to separate files. As for future plans, those also maybe should be separate but there are better excuses to sometimes make mention of them in the main files too, since in effect they are part of the current version that just haven't been fleshed out yet. -- Darren Duncan
Re: r29129 - docs/Perl6/Spec
pugs-comm...@feather.perl6.nl wrote: Author: lwall Date: 2009-11-19 05:34:29 +0100 (Thu, 19 Nov 2009) New Revision: 29129 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] as several folks have suggested, rename "blorst" to "blast" I'm curious about this change. I quickly figured out that "blorst" was derived from "BLock OR STatement" (quoting the previous rev: "In fact, most of these phasers will take either a block or a statement (known as a I in the vernacular)). The best that I can figure for "blast" is "BLock And STatement", which seems to me like a less-descriptive name. And "blast" is less likely to google up the results I need. So, what exactly _is_ the derivation of "blast"? =thom
Re: r29144 - docs/Perl6/Spec
Hello! On Fri, Nov 20, 2009 at 09:39:13AM +0100, pugs-comm...@feather.perl6.nl wrote: > -constant Dog $fido .= new; # okay: a constant Dog object > -constant Dog $fido = Dog.new; # same thing > -constant Dog $fido = $fido.new; # wrong: invalid self-reference > -constant (Dog $fido .= new);# wrong: cannot use .= with parens > +my Dog $fido .= new; # okay: a constant Dog object > +my Dog $fido = Dog.new; # same thing > +my Dog $fido = $fido.new; # wrong: invalid self-reference > +my (Dog $fido .= new);# wrong: cannot use .= inside signature s/constant Dog/Dog/? Or am I missing something? -Edwin
r29145 - docs/Perl6/Spec/S32-setting-library
Author: masak Date: 2009-11-20 14:15:01 +0100 (Fri, 20 Nov 2009) New Revision: 29145 Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod Log: [S32/Containers] fixed copy/paste error Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod === --- docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 08:39:12 UTC (rev 29144) +++ docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 13:15:01 UTC (rev 29145) @@ -830,8 +830,10 @@ A set of unique values. When used as a hash always treats the set's values as the keys of the hash, returning C for set elements. See C for a container that can represent different sets -as keys are added or deleted. +as keys are added or deleted. A C responds to hash operators as +if it were a C. + =over =item pick @@ -839,11 +841,7 @@ our multi method pick ( $set: Int $num = 1, Bool :$replace ) our multi method pick ( $set: Whatever, Bool :$replace ) -Like an ordinary list pick, but returns keys of the bag weighted by -values, as if the keys were replicated the number of times indicated -by the corresponding value and then list pick used. C is the -mutable form of C. A C responds to hash operators as -if it were a C. +Works like an ordinaty list C. =back
r29148 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 16:53:45 +0100 (Fri, 20 Nov 2009) New Revision: 29148 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] fix fossil found by edwin.steiner++ nail down that constants are still constants Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 15:41:57 UTC (rev 29147) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 15:53:45 UTC (rev 29148) @@ -15,7 +15,7 @@ Created: 8 Mar 2004 -Last Modified: 19 Nov 2009 +Last Modified: 20 Nov 2009 Version: 178 =head1 Overview @@ -4330,7 +4330,7 @@ instead of C<=> as the initializer. In that case, the left hand side of the infix operator will be the variable's prototype object: -my Dog $fido .= new; # okay: a constant Dog object +my Dog $fido .= new; # okay: a Dog object my Dog $fido = Dog.new; # same thing my Dog $fido = $fido.new; # wrong: invalid self-reference my (Dog $fido .= new);# wrong: cannot use .= inside signature @@ -4428,11 +4428,20 @@ my constant companion = 'Fido'; has constant $.pi = 22/7; -state constant $latch = snapshot(); +state constant $latch = snapshot(); # careful with this! -In these cases the explicit scoping determines when the initializer is -evaluated. +However, the constant declarator is intended to create values the +compiler can inline, so it always evaluates its value at BEGIN time. +Thus, while the extra scope declarator may say where the value is +stored and when that storage is initialized, it cannot change the value +of that from instance to instance. In general, if you want something +that doesn't vary over the nomral lifetime of a scope declarator, +initialize it to a readonly value using C<::=> rather than declaring +it as a constant. Then each time the scope declarator is used, +it can initialize to a different readonly value: +state $latch ::= snapshot(); # each clone gets its own value of $latch + =head1 Argument List Interpolating Perl 5 forced interpolation of a function's argument list by use of
r29149 - docs/Perl6/Spec/S32-setting-library
Author: lwall Date: 2009-11-20 17:06:23 +0100 (Fri, 20 Nov 2009) New Revision: 29149 Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod Log: [S32/Containers] minor typos Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod === --- docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 15:53:45 UTC (rev 29148) +++ docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 16:06:23 UTC (rev 29149) @@ -694,11 +694,12 @@ =item push - our Int multi method push ( @hash: *...@values ) is export + our Hash multi method push ( @hash: *...@values ) is export Like hash assignment insofar as it accepts either C objects or -alternating keys and values; however, unlike assignment, when -a duplicate key is detected, coerces the colliding entry's value to an +alternating keys and values; also like in that it returns the new hash; +However, unlike assignment, when a duplicate key is detected, +C coerces the colliding entry's value to an array and pushes the Pair's value onto that array. Hence to invert a hash containing duplicate values without losing (associative) information, say: @@ -841,7 +842,7 @@ our multi method pick ( $set: Int $num = 1, Bool :$replace ) our multi method pick ( $set: Whatever, Bool :$replace ) -Works like an ordinaty list C. +Works like an ordinary list C. =back @@ -860,7 +861,7 @@ our multi method pick ( $bag: Int $num = 1, Bool :$replace ) our multi method pick ( $bag: Whatever, Bool :$replace ) -Like an ordinary list pick, but returns keys of the bag weighted by +Like an ordinary list C, but returns keys of the bag weighted by values, as if the keys were replicated the number of times indicated by the corresponding value and then list pick used. C is the mutable form of C. A C responds to hash operators as
r29150 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 17:19:09 +0100 (Fri, 20 Nov 2009) New Revision: 29150 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] typo Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 16:06:23 UTC (rev 29149) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 16:19:09 UTC (rev 29150) @@ -4435,7 +4435,7 @@ Thus, while the extra scope declarator may say where the value is stored and when that storage is initialized, it cannot change the value of that from instance to instance. In general, if you want something -that doesn't vary over the nomral lifetime of a scope declarator, +that doesn't vary over the normal lifetime of a scope declarator, initialize it to a readonly value using C<::=> rather than declaring it as a constant. Then each time the scope declarator is used, it can initialize to a different readonly value:
r29151 - docs/Perl6/Spec/S32-setting-library
Author: lwall Date: 2009-11-20 17:21:42 +0100 (Fri, 20 Nov 2009) New Revision: 29151 Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod Log: [S32/Containers] typo Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod === --- docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 16:19:09 UTC (rev 29150) +++ docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-11-20 16:21:42 UTC (rev 29151) @@ -697,7 +697,7 @@ our Hash multi method push ( @hash: *...@values ) is export Like hash assignment insofar as it accepts either C objects or -alternating keys and values; also like in that it returns the new hash; +alternating keys and values; also like in that it returns the new hash. However, unlike assignment, when a duplicate key is detected, C coerces the colliding entry's value to an array and pushes the Pair's value onto that array. Hence to invert
r29153 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 18:43:16 +0100 (Fri, 20 Nov 2009) New Revision: 29153 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] add infix: to match infix:, suggested by TheDamian++ Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 17:25:59 UTC (rev 29152) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 17:43:16 UTC (rev 29153) @@ -16,7 +16,7 @@ Created: 8 Mar 2004 Last Modified: 20 Nov 2009 -Version: 178 +Version: 179 =head1 Overview @@ -963,12 +963,12 @@ C<< infix:<&> >>, but with left-to-right evaluation guaranteed, for use in guarded patterns: -$target ~~ MyType also .mytest1 also .mytest2 +$target ~~ MyType also *.mytest1 also *.mytest2 This is useful when later tests might throw exceptions if earlier tests don't pass. This cannot be guaranteed by: -$target ~~ MyType & .mytest1 & .mytest2 +$target ~~ MyType & *.mytest1 & *.mytest2 =back @@ -984,6 +984,24 @@ =item * +C<< infix: >>, short-circuit junctional or operator + +EXPR else EXPR else EXPR ... + +Can be used to construct ORed patterns with the same semantics as +C<< infix:<|> >>, but with left-to-right evaluation guaranteed, for use +in guarded patterns where the left argument is much more easily +falsifiable than the right: + +$target ~~ *.mycheaptest else *.myexpensivetest + +This is also useful when you want to perform tests in order +of safety: + +$target ~~ MyType else *.mysafetest else *.mydangeroustest + +=item * + C<< infix:<^> >>, one() operator $a ^ $b ^ $c ...
r29155 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 21:13:08 +0100 (Fri, 20 Nov 2009) New Revision: 29155 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] destroy two low-powered, obscure, short-circuiting operators in favor of one high-powered, obscure-but-transparent, S metaoperator Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 17:56:13 UTC (rev 29154) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 20:13:08 UTC (rev 29155) @@ -16,7 +16,7 @@ Created: 8 Mar 2004 Last Modified: 20 Nov 2009 -Version: 179 +Version: 180 =head1 Overview @@ -40,7 +40,7 @@ L Additive + - +| +^ ~| ~^ ?| ?^ L Replication x xx X Concatenation ~ -X Junctive and & also +X Junctive and & X Junctive or | ^ L Named unary sleep abs sin temp let N Structural infix but does <=> leg cmp .. ..^ ^.. ^..^ @@ -953,17 +953,14 @@ $a & $b & $c ... -=item * - -C<< infix: >>, short-circuit junctional and operator - -EXPR also EXPR also EXPR ... - -Can be used to construct ANDed patterns with the same semantics as -C<< infix:<&> >>, but with left-to-right evaluation guaranteed, for use +By default junctions are allowed to reorder the comparisons in any +order that makes sense to the optimizer. To suppress this, use +the C metaoperator for force sequential evaluation, which will +construct a list of ANDed patterns with the same semantics as C<< +infix:<&> >>, but with left-to-right evaluation guaranteed, for use in guarded patterns: -$target ~~ MyType also *.mytest1 also *.mytest2 +$target ~~ MyType S& *.mytest1 S& *.mytest2 This is useful when later tests might throw exceptions if earlier tests don't pass. This cannot be guaranteed by: @@ -984,21 +981,20 @@ =item * -C<< infix: >>, short-circuit junctional or operator - -EXPR else EXPR else EXPR ... - -Can be used to construct ORed patterns with the same semantics as -C<< infix:<|> >>, but with left-to-right evaluation guaranteed, for use -in guarded patterns where the left argument is much more easily +By default junctions are allowed to reorder the comparisons in +any order that makes sense to the optimizer. To suppress this, +use the C metaoperator for force sequential evaluation, which +will construct a list of ORed patterns with the same semantics as +C<< infix:<|> >>, but with left-to-right evaluation guaranteed, for +use in guarded patterns where the left argument is much more easily falsifiable than the right: -$target ~~ *.mycheaptest else *.myexpensivetest +$target ~~ *.mycheaptest S| *.myexpensivetest This is also useful when you want to perform tests in order of safety: -$target ~~ MyType else *.mysafetest else *.mydangeroustest +$target ~~ MyType S| *.mysafetest S| *.mydangeroustest =item * @@ -1006,6 +1002,9 @@ $a ^ $b ^ $c ... +The C variant guarantees left-to-right evaluation, and in boolean +context short-circuits to false if it sees a second match. + =back =head2 Named unary precedence @@ -3640,7 +3639,7 @@ operators yourself. Similarly, the carets that exclude the endpoints on ranges are there by convention only. -In contrast to that, Perl 6 has six standard metaoperators for +In contrast to that, Perl 6 has seven standard metaoperators for turning a given existing operator into a related operator that is more powerful (or at least differently powerful). These differ from a mere naming convention in that Perl automatically generates these new @@ -4252,6 +4251,35 @@ Multidimensional lists should be handled properly. +=head2 Sequential operators + +The sequence metaoperator, C, may be followed by any non-fiddly infix operator. +It suppresses any explicit or implicit parallelism, and prevents the optimizer +from reordering the operand evaluations. The 'S' can be thought of as standing +for Sequential, Serial, Synchronous, Short-circuit, Single-thread, and Safe. +Among other things. In particular, we can have: + +a S& b S& c short-circuited AND junction +a S| b S| c short-circuited OR junction +a S^ b S^ c short-circuited XOR junction +a S»op« b single-threaded hyperop +a SX* b single-threaded X* +a SX[*] b single-threaded X* +a S[X*] b single-threaded X* +a S+ b suppress arg reordering by ignorant optimizer + +This metaoperator has the same precedence and associativity as its base operator. +The compiler is free to discard any C metaoperator that is provably redundant, +such as the one in C. The compiler is free to intuit an C on any +operator involving known volatile operands where that does not otherwise +change the semantics of the operator. + +Conjectural: since metaoperators are notionally applied from inside to outside, +serializing a reversed opera
r29157 - docs/Perl6/Spec
Author: lwall Date: 2009-11-20 21:19:44 +0100 (Fri, 20 Nov 2009) New Revision: 29157 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] tweaks, add conjectural RSR case Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-11-20 20:16:12 UTC (rev 29156) +++ docs/Perl6/Spec/S03-operators.pod 2009-11-20 20:19:44 UTC (rev 29157) @@ -4274,12 +4274,16 @@ operator involving known volatile operands where that does not otherwise change the semantics of the operator. -Conjectural: since metaoperators are notionally applied from inside to outside, -serializing a reversed operator depends on the order of the metaoperators: +[Conjectural: since metaoperators are notionally applied from inside +to outside, the semantics of serializing and reversing depends on +the order of the metaoperators: a SR/ b evaluates b, then a, then does b/a a RS/ b evaluates a, then b, then does b/a +a RSR/ bevaluates b, then a, then does a/b +...maybe. Can argue it all the other way too...] + =head2 Nesting of metaoperators Any ordinary infix operator may be enclosed in square brackets @@ -4300,7 +4304,7 @@ This is convenient for function application: 1,1 ... &[+] # fibonacci series -sort &[Rleg], @list # reverse sort as strings +sort &[Rleg], @list# reverse sort as strings The C<&[op]> form always refers to a binary function of the operator, even if it is underlyingly defined as a variadic list-associative operator.