To send data over a channel, we use the ! operator. It is a binary operator. On the left-hand side is the name of the channel we want to communicate on, and on the right-hand side is data matching the channel's protocol.
For example, the PROC "main" gets three channel ends: the read (or input) end of the channel kyb, and the write (or output) ends of both scr and err. The protocol of these three channels is simple: they communicate single BYTEs.
So, to send a single byte, you could do something like:
scr ! 65
This says to communicate the BYTE with the value 65 over the channel scr. Of course, we might rather say:
scr ! 'A'
simply because it is easier to read. The process out.string is defined in course.module.
Add a few bits
Lets add a few bits to this program.
- First, print a witty message (like "Press a key to continue"), and then read from the keyboard. This will require you to declare a variable of type BYTE outside the SEQ, and to do a read operation using the ? operator. After the user presses a key, your program should say "Hello, world!" or similar.
- Write a new PROC. Call it "hello", and make it take the output end of a BYTE channel as a parameter. Call that end s. Your new PROC should do nothing more than send the string "Hello, world!*n" down the channel.
- In the PROC "main", replace the execution of the out.string processes with the execution of your new process, "hello".
- Although apparently unnecessary, wrap the execution of the "hello" process in a SEQ.
- Modify your SEQ so it is instead SEQ i = 0 FOR 10. This is called a replicated SEQ. It is, in some ways, like a for loop in other languages.
- Replace the replicated SEQ with a WHILE TRUE statement.
None of this is particularly amazing. However, it gives you a few small things you can do step-by-step to change your program in ways that might look familiar from other languages.