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

Chris Muller asqueaker at gmail.com
Sun Oct 7 17:45:11 UTC 2018


Ah.  Yes, it seems I was locked into my projects context, and knowing
my own specific Stream types.  I considered sending #position:
instead, but wanted to avoid any possible side-effects -- I simply
wanted to be sure the state of the object was not disturbed, but
you've helped me realize the #next: could have side-effects itself
beyond 'position' which may need undone.

I'm not up to testing all of the stream types so I probably will do
this peeking higher up in my app code.

Thanks.
On Sun, Oct 7, 2018 at 11:59 AM tim Rowledge <tim at rowledge.org> wrote:
>
> 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
> --
> 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