r25821 - docs/Perl6/Spec

2009-03-14 Thread pugs-commits
Author: masak
Date: 2009-03-14 13:34:42 +0100 (Sat, 14 Mar 2009)
New Revision: 25821

Modified:
   docs/Perl6/Spec/S12-objects.pod
Log:
specced syntactic 'where' sugar in param lists

Modified: docs/Perl6/Spec/S12-objects.pod
===
--- docs/Perl6/Spec/S12-objects.pod 2009-03-13 15:44:50 UTC (rev 25820)
+++ docs/Perl6/Spec/S12-objects.pod 2009-03-14 12:34:42 UTC (rev 25821)
@@ -12,9 +12,9 @@
 
   Maintainer: Larry Wall la...@wall.org
   Date: 27 Oct 2004
-  Last Modified: 12 Mar 2009
+  Last Modified: 14 Mar 2009
   Number: 12
-  Version: 76
+  Version: 77
 
 =head1 Overview
 
@@ -1305,6 +1305,18 @@
 since all the type constraints in a signature parameter are just
 anded together anyway.
 
+You can leave out the block when matching against a literal value of some
+kind:
+
+multi sub fib ($n where 0|1) { return $n }
+multi sub fib (Int $n) { return fib($n-1) + fib($n-2) }
+
+In fact, you can leave out the 'where' declaration altogether:
+
+multi sub fib (0) { return 0 }
+multi sub fib (1) { return 1 }
+multi sub fib (Int $n) { return fib($n-1) + fib($n-2) }
+
 Subtype constraints are used as tiebreakers in multiple dispatch:
 
 use Rules::Common :profanity;



r25822 - docs/Perl6/Spec/S32-setting-library

2009-03-14 Thread pugs-commits
Author: masak
Date: 2009-03-14 13:34:50 +0100 (Sat, 14 Mar 2009)
New Revision: 25822

Modified:
   docs/Perl6/Spec/S32-setting-library/IO.pod
Log:
replaced underscores with dashes in variable names in IO.pod

Modified: docs/Perl6/Spec/S32-setting-library/IO.pod
===
--- docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 12:34:42 UTC (rev 
25821)
+++ docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 12:34:50 UTC (rev 
25822)
@@ -16,8 +16,8 @@
Tim Nelson wayl...@wayland.id.au
 Daniel Ruoso dan...@ruoso.com
  Date:  19 Feb 2009 extracted from S29-functions.pod; added stuff from 
S16-IO later
- Last Modified: 23 Feb 2009
- Version:   2
+ Last Modified: 14 Mar 2009
+ Version:   3
 
 The document is a draft.
 
@@ -261,12 +261,12 @@
 
 =over
 
-=item method Int input_record_count()
+=item method Int input-record-count()
 
 Returns a count of the number of records (lines?) that have been input.  
 Now with cleaned-up localization usage.
 
-=item method Str input_record_separator() is rw
+=item method Str input-record-separator() is rw
 
 This regulates how readline behaves.
 
@@ -284,30 +284,30 @@
 that the next input character belongs to the next paragraph,
 even if it's a newline.
 
-Remember: the value of input_record_separator is a string, not a regex.
+Remember: the value of input-record-separator is a string, not a regex.
 awk has to be better for something. :-)
 
-=item method Str input_field_separator() is rw
+=item method Str input-field-separator() is rw
 
 This regulates how readfield behaves.
 
-=item method Str input_escape() is rw
+=item method Str input-escape() is rw
 
 This allows the definition of a escape character, which should be used
 by readline and readfield.
 
 =item method Str readline()
 
-Reads the stream before it finds a $.input_record_separator and
-returns it (including the separator). If $.input_escape is set, it
+Reads the stream before it finds a $.input-record-separator and
+returns it (including the separator). If $.input-escape is set, it
 should pay attention to that.
 
 =item method Str readfield()
 
-Reads the stream before it finds a $.input_field_separator and returns
+Reads the stream before it finds a $.input-field-separator and returns
 it (including the separator). If a readfield finds a
-$.input_record_separator it consumes the record separator, but returns
-undef. If $.input_escape is set, it should pay attention to that.
+$.input-record-separator it consumes the record separator, but returns
+undef. If $.input-escape is set, it should pay attention to that.
 
 =item method Str getc(Int $char? = 1)
 
@@ -328,20 +328,20 @@
 
 =over
 
-=item method Int output_record_count()
+=item method Int output-record-count()
 
 Returns a count of the number of records (lines?) that have been output.  
 
-=item method Str output_record_separator() is rw
+=item method Str output-record-separator() is rw
 
 This regulates how say and print(%hash) behaves.
 
-=item method Str output_field_separator() is rw
+=item method Str output-field-separator() is rw
 
 This regulates how print(@arr), say(@arr), print(%hash) and
 say(%hash) behave.
 
-=item method Str output_escape() is rw
+=item method Str output-escape() is rw
 
 This allows the definition of a escape character, which should be used
 by say and print to preserve the record/field semantics.
@@ -351,27 +351,27 @@
 =item method Bool say(Str $str)
 
 Sends $str to the data stream doing proper encoding conversions. Say
-sends an additional $.output_record_separator. This should also
-convert \n to the desired $.output_record_separator.
+sends an additional $.output-record-separator. This should also
+convert \n to the desired $.output-record-separator.
 
 =item method Bool print(Array @arr)
 
 =item method Bool say(Array @arr)
 
-Sends each element of @arr separated by $.output_field_separator. Say
-should add an additional $.output_record_separator. If an element
-contains the $.output_record_separator or the
-$.output_field_seaparator and a $.output_escape is defined, it should
+Sends each element of @arr separated by $.output-field-separator. Say
+should add an additional $.output-record-separator. If an element
+contains the $.output-record-separator or the
+$.output-field-seaparator and a $.output-escape is defined, it should
 do the escaping.
 
 =item method Bool print(Hash %hash)
 
 =item method Bool say(Hash %hash)
 
-Sends each pair of the hash separated by $.output_record_separator,
-with key and value separated by $.output_field_separator. If one of
-those contains a $.output_record_separator or a
-$.output_field_seaparator and $.output_escape is set, it should do the
+Sends each pair of the hash separated by $.output-record-separator,
+with key and value separated by $.output-field-separator. If one of
+those contains a $.output-record-separator or a
+$.output-field-seaparator and 

r25823 - docs/Perl6/Spec/S32-setting-library

2009-03-14 Thread pugs-commits
Author: masak
Date: 2009-03-14 13:34:54 +0100 (Sat, 14 Mar 2009)
New Revision: 25823

Modified:
   docs/Perl6/Spec/S32-setting-library/IO.pod
Log:
replaced 'record' with 'line' in IO.pod

'record' is fine and understandable in the Unix world, and used by
tools such as awk -- but line is immediately understandable and shorter.

Modified: docs/Perl6/Spec/S32-setting-library/IO.pod
===
--- docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 12:34:50 UTC (rev 
25822)
+++ docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 12:34:54 UTC (rev 
25823)
@@ -17,7 +17,7 @@
 Daniel Ruoso dan...@ruoso.com
  Date:  19 Feb 2009 extracted from S29-functions.pod; added stuff from 
S16-IO later
  Last Modified: 14 Mar 2009
- Version:   3
+ Version:   4
 
 The document is a draft.
 
@@ -261,16 +261,16 @@
 
 =over
 
-=item method Int input-record-count()
+=item method Int input-line()
 
-Returns a count of the number of records (lines?) that have been input.  
+Returns the number of lines (records) that have been input.
 Now with cleaned-up localization usage.
 
-=item method Str input-record-separator() is rw
+=item method Str input-line-separator() is rw
 
 This regulates how readline behaves.
 
-The input record separator, newline by default.
+The input line (record) separator, newline by default.
 This influences Perl's idea of what a ``line'' is.
 Works like awk's RS variable, including treating empty lines
 as a terminator if set to the null string.
@@ -284,7 +284,7 @@
 that the next input character belongs to the next paragraph,
 even if it's a newline.
 
-Remember: the value of input-record-separator is a string, not a regex.
+Remember: the value of input-line-separator is a string, not a regex.
 awk has to be better for something. :-)
 
 =item method Str input-field-separator() is rw
@@ -298,7 +298,7 @@
 
 =item method Str readline()
 
-Reads the stream before it finds a $.input-record-separator and
+Reads the stream before it finds a $.input-line-separator and
 returns it (including the separator). If $.input-escape is set, it
 should pay attention to that.
 
@@ -306,7 +306,7 @@
 
 Reads the stream before it finds a $.input-field-separator and returns
 it (including the separator). If a readfield finds a
-$.input-record-separator it consumes the record separator, but returns
+$.input-line-separator it consumes the line separator, but returns
 undef. If $.input-escape is set, it should pay attention to that.
 
 =item method Str getc(Int $char? = 1)
@@ -328,11 +328,11 @@
 
 =over
 
-=item method Int output-record-count()
+=item method Int output-line()
 
-Returns a count of the number of records (lines?) that have been output.  
+Returns the number of lines (records) that have been output so far.
 
-=item method Str output-record-separator() is rw
+=item method Str output-line-separator() is rw
 
 This regulates how say and print(%hash) behaves.
 
@@ -344,23 +344,23 @@
 =item method Str output-escape() is rw
 
 This allows the definition of a escape character, which should be used
-by say and print to preserve the record/field semantics.
+by say and print to preserve the line/field semantics.
 
 =item method Bool print(Str $str)
 
 =item method Bool say(Str $str)
 
 Sends $str to the data stream doing proper encoding conversions. Say
-sends an additional $.output-record-separator. This should also
-convert \n to the desired $.output-record-separator.
+sends an additional $.output-line-separator. This should also
+convert \n to the desired $.output-line-separator.
 
 =item method Bool print(Array @arr)
 
 =item method Bool say(Array @arr)
 
 Sends each element of @arr separated by $.output-field-separator. Say
-should add an additional $.output-record-separator. If an element
-contains the $.output-record-separator or the
+should add an additional $.output-line-separator. If an element
+contains the $.output-line-separator or the
 $.output-field-seaparator and a $.output-escape is defined, it should
 do the escaping.
 
@@ -368,9 +368,9 @@
 
 =item method Bool say(Hash %hash)
 
-Sends each pair of the hash separated by $.output-record-separator,
+Sends each pair of the hash separated by $.output-line-separator,
 with key and value separated by $.output-field-separator. If one of
-those contains a $.output-record-separator or a
+those contains a $.output-line-separator or a
 $.output-field-seaparator and $.output-escape is set, it should do the
 escaping.
 



Re: r25807 - docs/Perl6/Spec

2009-03-14 Thread Larry Wall
On Thu, Mar 12, 2009 at 06:29:19PM -0700, Jon Lang wrote:
:  +To declare an item that is parsed as a simple term, you must use the
:  +form C term:foo , or some other form of constant declaration such
:  +as an enum declaration.  Such a term never looks for its arguments,
:  +is never considered a list prefix operator, and may not work with
:  +subsequent parentheses because it will be parsed as a function call
:  +instead of the intended term.  (The function in question may or
:  +may not exist.)  For example, Crand is a simple term in Perl 6
:  +and does not allow parens, because there is no Crand() function
:  +(though there's a C$n.rand method).
: 
: So if I were to say:
: 
: rand $n:
: 
: is the compiler smart enough to notice that trailing colon and
: recognize this as an indirect method call rather than two adjacent
: terms?

No, currently under STD you get:

Obsolete use of rand(N); in Perl 6 please use N.rand or (1..N).pick instead 
at (eval) line 1:

: Or would I have to say:
: 
: rand($n:)
: 
: to get the indirect method call?

That would work, but then why not:

rand*$n
$n*rand
$n.rand
(1..$n).pick

In fact, given that you usually want to integerize anyway, I could
almost argue myself out of supporting the $n.rand form as well...

Larry


r25830 - docs/Perl6/Spec/S32-setting-library

2009-03-14 Thread pugs-commits
Author: lwall
Date: 2009-03-14 18:32:42 +0100 (Sat, 14 Mar 2009)
New Revision: 25830

Modified:
   docs/Perl6/Spec/S32-setting-library/IO.pod
Log:
[IO] Massive overhaul, long overdue due to neglect of TimToady--


Modified: docs/Perl6/Spec/S32-setting-library/IO.pod
===
--- docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 17:11:19 UTC (rev 
25829)
+++ docs/Perl6/Spec/S32-setting-library/IO.pod  2009-03-14 17:32:42 UTC (rev 
25830)
@@ -13,11 +13,11 @@
 Mark Stosberg m...@summersault.com
 Carl Mäsak cma...@gmail.com
 Moritz Lenz mor...@faui2k3.org
-   Tim Nelson wayl...@wayland.id.au
+Tim Nelson wayl...@wayland.id.au
 Daniel Ruoso dan...@ruoso.com
  Date:  19 Feb 2009 extracted from S29-functions.pod; added stuff from 
S16-IO later
  Last Modified: 14 Mar 2009
- Version:   4
+ Version:   5
 
 The document is a draft.
 
@@ -27,97 +27,125 @@
 
 =head2 IO
 
+[Note: if a method declaration indicates a method name qualified by
+type, it should be taken as shorthand to say which role or class the
+method is actually declared in.]
+
 =over 4
 
+=item open
+
+multi open (Str $name,
+   Bool :$rw = False,
+   Bool :$bin = False,
+   Str  :$enc = Unicode,
+   Any  :$nl = \n,
+   Bool :$chomp = True,
+   ...
+   -- IO
+) is export
+
+A convenience method/function that hides most of the OO complexity.
+It will only open normal files.  Text is the default.  Note that
+the Unicode encoding implies figuring out which actual UTF is
+in use, either from a BOM or other heuristics.  If heuristics are
+inconclusive, UTF-8 will be assumed.  (No 8-bit encoding will ever
+be picked implicitly.)  A file opened with C:bin may still be
+processed line-by-line, but IO will be in terms of CBuf rather
+than CStr types.
+
 =item getc
 
-our Bool method getc (IO $self: *...@list)
+method getc (Int $chars = 1 -- Char)
 
 See below for details.
 
 =item print
 
-our Bool method print (IO $self: *...@list)
-our Bool multi print (*...@list)
-our Bool method print (Str $self: IO $io)
+method print (*...@list -- Bool)
+multi print (*...@list -- Bool)
+method Str::print (IO $io -- Bool)
+method Array::print (IO $io -- Bool)
+method Hash::print (IO $io -- Bool)
 
 See below for details.
 
 =item say
 
-our Bool method say (IO $self: *...@list)
-our Bool multi say (*...@list)
-our Bool method say (Str $self: IO $io)
+method say (*...@list -- Bool)
+multi say (*...@list -- Bool)
+method Str::say (IO $io -- Bool)
+method Array::say (IO $io -- Bool)
+method Hash::say (IO $io -- Bool)
 
 See below for details.
 
 =item printf
 
-our Bool method printf (IO $self: Str $fmt, *...@list)
-our Bool multi printf (Str $fmt, *...@list)
+method printf (Str $fmt, *...@list -- Bool)
+multi printf (Str $fmt, *...@list -- Bool)
 
 See below for details.
 
 =item uri
 
-IO::Streamable method uri(Str $uri);
-IO::Streamable sub uri(Str $uri);
+method uri(Str $uri -- IO::Streamable);
+sub uri(Str $uri -- IO::Streamable);
 
-Returns an appropriate IO::Streamable descendant, with the type depending on 
the uri 
+Returns an appropriate CIO::Streamable descendant, with the type depending 
on the uri 
 passed in.  Here are some example mappings:
 
- URI type IO type
-  ===
- file:IO::File or IO::Directory
- ftp: IO::Socket::TCP (data channel)
- http:IO::Socket::TCP
+URI type IO type
+ ===
+file:IO::File or IO::Directory
+ftp: IO::Socket::TCP (data channel)
+http:IO::Socket::TCP
 
 These can naturally be overridden or added to by other modules.  
 
-=item %*PROTOCOLS global variable
+=item %*PROTOCOLS context variable
 
-For each protocol, stores a type name that should be instantiated by calling 
the .uri() 
+For each protocol, stores a type name that should be instantiated by calling 
the Curi 
 constructor on that type, and passing in the appropriate uri.  
 
 =back
 
 =head1 Roles
 
-The functionality of IO objects is broken down into several roles,
+The functionality of CIO objects is broken down into several roles,
 which should identify the features each object supports.
 
 =head2 IO
 
-The base role only tags that this is an IO object for more generic
+The base role only tags that this is an CIO object for more generic
 purposes. It doesn't specify any methods or attributes.
 
 =head2 IO::Readable
 
 This role provides unbuffered read access to the data stream.
 
-role   IO::Readable {
-   has $.isReadable;
+role IO::Readable {
+has $.isReadable;
+method read($buf is rw, Int $bytes -- Int)
+}
 
-   method Int read($buf is rw, Int $bytes)
-}
+When the C$.isReadable is set, it tries to change the readability of the 
filehandle.  This 
+is not 

Re: r25807 - docs/Perl6/Spec

2009-03-14 Thread Jon Lang
On Sat, Mar 14, 2009 at 7:29 AM, Larry Wall la...@wall.org wrote:
 : So if I were to say:
 :
 :     rand $n:
 :
 : is the compiler smart enough to notice that trailing colon and
 : recognize this as an indirect method call rather than two adjacent
 : terms?

 No, currently under STD you get:

    Obsolete use of rand(N); in Perl 6 please use N.rand or (1..N).pick 
 instead at (eval) line 1:

 : Or would I have to say:
 :
 :     rand($n:)
 :
 : to get the indirect method call?

 That would work, but then why not:

    rand*$n
    $n*rand
    $n.rand
    (1..$n).pick

 In fact, given that you usually want to integerize anyway, I could
 almost argue myself out of supporting the $n.rand form as well...

It's largely a matter of principle: if I can say $x.foo, I expect to
be able to say foo $x: as well.  Every time you introduce an exception
to the rule, you're throwing something in that has the potential to
cause confusion; so you should do so with some caution.  I think that
best uses should include something to the effect of avoid using the
same identifier for both a term and a routine.  IMHO, rand should
either be a term or a method; but not both.

There are also some linguistic reasons for this best uses proposal:
people tend to think of terms as nouns and routines as verbs.  And
gerunds are more akin to foo than to term:foo.

Left-field idea here: there was recently some discussion on this list
about the possibility of continuous ranges, which would be in contrast
to how 1..$n is a discrete list of options.  If you were to do this,
then you could use .pick on a continuous range to generate a random
number anywhere within its bounds.  So:

(1 to 5).pick

(where infix:to creates a continuous range, inclusive of both
boundaries) would in theory be as likely to return 2.5 or pi as 3.
IMHO, this does a better job of handling what most people want rand to
do when they start thinking in terms of assigning parameters to it.
And with that in place, rand could become a term that's short for
something like:

pick (0 to^ 1):

-- 
Jonathan Dataweaver Lang