[ANSI-Smalltalk] #contents on WriteStream
John O'Keefe
wembley.instantiations at gmail.com
Fri Oct 17 13:12:48 BST 2008
In VA Smalltalk
(WriteStream on: String new) nextPutAll: 'abc'; skip: -1;
contents
also answers 'ab'.
John O'Keefe [|], Principal Smalltalk Architect, Instantiations Inc.
On Thu, Oct 16, 2008 at 10:04 PM, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
>
> On 16 Oct 2008, at 8:14 pm, Paolo Bonzini wrote:
>
> In the standard, the definition of #contents for <WriteStream> comes
>> from <collectionStream> so that this:
>>
>> (WriteStream on: String new) nextPutAll: 'abc'; skip: -1;
>> contents
>>
>> should "return a collection that contains the receiver's past and future
>> sequence values, in order", i.e. 'abc'. To me it makes more sense that
>> it returns 'ab'.
>>
>
> In Squeak and VisualWorks the answer is indeed 'ab',
> which I find rather counterintuitive. The $c is,
> after all, still part of the contents, and skip: 1
> will reveal it.
>
> In implementation terms, it's the difference between
>
> ^collection copyFrom: 1 to: position
>
> and
>
> ^collection copyFrom: 1 to: readLimit
>
> My library, written to the standard, does the latter;
> Squeak and VisualWorks do the former.
>
> The meaning of #contents in the standard is
> "a collection containing the complete contents of the stream".
>
> If you do
> (ReadStream on: 'abc') skip: 2; contents
> you get all the characters, not just the remaining ones.
>
> Nasty one: the standard's definition is simple, sensible,
> and easy to implement (except for file streams, of course,
> (:-)). But implementations do something else.
>
> What do other Smalltalks than Squeak and VW do?
>
>
>
>
> _______________________________________________
> ANSI-Smalltalk mailing list
> ANSI-Smalltalk at lists.openskills.org
> http://lists.openskills.org/cgi-bin/mailman/listinfo/ansi-smalltalk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openskills.org/pipermail/ansi-smalltalk/attachments/20081017/a849fef0/attachment.html
More information about the ANSI-Smalltalk
mailing list