Call for review: traits, lift
Hi, I've written a few tests for two things that I feel I don't really understand, traits and the `lift' statement prefix. You can find them in t/spec/S14-traits/basic.t t/spec/S04-statements/lift.t I'd appreciate it if you could take a look at them and tell me if they conform to what the spec says. If I understood the specs correctly, variables can be lifted, so you can write sub f (lift $a + $b); { my $a is context = 3; my $b is context = 4; say f(); } (At least STD.pm doesn't complain about this) Is that correct? And if yes, do these variables need to be context variables? Cheers, Moritz
Re: Call for review: traits, lift
Moritz Lenz wrote: sub f (lift $a + $b); I mean 'sub f() { lift $a + $b }', sorry.
r26645 - docs/Perl6/Spec
Author: moritz Date: 2009-05-03 21:17:22 +0200 (Sun, 03 May 2009) New Revision: 26645 Modified: docs/Perl6/Spec/S05-regex.pod Log: [S05] a quantified capture that matches zero times produces a Nil Modified: docs/Perl6/Spec/S05-regex.pod === --- docs/Perl6/Spec/S05-regex.pod 2009-05-03 18:19:33 UTC (rev 26644) +++ docs/Perl6/Spec/S05-regex.pod 2009-05-03 19:17:22 UTC (rev 26645) @@ -2694,7 +2694,7 @@ If a subpattern is directly quantified (using Iany quantifier), it no longer produces a single CMatch object. Instead, it produces a list of CMatch objects corresponding to the sequence of individual matches -made by the repeated subpattern. +made by the repeated subpattern (or a CNil if it matched zero times). =item *
r26647 - docs/Perl6/Spec
Author: moritz Date: 2009-05-03 21:17:38 +0200 (Sun, 03 May 2009) New Revision: 26647 Removed: docs/Perl6/Spec/update docs/Perl6/Spec/update.bat Log: [docs] remove update scripts Those are now unnecessary after the syn documents moved from perl.org to the pugs repo Deleted: docs/Perl6/Spec/update === --- docs/Perl6/Spec/update 2009-05-03 19:17:32 UTC (rev 26646) +++ docs/Perl6/Spec/update 2009-05-03 19:17:38 UTC (rev 26647) @@ -1,89 +0,0 @@ -#!/usr/bin/env perl - -exit; -use strict; -use warnings; - -use FindBin; -use File::Path; - -refresh_specs(); - -sub refresh_specs { -my $BaseURI = 'http://svn.perl.org/perl6/doc/trunk/design/syn'; -my %Spec = qw( -01 Overview 02 Syntax 03 Operator 04 Block -05 Rule 06 Subroutine 09 Structure10 Package -11 Module 12 Object 13 Overload -); -my $naming_rule = sub { S$_[0].pod }; -my $logfile = $FindBin::Bin/.spec-revision; -refresh_specs_from_source($BaseURI, \%Spec, $naming_rule, $logfile); - -my $PugsBaseURI = 'http://svn.pugscode.org/pugs/docs/Perl6/Spec'; -my %SpecInPugs = qw( -17 Concurrency 22 CPAN 26 Documentation 29 Functions -); -$naming_rule = sub { $SpecInPugs{$_[0]}.pod }; -$logfile = $FindBin::Bin/.pugs-spec-revision; -refresh_specs_from_source($PugsBaseURI, \%SpecInPugs, $naming_rule, - $logfile); -} - -sub refresh_specs_from_source { -my ($BaseURI, $Spec, $naming_rule, $logfile) = @_; -my %Spec = %$Spec; - -# okay, we are at author side - refresh Synopses -if (!eval { require LWP; require LWP::Simple; 1 }) { -warn LWP or LWP::Simple not installed: $...@\n; -return; -} - -our $ua; -LWP::Simple-import('$ua'); - -local $| = 1; -print == Refreshing specs from $BaseURI...\n; -$ua-timeout(10); - -my $request = HTTP::Request-new(HEAD = $BaseURI); -my $response = $ua-request($request); - -$response-is_success or return; - -$ua-timeout(60); - -my $etags = $response-header('ETag') or return; -($etags =~ /(\d+)/) or return; - -my $remote_revision = $1; -my $local_revision = -1; - -if ( defined($logfile) and open(my $in, $logfile) ) { -chomp($local_revision = $in); -close $in; -} - -if ($local_revision == $remote_revision) { -print == No changes at $BaseURI.\n; -return; -} - -print == Synchronizing to revision $remote_revision of $BaseURI:\n; - -for my $num (sort keys %Spec) { -my $file = $Spec{$num}; -print $num -- Spec/$file\n; -my $remote_file = $naming_rule-($num); -LWP::Simple::mirror( -$BaseURI/$remote_file = $FindBin::Bin/$file.pod -); -} - -if(defined($logfile)) { -open my $out, $logfile or return; -print $out $remote_revision, \n; -close $out; -} -} Deleted: docs/Perl6/Spec/update.bat === --- docs/Perl6/Spec/update.bat 2009-05-03 19:17:32 UTC (rev 26646) +++ docs/Perl6/Spec/update.bat 2009-05-03 19:17:38 UTC (rev 26647) @@ -1,4 +0,0 @@ -...@echo off - -perl update -pause
r26648 - docs/Perl6/Spec
Author: moritz Date: 2009-05-03 21:17:43 +0200 (Sun, 03 May 2009) New Revision: 26648 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] a few more X... tags Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-05-03 19:17:38 UTC (rev 26647) +++ docs/Perl6/Spec/S04-control.pod 2009-05-03 19:17:43 UTC (rev 26648) @@ -578,6 +578,7 @@ { say $^x } if foo(); =head2 The Cgather statement prefix +XgatherXtake A variant of Cdo is Cgather. Like Cdo, it is followed by a statement or block, and executes it once. Unlike Cdo, it evaluates @@ -645,6 +646,7 @@ happen more than once). =head2 The Clift statement prefix +Xlift When writing generic multi routines you often want to write a bit of code whose meaning is dependent on the context of the caller. It's @@ -679,6 +681,7 @@ lexical scope looks like at run time. That's okay.) =head2 Other Cdo-like forms +Xdo Other similar CCode-only forms may also take bare statements, including Ctry, Ccontend, Casync, and Clazy. These constructs
Re: Docstrings in Perl 6
Hinrik Örn Sigurðsson wrote: I've been thinking lately about how Perl 6 might offer functionality similar to Python's docstrings. That is, documentation which is tied directly to a particular routine, class or module[1]. This is something which would is very useful in a REPL, and for documentation readers[2]. For the latest S26 proposal that I'm (very quietly) working on, I'm considering two possible mechanisms to support tying docs to specific components of a program. The first is an Cis doc trait: method reverse ( Bool $recursive is docReverse any nested LLists too ) is docReturns a copy of the LList with the order of elements reversed. { my @result; for @.list { @result.unshift($_); } return @result; } The second is a generalized Pod comment form: method reverse #={ Returns copy of LList with order of elems reversed. } ( Bool $recursive #={ reverse nested LLists too } ) { my @result; for @.list { @result.unshift($_); } return @result; } Each approach has advantages and disadvantages. Feedback via this forum would be most welcome. Something similar could be done for MODULE, CLASS, GRAMMAR, ROLE, TOKEN, and REGEX. Indeed. And with both of the above alternatives that's also true. One advantage to using Pod blocks in place of actual strings a la Python, is that the documentation is still independent of the source code, and need not be in the same file. That's certainly true of your proposal. However, many might argue that one *disadvantage* of using Pod blocks plus :name that way is that the documentation is independent of the source code, and need not be in the same file. ;-) Damian
r26655 - docs/Perl6/Spec
Author: lwall Date: 2009-05-04 05:36:15 +0200 (Mon, 04 May 2009) New Revision: 26655 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] clarify parsing of statement controls Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-05-04 03:14:22 UTC (rev 26654) +++ docs/Perl6/Spec/S04-control.pod 2009-05-04 03:36:15 UTC (rev 26655) @@ -12,8 +12,8 @@ Maintainer: Larry Wall la...@wall.org Date: 19 Aug 2004 - Last Modified: 19 Apr 2009 - Version: 76 + Last Modified: 3 May 2009 + Version: 77 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -695,6 +695,29 @@ For purposes of flow control, none of these forms are considered loops, but they may easily be applied to a normal loop. +Note that any construct in the statement_prefix category defines +special syntax. If followed by a block it does not parse as a +list operator or even as a prefix unary; it will never look for any +additional expression following the block. In particular, + +foo( try {...}, 2, 3 ) + +calls the Cfoo function with three arguments. And + +do {...} + 1 + +add 1 to the result of the do block. On the other hand, if a +statement_control is followed by a non-block statement, all nested +blockless statement_controls will terminate at the same statement +ending: + +do do do foo(); bar 43; + +is parsed as: + +do { do { do { foo(); }}}; bar(43); + + =head1 Switch statements XgivenXwhenXswitchXcaseXdefault
r26657 - docs/Perl6/Spec
Author: lwall Date: 2009-05-04 05:39:46 +0200 (Mon, 04 May 2009) New Revision: 26657 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] random minor cleanup Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-05-04 03:36:39 UTC (rev 26656) +++ docs/Perl6/Spec/S02-bits.pod2009-05-04 03:39:46 UTC (rev 26657) @@ -1003,7 +1003,7 @@ such as sleep(), may also take CNum arguments, but CInstant arguments must be explicitly created via any of various culturally aware time specification APIs that, by and large, are outside the -CORE of Perl 6, with the possible exception of a constructor taking a +CCORE of Perl 6, with the possible exception of a constructor taking a native TAI value. In numeric context a CDuration happily returns a CNum representing seconds. If pressed for a number, an CInstant will return the length of time in atomic seconds from the TAI epoch, @@ -1778,11 +1778,12 @@ is unspecified and must be searched for according to the nature of what follows. Generally this means that an initial C:: following the main sigil is a no-op on names that are known at compile time, though -C:: can also be used to introduce an interpolation (see below). +C::() can also be used to introduce an interpolation (see below). Also, in the absence of another sigil, C:: can serve as its own sigil indicating intentional use of a not-yet-declared package name. -Unlike in Perl 5, if a sigil is followed by comma, semicolon, colon, +Unlike in Perl 5, if a sigil is followed by comma, semicolon, a colon +not followed by an identifier, or any kind of bracket or whitespace (including Unicode brackets and whitespace), it will be taken to be a sigil without a name rather than a punctuational variable. This allows you to use sigils as coercion
r26658 - docs/Perl6/Spec/S32-setting-library
Author: lwall Date: 2009-05-04 05:42:39 +0200 (Mon, 04 May 2009) New Revision: 26658 Modified: docs/Perl6/Spec/S32-setting-library/Callable.pod docs/Perl6/Spec/S32-setting-library/Containers.pod Log: [Callable] defined defined on Code [Containers] de-List routines that should return Capture instead, like pick [Containers] define :delete and :exists as normative [Containers] explicate (some of) the relationship of junctions to sets Modified: docs/Perl6/Spec/S32-setting-library/Callable.pod === --- docs/Perl6/Spec/S32-setting-library/Callable.pod2009-05-04 03:39:46 UTC (rev 26657) +++ docs/Perl6/Spec/S32-setting-library/Callable.pod2009-05-04 03:42:39 UTC (rev 26658) @@ -10,8 +10,8 @@ Maintainer:Larry Wall la...@wall.org Contributions: Tim Nelson wayl...@wayland.id.au Date: 26 Feb 2009 - Last Modified: 26 Feb 2009 - Version: 1 + Last Modified: 3 May 2009 + Version: 2 The document is a draft. @@ -38,9 +38,17 @@ method Signature signature() {...} method Code assuming(...) {...} method do() {...} # See LS12/Introspection + method Bool defined {...} # XXX What does do() return? I mean, it's a method body, but what's that? } +For CCode, the C.defined method returns whether a body has +been defined. A body consisting only of C..., C!!!, or C??? +(with optional message arguments) does not count as defined. + +To test if a name has been declared, look up the symbol in the +appropriate symbol table. + =head2 Block # Executable objects that have lexical scopes Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod === --- docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-05-04 03:39:46 UTC (rev 26657) +++ docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-05-04 03:42:39 UTC (rev 26658) @@ -15,8 +15,8 @@ Moritz Lenz mor...@faui2k3.org Tim Nelson wayl...@wayland.id.au Date: 19 Feb 2009 extracted from S29-functions.pod - Last Modified: 10 Apr 2009 - Version: 5 + Last Modified: 3 May 2009 + Version: 6 The document is a draft. @@ -190,10 +190,10 @@ =item pick - our List multi method pick ( @values: Int $num = 1, Bool :$repl ) - our List multi method pick ( @values: Whatever, Bool :$repl ) - our List multi pick ( Int $num, Bool :$repl, *...@values ) - our List multi pick ( Whatever, Bool :$repl, *...@values ) + our multi method pick ( @values: Int $num = 1, Bool :$repl ) + our multi method pick ( @values: Whatever, Bool :$repl ) + our multi pick ( Int $num, Bool :$repl, *...@values ) + our multi pick ( Whatever, Bool :$repl, *...@values ) Cpick takes a list or array of values and returns a random selection of elements from the list (without replacement unless @@ -212,6 +212,9 @@ @byte = (0,1).pick(8, :repl); for (1..20).pick(*, :repl) - $die_roll { ... } +Due to the normal semantics of returning a CCapture, a pick of a +single element may be used as an item without requiring C.[0]. + =item join our Str multi method join ( @values: Str $separator = '' ) @@ -274,6 +277,8 @@ } } +Note that strings are now reversed with Cflip. + =item sort our Array multi method sort( @values: *by ) @@ -433,13 +438,16 @@ the end of an Array shorten the length of the Array, unless doing so would violate an Cis shape() definition. -C@indices is interpreted the same way as subscripting is in terms of -slices and multidimensionality. See Synopsis 9 for details. +The interpretation of C@indices is subject to change. +The normal way to delete is by applying a C:delete adverb to +any subscripting operation. Returns the value(s) previously held in deleted locations. -An unary form is expected. See CHash::delete. +=item :delete +This adverb may be applied to any subscripting operation. The operation +returns the elements normally, but reads them out destructively. =item exists @@ -451,9 +459,17 @@ Supplying a different number of indices than invocant has dimensions is an error. -A unary form is expected. See CHash::delete. +The normal way to test for existence is to apply the C:exists +adverb to a subscripting operation. +=item :exists +This adverb may be applied to any subscripting operation. The +operation returns true if specified element exists. If a slice +is specified by the subscript, a CCapture of CBool is returned, +which can be processed using junctions. + + =item pop our Scalar multi method pop ( @array: ) is export @@ -474,7 +490,7 @@ =item splice - our List multi method splice( @array is rw: Int $offset = 0, Int $size?, *...@values ) is export + our multi method splice( @array is rw: Int $offset = 0, Int $size?, *...@values ) is export Csplice fills many niches in array-management, but its fundamental behavior is to remove
r26659 - docs/Perl6/Spec/S32-setting-library
Author: lwall Date: 2009-05-04 05:55:43 +0200 (Mon, 04 May 2009) New Revision: 26659 Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod Log: incomplete plural to singular tranformation on key tests Modified: docs/Perl6/Spec/S32-setting-library/Containers.pod === --- docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-05-04 03:42:39 UTC (rev 26658) +++ docs/Perl6/Spec/S32-setting-library/Containers.pod 2009-05-04 03:55:43 UTC (rev 26659) @@ -537,15 +537,15 @@ =item values - multi method keys ( @array: Matcher $indextests? ) is export - multi method kv ( @array: Matcher $indextests? ) is export - multi method pairs ( @array: Matcher $indextests? ) is export - multi method values ( @array: Matcher $indextests? ) is export + multi method keys ( @array: Matcher $indextest? ) is export + multi method kv ( @array: Matcher $indextest? ) is export + multi method pairs ( @array: Matcher $indextest? ) is export + multi method values ( @array: Matcher $indextest? ) is export Iterates the elements of C@array, in order. -If C$indextests is provided, only elements whose indices match -C$index ~~ @indextests are iterated. (To select on values use Cgrep.) +If C$indextest is provided, only elements whose indices match +C$index ~~ $indextest are iterated. (To select on values use Cgrep.) What is returned at each element of the iteration varies with function. Cvalues returns the value of the associated element; Ckv returns @@ -588,17 +588,17 @@ =item values - multi method keys ( %hash: Matcher $keytests? ) is export - multi method kv ( %hash: Matcher $keytests? ) is export - multi method pairs ( %hash: Matcher $keytests? ) is export - multi method values ( %hash: Matcher $keytests? ) is export + multi method keys ( %hash: Matcher $keytest? ) is export + multi method kv ( %hash: Matcher $keytest? ) is export + multi method pairs ( %hash: Matcher $keytest? ) is export + multi method values ( %hash: Matcher $keytest? ) is export Iterates the elements of C%hash in no apparent order, but the order will be the same between successive calls to these functions, as long as C%hash doesn't change. -If C$keytests is provided, only elements whose keys evaluate -C$key ~~ $keytests as true are iterated. +If C$keytest is provided, only elements whose keys evaluate +C$key ~~ $keytest as true are iterated. What is returned at each element of the iteration varies with function. Ckeys only returns the key; Cvalues the value; Ckv returns both as
r26660 - docs/Perl6/Spec
Author: lwall Date: 2009-05-04 05:57:29 +0200 (Mon, 04 May 2009) New Revision: 26660 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] previous patch confused statement prefixes with statement controls Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-05-04 03:55:43 UTC (rev 26659) +++ docs/Perl6/Spec/S04-control.pod 2009-05-04 03:57:29 UTC (rev 26660) @@ -707,8 +707,8 @@ do {...} + 1 add 1 to the result of the do block. On the other hand, if a -statement_control is followed by a non-block statement, all nested -blockless statement_controls will terminate at the same statement +statement_prefix is followed by a non-block statement, all nested +blockless statement_prefixes will terminate at the same statement ending: do do do foo(); bar 43;
r26662 - docs/Perl6/Spec
Author: lwall Date: 2009-05-04 06:29:35 +0200 (Mon, 04 May 2009) New Revision: 26662 Modified: docs/Perl6/Spec/S14-roles-and-parametric-types.pod Log: [S14] syntax category declarations need symbol in brackets Modified: docs/Perl6/Spec/S14-roles-and-parametric-types.pod === --- docs/Perl6/Spec/S14-roles-and-parametric-types.pod 2009-05-04 04:21:10 UTC (rev 26661) +++ docs/Perl6/Spec/S14-roles-and-parametric-types.pod 2009-05-04 04:29:35 UTC (rev 26662) @@ -11,8 +11,8 @@ Contributions: Tim Nelson wayl...@wayland.id.au Jonathan Worthington jn...@jnthn.net Date: 24 Feb 2009, extracted from S12-objects.pod - Last Modified: 30 Apr 2009 - Version: 4 + Last Modified: 3 May 2009 + Version: 5 =head1 Overview @@ -353,8 +353,8 @@ role xxx { has Int $.xxx; -multi trait_auxiliary:is(xxx $trait, Class $container; $arg?) {...} -multi trait_auxiliary:is(xxx $trait, Any $container; $arg?) {...} +multi trait_auxiliary:is(xxx $trait, Class $container; $arg?) {...} +multi trait_auxiliary:is(xxx $trait, Any $container; $arg?) {...} } Then it can function as a trait. A well-behaved trait handler will say @@ -366,19 +366,19 @@ matching, you can also say: class MyBase { -multi trait_auxiliary:is(MyBase $base, Class $class; $arg?) {...} -multi trait_auxiliary:is(MyBase $tied, Any $container; $arg?) {...} +multi trait_auxiliary:is(MyBase $base, Class $class; $arg?) {...} +multi trait_auxiliary:is(MyBase $tied, Any $container; $arg?) {...} } These capture control if CMyBase wants to capture control of how it gets used by any class or container. But usually you can just let it call the generic defaults: -multi trait_auxiliary:is(Class $base, Class $class; $arg?) {...} +multi trait_auxiliary:is(Class $base, Class $class; $arg?) {...} which adds C$base to the isa list of C$class, or -multi trait_auxiliary:is(Class $tied, Any $container; $arg?) {...} +multi trait_auxiliary:is(Class $tied, Any $container; $arg?) {...} which sets the tie type of the container to the implementation type in C$tied. @@ -389,8 +389,8 @@ auxiliaries. Here's Cwill, which (being syntactic sugar) merely delegates to back to is: -multi sub trait_auxiliary:will($trait, $container; arg) { -trait_auxiliary:is($trait, $container, arg); +multi sub trait_auxiliary:will($trait, $container; arg) { +trait_auxiliary:is($trait, $container, arg); } Other traits are applied with a single word, and we call one of those a @@ -399,7 +399,7 @@ role as { has ReturnType $.as; -multi sub trait_verb:as($container; ReturnType $arg) { +multi sub trait_verb:as($container; ReturnType $arg) { $container does as($arg); } ... @@ -409,7 +409,7 @@ compile-time traits are applied one at a time, like mixin roles. You can, in fact, apply a trait to a container at run time, but if you do, it's just an ordinary mixin role. You have to call the -appropriate Ctrait_auxiliary:is() routine yourself if you want it to +appropriate Ctrait_auxiliary:is() routine yourself if you want it to do any extra shenanigans. The compiler won't call it for you at run time like it would at compile time.