[squeak-dev] PositionableStream >> #peekBack behavior

Eric Gade eric.gade at gmail.com
Thu Aug 6 18:27:51 UTC 2020


Hello,

What is the expected behavior for a stream that is at position 1 when you
send #peekBack? Intuitively I'd expect to get the first element of the
underlying collection as a response. But instead I am getting nil.

Here is an example that is failing:
```
elem := #(1 2 3 4).
stream := ReadStream on: elem.
first := stream next.
first = 1.
back := stream peekBack.
back = first.
```
The last message is currently responding false. In Pharo this returns true,
so there are differences.

The currently implementation of PositionableStream >> #peekBack is:
```
peekBack
"Return the element at the previous position, without changing position.
Use indirect messages in case self is a StandardFileStream."

| element |
self position = 0 ifTrue: [self errorCantGoBack].
self position = 1 ifTrue: [self position: 0.  ^ nil].
self skip: -2.
element := self next.
self skip: 1.
^ element
```

I can see the nil being returned there explicitly, so that's "where it's
happening." Should this be the case though?

Thanks


-- 
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200806/5d57d3b4/attachment.html>


More information about the Squeak-dev mailing list