The first step is to include 'module.js' and 'core.js' script. The 'module.js' file is just a simple AMD module resolver, so you can use another one.
<script src="lang/module.js"></script>
<script src="lang/core.js"></script>
There are three stages of the code:
There are two common ways to execute the code in a JavaScript string. Both ways use read_eval function that parses the string to a Lisp data structure, compiles the data structure to a function and calls the function that returns the result of the last statement in the source code.
To have an access to the compiler object, you should use 'require' (AMD) or 'define.resolve' (bundled custom module system) functions
In this case a fresh default environment is used every time the read_eval function is called and global defs are forgotten.
In this case a fresh default environment or an environment ammended by 'bindings' object is created once and can be reused among multiple read_eval calls.
A result of the evaluated function is a Lisp data structure.
A data stucture can be converted to a string by COFY.print(data), processed by Cofy using COFY.eval(data) or cofy.eval(data), or processed by a JavaScript function. It can be also processed by a previously compiled cofy function.
There are more functions to interract with Cofy: COFY.read(code-string) to parse the data or program, COFY.compile(data) to compile the data to a cofy program, and COFY.read_eval_print(code-string) to do the entire transformation from an input string to an output string.
Examples (taken from working unit tests)
The evaluation environment is capability-based. The evaluated code has access only to the external objects and functions passed by the invoking code. However passing e.g. one specific DOM element gives access to the entire DOM, as there are public parent links in the element. This can be solved by passing functions that manipulate the element instead.