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

2006-08-11 Thread Audrey Tang


在 2006/8/11 下午 3:00 時,Luke Palmer 寫到:


On 8/11/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
 Some object types can behave as value types.  Every object can  
produce
 a "safe key identifier" (C 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


I'm glad you "fixed" this typo.


It's been fixed in r10805.

+no explicit call to C was performed by the time the  
mainline code

+finishes.


I don't see a purpose for this.  Isn't it better to have a simple,
predictable call at the end of the program regardless?  If a module
wants to call MAIN differently, it can use .wrap.


Or even simpler:

MAIN(...); exit;

I agree that a predictable call is better.


+If C is declared as a method, the name of the invoked
+program is passed as the "invocant".


What a hack.  Please don't do that.


If any, the invocant should be an instantiated object of type Main,  
to go with the
idea of method declaration.  If Main can be instantiated somehow so  
that it knows
about the program name, then it can be made to work, but as specced  
it feels unnatural

to me as well.

Thanks,
Audrey

PGP.sig
Description: This is a digitally signed message part


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

2006-08-11 Thread Markus Laire

On 8/11/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


+To return from other types of code structures, the C function
+is used.  The first argument, if supplied, specifies a C
+for the control structure to leave.  The C and will be
+smart-matched against the dynamic scope objects from inner to outer.
+The first that matches is the scope that is left.


s/and //


+As with module and class declarations, a sub or method declaration
+ending in semicolon is allowed at the outermost file scope if it is the
+first such declaration, in which case the rest of the file is the body:
+
+sub MAIN ($directory, :$verbose, *%other, [EMAIL PROTECTED]);
+for @filenames { ... }
+
+Proto or multi definitions may not be written in semicolon form,
+nor may C subs within a module or class.  (A C routine
+is allowed in a module or class, but is not usually invoked unless
+the file is run directly (see a above).  This corresponds to the
+"unless caller" idiom of Perl 5.)  In general, you may have only one
+semicolon-style declaration that controls the whole file.


Should the following text now be removed from S06:


--- S06.pod.orig2006-08-11 11:50:46.0 +0300
+++ S06.pod 2006-08-11 11:51:08.0 +0300
@@ -159,14 +159,6 @@

sub foo {...} # Yes, those three dots are part of the actual syntax

-The old Perl 5 form:
-
-sub foo;
-
-is a compile-time error in Perl 6 (because it would imply that the body of the
-subroutine extends from that statement to the end of the file, as C and
-C declarations do).
-
Redefining a stub subroutine does not produce an error, but redefining
an already-defined subroutine does. If you wish to redefine a defined sub,
you must explicitly use the "C" trait.


--
Markus Laire


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

2006-08-11 Thread Luke Palmer

On 8/11/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

 Some object types can behave as value types.  Every object can produce
 a "safe key identifier" (C 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


I'm glad you "fixed" this typo.


+no explicit call to C was performed by the time the mainline code
+finishes.


I don't see a purpose for this.  Isn't it better to have a simple,
predictable call at the end of the program regardless?  If a module
wants to call MAIN differently, it can use .wrap.


+If C is declared as a method, the name of the invoked
+program is passed as the "invocant".


What a hack.  Please don't do that.

Luke


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

2006-08-10 Thread Larry Wall
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


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

2006-08-10 Thread Jonathan Scott Duff
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 :)

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]


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

2006-08-10 Thread Darren Duncan

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] r10804 - doc/trunk/design/syn

2006-08-10 Thread larry
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" (C 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 C function
 
-A C 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 C.
+As mentioned above, a C 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 C.
+
+To return from other types of code structures, the C function
+is used.  The first argument, if supplied, specifies a C
+for the control structure to leave.  The C 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 C 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 C is a C, 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 C 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 C 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 C named "C", and
+
+=item c)
+
+no explicit call to C 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 C and passed to
+C as its arguments, so switches may be bound as named args and
+other arguments to the program may be bound to positional p