Re: r25329 - docs/Perl6/Spec
That mention of $| is confusing, since $| has nothing to do with changing where output goes in p5. All it does is cause output to be autoflushed.. The Perl5 analog to $DEFOUT would seem to be the select() function... On 2/14/09, pugs-comm...@feather.perl6.nl pugs-comm...@feather.perl6.nl wrote: Author: wayland Date: 2009-02-14 07:37:40 +0100 (Sat, 14 Feb 2009) New Revision: 25329 Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S16-io.pod Log: S02: Moved comment about standard file handles to S16. S16: Did more clearing up, and fixed some stupid things I did last time Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod 2009-02-14 05:38:34 UTC (rev 25328) +++ docs/Perl6/Spec/S02-bits.pod 2009-02-14 06:37:40 UTC (rev 25329) @@ -2054,8 +2054,7 @@ =item * -Standard input is C$*IN, standard output is C$*OUT, and standard error -is C$*ERR. The magic command-line input handle is C$*ARGFILES. +The magic command-line input handle is C$*ARGFILES. The arguments themselves come in C@*ARGS. See also Declaring a MAIN subroutine in S06. Modified: docs/Perl6/Spec/S16-io.pod === --- docs/Perl6/Spec/S16-io.pod2009-02-14 05:38:34 UTC (rev 25328) +++ docs/Perl6/Spec/S16-io.pod2009-02-14 06:37:40 UTC (rev 25329) @@ -10,9 +10,10 @@ Author:Largely, the authors of the related Perl 5 docs. Maintainer:Larry Wall la...@wall.org Contributions: Mark Stosberg m...@summersault.com +Tim Nelson wayl...@wayland.id.au Date: 12 Sep 2006 - Last Modified: 1 May 2007 - Version: 18 + Last Modified: 14 Feb 2009 + Version: 19 This is a draft document. Many of these functions will work as in Perl 5, except we're trying to rationalize everything into roles. For @@ -22,6 +23,21 @@ corresponding global function, it's merely an exported version of the method. +=head1 Default IO handles + +In Perl 6, there are the Istandard handles, and the Idefault handles. + +The Istandard ones are our old familiar friends (with new names). Standard input is +C$*IN, standard output is C$*OUT, and standard error is C$*ERR. + +However, the Idefault ones replace the Perl 5 $| variable with three new variables. +At the start of the program, the default handles (C$*DEFIN, C$*DEFOUT, and +C$*DEFERR) are aliased to the standard handles, but may be temporarily or permanently +rebound to some other file handle. + +Many of the roles and functions below will operate on the default handles. To set all 3 +at once, do C($*DEFIN, $*DEFOUT, $*DEFERR) ::= ($*IN, $*OUT, $*ERR). + =head1 Roles The functionality of IO objects is broken down into several roles, @@ -127,6 +143,21 @@ =back +=head2 IO::Seekable + +=over + +=item method Bool eoi() + +Returns true if it's the end of the input (ie. end of file or whatever), returns false if +not, returns undef if we can't say for certain. + +=item IO.seek + +=item IO.tell + +=back + =head2 IO::Encoded This is a generic role for encoded data streams. @@ -165,7 +196,6 @@ This allows the definition of a escape character, which should be used by say and print to preserve the record/field semantics. - =back =head2 IO::Readable::Encoded @@ -202,13 +232,34 @@ the latter case C$! is set). The C:async flag lets the call return an undefined value if no character is immediately available. -=cut +=item IO.lines +our List multi method lines (IO $handle:) is export; +our List multi lines (Str $filename); + +Returns all the lines of a file as a (lazy) List regardless of context. +See also Cslurp. + +=item IO.slurp + +our Item multi method slurp (IO $handle: *%opts) is export; +our Item multi slurp (Str $filename, *%opts); + +Slurps the entire file into a Str or Buf regardless of context. +(See also Clines.) Whether a Str or Buf is returned depends on +the options. + +=back + =head2 IO::Writeable::Encoded This role provides encoded access to a writeable data stream, implies IO::Encoded. Might imply IO::Buffered, but that's not a requirement. +If these are called in their non-object form, they operate on C$*DEFOUT, except in the +case of warn(), which operates on C$*DEFERR. The form with leading dot prints C$_ to +the appropriate default handle unless an explicit filehandle is supplied. + =over =item method Bool print(Str $str) @@ -248,11 +299,6 @@ be followed by a colon, and any indirect object more complicated than a variable should be put into parentheses. -If IO is omitted, prints to C$*DEFOUT, which is aliased to C$*OUT -when the program starts but may be temporarily or permanently rebound to -some other file handle. The form with leading dot prints C$_ to C$*DEFOUT -unless an explicit filehandle is supplied. - It
Re: r25328 - docs/Perl6/Spec
On Sat, Feb 14, 2009 at 6:38 AM, pugs-comm...@feather.perl6.nl wrote: +=head2 IO::Openable + +This role implies that the object can be connected to, or listened on. + +=over 4 + +=item open + + method Bool open(); + +Attempts to open the handle. Depending on the implementation, this could be an open() +call, a connect(), a listen(), or something similar. + +=back + I'm not sure if I really hate or love this. I'm not quite convinced if the use of it anyway. +=head2 IO::Socket + +role IO::Socket does IO::POSIX does IO::Openable does IO::Closeable { +... +} + +=over + +=item IO.accept + +=item IO.bind + +=item Socket.pair + +our List of IO method pair(Int $domain, Int $type, Int $protocol) + +A wrapper for socketpair(2), returns a pair of IO objects representing the +reader and writer ends of the socket. + + use Socket; + ($r, $w) = Socket.pair(AF_UNIX, SOCK_STREAM, PF_UNSPEC); + + +=back + Why should this do POSIX? What about non-POSIX operating systems? +=item syscall + That functions should be well hidden +=item sysopen + I vote for sysopen (and all other sys functions) to be wiped out of existence. +=head1 Classes + +=head2 IO::File + +This does file input and output. + +class IO::File does IO::POSIX does IO::Closeable does IO::Openable { +... +} + +=over + +=item init + + method init(String $filename, $options?); + method init(Int $fd); + + # Read + $fobj = new IO::File($filename); + + # Write + $fobj = new IO::File($filename, :w); + + # Read using file descriptor + $fobj = new IO::File($fd); + +Associate an IO object with an already-open file descriptor, +presumably passed in from the parent process. + +=back Why should this do POSIX? What about non-POSIX operating systems? Why is that function called init, and not open? That's rather non-intuitive. This should do IO::Seekable and (to be written) IO::Stattable. +=head2 IO::FileSystem + +This reads directories, worries about ownership and permissions, and the like. + +class IO::FileSystem does IO::POSIX does IO::Closeable does IO::Openable { +... +} Why should this do POSIX? What about non-POSIX operating systems? +=head2 IO::Socket::INET + +class IO::Socket::INET does IO::Socket { +... +} + +=over + +=item init + + method Bool init($RemoteHost, $RemotePort, $LocalHost?, $LocalPort?); + +=item open($Listen?); + +If $Listen is 0, it does a connect(). If $Listen is 1, it does a connect() and a +listen(). If $Listen is 2, it does a listen(), but no connect(). + I *really* hate that interface, and I don't see how it covers an accepting socket. IMO there should be two calls method IO connect($RemoteHost, $RemotePort, *%options) where *%options can contain things like the local address, non-blockingness, etc... method IO::Accepting listen($LocalHost, $LocalPort, *%options) role IO::Accepting does IO::Socket { IO accept(); } -=head1 Input and Output +=head2 IO::Pipe -=over 4 +class IO::Pipe does IO::POSIX does IO::Closeable does IO::Openable { +... +} Why should this do POSIX? What about non-POSIX operating systems? Regards, Leon Timmermans
Re: r25328 - docs/Perl6/Spec
On 2009 Feb 14, at 12:01, Leon Timmermans wrote an unending refrain of: Why should this do POSIX? What about non-POSIX operating systems? I think the point here is that on POSIX systems that gets you ioctl() and fcntl(), and on non-POSIX systems either they don't exist or they throw runtime errors. Aside from my earlier suggestion that non-POSIX systems generally have similar functions for which we should consider a common rubric, I'm not sure if this (does IO::POSIX) is backwards or if my/our(?) understanding of does is backwards, or possibly tangential. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH PGP.sig Description: This is a digitally signed message part
Re: r25328 - docs/Perl6/Spec
On Sat, Feb 14, 2009 at 10:31 PM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: I think the point here is that on POSIX systems that gets you ioctl() and fcntl(), and on non-POSIX systems either they don't exist or they throw runtime errors. Aside from my earlier suggestion that non-POSIX systems generally have similar functions for which we should consider a common rubric, I'm not sure if this (does IO::POSIX) is backwards or if my/our(?) understanding of does is backwards, or possibly tangential. IMO IO::POSIX should do exactly what it says it does: implement POSIX as closely as possible. Since we probably can't implement much of it on non-POSIX platforms, I don't think it should be part of our specification (though I do think it should be part of our implementation, because it is definitely useful). I think it would be a lot better to implement a more portable wrapper around the necessary functionality. Regards, Leon
r25334 - docs/Perl6/Spec
Author: lwall Date: 2009-02-14 23:56:24 +0100 (Sat, 14 Feb 2009) New Revision: 25334 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] allow *.foo to mean - $obj { $obj.foo } Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-02-14 20:56:51 UTC (rev 25333) +++ docs/Perl6/Spec/S02-bits.pod2009-02-14 22:56:24 UTC (rev 25334) @@ -821,9 +821,14 @@ produces a function of a single argument: -{ $^x - 1 } +{ $_ - 1 } -This closure is of type CCode:($), not CWhatever, so that constructs can distinguish +Likewise, the single dispatcher recognizes C*.meth and returns C{ $_.meth }, +so it can be used where patterns are expected: + +@primes = grep *.prime, 2..*; + +These closures are of type CCode:($), not CWhatever, so that constructs can distinguish via multiple dispatch: 1,2,3 ... *