Re: [Pharo-users] can I do this with a stream or a format

2019-05-17 Thread Tim Mackinnon
Actually that is the hidden gem on all of this - thinking about the common things people do through new eyes, has forced me to learn new things (and that feels very compatible with Pharo). I also thank everyone here for entertaining these questions and hopefully help build another way for

Re: [Pharo-users] can I do this with a stream or a format

2019-05-17 Thread Esteban Maringolo
The good thing about these exercises is that you know about new selectors, I didn't know there was an #allButLast and #allButLastDo:. Regards, Esteban A. Maringolo On Fri, May 17, 2019 at 5:44 AM Sven Van Caekenberghe wrote: > I would make that > > ^ String new: gifts size * 10

Re: [Pharo-users] can I do this with a stream or a format

2019-05-17 Thread Sven Van Caekenberghe
I would make that ^ String new: gifts size * 10 streamContents: [ :stream | gifts allButLastDo: [:each | stream nextPutAll: each; nextPutAll: ', ']. stream nextPutAll: 'and '; nextPutAll: gifts last ] Your iteration is well done, clear and to the point. > On 17 May 2019, at 02:44,

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Richard O'Keefe
stream := WriteStream on: (String new: gifts size * "estimated size per gift" 10). "The number after #new: is the *initial* allocation; the stream will reallocate it as needed." gifts allButLastDo: [:each | stream nextPutAll: each; nextPutAll: ', ']. stream nextPutAll: 'and '; nextPutAll:

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
I made the error somehow. Sorry for the confusion. Roelof Op 16-5-2019 om 22:29 schreef Esteban Maringolo: Oh... the expected output was 'e1, e2, e3 and e4', I read "all" instead of "and".

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Esteban Maringolo
Oh... the expected output was 'e1, e2, e3 and e4', I read "all" instead of "and". Now it makes sense. Esteban A. Maringolo On Thu, May 16, 2019 at 5:09 PM Roelof Wobben wrote: > and this is working > > String > streamContents: [ :stream | > gifts

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
and this is working String                 streamContents: [ :stream |                     gifts allButLast                         do: [ :each | stream nextPutAll: each ]                         separatedBy: [ stream                          

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
nope, it takes also the last one and that schould not be used. Op 16-5-2019 om 21:51 schreef Roelof Wobben: I think this is better  ^  String streamContents: [:stream | gifts do: [:each | stream

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Esteban Maringolo
Sorry, I misses the "all" part at the end (I don't see how that could add something, but if it's in the requirements...) Then it should be like this: String streamContents: [:stream | gifts allButLast do: [:each | stream nextPutAll: each ] separatedBy: [ stream nextPut: $,; space ].

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
I think this is better  ^  String streamContents: [:stream | gifts do: [:each | stream nextPutAll: each ] separatedBy: [ stream nextPut: $,; space ] stream nextputAll: 'all'; nextPut: ','; nextPut: gifts last] Op 16-5-2019

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
oke, and then do something like : stream := String streamContents: [:stream | gifts do: [:each | stream nextPutAll: each ] separatedBy: [ stream nextPut: $,; space ] ] stream nextputAll: 'all' stream nextPut: ',' stream nextPut: gifts last Roelof

Re: [Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Esteban Maringolo
Maybe this is a better way to build what you want. String streamContents: [:stream | gifts do: [:each | stream nextPutAll: each ] separatedBy: [ stream nextPut: $,; space ] ] Esteban A. Maringolo On Thu, May 16, 2019 at 4:21 PM Roelof Wobben wrote: > Hello, > > Im testing all my

[Pharo-users] can I do this with a stream or a format

2019-05-16 Thread Roelof Wobben
Hello, Im testing all my solutions with critiz and can solve almost all problems, Only this one I cannot figure out. I have this code (gifts allButLast inject: '' into: [ :str :each | str , each , ', ' ]) , 'and ' ,