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

Default value for readLines shouldn't be 1 #12788

Closed
dom96 opened this issue Dec 1, 2019 · 4 comments · Fixed by #12807
Closed

Default value for readLines shouldn't be 1 #12788

dom96 opened this issue Dec 1, 2019 · 4 comments · Fixed by #12807

Comments

@dom96
Copy link
Contributor

dom96 commented Dec 1, 2019

I was just doing Advent of Code and used readLines in a loop, I was confused to see it return a single line... https://nim-lang.org/docs/io.html#readLines%2Cstring

Example

for line in readLines("blah.txt"):
  echo line

Current Output

One line

Expected Output

All lines

Possible Solution

  • Deprecate this function and introduce one that does not have the n as a default argument
@simonkrauter
Copy link
Contributor

This confused me too a while ago.

@zevv
Copy link
Contributor

zevv commented Dec 2, 2019

Are you not better off using io.lines() instead, it being an iterator instead of a proc?

https://nim-lang.org/docs/io.html#lines.i%2Cstring

@cooldome
Copy link
Member

cooldome commented Dec 3, 2019

io.lines() is always better except cases when it is not available for example in VM.

@Clyybber
Copy link
Contributor

Clyybber commented Dec 3, 2019

Nowadays this: https://github.com/nim-lang/Nim/pull/12284/files#diff-93574743bf0f766ad08398709499ef6aR18 works in the VM, though its not io.lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants