Problems with do:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems with do:

Andy Burnett
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
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

Ralph Johnson
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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

Mathieu SUEN
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
> [hidden email]
> 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
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

stephane ducasse-2
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
>> [hidden email]
>> 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
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

stéphane ducasse-2
In reply to this post by Ralph Johnson
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
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

Ralph Johnson
On 9/17/06, stéphane ducasse <[hidden email]> 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
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

stephane ducasse-2
this is what I thought but I did not dare changing the code :)


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Problems with do:

Mathieu SUEN
In reply to this post by Ralph Johnson
Ralph Johnson a écrit :

> On 9/17/06, stéphane ducasse <[hidden email]> 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 mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners