Dentdoche
Dentdoche is a Lisp interpreter in node.js that abstracts away the difficulties of asynchronous programming so that functions calling callbacks can be treated as regular functions returning values.
Dentdoche is just a regular node library that is included in the source code, so no extra build step is necessary. Functions defined in Dentdoche can call Javascript functions, and Javascript functions can call functions defined with Dentdoche, because Dentdoche functions compile to Javascript functions. The two languages can be used and live together, side by side, in the same source file.
Dentdoche code can be written either as Javascript literals, or as S-expressions that are parsed. The parsed S-expression compile to Javascript literals, that in turn compile into something that can be evaluated in Javascript.
Example usage
Consider this Javascript function that concatenates files:
var fs = ; { fs;}
In Dentdoche, you would write
var fs = ;var dd = ; dd;dd; ;
but one could also write it directly using Javascript literals:
var fs = ;var dd = ; dd;dd; var filecat2 = dd;
Also, generalizing the function for more files is simple.
var filecatMany = dd;
Documentation
The documentation is partial and written for the Dentdoche in parsed mode. Please see the test cases for up-to-date usage examples. In parsed mode, the included Dentdoche module must be named dd as in
var dd = ;
This is because the generated code will assume that the exported symbols can be referred to as dd.symbolName
.
In order to just run some code for side effects, you can
;
Several expressions can be evaluated within the same string:
;
Global variables can be defined with def
:
;
or as in
;
A function that delivers its result as return value can be defined with dfn
:
; ;
and likewise, a function that calls a callback cb
as cb(error, result)
, can be defined as
; ;
By default, functions not defined by Dentdoche will be assumed to return their results through their return value. However, Dentdoche can be told that they deliver their results through a callback:
;
or
dd;;
Note that in the above two functions, we must use dafn
and not dfn
, because the expression inside involves asynchronous computations.
Anonymous functions can also be defined, either as delivering their result through return value (using fn
) or by calling a callback (using afn
):
;;;;
The sync
keyword can also be used to override a function that was previously set to being async. All these keywords (sync
, async
and async1
) override what was previously associated with a function:
dd;;
This means that you can write regular callback-style code in Dentdoche, but with Lisp syntax.
Macros are regular Javascript functions that transform programs. Here is a macro that defines or
in a lazy way:
{ var args = ; if argslength == 0 return false; else return 'if' true or; } ;
See the test cases in order to understand how to really make use of Dentdoche.
Licence
Copyright Jonas Östlund 2015. Released under EPL (Eclipse Public Licence).