doc: fix imprecision in IO.FS.Stream.getLine and IO.FS.Handle.getLine - #14754
Open
ia0 wants to merge 1 commit into
Open
doc: fix imprecision in IO.FS.Stream.getLine and IO.FS.Handle.getLine#14754ia0 wants to merge 1 commit into
ia0 wants to merge 1 commit into
Conversation
This PR fixes imprecise documentation for `IO.FS.Stream.getLine` and `IO.FS.Handle.getLine`. If the stream does not end with a newline (or line break), then `getLine` will return a `String` that does not end with a newline. Reciprocally, this situation can only occur when reaching an EOF.
Note that the documentation of `read` does not necessarily need to be similarly updated. This is because `read` will always emit an empty array, even after a partially filled array.
This is based on testing only, not necessarily intent of the code. Here are reproduction steps:
```lean4
def main : IO Unit := do
repeat do
let line ← (← IO.getStdin).getLine
IO.println s!"XXX{line}YYY"
```
Running with the following input where `%` indicates EOF (e.g. using Ctrl-D if there was no input since last newline or EOF, or using Ctrl-D twice there was: once to flush the buffer and once to indicate EOF):
```
hello
foo%%
```
gives the following output (when `YYY` does not start a line, it means `getLine` did not end with a newline):
```
XXXhello
YYY
XXX
YYY
XXXfooYYY
XXXYYY
```
|
Mathlib CI status (docs):
|
Collaborator
|
Reference manual CI status:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes imprecise documentation for
IO.FS.Stream.getLineandIO.FS.Handle.getLine. If the stream does not end with a newline (or line break), thengetLinewill return aStringthat does not end with a newline. Reciprocally, this situation can only occur when reaching an EOF.Note that the documentation of
readdoes not necessarily need to be similarly updated. This is becausereadwill always emit an empty array, even after a partially filled array.This is based on testing only, not necessarily intent of the code. Here are reproduction steps:
Running with the following input where
%indicates EOF (e.g. using Ctrl-D if there was no input since last newline or EOF, or using Ctrl-D twice there was: once to flush the buffer and once to indicate EOF):gives the following output (when
YYYdoes not start a line, it meansgetLinedid not end with a newline):