Cicada ---> Online Help Docs

Summary

Cicada is a small interpreted language that plugs into C (or C++) code. That gives you both:

Embedding Cicada into a C program:

  1. Include the cicada.h header file.
  2. Run Cicada by making a C function call: runCicada(f, s, r). Here f is an array of C functions to expose to Cicada; s is any script to run; and r tells Cicada whether to run an interactive terminal.
  3. Cicada can callback other C functions in your code. This last step is how the two languages communicate: the callback passes Cicada variables and arrays into the C code for fast processing.
  4. It’s recommended to write a Cicada wrapper for each C function, to ensure that the arguments get passed into C correctly.
  5. Pass an -lcicada option to the linker.

* * *

Here’s an example:


    #include <cicada.h>
   
    ccInt countOddsF(argsType args)    // (for positive numbers)
    {
       ccInt *n, *c, i;               // by default, ccInt = int
       getArgs(args, &n, &c);
       *c = 0;
       for (i = 0; i < args.indices[0]; i++) *c += n[i] % 2;
       return 0;
    }
   
    const char *wrapperScript =
       "numOdd :: { n :: [] int, c :: int; n[] = args[1], $countOdds(n, c), return c }";
   
    int main(int argc, char **argv)
    {
       const Cfunction fs[] = { { "countOdds", &countOddsF } };
       return runCicada(fs, wrapperScript, true);
    }
   

Running this program lets us interactively process any data we want. And since the counting is done in C, it’ll run fast even on a huge dataset.


    > numOdd({ 3, 5, 6, 7, 8 })
   
    3
   
    > if numOdd(bigList) > 1e6 then ...
   


Prev: Table of Contents    Next: Example: memory networks in Cicada


Last update: November 12, 2025