Playing around with the "dollar-matching-question" I attempted to copy a Writestream and set the position to the end of the stream with >>setToEnd - it didn't work. Is this expected behaviour? If yes, how can I create a copy of a WriteStream to which I can append new stuff?
ex: |s c | s := String new writeStream. s nextPutAll: 'bbb'. c := s contents setToEnd "position is 0 instead of 3" Steffen _______________________________________________________________________ Jetzt neu! Schützen Sie Ihren PC mit McAfee und WEB.DE. 30 Tage kostenlos testen. http://www.pc-sicherheit.web.de/startseite/?mc=022220 _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Steffen Märcker wrote:
> Playing around with the "dollar-matching-question" I attempted to copy > a Writestream and set the position to the end of the stream > with >>setToEnd - it didn't work. Is this expected behaviour? If yes, > how can I create a copy of a WriteStream to which I can append new > stuff? > > ex: > > |s c | > s := String new writeStream. > s nextPutAll: 'bbb'. > > c := s contents setToEnd "position is 0 instead of 3" The last line sends #setToEnd to the String return value of #contents, which gives an error. If you just send #contents, the stream's position is 3. I'm not quite sure what you were doing to get the position set to somewhere other than the end. If you do manage it (e.g. with "s skip: -1"), then #setToEnd works fine and sets it back to 3. Ahah! I think I've guessed: were you running these lines in a Workspace? If you run some of the lines individually, you end up with two variables called "s": one defined as a temporary at the top, and one auto-defined as a workspace variable when running (say) the second line on its own. If you then inspect s, it will interpreted as the workspace variable, whose value is an empty stream, position=0. The easiest solution to this is just not to define temporaries in a workspace. That way all the variables are auto-defined, and all have the same lifespan as the workspace, so you can always look at their values from the Variables tab or with Inspect. Cheers, Steve _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Steffen Märcker
I am sorry, there is an typo, correct is:
> |s c | > s := String new writeStream. > s nextPutAll: 'bbb'. > > c := s contents writeStream setToEnd "position is 0 instead of 3" @Nic: So is setToEnd not ment to set the writePosition in a WriteStream? My underlying problem is, that I want to get a copy of the stream on a copy of the underlying collection too. That's why I cannot use > c := s copy. > c nextPutAll: 'hello'. ... both streams would write to the same string. Is there a better way than > c := (String new writeStream) nextPutAll: s contents; yourself. ? @Steven Kelly: Thanks for your answer. The code snipped is cutted out of a class to be executable in an workspace for the other list members. Ciao, Steffen _________________________________________________________________________ In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten! Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114 _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Steffen Märcker
Ah, then you want to use #with: not #on:, like this:
s := WriteStream with: 'foo' copy. s nextPut: $d. s contents "=> 'food' " I found it by looking for writers of the position instance variable. However, I think there's a good case for saying #setToEnd should be implemented in WriteStream to set position to writeLimit. I'm not sure what that would break in the current senders. Steve > -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On > Behalf Of Steffen Märcker > Sent: 25 September 2008 14:28 > To: [hidden email] > Subject: Re: [vwnc] WriteStream>>setToEnd > > I am sorry, there is an typo, correct is: > > > |s c | > > s := String new writeStream. > > s nextPutAll: 'bbb'. > > > > c := s contents writeStream setToEnd "position is 0 instead of 3" > > > @Nic: So is setToEnd not ment to set the writePosition in a WriteStream? > My underlying problem is, that I want to get a copy of the stream on a > copy of the underlying collection too. That's why I cannot use > > > c := s copy. > > c nextPutAll: 'hello'. > > ... both streams would write to the same string. Is there a better way > than > > > c := (String new writeStream) nextPutAll: s contents; yourself. ? > > > > @Steven Kelly: Thanks for your answer. The code snipped is cutted out > of a class to be executable in an workspace for the other list members. > > > Ciao, > Steffen > _______________________________________________________________________ > __ > In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und gestalten! > Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114 > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |