Skip to content
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

Closed
p6rt opened this issue Dec 9, 2008 · 5 comments
Closed

Implementation of IO.lines and lines(Str) #474

p6rt opened this issue Dec 9, 2008 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Dec 9, 2008

Migrated from rt.perl.org#61214 (status was 'resolved')

Searchable as RT61214$

@p6rt
Copy link
Author

p6rt commented Dec 9, 2008

From @bacek

Hello.

There is patch for implemtation of IO.lines and lines(Str)

--
Bacek

@p6rt
Copy link
Author

p6rt commented Dec 9, 2008

From @bacek

lines.patch
commit 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
 

@p6rt
Copy link
Author

p6rt commented Dec 9, 2008

From @jnthn

On Tue Dec 09 03​:10​:00 2008, bacek wrote​:

There is patch for implemtation of IO.lines and lines(Str)

Applied in r33705.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Dec 9, 2008

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Dec 9, 2008

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Dec 9, 2008
@p6rt p6rt added the patch label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant