<div dir="ltr"><div><div>Bob,<br></div>been there, done that in SqueaXTream: but with a slightly different inst var:<br><br><font face="Georgia"><font face="Georgia">next<br>
<br>
<primitive: 65><br>
position >= readLimit<br>
ifTrue: [^endOfStreamAction value] "a new instance variable the user can
leave nil or set to preferred marker"<br>
ifFalse: [^collection at: (position := position + 1)]</font></font><br><br></div>It works for a block, nil, etc ...<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/7/23 Bob Arning <span dir="ltr"><<a href="mailto:arning315@comcast.net" target="_blank">arning315@comcast.net</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<font face="Georgia">Given that there might be a performance issue
in some (rare) cases, but especially because of the potential for
the wrong handler seeing the exception, another approach might be
more acceptable. Some possibilities:<br>
</font><br>
<font face="Georgia"><font face="Georgia"><font face="Georgia">=======================</font><br>
next<br>
<br>
<primitive: 65><br>
position >= readLimit<br>
ifTrue: [^eos] "a new instance variable the user can
leave nil or set to preferred marker"<br>
ifFalse: [^collection at: (position := position + 1)]<br>
=======================<br>
</font>nextIfNone: aBlock<br>
<br>
<primitive: 65><br>
position >= readLimit<br>
ifTrue: [^aBlock value]<br>
ifFalse: [^collection at: (position := position + 1)]<br>
</font><br>
<font face="Georgia">=======================</font><br>
nextOrEOS: endOfStreamMarker<br>
<br>
<primitive: 65><br>
position >= readLimit<br>
ifTrue: [^endOfStreamMarker]<br>
ifFalse: [^collection at: (position := position + 1)]<br>
<font face="Georgia">=======================</font><br>
nextOrSelf<br>
<br>
<primitive: 65><br>
position >= readLimit<br>
ifTrue: [^self] "if the stream is known not to contain
itself, then self could be the marker"<br>
ifFalse: [^collection at: (position := position + 1)]<br>
<font face="Georgia">=======================</font><br>
<br>
Cheers,<br>
Bob<div><div class="h5"><br>
<font face="Georgia"><br>
</font>
<div>On 7/22/13 8:59 PM, Levente Uzonyi
wrote:<br>
</div>
<blockquote type="cite">On Mon, 22 Jul 2013, Frank Shearar wrote:
<br>
<br>
<blockquote type="cite">I'm half-tempted to say "in that case the
user should use Xtreams".
<br>
Because the weird behaviours around #next and #atEnd were pretty
much<br>
the main drivers behind it.
<br>
<br>
Do you use EndOfStream like this (to allow nil objects in a
Stream of objects)?
<br>
</blockquote>
<br>
Your question is misleading. nil can be in any stream, but #next
will also return nil, when the stream is #atEnd. If you know that
your stream doesn't have nils in it, then using #next is safe (and
fast), otherwise you should not rely on #next's return value to
decide if it was a valid read or not. That's what #atEnd is for.
<br>
<br>
Signaling an Exception when a ReadStream is #atEnd should not
really cause performance issues. It can only be a problem, when
you are repeatedly reading from short streams. Xtreams also uses
this technique.
<br>
<br>
<br>
Levente
<br>
<br>
<blockquote type="cite">
<br>
frank
<br>
<br>
On 22 July 2013 17:09, Chris Muller <a href="mailto:asqueaker@gmail.com" target="_blank"><asqueaker@gmail.com></a>
wrote:
<br>
<blockquote type="cite">What if a system needs to allow nil
objects in a Stream of objects and
<br>
have it be treated as just another object in the stream rather
than
<br>
the EOS marker?
<br>
<br>
So, maybe ReadStream>>#next _should_ be signaling
EndOfStream, so the
<br>
sender of #next can know the difference in that scenario.
Since the
<br>
defaultAction is ^nil, presumably we could simply change #next
to do
<br>
that with no breakage...
<br>
<br>
On Mon, Jul 22, 2013 at 9:02 AM, Frank Shearar
<a href="mailto:frank.shearar@gmail.com" target="_blank"><frank.shearar@gmail.com></a> wrote:
<br>
<blockquote type="cite">EndOfStream has no references in the
base image. It claims to be used
<br>
by ReadStream >> #next, but that's not true.
<br>
<br>
Time to die/deprecate?
<br>
<br>
frank
<br>
<br>
</blockquote>
</blockquote>
<br>
<br>
</blockquote>
<br>
<br>
</blockquote>
<br>
</div></div></div>
<br><br>
<br></blockquote></div><br></div>