<div dir="ltr"><div dir="auto"><div id="gmail-m_-983000967231994215AppleMailSignature">Hi Denis,</div><div><br>On Apr 4, 2018, at 7:32 AM, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com" target="_blank">dionisiydk@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr">Hi Eliot.<div><br><div class="gmail_extra"><div class="gmail_quote">2018-04-04 16:12 GMT+02:00 Eliot Miranda <span dir="ltr"><<a href="mailto:eliot.miranda@gmail.com" target="_blank">eliot.miranda@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Hi Denis, Hi Sven,</div><span><div><br>On Apr 4, 2018, at 3:16 AM, Denis Kudriashov <<a href="mailto:dionisiydk@gmail.com" target="_blank">dionisiydk@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>Hi.</div><div><br></div>#next returning nil is definitely looks bad because we will always have case when nil value will not means the end:<div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div>#(1 nil 2) readSteam next; next; atEnd</div><div><br></div></blockquote>But I understand that in many cases analysing #next for nil is much more suitable than #atEnd. I am sure that it can be always avoided but it can be not easy to do.<div>Alternatively we can reify real EndOfStream object which will be used as result of reading operation when stream is at end.</div><div>It can provide nice API like #ifEndOfStream:. which will reflect intention in much cleaner way than ifNil: checks. </div></div></div></blockquote><div><br></div></span>There is a much better scheme which is to allow streams to have an end-of-file element in an inst var, "endOfStream".  It is initialised with the stream itself (nil cannot be used as we want it as a value).  If the end of the stream is reached and <span style="background-color:rgba(255,255,255,0)">endOfStream == self an EndIfStream exception is raised.  Otherwise the value of endOfStream is answered.  </span></div></blockquote><div><br></div><div>Does it mean that at the end of stream:</div></div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>aStream next == aStream</div></div></div></div></blockquote><div><div class="gmail_extra"><div class="gmail_quote"><div> ?</div></div></div></div></div></div></blockquote><div><br></div>Of course not.  Did you read what I write above?  <span style="background-color:rgba(255,255,255,0)">If the end of the stream is reached and endOfStream == self an EndIfStream exception is raised.   The idea is that endOfStream == self is a market that the default behaviour should occur at end of stream, and in all other cases the endOfStream should be returned.</span><div><br></div><div>e.g. </div><div><br></div><div>ReadStream>>next<div><span class="gmail-Apple-tab-span" style="white-space:pre">    </span>"Primitive. Answer the next object in the Stream represented by the</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span>receiver. Fail if the collection of this stream is not an Array or a String.</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>Fail if the stream is positioned at its end, or if the position is out of</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">      </span>bounds in the collection. Optional. See Object documentation</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">   </span>whatIsAPrimitive."</div><div><br></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">       </span><primitive: 65></div><div><span class="gmail-Apple-tab-span" style="white-space:pre">  ^</span>position >= readLimit</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>ifTrue: [<b>self pastEnd</b>]</div><div><span class="gmail-Apple-tab-span" style="white-space:pre">              </span>ifFalse: [collection at: (position := position + 1)]</div><div><br></div><div>ReadStream>>pastEnd</div><div><span style="white-space:pre"> "The stream is at its end; respond appropriately.  If the endOfStream element has</span><br></div><div><span style="white-space:pre">       been set, answer it, otherwise raise an exception."<br></span></div><div><span style="white-space:pre">   ^endOfStream == self</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">     </span><span style="white-space:pre">     ifTrue: [self class endOfStreamSignal signal]</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">    </span><span style="white-space:pre">     ifFalse: [</span><span style="white-space:pre">endOfStream]</span><span style="white-space:pre"><br></span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">then for the current behavior of answering nil on end of stream endOfStream is set to nil.  By default endOfStream would be initialized to self, meaning that an exception is raised on end of stream by default.</span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre"><br></span></div><div><span style="white-space:pre">And I'm wrong.  This scheme is not used in VisualWorks.  They ripped it out after I left.  It's not in vw7.7.</span></div><div><span style="white-space:pre"><br></span></div><blockquote type="cite"><div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><span style="background-color:rgba(255,255,255,0)">We can't answer nil because in some applications (streams of objects) nil is a valid element to read from the steam and we need to manufacture a unique sentinel.</span><div><br></div><div>We made this change in VisualWorks and it works well.  One can avoid using atEnd and lion for the sentinel instead, which is much cleaner and faster and less problematic than atEnd.</div><div><div class="gmail-m_-983000967231994215h5"><div><br><blockquote type="cite"><div><div dir="ltr"><div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-04-04 12:00 GMT+02:00 Sven Van Caekenberghe <span dir="ltr"><<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span><br>
<br>
> On 4 Apr 2018, at 11:38, Nicolas Cellier <<a href="mailto:nicolas.cellier.aka.nice@gmail.com" target="_blank">nicolas.cellier.aka.nice@gmai<wbr>l.com</a>> wrote:<br>
><br>
> Hi Sven,<br>
> See also discussion at <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232" rel="noreferrer" target="_blank">https://github.com/OpenSmallta<wbr>lk/opensmalltalk-vm/pull/232</a><br>
<br>
</span>Thanks Nicolas, I had already seen parts of it.<br>
<br>
Now, I still want image level changes to be based on clear semantic definitions of the abstract stream API, we're not just talking about file or unix streams, the general Smalltalk concept.<br>
<br>
For reading, they are IMHO,<br>
<br>
#next<br>
#readInto:startingAt:count:<br>
#peek<br>
#atEnd<br>
#upToEnd (can be derived but still the semantics are important in relation to #atEnd)<br>
<br>
For writing, we have<br>
<br>
#nextPut:<br>
#next:putAll:startingAt:<br>
#flush<br>
<br>
For both, we have<br>
<br>
#atEnd<br>
#close<br>
#closed (new)<br>
<br>
So, I know, #next returning nil exists, but is it universally/officially defined as such ? Where is that documented ?<br>
<br>
Positioning, sizing are not universal, IMHO, but should be clearly defined as well.<br>
<div class="gmail-m_-983000967231994215m_1512194409756006877HOEnZb"><div class="gmail-m_-983000967231994215m_1512194409756006877h5"><br>
> 2018-04-04 11:32 GMT+02:00 Sven Van Caekenberghe <<a href="mailto:sven@stfx.eu" target="_blank">sven@stfx.eu</a>>:<br>
> Somehow, somewhere there was a change to the implementation of the primitive called by some streams' #atEnd.<br>
><br>
> IIRC, someone said it is implemented as 'remaining size being zero' and some virtual unix files like /dev/random are zero sized.<br>
><br>
> Now, all kinds of changes are being done image size to work around this.<br>
><br>
> I am a strong believer in simple, real (i.e. infinite) streams, but I am not sure we are doing the right thing here.<br>
><br>
> Point is, I am not sure #next returning nil is official and universal.<br>
><br>
> Consider the comments:<br>
><br>
> Stream>>#next<br>
>   "Answer the next object accessible by the receiver."<br>
><br>
> ReadStream>>#next<br>
>   "Primitive. Answer the next object in the Stream represented by the<br>
>   receiver. Fail if the collection of this stream is not an Array or a String.<br>
>   Fail if the stream is positioned at its end, or if the position is out of<br>
>   bounds in the collection. Optional. See Object documentation<br>
>   whatIsAPrimitive."<br>
><br>
> Note how there is no talk about returning nil !<br>
><br>
> I think we should discuss about this first.<br>
><br>
> Was the low level change really correct and the right thing to do ?<br>
><br>
> Note also that a Guille introduced something new, #closed which is related to the difference between having no more elements (maybe right now, like an open network stream) and never ever being able to produce more data.<br>
><br>
> Sven<br>
><br>
><br>
><br>
><br>
<br>
<br>
</div></div></blockquote></div><br></div>
</div></blockquote></div></div></div></div><br><br>
<br></blockquote></div><br></div></div></div>
</div></blockquote><blockquote type="cite"><div><span></span><br></div></blockquote></div></div></div>