Simple expressions---variable names, numbers, character/string constants---look pretty much the same in Cicada as they do in C. Character constants are flanked by single quotes ('C'), strings by double-quotes ("my_string"), and numbers are read as either integer or floating-point depending on how they are written. Likewise, the assignment and arithmetic operators are the same between C and Cicada, except that Cicada also provides an exponentiation operator ‘^’ (e.g. 2^3 gives 8).
When we get to variable definitions, Cicada syntax starts to look significantly different from C. In C, variables definitions are noncoding statements that tell the compiler how to manage the stack. In Cicada, variable definitions are commands that allocate memory on the heap. The basic way to define a Cicada variable is to use the ‘::’ operator:
x :: int
Here x is the variable and int is the type. The allowed primitive types are int, double, char, string and bool (see Table 1). All Cicada variables must be defined before they can be used, and this type cannot change unless the variable is deleted and redefined.
In order to define an array, write the size of each dimension in square brackets just before the type of the array elements. For example,
myTable :: [5] [7] double
defines a two-dimensional (5x7) array of floating-point numbers. Square brackets are also used to access array elements, in the same way as in C:
print(myTable[2][3])
However: in Cicada, array indexing begins at 1.
It’s often convenient to define several variables or arrays of the same type together in one long command. For example:
x :: y :: z :: int
table1 :: table2 :: [5] double
This example script shows basic usage of variables and arrays. It’s easiest to type this into a file: say, ”pythagoras.cicada”..
| program to find the length of the hypotenuse of a right triangle
sides :: [2] double
hypotenuse :: double
response :: string
print("Side 1: ")
response = input()
read_string(response, sides[1])
print("Side 2: ")
response = input()
read_string(response, sides[2])
hypotenuse = (sides[1]^2 + sides[2]^2)^0.5
print("The hypotenuse has length ", hypotenuse, ".\n")
(The first line in this example is a comment, because of the vertical bar |. print(), input() and read_string() are three of Cicada’s 30-odd built-in functions.) To run our script file from Cicada’s command prompt, type
> run("pythagoras")
If we want to define our own functions we again use the :: operator, but with curly braces containing the function code in place of a variable type. A standard Cicada function consists of three parts: 1) variable definitions; 2) a code command; 3) the executable code of the function. Unlike C functions, a Cicada function doesn’t predefine either its arguments or its return value. Its arguments are accessed through an args variable, and the arguments themselves can be modified by the function. The return command works the same way as in C. Finally, the basic syntax for calling a function is the same as in C, although in Cicada fancier kinds of function calls are also possible.
Here is a more elaborate version of our previous example that uses functions, as well as if statements and for loops whose syntax is a bit different from C.
| program to find the length of the hypotenuse of a right triangle
GetSide :: {
response :: string
side_length :: double
code
side_length = 0
print("Side ", args[1], ": ")
response = input()
read_string(response, side_length)
if side_length > 0 then (
return side_length )
else (
print("Side length must be positive\n")
exit )
}
sides :: [2] double
hypotenuse :: double
counter :: int
for counter in <1, 2> (
sides[counter] = GetSide(counter) )
hypotenuse = (sides[1]^2 + sides[2]^2)^0.5
print("The hypotenuse has length ", hypotenuse, ".\n")
Cicada also has while ... do and loop ... until loops. There is no ‘goto’ statement. The equality test ‘==’ is the same as in C, but the not-equal test uses the symbol ‘/=’ which is different from C.
To exit Cicada type “exit” at the command prompt. If there is no command prompt then Cicada is probably stuck and we need to force quit.
Last update: November 12, 2025