Chicken (Scheme implementation)
From Wikipedia, the free encyclopedia
Chicken Scheme | |
---|---|
Developed by | Felix Winkelmann |
Latest release | 3.2 / May, 2008 |
OS | Cross-platform |
Genre | Programming language |
License | BSD License |
Website | call-with-current-continuation.org |
Standard(s) | R5RS (mostly), R6RS (α) |
Chicken is a compiler and interpreter for the Scheme programming language that compiles Scheme code to standard C. It is mostly R5RS compliant and offers many extensions to the standard. Chicken is free software available under the BSD license.
Contents |
[edit] Design
Like many Scheme compilers, Chicken uses standard C as an intermediate language. A Scheme program is translated into C by the Chicken compiler, and then a C compiler translates the C program into machine code for the target architecture, producing an executable program. The universal availability of C makes it ideal for this purpose.
Chicken's design was inspired by a 1994 paper by Henry Baker that outlined an innovative strategy for Scheme compilation into C. A scheme program is compiled into C functions. These C functions never reach the return statement; instead, they call a new continuation when complete. These continuations are C functions themselves and are passed on as extra arguments to other C functions. They are calculated by the compiler.
So far, this is the essence of continuation-passing style. Baker's novel idea is to use the C stack for the Scheme heap. Hence, normal C stack operations such as automatic variable creation, variable-sized array allocation, and so on can be used. When the stack fills up (that is, the stack pointer reaches the top of the stack), a garbage collection can be initiated. The design used is a copying garbage collector originally devised by C.J. Cheney, which copies all live continuations and other live objects to the heap. Despite this, the C code does not copy C stack frames, only Scheme objects, so it does not require knowledge of the C implementation.
In full, the Scheme heap consists of the C stack as the nursery together with the two heaps required by the generational garbage collector. This approach gives the speed of the C stack for many operations, and it allows the use of continuations as simple calls to C functions. Further, Baker's solution guarantees asymptotic tail recursive behavior, as required by the Scheme language standard. The implementation in the Chicken scheme compiler is even asymptotically safe for space.
[edit] Limitations and deviations from the standard
Chicken Scheme is mostly R5RS-compliant. The basic distribution offers only part of the numerical tower and Lisp-macros instead of hygienic macros. The missing features can be installed as extensions (see below).
There is currently a maximum of 126 arguments to a procedure. There is a workaround for some architectures that extends the maximum number of arguments per procedure to 1000.
[edit] Add-on software
Chicken has a large repository of additional libraries and programs called "eggs". This eggs system is quite similar to RubyGems. It too does not integrate with the packaging system of the user's operating system. SWIG also supports Chicken.
[edit] See also
- Tail recursion
- Cheney's algorithm
- M.T.A.
- Adamantix, a security-oriented Linux distribution which uses Chicken as its extension language
[edit] References
- CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A., the paper that inspired Chicken's design
- Cheney, C.J. "A Nonrecursive List Compacting Algorithm". CACM 13,11 (Nov. 1970),677-678.