CTCL

Expressions

i = 5 - j
k = j \ 2
turn row (j+1) blue
Expressions are largely the same as in most other computer languages such as C, Pascal, BASIC and FORTRAN. There is no need for extensive arithmetic in light displays; however, certain operations such as "mod" are frequently used. For historical reasons, the conventions for C were not entirely followed (as in, I didn't know C from a NAND gate when CTCL was designed. Those were my Pascal, Prolog and Lisp days. I actually programmed a tree using Prolog but then the stack overflowed halfway through the first song....)

The arithmetic operators are
  +    addition
  -    subtraction
  *    multiplication
  /    integer division
  \    integer remainder ("mod")
Using "%" for the "mod" operator will work, but this makes the language dependent on the underlying C compiler; it will not work with Pascal, for example, since it is the backslash "\" that is translated as the Pascal "MOD" operator and "/" that is translated as "DIV". We say all this simply to point out that if the compiler is changed in the future to produce code in a language not yet invented, we don't want to have to retrofit to C operations. Using the operations given is best.

Parentheses are used to group operations together. The hierarchy is the usual one, i.e. * / \ are done before + -, and left to right.

Expressions in if and do statements will probably work, but there are no guarantees. When in doubt, enclose them in parentheses.

As noted in the turn statement, expressions may be used there if they are enclosed in parentheses; however, the "mod" operation may not work there -- not that I have ever seen a need for "mod" in that context. I've put in code to take care of it, but never used it in practice.

Assignment Statements

Assignment statements are just about the same everywhere. CTCL assignments consist of a variable on the left-hand side, and equal sign ("="), and an expression. The expression may contain function calls. Example:
j = 5 - i