Debugging assistance please :-)

Avi Bryant avi at beta4.com
Tue Oct 26 11:32:41 UTC 2004


On Oct 26, 2004, at 1:26 PM, Christopher Barham wrote:

> Hi,
>
> I'm fairly new to Squeak and Smalltalk, I've been playing with various
> programming snippets to improve my fluency.
>
> I have some Ruby code that generates an Ascii representation of a 
> Mandelbrot
> fractal, and thought it may be fun to translate over to squeak.
>
> I've managed to tie myself in knots with a basic syntax error, and I 
> can't
> spot it - can anyone mentor me and point me towards the error?  It's 
> driving
> me nuts :-)

Well, your "syntax" error (or rather, the semantic error that happens 
to be caught by the compiler) is that you're sending #whileTrue: to 
something that isn't a block - it should be

[e > -1.2] whileTrue: [...]

rather than

(e > -1.2) whileTrue: [...]

and ditto elsewhere in your code.

Intuitively, you need this because the comparison of e with -1.2 is 
going to be evaluated many times, and so it needs to be inside a block 
to allow that to happen.  That's why #whileTrue: is sent to a block, 
but #ifTrue: isn't.

Looking ahead a couple of steps, let me just point out that Smalltalk 
doesn't special case the precedence of arithmetic operators (they're 
left to right like any other selector), so you may want to add in a few 
parentheses here and there.

Avi




More information about the Squeak-dev mailing list