First steps

Posted: 2011/06/15 in programming
Tags: ,

Installing

Getting GNU Smalltalk installed is a very easy process, as it comes with your favourite Linux / Unix flavour and due to the MacPorts Project even on the Mac. It’s possible that the version provided by your operating system of choice is a bit outdated, so you may should download the latest stable sources from the GNU Smalltalk website and build it for yourself. You just need to install the development-versions of the libraries as explained in the link above and then type the famous trio:

./configure
make
make install

The latter you should of course do as a root-user. After typing make it is a good advise to type make check, too. I for example had some troubles on a Debian PowerPC machine with imprecisions in floating point operations. If all is fine you should find (amongst others) a binary called gst somewhere on your system.

Playing around

Then I began feeling somehow lost. Where to start? I figured out, that in contrast to other Smalltalks, you can type your code in normal textfiles like you do in other (C-inspired) languages, too. Name your file with the prefix .st and run it with the commandline interpreter gst like that:

gst yourfile.st

That’s the reason they’re greeting you on  their website with the slogan “The Smalltalk for those who can type”. Unlike other Smalltalks, you don’t need an IDE to start coding, just type in all your code in ordinary text files.

So let’s play a little bit:

marc$ gst
GNU Smalltalk ready

st> 'What''s so special about Smalltalk?' printNl.
'What''s so special about Smalltalk?'
'What''s so special about Smalltalk?'

Uhm, that’s looking strange. In PHP we would do something like

print "What's so special about PHP?";

In Smalltalk (nearly) everything is an object. So 'sometext' immediately creates an object of the class String with the value sometext.

As everything is an object, even the instruction to print something is a message that is sent to a String object (yes, in Smalltalk you call methods messages, which are sent to objects). So in our example the message printNl is sent directly to the newly created String object. And this is exactly what it does: printing the string to the user (and appending a newline character). But why, you may ask, the string is printed twice? Because gst many messages in Smalltalk are designed to return the last parameter.

Now it’s time to dig a little bit deeper into the world of (GNU) Smalltalk. A good place to start is the free book Computer Programming using GNU Smalltalk by Canol Gökel.

Links
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s