Saying "Hello World"

Type the following program into your editor:

#INCLUDE "course.module"
PROC main (CHAN BYTE kyb?, scr!, err!)
  SEQ
    out.string("Hello, ", 0, scr!)
    out.string("world!*n", 0, scr!)
:


Then, on the command line, compile and run your program.

[mreynolds:~]  kroc first.occ
[mreynolds:~] ./first

If all goes well, you should see the words "Hello, world!" printed to the screen. The *n is a newline character in an occam string.

Break some stuff

Next, break a few things. This will help you learn a few syntax errors early, so when you encounter variants of them later, they won't surprise/baffle you. With your partner, make note in your lab book what the error is, and what you think it means. Note: these are not meant to be cumulative. Fix each break after you introduce it before proceeding.

  1. There are two spaces before the SEQ, and four spaces before each of the calls to out.string. Try removing one of the spaces before the SEQ. Then, try indenting either (or both) of the out.string lines.
  2. Remove the ! from the use of scr in one of the calls to out.string.
  3. Replace one of the uses of scr with kyb instead. Keep the ! for the moment.
  4. Flip the ! to a ?, and see if the error changes.
  5. Get rid of the SEQ, and outdent each of the out.string lines two spaces.
  6. Change the SEQ to a PAR.


A few notes

A few notes about the code:

  • The SEQ means sequence. If you want to do more than one thing in a row, you need to have a SEQ. The body of a PROCess definition, therefore, can be said to only contain one process (in this case, a SEQ).
  • The last PROC in a file is the one that is executed. It is called the top-level process. It can grab three channels from the environment: an input channel from the keyboard, and two output channels (one to standard out, and one to standard error). They are channels of bytes, as denoted by the type declaration CHAN BYTE, and they have directions: ? for input, ! for output.
  • The PROC defines a process that will run. The header of the PROC "main" indicates that it expects to receive three channel ends.