[squeak-dev] Would a PositionableStream>>#peek: be reasonable?

tim Rowledge tim at rowledge.org
Sun Oct 7 16:59:18 UTC 2018

The only issue I can think of here is that it might be necessary to use "self position: priorPos" or similar in some forms of Stream. Stuff like socket streams perhaps, where moving forwards/backwards could possibly involve flushing & loading of buffers and other occasionally mind-warping actions.

> On 2018-10-06, at 7:07 PM, Chris Muller <asqueaker at gmail.com> wrote:
> I have a ReadStream I would like to peek at the next few characters
> instead of only the very next character.  Here's a simple 1-minute
> implementation proposal, but since it seems strange this was never
> added before, I wanted to check my sanity with the brilliant developer
> folk, here.
> PositionableStream>>peek: anInteger
>    "Answer what would be returned if the message next: anInteger
> without advancing the internal position pointer."
>    | priorPos result |
>    priorPos := position.
>    result := self next: anInteger.
>    position := priorPos.
>    ^ result
> Thanks,
>  Chris

tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Strange OpCodes: BPB: Branch on Program Bug

More information about the Squeak-dev mailing list