CTCL

Procedures

procedure bars_up
  parameters
    repeats    -- how many times to run bars up the tree
    speed      -- actually, the delay time. 0 for tick track.
  color_parameters
    colora     -- bar color
    colorb     -- background color
  local
    i          -- loop counters
    j
begin_procedure
  do j = 1 to repeats
    do i = 4 to 1 step -1
      turn row i colora off colorb
      call tdelay(speed)
      turn row i colorb off colora
    enddo
  enddo
endproc
Procedures are defined after the global variables and before the main program. There is no pretense of a capability of recursion; every procedure must be defined before it is called.

Procedures begin with the word procedure followed by the name of the procedure. The same caveats apply as in C/C++; names like "time" are likely to be used by the underlying libraries; however, names like "bars_up" and "twinkle" are probably safe.

Parameters are listed under the word parameter, one to a line. At first, this seems silly, but, as in the code shown, this leaves plenty of room for comments as to what each parameter is for. Similar remarks apply below.

For historical reasons, color parameters are listed separately, under the word color_parameters. (At one time these were enum types, not integers.) This custom has been retained not only for backward compatibility, but also because it gives a consistency to the way procedures are called.

Next is the word local followed by the list of local variables. Nominally, all of these are integers, but they can also be colors.

The body of the procedure is enclosed between the words begin_procedure and endproc. (This seems kind of inconsistent; it may be changed.) Most of the time, we just copy an existing procedure and change it, rather than try to remember all of the keywords and patterns.

Procedures are usually kept in separate files in a directory and copied in as needed. The #include facility allows the programmer to include any file into the program.