You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm been working on an underlying Stream abstraction that we can use more broadly (STDIN, STDOUT, STDERR, Files, Network, etc)... and in trying to implement Stdin I'm realizing there may be some inconsistent behavior that we need to sort thru.
There is a TODO that readByte might be broken (and I'd say it is)... but I also see potential problems withreadLine.
Traditionally the API awaits until there is a full line in the buffer
If STDIN is closed during reading then anything in the read buffer is returned, (including an empty string)
Is this the correct behavior? It seems this makes it impossible to distinguish between inputs such as:
data\nbob\n\n (3 lines)
data\nbob\n (2 lines)
The result of calling readLine in a loop will always be 3 lines:
"data"
"bob"
""
IE, in the second case it appears an extra "line" has been added. Perhaps null should be returned when EOF is found (rather than aborting)... so then the inputs above would appear as:
data\nbob\n\n (3 lines)
"data"
"bob"
""
null
null, ...
data\nbob\n (2 lines)
"data"
"bob"
null
null, ...
There is also the question of what to do with an unterminated line (which can also have ambiguous behavior):
data\nbob (2 lines)
One solution here is to simply include the \n in the input rather than stripping it, making this case unambiguous, and I know some other languages take this path.
Thoughts?
The text was updated successfully, but these errors were encountered:
joshgoebel
changed the title
what is the correct behavior of Stdin.readLine?
What is the correct behavior of Stdin.readLine?
Sep 23, 2021
I'm been working on an underlying Stream abstraction that we can use more broadly (STDIN, STDOUT, STDERR, Files, Network, etc)... and in trying to implement Stdin I'm realizing there may be some inconsistent behavior that we need to sort thru.
There is a TODO that
readByte
might be broken (and I'd say it is)... but I also see potential problems withreadLine
.awaits
until there is a full line in the bufferIs this the correct behavior? It seems this makes it impossible to distinguish between inputs such as:
data\nbob\n\n
(3 lines)data\nbob\n
(2 lines)The result of calling readLine in a loop will always be 3 lines:
"data"
"bob"
""
IE, in the second case it appears an extra "line" has been added. Perhaps null should be returned when EOF is found (rather than aborting)... so then the inputs above would appear as:
data\nbob\n\n
(3 lines)"data"
"bob"
""
data\nbob\n
(2 lines)"data"
"bob"
There is also the question of what to do with an unterminated line (which can also have ambiguous behavior):
data\nbob
(2 lines)One solution here is to simply include the
\n
in the input rather than stripping it, making this case unambiguous, and I know some other languages take this path.Thoughts?
The text was updated successfully, but these errors were encountered: