New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of IO.lines and lines(Str) #474
Labels
Comments
From @bacekHello. There is patch for implemtation of IO.lines and lines(Str) -- |
From @baceklines.patchcommit 9ed96ea13fbe0a01c9961750a45fc84be29bab2a
Author: Vasily Chekalkin <bacek@bacek.com>
Date: Tue Dec 9 21:54:18 2008 +1100
Implement IO.lines method
diff --git a/languages/perl6/src/builtins/io.pir b/languages/perl6/src/builtins/io.pir
index 5b661f0..1560352 100644
--- a/languages/perl6/src/builtins/io.pir
+++ b/languages/perl6/src/builtins/io.pir
@@ -100,6 +100,16 @@ opened_ok:
.return(contents)
.end
+.sub 'lines' :multi('Str')
+ .param string filename
+ .local pmc contents
+
+ $P0 = 'open'(filename, 'r')
+ contents = $P0.'lines'()
+ 'close'($P0)
+
+ .return(contents)
+.end
=item unlink LIST
diff --git a/languages/perl6/src/classes/IO.pir b/languages/perl6/src/classes/IO.pir
index 9a906f1..6dd5f28 100644
--- a/languages/perl6/src/classes/IO.pir
+++ b/languages/perl6/src/classes/IO.pir
@@ -21,6 +21,9 @@ This file implements the IO file handle class.
p6meta = get_hll_global ['Perl6Object'], '$!P6META'
p6meta.'new_class'('IO', 'parent'=>'Any', 'attr'=>'$!PIO')
p6meta.'new_class'('IOIterator', 'parent'=>'Perl6Object', 'attr'=>'$!IO')
+
+ $P0 = get_hll_namespace ['IO']
+ '!EXPORT'('lines', 'from'=>$P0)
.end
=item print
@@ -105,6 +108,29 @@ Slurp a file into a string.
.return($S0)
.end
+=item 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 slurp.
+
+=cut
+
+.sub 'lines' :method :multi('IO')
+ .local pmc PIO, res
+ PIO = getattribute self, "$!PIO"
+ res = new 'List'
+
+ loop:
+ $S0 = PIO.'readline'()
+ unless $S0 goto done
+ res.'push'($S0)
+ goto loop
+
+ done:
+ .return (res)
+.end
=item eof
|
From @jnthnOn Tue Dec 09 03:10:00 2008, bacek wrote:
Applied in r33705. Thanks, Jonathan |
The RT System itself - Status changed from 'new' to 'open' |
@jnthn - Status changed from 'open' to 'resolved' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Migrated from rt.perl.org#61214 (status was 'resolved')
Searchable as RT61214$
The text was updated successfully, but these errors were encountered: