The First Session

In this chapter, we will go through the steps of creating and running a program with Alice. In the process, we will discuss the most commonly used Alice commands and operations.

Note that this tutorial is interactive, not passive. We strongly suggest that you have the computer in front of you while you read this chapter and that you try out the things we discuss as soon as we talk about them. The only way to become comfortable with a system is to work with it.

Starting Up Alice

Before you start your Alice session, you have to boot your DOS system. This procedure should be described in the documentation that came with your computer. Essentially, you insert the floppy disk that contains your DOS into the main floppy drive of your computer. Make sure that the label of the disk is face up, and that you insert the disk non-label edge first. Do not force the disk in -- just slide it gently until it clicks in place. You then close the ``tongue'' of the floppy drive and turn on your computer's power.

The system will perform a number of operations that it always has to do when it first starts up. You may be asked to enter the current date and time. Do so, then press [ENTER]. ([ENTER] is like the Carriage Return key on a typewriter. On an IBM-PC keyboard, it looks like this: [Enter]) Next, if your PC has a colour/graphics display card, you may tell the system what kind of monitor you have. If you have a colour monitor, enter the command

A> mode co80

then press [ENTER]. If you have a monochrome monitor, enter the command

A> mode bw80

then press [ENTER]. (Note that the A> shown above is the system prompt.) (You should NOT enter these commands if your PC has a monochrome display adapter. As a matter of fact, a MODE command is usually unnecessary, since the type of monitor you have is normally indicated by the dip switches in your computer. However, there are times when the MODE commands are necessary.) If you don't want to worry about the mode command, look up the ``-c'' option in the User Guide.

You're now ready to start up Alice. If you only have one floppy drive, open the tongue of the drive, carefully remove the DOS disk, and insert the Alice disk (label up, non-label edge first). If you have two floppy drives, you can leave the DOS disk where it is and insert the Alice disk in the other drive.

NOTE: If you have a hard disk drive (usually ``C:'') and wish to run Alice from it, the simplest method is to be on the C drive, insert the Alice floppy and type:

C> mkdir \alice
C> cd \alice
C> copy a:*.*

You can now run Alice from inside this directory. For details on how to do more involved hard disk installation, see the appendix on this topic in the User Guide.

You are now ready to start up Alice itself. If the Alice disk is in drive B, type the commands

A> B:
B> alice

If it is in drive A, just type

A> alice

and press [ENTER]. In a few moments, you'll see Alice display a copyright notice, the version number of your copy of Alice, and other information. When Alice is ready, it will display the following:

Screen Shot startmen not available

In the lower right hand corner of the screen is an example of a menu, a list of things that Alice can do for you. You'll be seeing a lot of menus as we go along, so we may as well talk about them for a bit.

You'll notice that the first and second lines of the menu are highlighted -- instead of being light letters on a dark background, you see dark letters on a light background.

The first line of a menu is always highlighted to make it stand out from the rest. The first line is the heading of the menu. The other lines are called the selections of the menu.

People using an IBM PC computer will notice that the selections of a menu are always labelled with letters. We won't usually show these in the tutorial, since different versions of Alice give the selections in different orders, so the labels won't always be the same. Instead of confusing people with the wrong letters, we'll just leave them out altogether.

Now we'll talk about choosing a selection from a menu. The easiest way to choose a selection is to press the letter that labels the selection. For example, if you want to choose selection (c), press the C key.

To see another way to select menu items, press the downarrow key on the PC keyboard.
















Location of Arrow Keys on Keyboard

You will see that the highlighting moves down to the next item on the menu. If you press the uparrow key, the highlighting moves up. Use these arrows keys so that the

What is Alice all about?

selection lights up, then press the space bar. This selects the highlighted entry from the menu.

When you have selected this line from the menu, Alice will give you its introductory talk. This talk also tells you about selecting things from menus and goes on to describe a few basics of using Alice. The talk is divided into sections that are about one screen's worth of text. At the end of each section, you're given a menu that lets you choose whether you want more of the introductory talk or that you've seen enough. If you aren't given a menu, press the space bar and you will return to whatever you were doing before.

Because you're following this tutorial, you shouldn't choose one of these introductory topics right now; however, the next time you try Alice, you may want to read through this material to see what's there.

To leave the introductory chat, choose the

Do nothing

selection from the menu. You'll see this selection on most Alice menus -- it just returns you to whatever you were doing previously. To select Do nothing from the menu, you do the same thing you did before. Move the highlighting with the uparrow key until Do nothing is highlighted, then press any key on the keyboard. Alternatively, you can just press the key corresponding to the letter that labels the selection.

What happens now? You return to the Starting Menu. This time we'll choose the selection

Edit a new program

As before, you choose this selection by highlighting it and pressing the space bar. You can also press the letter that labels the selection.

(Note: if Alice hasn't been installed properly, it is possible that you will see the message

Few macros defined (can't find ap.ini).
Press ESC to quit.

when Alice starts up. See the appendix on Trouble-shooting for what to do in this case.)

Once you have chosen the Edit a new program selection, Alice will display the following on the screen.

Screen Shot progtemp not available

This is the skeleton or template of a complete Pascal program. The cursor will be positioned at the beginning of the Statement line. The things we show underlined here are placeholders. On a monochrome screen, you will see them underlined; on a colour monitor they will be shown in blue; and on other monitors, they will be shown more brightly than other things on the screen. When you have filled in all the placeholders, you will have a Pascal program.

The screen also shows you two special lines, one at the top and one at the bottom. The top line is where you'll see error messages printed if and when you have a problem. The bottom line shows the name of the file you're using and the name of your current workspace; we'll talk about files and workspaces much later in this tutorial.

The program we are going to create is a simple one that writes out the first ten integers and their squares. When we're done, it will look like this.

program squares(input,output);
{This program prints out the first ten squares.}
var
    i : integer;  {A counter}
begin
for i := 1 to 10 do begin
    writeln(i,i*i);
    end;
end.

We're assuming that you already know Pascal, so we won't explain any of this for you.

Now let's go back to the program template.


The simplest way to create our program is to fill the placeholders in the order they appear. Actually, Alice lets you fill the placeholders in any order you choose. You can fill in the last placeholder and work backwards from there if you want, or jump around all over the place, but in this tutorial, we're going to start at the beginning.

The beginning is the Program-name placeholder. The name we've decided on is ``squares''. To fill this in, move the cursor to the placeholder and then just type the name. You can move the cursor by pressing any of the PC's arrow keys. (They're on the keypad at the right of your keyboard.) Alice will fill in the placeholder as you type. (Type it now.)

After you have typed the name, you have to show Alice that you are finished filling in the placeholder. There are several ways of doing this. One of the easiest is to type the TAB key. (The TAB key is to the left of the ``Q'' key and looks like this: [Tab]) Typing TAB always tells Alice that you're ready to move on to the next thing in the program.

When you press TAB, you will see the cursor jump to the word input on the program statement. We don't want to do anything to that, so push TAB again. This takes you to output. Push TAB one more time, and you'll get to the placeholder

{Comment that says what the routine does}

This placeholder should be filled with a comment that explains what the program does. Alice puts in this placeholder to encourage programmers to comment their programs adequately. As you will see, there are several other places where Alice automatically puts in comment placeholders as a suggestion to programmers.

Move the cursor to the Comment placeholder. Alice will now let you enter any comment you want. The one that appeared in our sample program was

{This program prints out the first ten squares.}

As you're typing in this comment, it's possible you'll make a typing error. Of course, typing errors can happen practically any time. To show you how easy typing errors are to correct, type half of the above comment, and then start pressing the backspace key. You will see that each time you press the backspace, you back up and erase one character in the comment. If you make a typing mistake, you can just erase it by backspacing over it. Once the mistake is erased, you can retype things correctly.

Practice backspacing over mistakes as you type in the comment. You can backspace over errors whenever you are filling in a placeholder for the first time. Changing mistakes is a little harder if you don't catch the mistake until later, but we'll talk about that some other time.

When you are through typing the comment, you have to tell Alice that you are finished filling in the placeholder. Once again, you do this by pressing TAB. You will see that TAB moves the cursor to the next line.

Next comes the Declarations placeholder. As you recall, we want to make the declaration

var
    i : integer;  {A counter}

TAB to the Declarations placeholder and type var followed by a space. Alice recognizes var as a keyword and will lay out the template

Screen Shot 1 7 vardec not available

You should understand what each of these placeholders means. Note that Alice puts room for a comment at the end of every declaration, in the interests of good programming style. The intention is that every variable declaration should have a comment describing what the variable will be used for.

As shown above, when Alice lays out the variable declaration template, the cursor is positioned at the start of the Name placeholder. Just type in the variable name i. To show that you have finished filling in the placeholder, press TAB twice.

You will see that the cursor jumps to the Type placeholder. Fill in the type integer, then press TAB again. The cursor will then jump to the Comment placeholder where you should fill in the comment. Remember that you can use backspacing to correct any errors you make, provided that you catch the mistake BEFORE you tell Alice you are finished filling in the placeholder.

The next placeholder is Statement. TAB to this placeholder, then type for followed by a space. Alice will recognize this keyword and lay out the template

Screen Shot 7 11 fortemp not available

We want to change this to the loop

for i := 1 to 10 do begin
    writeln(i,i*i);
    end;

By now, you should know how to fill in the variable placeholder -- type the variable name i, then TAB to show you're done. You should fill in the Start and Finish placeholders in the same way.

TAB to the Statement placeholder inside the for loop. This is where we want to type

writeln(i,i*i);

To do this, start by typing

writeln(

As soon as Alice sees this, it will complete the form of the procedure call by laying out

Screen Shot 8 10 writeln not available

Of course, writeln can write out more than one value, but Alice only shows one to begin with. The first value we want to print out is i. Type that in to the Value placeholder. To show that you've finished filling in one value, type what should come next, namely a comma. Alice will display

Screen Shot 8 10 writeln2 not available

so you can type in the second output value i*i. When you are finished typing this second output value, you can show that you are through with the output list by typing the ``)'' that ends the writeln instruction or by pressing TAB. (Note that if you press TAB, the cursor will not move ahead -- you're at the end of the executable part of your program, so there's no place for the cursor to go. Instead it moves back a short distance.)

Undoing Errors

There is always the chance that you will make an error while you are entering this program. If you do, one of the easiest ways to correct your error is to UNDO it. UNDO is an Alice command that undoes the last thing that you did.

The fastest way to issue the UNDO command is to press [CTRL-U]. (Remember that this means you hold down the CTRL key and press U). Do that now. You will see that the writeln changes into

Screen Shot 9 9 writeln2 not available

again, the way it was before we filled in the i*i. Pressing [CTRL-U] undoes the last thing you did.

Now, press [CTRL-U] again. You will see that Alice will undo the second last thing you did. Pressing [CTRL-U] again and again will keep on undoing things further and further back. In this way, you can get rid of old mistakes quickly. There's a limit to how far you can go back, because Alice only keeps a record of the most recent changes; however, the number Alice keeps is enough for most purposes.

Now, press [CTRL-R]. This is the REDO key. REDO will redo whatever undo just undid. Pressing [CTRL-R] several times will bring back everything that [CTRL-U] took away.

Remember UNDO ([CTRL-U]) and REDO ([CTRL-R]). They'll help you get out of trouble if you make mistakes.

Errors

While we're on the subject of errors, let's make one to find out what happens. When you first pressed UNDO, you got a statement of the form

writeln(i,Value);

You've undone and redone a number of things since then, but by redoing or undoing things, you should be able to get back to this point. When you've got this, move the cursor to the Value placeholder. As an example of an error, type in the name junk here and press TAB, so you get

writeln(i,junk);

This is an error because there is no variable named junk declared in your program. To show that there is an error, Alice will highlight the junk and print an error message at the top of the screen.

Screen Shot junkscr not available

This is one of the great beauties of Alice -- as soon as you make this kind of mistake, it tells you about it. You can then correct it immediately or leave it for a while and come back later.

By the way, you may be worried because the j in junk doesn't look highlighted on your screen. Instead, the j is blinking. The problem here is that if Alice put a highlighted cursor on a highlighted letter, you wouldn't be able to see that the cursor was there. For this reason, Alice makes the letter blink instead.

Now, let's correct the error that we just made. How do you do this? Just press [CTRL-U] to undo what you just did. The junk disappears and you get back the original Value placeholder. You can then fill in the i*i the way it should be.

To summarize, you now know about two ways to correct mistakes. If you notice the mistake while you are still filling in the placeholder, just backspace over the mistake and retype things correctly. If you have told Alice you're finished filling in the placeholder and THEN you see the mistake, just press [CTRL-U] to undo what you entered, then retype.

Running the Program

When you have the sample program written up properly, you are ready to run it. Alice gives you two ways to run a program: normal execution and ``single-stepping.''

To execute a program normally, you issue the RUN command. The fastest way to do this is to press [F1]. Output for the program (the table of squares) will be displayed on the screen. The output will stay on the screen until you press a key (any key will do); then Alice will go back to the source code, the way it was before the program ran.

Single-stepping runs through a program one instruction at a time. The fastest way to single-step through a program is to press [F2] over and over again. Each time you press this key, Alice will execute another instruction of your program. The cursor moves through the program as you single-step to show which instruction is being executed. In this way, you can see your program being executed. This helps you debug a program by giving you a picture of your program as it executes.

Run your program normally first. You will see that Alice clears the screen and uses the whole screen to show your output. When the program has finished executing, the output is left on the screen to give you a chance to read it. When you are finished looking at the output, press any key (e.g. the space bar) and Alice will go back to your program's source code.

Now run your program with single-stepping. This time, you see that Alice splits your screen in half.

Screen Shot singstep not available

In the upper half, it shows the statements of your program, as you execute these statements one by one. In the lower half, you'll see the output that the program creates.

When you are finished single-stepping through your program, you'll want to return the screen to normal; otherwise, it will stay split into two halves. To return the screen to normal, press [F6] and choose the selection

Debug off

from this menu. To do this, you can either press the letter that labels the selection, or highlight the selection and press the space bar.

Stopping Your Program

It's important at this time that you know how to stop or break a running program. You'll need to do this if a program runs on too long, perhaps because of what is called an infinite loop.

When an Alice program is running, you can halt it by pressing [CTRL-BREAK]. On the IBM PC, this key has ``Break'' written on the front and ``Scroll Lock'' written on the top.

If the output from a program is being printed too fast, you may want to tell the program to pause. Of course, you can stop the program with a Break and set it going again through ways you will learn later, but in general you will not want to do this. There is a special feature of the IBM-PC that pauses any program, and Alice is no exception. To pause Alice, hold down CTRL and ``Num Lock'' at the same time. Press any other key to get things going again.

Saving Your Program

Now that you've created a program, you'll likely want to save a copy in a file -- otherwise, the program you have created will disappear when you quit Alice.

Press [F8]. This calls up the Files Menu.

Screen Shot filemen not available

The selection we want is Save. Choose this selection by pressing the letter that labels it or by highlighting it and pressing the space bar.

You will see that Alice displays a menu of the possible files and directories where you can save your program. This is called a File Name Menu. Directories are marked with a ``<dir>'' after their names. Now the files that are listed here are files that already exist, and we want to save our program in a new file. Therefore, choose the selection

Enter a file name

from this menu. At the bottom of the screen, Alice will ask the question

File Name?

to find out the name of the file where you want to store the program. We suggest that you reply

squares

``Squares'' is a good name for our program. When you have typed the file name, press [ENTER] to show that you are finished.

Note that Alice saves programs in a special format, not as normal source code text. This is like the format that Alice uses internally to store programs that are being edited. Alice is the only program that understands this format, so there is no point in trying to examine files in which Alice has stored programs. To indicate that a file contains a special-format Alice Pascal program, Alice automatically puts ``.ap'' on the end of every file used to hold a program, provided there isn't already a dot in the file name.

By the way, Alice gives you a quicker way to save programs: just press [ALT-S] and Alice will behave as if you selected Save from the Files Menu. If you remember this trick, all well and good; if not, you can always do things the long way by pressing [F8] to call the Files Menu, then choosing the right selection.

Quitting Alice

Once you have saved your program in a file, you can leave Alice. You likely noticed that the Files Menu had a selection that read

Quit Alice

Choosing this selection quits Alice.

If you try to leave Alice before you have saved your program, Alice will display the following menu of possible actions.

Screen Shot safemen not available

The theory is that you normally want to save any programs or changes to programs that you have made while working with Alice. Therefore, Alice won't let you go immediately if you have things that haven't been saved yet.

To choose a selection from this menu, just highlight any selection and press any key on the keyboard. If you really do want to quit without saving, choose the last selection of the menu. If you didn't really want to quit, choose the first selection.

Alice also offers a quick way to quit: just press [ALT-Q]. This works exactly like choosing Quit ALICE from the Files Menu.

Quit Alice, then start Alice up again. It's time for you to experiment and get some practice using Alice. If you get comfortable with Alice now, you'll find later sections will be a lot easier to follow. Try out all the things listed in the chapter summary below.

Chapter Summary

In this chapter, we talked about

  1. Starting up Alice with the ``Alice'' command.
  2. Choosing things from the Starting Menu that Alice displays when it starts up.
  3. Filling in placeholders by moving the cursor to the placeholder, typing whatever you want, then showing that you're done by typing TAB.
  4. Correcting typing mistakes by backspacing.
  5. The UNDO command ([CTRL-U]).
  6. The REDO command ([CTRL-R]).
  7. The RUN command ([F1]).
  8. Single-stepping with [F2].
  9. Returning your screen to normal by pressing [F6] and choosing the selection Debug off from the menu you are given.
  10. Calling up the Files Menu with [F8].
  11. Saving your program by choosing Save from the Files Menu or by pressing [ALT-S].
  12. Using the TAB key to move through a program.
  13. Quitting by choosing Quit ALICE from the Files Menu or by pressing [ALT-Q].