logo       

Re: I am a total beginner with some questions: msg#00079

lang.smalltalk.squeak.beginners

Subject: Re: I am a total beginner with some questions

Michael Haupt wrote:
Hi,

I wonder why no one has recommended the excellent "Squeak by Example"
book yet... to get a hang of what programming in Squeak looks (and
feels) like, you *really* ought to work your way through this book.
It's available as a free PDF download: http://www.squeakbyexample.org/

Now, on to your problem...

On Wed, Apr 9, 2008 at 2:38 AM, kennellgr <cboneg5@xxxxxxxxx> wrote:
I appreciate the help. I tried it out and it works. I have one problem
though. I created a method called "gdkDKeyDown" (gdk is my innitials so I
put it before my methods) and when I type gdkDKeyDown in a workspace and
print it it says nil (it's supposed to say true or false) how do I make it
return a value?

In Smalltalk (and hence, also in Squeak), you cannot simply invoke a
method by typing its name and issuing "do it" or "print it" - instead,
you send a message to an object. To be able to do that, you need to
implement the method in some class so that instances of that class can
actually understand the message (and effectively execute the method).


A little bit more explanations: Why this nil?

If you take a look further at a formal description of Smalltalk syntax, you will see that this sentence:
gdkDKeyDown.
can only be interpreted as a variable, and in this case an undeclared variable (from the workspace, only global variables from the Smalltalk SystemDictionary are visible, also as variables attached to the workspace as explained below).

When you evaluate ("doIt") from a workspace, then such undeclared variables are automatically declared as workspace variables.

And since no value has ever been assigned to this workspace variable, it is initialized with an instance of UndefinedObject, that is nil (the sole instance of UndefinedObject in fact).

When you think of it, the meaning is simply undefined, something like the NULL pointer in other languages... except that in Smalltalk this is just an object among other objects. Yes as if you could operate on the NULL pointer without crashing the application with a segmentation fault.
Isn't it a nice property?

You now need to find to which object you should send the gdkDKeyDown message...

Please look at "Squeak by Example"; I really feel you need to do that
before you start. :-)


I strongly second Michael advice.

Cheers

Nicolas


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise