Hello, World

Keeping with the tradition, the official place to start for a beginner with A4 is learning how to write a program that prints "Hello, world" to the screen.

This tutorial will cover slightly more than just that, but it should still be a good starting point for anybody who's new to programming. (More experienced folk should perhaps just type ./a4 usage.)

Some degree of computer literacy is still assumed here, but as long as you've used a computer for a few years it should be easy to learn how to program it!

Starting A4

Once you've downloaded and extracted A4, you can open a new file with the new command. To do this, you'll need to open a command line on your computer and navigate to the directory containing A4.

On a Unix/Linux/Mac operating system, if the a4 executable is in the current directory, you'd type:

./a4 new myfile.a4

On Windows the ./ isn't used:

a4 new myfile.a4

In either case, the new command will leave you at a shell where you can type commands or evaluate things within the new file.

Get On With It...

Ok, just type 'Hello, world' print and press enter.

It should look something like this:

<A4> 'Hello, world' print
Hello, world
  -> Hello, world

You may notice that the text is printed twice. That's because the shell will also print the result of each command it evaluates (after the -> arrow), and the result of sending the print command to a string ('Hello, world') happens to be the value of the string.

This makes it a little easier to make calculations and check things, because you don't need to explicitly print the final result:

<A4> 1 + 1
  -> 2

Saving, Exiting & Resuming

When you're done, just press CTRL+D to exit the shell and save the A4 file. [TODO: Is it the same key combo on Windows? Maybe a change will be required there...]

You can create a new variable that will be saved in the file using the <- operator:

<A4> msg <- 'Hello, world'
  -> Hello, world

You can reopen the file after you've exited by typing ./a4 resume myfile.a4 (or equivalent), and check that your variable is still there:

<A4> msg
  -> Hello, world

(There are also new-and-forget and resume-and-forget commands for when you don't want to save the state at the end.)

Things To Watch Out For

The ' and ! characters are special in Smalltalk, so in order to use them inside a string they need to be escaped by repeating them, so to print Hello, world! you'd type 'Hello, world!!' and to print Hello, 'world' you'd type 'Hello, ''world'''.

What To Do Next?

For starters, see what this does:

<A4> 'foo' red, 'bar' blue

Then try help, see if that leads you in an interesting direction.

If you're out of ideas (or if the help system pointed you back here), then you might as well move on to Hello, Graphics.