I need someone to poke me with a clue stick please!
I am trying to step through a file a line at a time. I had the idea that this should work
aFileStream nextLine do: [ :line| Transcript show: line; cr.].
Unfortunately (as will be obvious to everyone) what it actually does is print a character at a time. It took me a while to realise that - aFileStream nextLine - is returning a string and the - do: - passing the block to each character.
I need a way of passing the block to the string a line at a time. Or perhaps I have got this totally back to front and there is a much easier way of doing this?
Cheers AB
You could do something like [aFileStream atEnd] whileFalse: [line := aFileStream nextLine. Transcipt show: line: cr.]
Alternatively, you could convert your stream of characters into a stream of lines. I described something similar in http://wiki.cs.uiuc.edu/PatternStories/FunWithStreams but it created a stream of words instead of a stream of lines. Read that, and you should be able to make a LineStream pretty easily.
-Ralph Johnson
Ralph Johnson a écrit :
You could do something like [aFileStream atEnd] whileFalse: [line := aFileStream nextLine. Transcipt show: line: cr.]
Alternatively, you could convert your stream of characters into a stream of lines. I described something similar in http://wiki.cs.uiuc.edu/PatternStories/FunWithStreams but it created a stream of words instead of a stream of lines. Read that, and you should be able to make a LineStream pretty easily.
-Ralph Johnson _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Thanks
Very cool :)
Do you mind if I use it for reading token in the NewCompiler?
Math
this is free mathieu. This is a pattern. Use it :)
stef
On 17 sept. 06, at 19:51, Mathieu wrote:
Ralph Johnson a écrit :
You could do something like [aFileStream atEnd] whileFalse: [line := aFileStream nextLine. Transcipt show: line: cr.]
Alternatively, you could convert your stream of characters into a stream of lines. I described something similar in http://wiki.cs.uiuc.edu/PatternStories/FunWithStreams but it created a stream of words instead of a stream of lines. Read that, and you should be able to make a LineStream pretty easily.
-Ralph Johnson _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
Thanks
Very cool :)
Do you mind if I use it for reading token in the NewCompiler?
Math
Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
hi ralph
why in your pattern you have block around Stream classes ?
Stef
On 17 sept. 06, at 01:28, Ralph Johnson wrote:
You could do something like [aFileStream atEnd] whileFalse: [line := aFileStream nextLine. Transcipt show: line: cr.]
Alternatively, you could convert your stream of characters into a stream of lines. I described something similar in http://wiki.cs.uiuc.edu/PatternStories/FunWithStreams but it created a stream of words instead of a stream of lines. Read that, and you should be able to make a LineStream pretty easily.
-Ralph Johnson _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
On 9/17/06, stéphane ducasse ducasse@iam.unibe.ch wrote:
hi ralph
why in your pattern you have block around Stream classes ?
Stef
It was a mistake. It was supposed to be a hyperlink, and [] are the hyperlink delimiters on WikiWorks, but the code was inside a /pre tag, so hyperlinks don't work. I fixed it.
Thanks!
-Ralph
Ralph Johnson a écrit :
On 9/17/06, stéphane ducasse ducasse@iam.unibe.ch wrote:
hi ralph
why in your pattern you have block around Stream classes ?
Stef
It was a mistake. It was supposed to be a hyperlink, and [] are the hyperlink delimiters on WikiWorks, but the code was inside a /pre tag, so hyperlinks don't work. I fixed it.
Thanks!
-Ralph
:) I thought you were using a really strange dialect of smalltalk so I go through my installed smalltalk to search for a basicNew on BlockContext :)
Math
beginners@lists.squeakfoundation.org