Smalltalk Hello World

A long, long time ago, before even the 8080, I could do this (on the SinclairSpectrum):

   10 PRINT "Hello World"         (* see footnote)

My reward:

  Hello World

A few years later, I got hold of a PC and a copy of KernighanAndRitchie, and armed with the knowledge it bestowed, I opened my TextEditorOfChoice?, and entered:

  #include <stdio.h>

int main() { printf("Hello world\n"); return 0; }

Sometime later, in the early stages of trying to understand PerlLanguage (which is an ongoing task), I'm sure that at the CommandPrompt, I tried typing something like:

  perl -e "print qq{Hello World\n}" 

NB, I didn't type the following, as it doesn't work on a Windows command prompt:

  perl -e 'print "Hello World\n"'

I'm also sure that at some time, armed with my TextEditorOfChoice?, I compiled the following abhorrence:

  #include <iostream>

using namespace std;

int main() { cout << "Hello World" << eol; return 0; }

Hell, one time I even booted a SchemeLanguage interpreter, and at the CommandPrompt, I typed:

  (display "Hello World\n")

(And I believe I even persuaded a CommonLisp variant to play ball with a similar invokation). By the time I got to Ruby, I was in the swing of things:

  puts "Hello World"

didn't phase me at all. I was feeling pretty happy with myself. Hell, there's no programming language which I can't convince to emit a hackneyed greeting aimed at no one in particular.

So, maybe I'm getting blase, I thought I'd have a go at doing the same in Smalltalk, how hard could that be? So, according to my understanding the correct incantation is:

  Transcript show: 'Hello World'.

Seems fair enough.

However, at this stage I run into metaphorical difficulties (by which I mean I run into difficulties involving metaphors, not that the difficulties I run into are metaphorical). So far I've tried two versions of Smalltalk (Squeak and VisualWorks), and I've yet to find anything approximating a CommandPrompt. Sure, there's windows you can type text into, but when hitting the enter key, nothing in particular seems to happen. I can't even get a Syntax Error, or any kind of acknowledgement that I'm even typing. Now don't get me wrong here, there's no shortage of windows, and there seems to be a programming language in there somewhere? However, this is most confusing.

As a postscript, I've found that if I enter the following into VisualWorks:

  Transcript show: 'Hello World' printString.

and then highlight it and right-click and select "Do it", the following text appears (albeit with no carriage return):

  'Hello World'

Which seems close to my intent, but I've no way of knowing if that message actually appeared on STDOUT, and I have a suspicion that it didn't. Anyways, I'll keep bashing at my keyboard, I'm sure one millionth of a Shakespeare play will eventually emerge...

[or you could learn the basic command keys, cmd d|i|p, do it, inspect it, and print it, then simply typing Transcript show: 'Hello World' cmd+P would print the result you were looking for. Cmd + I would pull up an inspector on the hello world string. In essence, the entire Smalltalk environment is a single permanent long term command shell environment, every text box anywhere in the image is executable part of that shell, far more advanced than a simple dos like command shell that doesn't maintain state between sessions. You can highlight any text anywhere and use those hotkeys to invoke it, do it, print it, inspect it, whatever. If you create a test object, it just lives on until there are no more references to it, even if you change it's class, there is no compile/run/debug/recreate state cycle, it's always runtime. ]

The following,

   Transcript show: 'Hello World'; cr
prints

   Hello World

to the Transcript with a carriage return. Adding a printString causes the Transcript to show a representation of the string 'Hello World' which representation includes quotes. IOW, not the same thing. Also, you should consider selecting and evaluating a piece of code (with ctrl-d in VW) to be the equivalent of Perl's

   perl -q "<code>"
And a damn sight less verbose it is too.

Sometimes there's a way to access stdin and stdout, there's a package for VW 7.3 called Standard IO Streams that allows it. The Smalltalk (and especially VW's) philosophy is that the language is self-contained and can't rely on OS-specific junk, let alone obsolete crap like stdin and stdout. That's why you have the Transcript instead. Consider that if you use Standard IO Streams except where it is desperately needed, you are breaking your code.


OctoberZeroFive

CategorySmalltalk


EditText of this page (last edited June 17, 2006) or FindPage with title or text search