Re: [svn:perl6-synopsis] r10758 - doc/trunk/design/syn
On Thu, Aug 10, 2006 at 01:17:45PM +0800, Agent Zhang wrote: : On 8/10/06, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: : @@ -1339,8 +1339,8 @@ : : =head2 Undefined types : : -These can behave as values or objects of any class, but always return : -a C.valid that evaluates to false. One can create them with the : +These can behave as values or objects of any class, except that : +Cdefined always returns false. One can create them with the : built-in Cundef and Cfail functions. (See S02 for how failures : are handled.) : : s/Cdefined /C.defined/ I left out the dot on purpose since it's defined($x) as well as $x.defined. Larry
Re: [svn:perl6-synopsis] r10758 - doc/trunk/design/syn
[EMAIL PROTECTED] writes: Modified: doc/trunk/design/syn/S02.pod +Some object types can behave as value types. Every object can produce +a safe key identifier (CSKID for short) that uniquely identifies the +object for hashing and other value-base comparisons. Normal objects Is that meant to say value-based? -- Aaron Crane
[svn:perl6-synopsis] r10780 - doc/trunk/design/syn
Author: audreyt Date: Thu Aug 10 09:16:15 2006 New Revision: 10780 Modified: doc/trunk/design/syn/S02.pod Log: * S02: Add a infix_prefix_meta_operator grammatical category to carry the generic chain-associative negation modifier !. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podThu Aug 10 09:16:15 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 10 Aug 2004 - Last Modified: 9 Aug 2006 + Last Modified: 10 Aug 2006 Number: 2 - Version: 61 + Version: 62 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -2215,6 +2215,7 @@ scope_declarator:has has $.x; statement_control:if if $condition {...} else {...} statement_modifier:if ... if $condition +infix_prefix_meta_operator:! $x !~~ 2; infix_postfix_meta_operator:= $x += 2; postfix_prefix_meta_operator:{'»'} @array »++ prefix_postfix_meta_operator:{'«'} -« @magnitudes
Re: underscores in the core lib
I think .valid is an excellent argument for underscores all by itself. Unless you already know what it means you don't have any clue that its not actualy the word valid instead of val_id. I don't know of any other problems like this, but at very least that should be changed. Don't we still try and follow the rule of least surprise!! ? I was realy surprised to find out that valid was value_id, especialy since the last reference I saw to it was along side defined, undefined, etc, so I assumed it was related to that. /me scratches his noggin. I don't have any other arguments for _, but it would be interesting to hear the reasoning agianst it. The builtin versus userdefined is getting realy blury in p6 anyway so it seems weird to use this as a way to define it, after all it's not like all user functions WILL have _ in there name. On 8/6/06, Ashley Winters [EMAIL PROTECTED] wrote: On 8/6/06, Yuval Kogman [EMAIL PROTECTED] wrote: Hi, Audrey mentioned that Perl 6 is trying to avoid underscores in the core library. It came up when I asked why valid isn't called value_id because if ( $user_input.valid ) { } reads fairly confusingly. So, a few questions: 1. what is the official naming style for the Pelr 6 standard library (not just functions, but methods for core objects, the MOP, the compiler toolchain, the truely absolutely core modules, etc). 2. What is bad about underscores? From what I know most people tend to think that $object.do_that_action is the clearest way of naming methods, and the technical reasons to avoid these (long symbol names, lots of typing) are no longer really valid nowadays (with editor autocompletion, etc). Nothing is wrong with underscores. In fact, under_scores and camelCase/StudlyCaps should be encouraged Iin user code. When you see function_name() or functionName() or _functionname(), it should be obvious to any Perl programmer that it's *not* a standard Perl function -- it's a user/module function. When you see SCARYCAPS, you should expect out-of-band implicit (action-at-a-distance) behaviour from whatever code it in it. Think of underscores and caps as a form of twigil. $scalar, @array, %hash, sub, _internal, userFunction, user_function, RefugeeWindowsProgrammer, Let_There_Be_Poetry, MAGIC, UNAUTHORIZED_USER_MAGIC. And, just like $scalars can hold arrays, somesub could be a standard function or a user function (or a standard function which a user reimplemented -- you never know). - Ashley Winters -- -- __ Eric Hodges
[svn:perl6-synopsis] r10782 - doc/trunk/design/syn
Author: audreyt Date: Thu Aug 10 09:35:52 2006 New Revision: 10782 Modified: doc/trunk/design/syn/S04.pod Log: * S04: Clarify that the following forms are hash composers: $h = {}; $h = {%h}; * Also change the archaic $coderef etc in examples to simply $code. Modified: doc/trunk/design/syn/S04.pod == --- doc/trunk/design/syn/S04.pod(original) +++ doc/trunk/design/syn/S04.podThu Aug 10 09:35:52 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 19 Aug 2004 - Last Modified: 9 Aug 2006 + Last Modified: 11 Aug 2006 Number: 4 - Version: 32 + Version: 33 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -741,30 +741,34 @@ operator is expected. (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 -appears to delimit nothing but a comma-separated list starting with -a pair (counting a single pair as a list of one element), the closure -will be immediately executed as a hash composer. - -$hashref = { a = 1 }; -$hashref = { a = 1, $b, $c, %stuff, @nonsense }; - -$coderef = { a, 1 }; -$coderef = { a = 1, $b, $c == print }; +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 +nothing but a comma-separated list starting with a pair or a hash (counting +a single pair or hash as a list of one element), the closure will be +immediately executed as a hash composer. + +$hash = { }; +$hash = { %stuff }; +$hash = { a = 1 }; +$hash = { a = 1, $b, $c, %stuff, @nonsense }; + +$code = { ; }; +$code = { @stuff }; +$code = { a, 1 }; +$code = { a = 1, $b, $c == print }; If you wish to be less ambiguous, the Chash list operator will explicitly evaluate a list and compose a hash of the returned value, while Csub introduces an anonymous subroutine: -$coderef = sub { a = 1 }; -$hashref = hash(a = 1); -$hashref = hash(a, 1); +$code = sub { a = 1 }; +$hash = hash(a = 1); +$hash = hash(a, 1); If a closure is the right argument of the dot operator, the closure is interpreted as a hash subscript. -$ref = {$x}; # closure because term expected +$code = {$x}; # closure because term expected if $term{$x} # subscript because postfix expected if $term {$x} # expression followed by statement block if $term.{$x} # valid subscript with dot @@ -772,7 +776,7 @@ Similar rules apply to array subscripts: -$ref = [$x]; # array composer because term expected +$array = [$x]; # array composer because term expected if $term[$x] # subscript because postfix expected if $term [$x] # syntax error (two terms in a row) if $term.[$x] # valid subscript with dot @@ -780,7 +784,7 @@ And to the parentheses delimiting function arguments: -$ref = ($x); # grouping parens because term expected +$scalar = ($x);# grouping parens because term expected if $term($x) # function call because operator expected if $term ($x) # syntax error (two terms in a row) if $term.($x) # valid function call with dot @@ -889,7 +893,7 @@ my $x = 1; my sub bar { print $x } # not cloned yet my baz = { bar(); print $x }; # cloned immediately - my $barref = bar; # now bar is cloned + my $code = bar;# now bar is cloned return baz; }
[svn:perl6-synopsis] r10783 - doc/trunk/design/syn
Author: audreyt Date: Thu Aug 10 09:40:48 2006 New Revision: 10783 Modified: doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S06.pod Log: * S03: Signature ~~ Signature now tests for compatibility, i.e. whether if anything that can bind to LHS can also bind to RHS. * S06: The want function now returns a Signature object, instead of a Context object with vaguely defined pseudo-class methods. This also unifies the calling convention with the returning convention. Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podThu Aug 10 09:40:48 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 8 Mar 2004 - Last Modified: 9 Aug 2006 + Last Modified: 11 Aug 2006 Number: 3 - Version: 54 + Version: 55 =head1 Changes to Perl 5 operators @@ -562,7 +562,9 @@ Num NumRange in numeric range match if $min = $_ = $max Str StrRange in string range match if $min le $_ le $max Capture Signature parameter bindingmatch if $cap can bind to $sig -Any Code:()simple closure truth*match if $x() (ignoring $_) +CodeSignature signature compatibility* match if $_ is a subset of $x + Signature Signature signature compatibility match if $_ is a subset of $x +Any Code:() simple closure truth*match if $x() (ignoring $_) Any Class class membership match if $_.does($x) Any Role role playing match if $_.does($x) Any Num numeric equality match if $_ == $x Modified: doc/trunk/design/syn/S06.pod == --- doc/trunk/design/syn/S06.pod(original) +++ doc/trunk/design/syn/S06.podThu Aug 10 09:40:48 2006 @@ -1763,6 +1763,10 @@ Specifies that the parameter cannot be modified (e.g. assigned to, incremented). It is the default for parameters. +$x = 5; + +sub f ($x) {} + =item Cis rw Specifies that the parameter can be modified (assigned to, incremented, @@ -1880,35 +1884,35 @@ =head2 The Cwant function -The Cwant function returns an object that contains information about -the context in which the current block, closure, or subroutine was +The Cwant function returns a CSignature object that contains information +about the context in which the current block, closure, or subroutine was called. -The returned context object is typically tested with a smart match (C~~) -or a Cwhen: +As with normal function signatures, you can test the result of Cwant with a +smart match (C~~) or a Cwhen: given want { -when Scalar {...} # called in scalar context -when List {...} # called in list context -when Lvalue {...} # expected to return an lvalue -when 2 {...} # expected to return two values +when :($) {...} # called in scalar context +when :(*@) {...} # called in list context +when :($ is rw) {...} # expected to return an lvalue +when :($,$) {...} # expected to return two values ... } -or has the corresponding methods called on it: +You can also use the postfix signature syntax to test for compatibility: + +ifwant:($) {...} # called in scalar context +elsif want:(*@) {...} # called in list context +elsif want:($ is rw) {...} # expected to return an lvalue +elsif want:($,$) {...} # expected to return two values + +The C.arity method also works here: -if(want.Scalar){...}# called in scalar context -elsif (want.List) {...}# called in list context -elsif (want.rw){...}# expected to return an lvalue -elsif (want.count 2) {...}# expected to return more than two values - -Note these are pseudo type associations. There's no such thing as an -Lvalue object, and a List is really an unbound argument list object, -parts of which may in fact be eventually bound into scalar context. +if want.arity 2{...} # expected to return more than two values =head2 The Cleave function -A Creturn statement causes the innermost surrounding subroutine, +A Creturn call causes the innermost surrounding subroutine, method, rule, token, regex (as a keyword), macro, or multimethod to return. Only declarations with an explicit keyword such as sub may be returned from. You may not return from a quotelike operator such
Re: underscores in the core lib
Eric skribis 2006-08-10 10:22 (-0600): I think .valid is an excellent argument for underscores all by itself. I think it's an argument for reconsidering the name of that method. valueid is only 2 characters more. I'm personally against non-prefix underscores in any core identifier. I agree that valid to mean value ID is a bad idea, though. It's extremely ambiguous. I don't have any other arguments for _, but it would be interesting to hear the reasoning agianst it. Forbidden underscore encourages the designers to think much harder about the best name, because it automatically rules out things like valid if you stick to sanity. It may be so that value ID itself is a bad name. Also, having_underscores leads_to longer_names, in my experience. Longer names are great for my own code, but I want core stuff to be consise and short. On 8/6/06, Ashley Winters [EMAIL PROTECTED] wrote: On 8/6/06, Yuval Kogman [EMAIL PROTECTED] wrote: Please do not answer above the quote. Regards, Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: underscores in the core lib
On Thu, Aug 10, 2006 at 07:02:13PM +0200, Juerd wrote: : Eric skribis 2006-08-10 10:22 (-0600): : I think .valid is an excellent argument for underscores all by itself. : : I think it's an argument for reconsidering the name of that method. : valueid is only 2 characters more. Okay, I'll just hop in my DeLorean and fix .valid yesterday. (Will probably leave some SKID marks though...) : I'm personally against non-prefix underscores in any core identifier. Yes, it's a design smell. The point of core is to huffman code common things, so something in core with _ should normally either be shorter or out of the core. Larry
[svn:perl6-synopsis] r10804 - doc/trunk/design/syn
Author: larry Date: Thu Aug 10 17:11:54 2006 New Revision: 10804 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S06.pod Log: First whack at defining semantics of MAIN subs. Typo from Aaron Crane++. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podThu Aug 10 17:11:54 2006 @@ -440,7 +440,7 @@ Some object types can behave as value types. Every object can produce a safe key identifier (CSKID for short) that uniquely identifies the -object for hashing and other value-base comparisons. Normal objects +object for hashing and other value-bases comparisons. Normal objects just use their address in memory, but if a class wishes to behave as a value type, it can define a C.SKID method that makes different objects look like the same object if they happen to have the same contents. Modified: doc/trunk/design/syn/S06.pod == --- doc/trunk/design/syn/S06.pod(original) +++ doc/trunk/design/syn/S06.podThu Aug 10 17:11:54 2006 @@ -13,9 +13,9 @@ Maintainer: Larry Wall [EMAIL PROTECTED] Date: 21 Mar 2003 - Last Modified: 9 Aug 2006 + Last Modified: 10 Aug 2006 Number: 6 - Version: 45 + Version: 46 This document summarizes Apocalypse 6, which covers subroutines and the @@ -1326,6 +1326,8 @@ =head2 Native types +[This stuff belongs in S02.] + Values with these types autobox to their uppercase counterparts when you treat them as objects: @@ -1912,31 +1914,36 @@ =head2 The Cleave function -A Creturn call causes the innermost surrounding subroutine, -method, rule, token, regex (as a keyword), macro, or multimethod -to return. Only declarations with an explicit keyword such as sub -may be returned from. You may not return from a quotelike operator such -as Crx//. +As mentioned above, a Creturn call causes the innermost +surrounding subroutine, method, rule, token, regex (as a keyword), +macro, or multimethod to return. Only declarations with an explicit +keyword such as sub may be returned from. You may not return from +a quotelike operator such as Crx//. + +To return from other types of code structures, the Cleave function +is used. The first argument, if supplied, specifies a CSelector +for the control structure to leave. The CSelector and will be +smart-matched against the dynamic scope objects from inner to outer. +The first that matches is the scope that is left. -To return from other types of code structures, the Cleave function is used: +The remainder of the arguments are taken to be a Capture holding the +return values. leave; # return from innermost block of any kind +leave *;# same thing leave Method; # return from innermost calling method -leave ?ROUTINE == 1,2,3; # Return from current sub. Same as: return 1,2,3 -leave foo == 1,2,3; # Return from innermost surrounding call to foo -leave Loop where { .label eq 'COUNT' }; # Same as: last COUNT; +leave ?ROUTINE, 1,2,3; # Return from current sub. Same as: return 1,2,3 +leave ?ROUTINE == 1,2,3; # same thing, force return as feed +leave foo, 1,2,3; # Return from innermost surrounding call to foo -Note that the last is equivalent to +Note that these are equivalent: +leave Loop where { .label eq 'COUNT' }; last COUNT; and, in fact, you can return a final loop value that way: -last COUNT == 42; - -If supplied, the first argument to Cleave is a CSelector, and will -be smart-matched against the dynamic scope objects from inner to outer. -The first that matches is the scope that is left. +last COUNT, 42; =head2 Temporization @@ -2384,3 +2391,101 @@ C OUTER::$varname specifies the C$varname declared in the lexical scope surrounding the current lexical scope (i.e. the scope in which the current block was defined). + +=head2 Declaring a CMAIN subroutine + +Ordinarily a top-level Perl script just evaluates its anonymous +mainline code and exits. During the mainline code, the program's +arguments are available in raw form from the C@ARGS array. At the end of +the mainline code, however, a CMAIN subroutine will be called with +whatever command-line arguments remain in C@ARGS. This call is +performed if and only if: + +=over + +=item a) + +the compilation unit was directly invoked rather than +by being required by another compilation unit, and + +=item b) + +the compilation unit declares a CRoutine named CMAIN, and + +=item c) + +no explicit call to CMAIN was performed by the time the mainline code +finishes. + +=back + +The command line arguments (or what's left of them after mainline +processing) is magically converted into a CCapture and passed to +CMAIN as its arguments, so switches may be bound as named
Re: [svn:perl6-synopsis] r10804 - doc/trunk/design/syn
At 5:11 PM -0700 8/10/06, [EMAIL PROTECTED] wrote: Log: First whack at defining semantics of MAIN subs. Congradulations! That is SUCH a great idea. Since Perl didn't have the concept of an explicit 'main' before like many other languages, I had been doing this for a long while in my non-tiny Perl programs, to make code easier to read, more consistent, and properly isolate conceptual lexicals from conceptual globals|constants: # 'use' statements # declare constants main(); sub main { ... } sub other { ... } # etc Or alternately I did: # 'use' statements # declare constants MAIN: { ... } sub other { ... } # etc And now there is a MAIN() that implicitly gets called, so no more main(); invoke or MAIN: anonymous block. One great thing that somehow I never thought to ask for. And of course, the actual implementation is a lot better, with all the various command-line options|args being mapped to normal Perl 6 args in an easy to understand and powerful way. The default USAGE() sub was a great idea too. I am SO going to use this. -- Darren Duncan
[svn:perl6-synopsis] r10805 - doc/trunk/design/syn
Author: audreyt Date: Thu Aug 10 19:18:48 2006 New Revision: 10805 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S03.pod Log: * Two small typo fix: value-bases comparison - value-based comparison Storeable - Storable Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podThu Aug 10 19:18:48 2006 @@ -440,7 +440,7 @@ Some object types can behave as value types. Every object can produce a safe key identifier (CSKID for short) that uniquely identifies the -object for hashing and other value-bases comparisons. Normal objects +object for hashing and other value-based comparisons. Normal objects just use their address in memory, but if a class wishes to behave as a value type, it can define a C.SKID method that makes different objects look like the same object if they happen to have the same contents. Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podThu Aug 10 19:18:48 2006 @@ -584,15 +584,15 @@ reversible by putting the leading term into a closure to defer the binding of C$_. For example: -$x ~~ .does(Storeable) # okay -.does(Storeable) ~~ $x # not okay--gets wrong $_ on left -{ .does(Storeable) } ~~ $x # okay--closure binds its $_ to $x +$x ~~ .does(Storable) # okay +.does(Storable) ~~ $x # not okay--gets wrong $_ on left +{ .does(Storable) } ~~ $x # okay--closure binds its $_ to $x Exactly the same consideration applies to Cgiven and Cwhen: -given $x { when .does(Storeable) {...} } # okay -given .does(Storeable) { when $x {...} } # not okay -given { .does(Storeable) } { when $x {...} } # okay +given $x { when .does(Storable) {...} } # okay +given .does(Storable) { when $x {...} } # not okay +given { .does(Storable) } { when $x {...} } # okay Boolean expressions are those known to return a boolean value, such as comparisons, or the unary C? operator. They may reference C$_
[svn:perl6-synopsis] r10807 - doc/trunk/design/syn
Author: larry Date: Thu Aug 10 20:19:02 2006 New Revision: 10807 Modified: doc/trunk/design/syn/S02.pod Log: Removed last vestige of $?SELF from the spec. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podThu Aug 10 20:19:02 2006 @@ -14,7 +14,7 @@ Date: 10 Aug 2004 Last Modified: 10 Aug 2006 Number: 2 - Version: 62 + Version: 63 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1149,9 +1149,7 @@ in fact be dynamically scoped within the compiler itself, and only appear to be lexically scoped because dynamic scopes of the compiler resolve to lexical scopes of the program. All C$? variables are considered -constants, and may not be modified after being compiled in, except insofar -as the compiler arranges in advance for such variables to be rebound (as -is the case with C$?SELF). +constants, and may not be modified after being compiled in. C$?FILE and C$?LINE are your current file and line number, for instance. C? is not a shortcut for a package name like C* is.
Re: [svn:perl6-synopsis] r10804 - doc/trunk/design/syn
On Thu, Aug 10, 2006 at 10:17:59PM -0500, Jonathan Scott Duff wrote: : On Thu, Aug 10, 2006 at 06:21:31PM -0700, Darren Duncan wrote: : At 5:11 PM -0700 8/10/06, [EMAIL PROTECTED] wrote: : Log: : First whack at defining semantics of MAIN subs. : : Congradulations! That is SUCH a great idea. : : I agree! No more caller() tricks to see if we're being required or : not because the trick is built-in to the language :) Damian and I independently came up with different versions of it a little while ago, and we worked it out in email, but I'd just never quite got around to hacking it into the spec. Glad you like it. Larry
Module/Class Authoritys
Quick question for the group. Can there be more than one authority? module Foo-0.0.1-cpan:JRANDOM-http://www.foo.org-mailto:[EMAIL PROTECTED] S11 would seem to indicate no (it states that names are made up of 3 parts), but I guess I am wondering if one of those parts can have multiple sub-parts in it? Thanks, - Stevan
Re: Module/Class Authoritys
At 12:35 AM -0400 8/11/06, Stevan Little wrote: Quick question for the group. Can there be more than one authority? module Foo-0.0.1-cpan:JRANDOM-http://www.foo.org-mailto:[EMAIL PROTECTED] S11 would seem to indicate no (it states that names are made up of 3 parts), but I guess I am wondering if one of those parts can have multiple sub-parts in it? Thanks, - Stevan Perhaps something like what is done with versions; eg: Foo-0.0.1-(cpan:JRANDOM|http://www.foo.org|mailto:[EMAIL PROTECTED]) But certainly, there should be delimiters of some kind surrounding the group, and not have it in the open with the same separators as what is used to separate the authority from the version etc. -- Darren Duncan