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
Classlib: Add 'rewind' to CollStream #2400
Classlib: Add 'rewind' to CollStream #2400
Conversation
@@ -59,6 +59,9 @@ CollStream : IOStream { | |||
pos_ { arg toPos; | |||
pos = toPos.clip(0, collection.size); | |||
} | |||
rewind { |n = 1| | |||
pos = max(0, pos - n); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you provide no argument, stream.rewind
, sounds like "fully rewind". Couldn't the default be that?
rewind { |n|
if(n.isNil) { pos = 0 } {
pos = max(0, pos - n)
}
}
I see your point. That would mean |
whatever you prefer, either way is fine! in this way it probably would be:
|
any opinions on that? I'm fine either way. |
I'd like to merge it as it is now, if there are no objections. |
There's an opportunity here to copy the interface from |
I think, because |
I would be OK with both so long as it introduces consistency between File and CollStream etc. This is not so "special" IMO since it is also found in C and Python, just historically motivated. FWIW C/C++ has std::rewind which without an argument returns to the beginning of the stream. That would make more sense to me as a default argument as well. But I'm fine either way, as @jamshark70 pointed out you usually want to move back by one. |
good! (I meant "special" relative to the semantic style elsewhere in sclang, where behaviour is normally not numbered but named, doneAction notwithstanding …) |
Ah, ok :) |
I'll do the seek implementation in a separate PR. |
I've been using CollStream as part of a parser, and it's very useful to roll back 1 or more characters.
Currently:
Proposed:
No rush on this.
(CollStream is as yet undocumented, btw.)