Yeah, I understand. The thing is that we will remove in the near future MultiByteFileStream. And not all streams have conceptually a position. Today there was a mail from Sven about that. On Mon, Nov 13, 2017 at 2:48 PM, Prof. Andrew P. Black <black@cs.pdx.edu> wrote:
On 2 Nov 2017, at 10:10 , Guillermo Polito <guillermopolito@gmail.com> wrote:
My first hunch is that you don't want to change PositionableStream. Because it works on collections and files (because of inheritance). But not on other kind of streams that are not part of the hierarchy, such as sockets. And we are cleaning that part.
Instead, some time ago Sven produced a really nice hierarchy of stream decorators. Check the package:
Zinc-Character-Encoding-Core
There you have
ZnBufferedReadStream
That implements buffering in an orthogonal way. Maybe it makes more sense to put such method there?
I wanted this to be something light-weight. I really donât want to have to wrap my stream in a decorator before peeking ahead.
Because Iâm doing this in SmaCC, I implemented #explore: (thatâs the name I chose) in SmaCCLineNumberStream. But I think that the general solution is to put this method in a Trait, so that it can be combined into any stream, whether or not that stream inherits from PositionableStream. There are probably other methods that could go in such a trait too.
Actually, the idea of resetting a stream to a prior position is much less general, and easier to implement, then general positionability. Over the weekend I posted an issue that discusses positioning a MultiButeFileStream â thatâs a good example.
Here is my implementation â really simple.
``` explore: aBlock "evaluate aBlock with this stream as argument. When done, reset my position to the current position."
| savedPosition | savedPosition := self position. [ ^ aBlock value: self ] ensure: [ self position: savedPosition ] ```
Andrew
-- Guille Polito Research Engineer Centre de Recherche en Informatique, Signal et Automatique de Lille CRIStAL - UMR 9189 French National Center for Scientific Research - *http://www.cnrs.fr <http://www.cnrs.fr>* *Web:* *http://guillep.github.io* <http://guillep.github.io> *Phone: *+33 06 52 70 66 13