Chicken (Scheme implementation)
   HOME

TheInfoList



OR:

Chicken (stylized as CHICKEN) is a
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
, specifically a
compiler In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs tha ...
and interpreter which implement a
dialect The term dialect (from Latin , , from the Ancient Greek word , 'discourse', from , 'through' and , 'I speak') can refer to either of two distinctly different types of linguistic phenomena: One usage refers to a variety of a language that is ...
of the programming language
Scheme A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, and which compiles Scheme
source code In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the ...
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 materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vi ...
. Chicken is
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
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 lice ...
. 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, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
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 Document, materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or electronic media, digital access (soft copies) materials, and may be a ...
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 Portable may refer to: General * Portable building, a manufactured structure that is built off site and moved in upon completion of site and utility work * Portable classroom, a temporary building installed on the grounds of a school to provide ...
. 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 A gambit (from Italian , the act of tripping someone with the leg to make them fall) is a chess opening in which a player sacrifices with the aim of achieving a subsequent advantage. The word '' gambit'' is also sometimes used to describe sim ...
and
Bigloo Bigloo is a programming language, a dialect of the language Lisp, an implementation of the language Scheme. It is developed at the French IT research institute French Institute for Research in Computer Science and Automation (INRIA). It is orie ...
), programs written in Chicken can be compiled for common popular
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
s such as
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, whi ...
,
macOS macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and la ...
, other
Unix-like A Unix-like (sometimes referred to as UN*X 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 Unix-li ...
systems,
Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for se ...
,
Haiku is a type of short form poetry originally from Japan. Traditional Japanese haiku consist of three phrases that contain a '' kireji'', or "cutting word", 17 '' on'' (phonetic units similar to syllables) in a 5, 7, 5 pattern, and a '' kigo'', or ...
, 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 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 ''embedded ...
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 In computer engineering, computer architecture is a description of the structure of a computer system made from component parts. It can sometimes be a high-level description that ignores details of the implementation. At a more detailed level, the ...
, 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 computati ...
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 data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, program stack, control stack, run-time stack, or mac ...
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 Waste collection is a part of the process of waste management. It is the transfer of solid waste from the point of use and disposal to the point of treatment or landfill. Waste collection also includes the curbside collection of recyclabl ...
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 tends to infinity. In projective geometry and related context ...
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 variable-length character encoding used for electronic communication. Defined by the Unicode Standard, the name is derived from ''Unicode'' (or ''Universal Coded Character Set'') ''Transformation Format 8-bit''. UTF-8 is capable of e ...
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 software packages. Often a table of contents is also stored, along with metadata. A software repository is typically managed by source control or repository managers. Package ...
of added libraries and programs, termed ''eggs''. This system is very similar to
RubyGems RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a "gem"), a tool designed to easily manage the installation of ge ...
. 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 In software engineering, version control (also known as revision control, source control, or source code management) is a class of systems responsible for managing changes to computer programs, documents, large web sites, or other collections ...
, 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 process. A canonical test
server Server may refer to: Computing *Server (computing), a computer program or a device that provides functionality for other programs or devices, called clients Role * Waiting staff, those who work at a restaurant or a bar attending customers and su ...
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 A scheme is a systematic plan for the implementation of a certain idea. Scheme or schemer may refer to: Arts and entertainment * ''The Scheme'' (TV series), a BBC Scotland documentary series * The Scheme (band), an English pop band * ''The Schem ...
, 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 A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another. Naming The term comes from the specification for Common Lisp, which explicit ...
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 (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mo ...
, via
Java Native Interface In software design, the Java Native Interface (JNI) is a foreign function interface programming framework that enables Java code running in a Java virtual machine (JVM) to call and be called by native applications (programs specific to a hardwa ...
(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 In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and ...
. 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).


See also

*
Tail recursion In computer science, a tail call is a subroutine call performed as the final action of a procedure. If the target of a tail is the same subroutine, the subroutine is said to be tail recursive, which is a special case of direct recursion. Tail recur ...
* 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 compilers and interpreters Software using the BSD license