Chicken (stylized as CHICKEN) is a
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
, specifically a
compiler
In computing, a compiler is a computer program that Translator (computing), translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primaril ...
and
interpreter which implement a
dialect
A dialect is a Variety (linguistics), variety of language spoken by a particular group of people. This may include dominant and standard language, standardized varieties as well as Vernacular language, vernacular, unwritten, or non-standardize ...
of the programming language
Scheme, and which compiles Scheme
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
to standard
C. It is mostly
R5RS compliant and offers many extensions to the standard. The newer R7RS standard is supported through an extension
library
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
.
Chicken is
free and open-source software
Free and open-source software (FOSS) is software available under a license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term encompassing free ...
available under a
BSD license
BSD licenses are a family of permissive free software licenses, imposing minimal restrictions on the use and distribution of covered software. This is in contrast to copyleft licenses, which have share-alike requirements. The original BSD lic ...
. It is implemented mostly in Scheme, with some parts in C for performance or to make embedding into C programs easier.
Focus
Chicken's focus is quickly clear from its slogan: "''A practical and portable Scheme system''".
Chicken's main focus is the practical application of Scheme for writing real-world software. Scheme is well known for its use in
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
curricula and programming language experimentation, but it has seen little use in business and industry. Chicken's community has produced a large set of
libraries
A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
to perform a variety of tasks. The Chicken wiki (the software running it is also a Chicken program) also contains a list of software that has been written in Chicken.
Chicken's other goal is to be
portable. By compiling to an
intermediate representation
An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
, in this case portable C (as do
Gambit and
Bigloo), programs written in Chicken can be compiled for common popular
operating system
An operating system (OS) is system software that manages computer hardware and software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ...
s such as
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
,
macOS
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
, other
Unix-like
A Unix-like (sometimes referred to as UN*X, *nix or *NIX) operating system is one that behaves in a manner similar to a Unix system, although not necessarily conforming to or being certified to any version of the Single UNIX Specification. A Uni ...
systems,
Windows
Windows is a Product lining, product line of Proprietary software, proprietary graphical user interface, graphical operating systems developed and marketed by Microsoft. It is grouped into families and subfamilies that cater to particular sec ...
,
Haiku
is a type of short form poetry that originated in Japan. Traditional Japanese haiku consist of three phrases composed of 17 Mora (linguistics), morae (called ''On (Japanese prosody), on'' in Japanese) in a 5, 7, 5 pattern; that include a ''kire ...
, and mobile platforms
iOS and
Android. It also has built-in support for
cross-compiling programs and extensions, which allows it to be used on various
embedded system
An embedded system is a specialized computer system—a combination of a computer processor, computer memory, and input/output peripheral devices—that has a dedicated function within a larger mechanical or electronic system. It is e ...
platforms.
Design
Like many Scheme compilers, Chicken uses standard C as an
intermediate representation
An intermediate representation (IR) is the data structure or code used internally by a compiler or virtual machine to represent source code. An IR is designed to be conducive to further processing, such as optimization and translation. A "good" ...
. 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
computer architecture, producing an executable program. The universal availability of C makes it useful for this purpose.
Chicken's design was inspired by a 1994 paper by
Henry Baker that outlined an innovative strategy to compile Scheme into C. A Scheme program is compiled into C
functions. These C functions never reach the ''return''
statement; instead, they call a new
continuation
In computer science, a continuation is an abstract representation of the control state of a computer program. A continuation implements ( reifies) the program control state, i.e. the continuation is a data structure that represents the computat ...
when complete. These continuations are C functions 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
call stack
In computer science, a call stack is a Stack (abstract data type), stack data structure that stores information about the active subroutines and block (programming), inline blocks of a computer program. This type of stack is also known as an exe ...
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
In analytic geometry, an asymptote () of a curve is a line such that the distance between the curve and the line approaches zero as one or both of the ''x'' or ''y'' coordinates Limit of a function#Limits at infinity, tends to infinity. In pro ...
tail recursive behavior, as required by the Scheme language standard. The implementation in the Chicken Scheme compiler is even asymptotically ''safe for space''.
Limitations and deviations from the standard
Chicken Scheme is mostly R5RS-compliant, with a few notable limitations and deviations. R7RS compatibility is supplied as an extension library.
The core system has basic support for
UTF-8
UTF-8 is a character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode Transformation Format 8-bit''. Almost every webpage is transmitted as UTF-8.
UTF-8 supports all 1,112,0 ...
characters, however the string indexing and manipulation procedures are not UTF-8 aware. An extension library exists which adds support for full UTF-8 awareness.
Add-on software
Chicken has a large
software repository
A software repository, or repo for short, is a storage location for Package format, software packages. Often a table of contents is also stored, along with metadata. A software repository is typically managed by source or version control, or rep ...
of added libraries and programs, termed ''eggs''. This system is very similar to
RubyGems.
Initially, these eggs were developed in one central svn repository, in which creating a tag would automatically cause a new version of the extension to become available for download. Currently, eggs can be developed anywhere and under any
version control system, while still maintaining ''semi-automatic'' release management when using most of the popular code hosting sites. This release method is VCS-agnostic in the sense that the user does not need to have these VCSes installed. The developer is free to host anywhere they choose, and can even choose to avoid public version control and distribute only plain tarballs.
For all released eggs, the latest version is tested automatically as part of a
continuous integration
Continuous integration (CI) is the practice of integrating source code changes frequently and ensuring that the integrated codebase is in a workable state.
Typically, developers Merge (version control), merge changes to an Branching (revisio ...
process. A canonical test
server exists, where the core system and all eggs are tested daily against the most recent development version (to catch regressive bugs), and the most recent stable version (to ensure that everything works for users of the stable system). Also, anyone can volunteer to supply further testing capacity, on different: hardware, operating systems, or core releases.
Features
Chicken supports most of R5RS standard
Scheme, but it also adds a few nonstandard features which are not available in all Scheme implementations.
Foreign function interface
Chicken compiling to C makes it possible to ''inject'' custom C code into the compiled result, which eases integrating with C libraries. Its
foreign function interface supports converting back and forth between most built-in C types and corresponding Scheme objects.
Also, extension libraries exist for interfacing to
Python,
Lua, and
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, via
Java Native Interface (JNI) or a bridge.
Cross-compiling
It is relatively easy to
cross-compile Scheme code to another platform (for example for embedded use on a device).
To make cross-compiling possible for Scheme code, Chicken imposes a model of separate compiling: A compiled module consists of two
shared libraries. One library contains the actual code which will be used at runtime (compiled for the target platform), and the other is an ''import module'', which will be used to load the code which runs at compile-time (on the host platform), such as procedural macro code.
The Chicken compiler can also be easily cross-compiled. After translation to C has been achieved, one can simply use a C compiler which is set up to build for another platform.
Modules and macros
Since version 4, Chicken has a built-in module system and support for low-level
hygienic macros through ''explicit renaming'' macros (before version 4, this was available through an add-on library). Standard ''syntax-rules'' macros are also supported, and ''implicit renaming'' macros, which is basically a ''reversed'' version of explicit renaming.
This mechanism trades performance for convenience. Each identifier not explicitly ''injected'' as unhygienic will be automatically renamed to avoid name capture. The performance cost occurs because ''implicit'' renaming requires the macro-expander to retraverse the expressions two more times. This cost is paid at expansion time, so a macro author must consider if longer compiling times are acceptable.
Remote debugger
Since version 4.11, Chicken comes shipped with a debugger named ''Feathers''. When Scheme code is compiled with the needed debugging option, ''debugging events'' are injected at specific points in the code. These are implemented as calls to a C function, which is relatively low-overhead when not actually debugging the code. When debugging, it will try to make a TCP connection to a Feathers server process, possibly on a different machine. The process is halted, the user may set breakpoints and start the program. Then, when the breakpoint is hit, the client (process being debugged) enters a command loop, which allows interrogation of the client, to read out variables, or mutate them.
Limited static type analysis
Chicken supports local flow analysis. This allows the compiler to catch variable type errors at compile-time, and perform type specialisation. This specialisation makes it possible to remove several safety checks for type detection at runtime when the type can be deduced at compile-time. This results in improved run-time performance.
This ''scrutinizer'' does not allow cross-module flow analysis, so it can only be used to optimize code that's part of one compiling unit (or module).
History
CHICKEN Scheme was originally developed by Felix Winkelmann on
Cygwin/gcc and later
Visual C++ 5.0 on
Windows 98
Windows 98 is a consumer-oriented operating system developed by Microsoft as part of its Windows 9x family of Microsoft Windows operating systems. It was the second operating system in the 9x line, as the successor to Windows 95. It was Software ...
.
He came up with the name "CHICKEN" arbitrarily as the "first thing that came to my mind that day" thinking of a plastic toy of
Feathers McGraw on his desk. As the project matured, he decided not to change the name out of superstition.
See also
*
Tail recursion
*
Cheney's algorithm
* "
M.T.A. (song)", a song reference in Baker's 1994 paper
*
Gambit (Scheme implementation)
*
Stalin (Scheme implementation)
References
External links
*
{{DEFAULTSORT:Chicken
Scheme (programming language) compilers
Scheme (programming language) interpreters
Scheme (programming language) implementations
Free and open source compilers
Free and open source interpreters
Software using the BSD license