Creating and Running Cinnameg Programs


Complete programs

Until now, you have used a web interface to run programs. It has some severe limitations on what it allows. To get away from that, you will need to write complete programs, and to run them yourself, without the help of the web interface.

You know how to write a Cinnameg program. To make it so that you can run it directly, choose a name for it. Then write

  Package name
   ...
  %Package
around your program, inserting your program name. The name should be of the same form as a name for a variable.

The next chapter shows an example of a full program.


Editor and program file

To create the program, use a text editor. Give your file a name that ends on .cmg. For example, you might call it stuff.cmg.


Compiling and running

Once the program is finished, create a terminal window. Then do the following two steps.

  1. Compile the program using the cmgc program. Command

      cmgc stuff
    
    compiles stuff.cmg, creating another file called stuff.cmo, which is the translated version.

    If there are any errors, fix them and compile again. If you do not want to see the program listing, use command

      cmgc -l stuff
    
    where you write dash-lower-case-ell.

  2. Run the program using cmgr. Command

      cmgr stuff
    
    runs stuff.cmo. You can only run the program after it has compiled without any errors.


Imports

Sometimes you want to use facilities from libraries. To do that, import the library. For example, there is a string library that offers some tools that you can use with strings. The full name of the library is collect/string. A program of the form

  Program name
    Import "collect/string".

    ...
  %Program


Summary

A full program gives you flexibility that the web interface does not. To make a full program, start the program with Package name and end it with %Package, where name is a program name that you choose.


Review

Debug loops by adding prints to see what is happening. Turn on the lights.

A few checks can identify problems with loops with very little work. It is worth doing them after you have written a loop.

Check whether you have initialized and updated all loop control variables.

Check whether you are using a limit variable in places where you should be using a loop control variable.