re-learning smalltalk

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

re-learning smalltalk

Damar Thapa-3
Hi,

I am trying smalltalk once again after 5/6 years -- a language hard to say goodbye!

I installed vw7.5nc and tried the tutorial http://www.cincomsmalltalk.com/tutorials/version7/tutorial1/weblogstats9.htm

I tried the following code from the above URL:

|stream line bag xFound|
bag := Bag new.
stream := 'ws000101.log' asFilename readStream.
[ stream atEnd ] whileFalse: [
  line := stream upTo: Character cr.
  line := line copyFrom: 50 to: line size.
  line := line copyFrom: (line indexOf: $/) to: line size.
  line := line copyUpTo: $,.
  xFound := line findString: '.asp' startingAt: 1.
  xFound > 0
  ifTrue:[ bag add: line. ]. ].
stream close.
bag inspect.

In the above,

 line := line copyFrom: 50 to: line size.
  line := line copyFrom: (line indexOf: $/) to: line size.
  line := line copyUpTo: $,.

is resulting "UndefinedObject>>unboundMethod" exception.  The above code without While loop works fine. Can somebody explains what is happening?

Thanks.

With regards,
Damar




Reply | Threaded
Open this post in threaded view
|

RE: re-learning smalltalk

Robin Barendregt

Just by looking at the code, one possible explanation might be that any line in the file after the first line is shorter than 50 characters, since the copyFrom: starts at that position.

 

Hth, Robin

 


From: Damar Thapa [mailto:[hidden email]]
Sent: zondag 6 mei 2007 3:42
To: [hidden email]
Subject: re-learning smalltalk

 

Hi,

I am trying smalltalk once again after 5/6 years -- a language hard to say goodbye!

I installed vw7.5nc and tried the tutorial http://www.cincomsmalltalk.com/tutorials/version7/tutorial1/weblogstats9.htm

I tried the following code from the above URL:

|stream line bag xFound|
bag := Bag new.
stream := 'ws000101.log' asFilename readStream.
[ stream atEnd ] whileFalse: [
  line := stream upTo: Character cr.
  line := line copyFrom: 50 to: line size.
  line := line copyFrom: (line indexOf: $/) to: line size.
  line := line copyUpTo: $,.
  xFound := line findString: '.asp' startingAt: 1.
  xFound > 0
  ifTrue:[ bag add: line. ]. ].
stream close.
bag inspect.

In the above,

 line := line copyFrom: 50 to: line size.
  line := line copyFrom: (line indexOf: $/) to: line size.
  line := line copyUpTo: $,.

is resulting "UndefinedObject>>unboundMethod" exception.  The above code without While loop works fine. Can somebody explains what is happening?

Thanks.

With regards,
Damar



Reply | Threaded
Open this post in threaded view
|

Re: re-learning smalltalk

Janko Mivšek
In reply to this post by Damar Thapa-3
Hi Damar,

First let me welcome back in Smalltalk wonderland :)

I just did that example and also got an error: This message needs a
positive integer argument. Here is a "diary" of my dealing with that
problem and this can help you to "get back into" debugging such problems:

1. Debugging shows that line size = 0 in:

        line := line copyFrom: 50 to: line size

    which is obviously wrong.

2. What is wrong with that line? Why it is empty?

Let me inspect a stream collection and specially its current position:
124. On that position we have Character lf (I'm on Linux). Hmm, here can
be a problem. The example code seems to expect cr as line-end but we
have a crlf combination.

3. Visualworks internaly use just cr for line-end, so we need to read a
file and make appropriate transformation. Usually it suffices to send a
read stream a message #lineEndTransparent :

stream := 'ws000101.log' asFilename readStream lineEndTransparent.

4. Let me rerun an example: again an error, but now on stream position
3536, again with lf! So above method didn' solve a problem? Let me
inspect position 124 again: in the middle of text. What about end of
line? still crlf.

5. Well let we be more specific about line end convention, let we use a
method #lineEndCRLF :

stream := 'ws000101.log' asFilename readStream lineEndCRLF.

Good, now we got a bag of urls as expected.


I hope that above debugging scenario will help you in a future too.

Best regards
Janko


Damar Thapa wrote:

> Hi,
>
> I am trying smalltalk once again after 5/6 years -- a language hard to
> say goodbye!
>
> I installed vw7.5nc and tried the tutorial
> http://www.cincomsmalltalk.com/tutorials/version7/tutorial1/weblogstats9.htm
>
> I tried the following code from the above URL:
>
> |stream line bag xFound|
> bag := Bag new.
> stream := 'ws000101.log' asFilename readStream.
> [ stream atEnd ] whileFalse: [
>   line := stream upTo: Character cr.
>   line := line copyFrom: 50 to: line size.
>   line := line copyFrom: (line indexOf: $/) to: line size.
>   line := line copyUpTo: $,.
>   xFound := line findString: '.asp' startingAt: 1.
>   xFound > 0
>   ifTrue:[ bag add: line. ]. ].
> stream close.
> bag inspect.
>
> In the above,
>
>  line := line copyFrom: 50 to: line size.
>   line := line copyFrom: (line indexOf: $/) to: line size.
>   line := line copyUpTo: $,.
>
> is resulting "UndefinedObject>>unboundMethod" exception.  The above code
> without While loop works fine. Can somebody explains what is happening?
>
> Thanks.
>
> With regards,
> Damar
>
>
>
>

--
Janko Mivšek
AIDA/Web
Smalltalk Web Application Server
http://www.aidaweb.si