Cicada ---> Online Help Docs

Introduction

Cicada is a simple, interpreted language that that embeds the user’s fast C and C++ routines. Compile the Cicada source code together with our own C/C++ files, and voilà, we have a command-line environment for executing our C routines and managing their data.

For example, suppose we’re writing a program to alphabetize a list of names. It’s a large list and will take quite a while to process, so we opt to write the sorting routine in C.


    int SortPhoneBook(int argc, char **argv)    // must be int(int, char**)
    {
       ...
    }
   

Having written the time-consuming step in C, it’ll be nice to be able to control it from a command line environment. So let’s incorporate SortPhoneBook() into Cicada, specifically the source file called userfn.c, and give it a name within the scripting language.


    UserFunction UserFunctionSet[] = { { "doSort", &SortPhoneBook } };
   

Finally, update Cicada’s Makefile if we added new source files, and re-compile.


    user-prompt% make cicada CC=gcc
   

Running Cicada now brings up a command prompt allowing us to make our list and sort it.


    > US_numbers := load("AllUSA.txt")
    > $doSort(US_numbers)
    > save("/Documents/SortedList.txt", US_numbers)
   

That’s it in a nutshell, modulo a few details. The scripting syntax should be straightforward, and you can change it if you don’t like it -- but at its heart this language has some unusual abilities. For example, many Cicada functions will call their own arguments.

The rest of this document describes the Cicada language three times over: through a longer example (Section 2), an explanation (Section 3 and 4), and a reference section (Section 5).


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


Last update: May 8, 2024