Jump to content

Chicken (Scheme implementation): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Sjamaan (talk | contribs)
Update latest release to 4.11.0, update links to https now that Let's Encrypt is being used instead of CACert
Sjamaan (talk | contribs)
Update latest release to 5.4.0 (released today)
(46 intermediate revisions by 23 users not shown)
Line 1: Line 1:
{{Short description|Scheme-based programming language implementation}}
{{Infobox Software
{{confused|chicken}}
| name = CHICKEN Scheme
{{Infobox programming language
| logo = [[File:Chicken Scheme logo and wordmark.svg|frameless|150px|alt=Logo for CHICKEN Scheme]]
| name = Chicken Scheme
| screenshot =
| logo = Chicken Scheme logo and wordmark.svg
| caption =
| logo caption = Logo for Chicken Scheme
| developer = The CHICKEN Team
| screenshot = Chicken 5.0.0.png
| author = Felix Winkelmann
| screenshot caption = Chicken 5.0.0 interpreter running on macOS
| released = {{Release date and age|2000|07|20}}<ref>Winkelmann, Felix {{cite web |url=http://groups.google.com/group/comp.lang.scheme/msg/edfb2da16fd89fae |title=''Announcing the CHICKEN Scheme-to-C compiler''}}, comp.lang.scheme</ref>
| paradigms = [[Multi-paradigm programming language|Multi-paradigm]]: [[Functional programming|functional]], [[Imperative programming|imperative]], [[Metaprogramming|meta]]
| latest release version = 4.11.0
| family = [[Lisp (programming language)|Lisp]]
| latest release date = {{Release date and age|2016|5|28}}
| designer = Felix Winkelmann
| programming language = [[Scheme (programming language)|Scheme]] and [[C (Programming Language)|C]]
| developer = The Chicken Team
| operating system = [[Cross-platform]]
| released = {{Start date and age|2000|07|20|df=yes}}<ref name="googlegroups">{{cite web |url=https://groups.google.com/group/comp.lang.scheme/msg/edfb2da16fd89fae |title=Announcing the Chicken Scheme-to-C compiler |last=Winkelmann |first=Felix |website=Google Groups (comp.lang.scheme) }}</ref>
| status = Active
| latest release version = 5.4.0
| genre = [[Programming language]]
| latest release date = {{Start date and age|2024|07|16|df=yes}}
| license = [[BSD License]]
| latest preview version =
| website = [https://www.call-cc.org/ call-cc.org]
| latest preview date = <!-- {{Start date and age|2020|MM|DD|df=yes}} -->
| standard = R5RS (mostly)
| typing = [[Dynamic typing|Dynamic]], [[Latent typing|latent]], [[Strong typing|strong]]
| scope = [[Scope (computer science)#Lexical scoping and dynamic scoping|Lexical]]
| programming language = [[Scheme (programming language)|Scheme]], [[C (Programming Language)|C]]
| platform = [[IA-32]], [[x86-64]], [[ARM architecture|ARM]], [[MIPS architecture|MIPS]], [[SPARC]]64, [[PowerPC]]
| operating system = [[Cross-platform]]: [[Microsoft Windows|Windows]], [[Linux]], [[macOS]], [[FreeBSD]], [[NetBSD]], [[OpenBSD]], [[Solaris (operating system)|Solaris]], [[IBM AIX|AIX]], [[Haiku (operating system)|Haiku]], [[Android (operating system)|Android]], [[iOS]]
| license = [[BSD licenses|BSD]]
| file ext = .scm
| file format = <!-- or: | file formats = -->
| website = {{official URL}}
| implementations =
| dialects =
| influenced by = [[Lisp (programming language)|Lisp]], [[Scheme (programming language)|Scheme]]
| influenced =
}}
}}


'''CHICKEN''' is a [[compiler]] and [[interpreter (computing)|interpreter]] for the [[Scheme (programming language)|Scheme programming language]] that compiles Scheme code to standard [[C programming language|C]]. It is mostly [[R5RS]] compliant and offers many extensions to the standard. CHICKEN is [[free software]] available under the [[BSD license]]. It is implemented mostly in Scheme, with some parts in C for performance or to make embedding into C programs easier.
'''Chicken''' (stylized as '''CHICKEN''') is a [[programming language]], specifically a [[compiler]] and [[Interpreter (computing)|interpreter]] which implement a [[Dialect (computing)|dialect]] of the programming language [[Scheme (programming language)|Scheme]], and which compiles Scheme [[source code]] to standard [[C (programming language)|C]]. It is mostly [[R5RS]] compliant and offers many extensions to the standard. The newer R7RS standard is supported through an extension [[Library (computing)|library]].<ref name="r7rs">{{cite web |url=https://wiki.call-cc.org/eggref/5/r7rs |title=r7rs (Chicken manual) |author=evhan |date=2018-11-09 |website=Chicken Scheme |access-date=2019-02-28}}</ref> Chicken is [[free and open-source software]] available under a [[BSD licenses|BSD license]]. It is implemented mostly in Scheme, with some parts in C for performance or to make embedding into C programs easier.


==Focus==
==Focus==
CHICKEN's focus is immediately clear from its tagline: "''A practical and portable Scheme system''".
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 curricula and programming language experimentation, but it hasn't seen much use in business and industry.<ref>{{cite web |url=http://community.schemewiki.org/?scheme-faq-general|title=Scheme FAQ}}, section "what is Scheme used for?"</ref> CHICKEN's community has produced a large set of [[#Add-on software|libraries]] for performing a variety of tasks. The CHICKEN wiki (the software running it is also a CHICKEN program) also contains [https://wiki.call-cc.org/Software a list of software] that people have written in CHICKEN.
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]] curricula and programming language experimentation, but it has seen little use in business and industry.<ref>{{cite web |url=http://community.schemewiki.org/?scheme-faq-general|title=Scheme FAQ}}, section "what is Scheme used for?"</ref> Chicken's community has produced a large set of [[#Add-on software|libraries]] 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.<ref>{{cite web |url=https://wiki.call-cc.org/Software |title=Software written in Chicken Scheme |last=Bex |first=Peter (sjamaan) |date=2018-08-16 |website=Chicken Scheme |access-date=2019-02-26}}</ref>


CHICKEN's other goal is to be portable. By compiling to portable C (like [[Gambit (Scheme implementation)|Gambit]] and [[Bigloo]]), programs written in CHICKEN can be compiled for common popular platforms like [[Linux]], [[Mac OS X]] and other [[Unix-like]] systems as well as [[Windows]], [[Haiku (operating system)|Haiku]] and the mobile platforms [[iOS]] and [[Android (operating system)|Android]].<ref>{{cite web |url=https://wiki.call-cc.org/portability |title=Portability}} page on the CHICKEN wiki</ref> It also has built-in support for cross-compilation of programs and extensions,<ref>{{cite web |url=https://wiki.call-cc.org/man/4/Cross%20development |title=''Cross development''}} - a section from the CHICKEN manual</ref> which allows it to be used on various embedded platforms.
Chicken's other goal is to be [[Software portability|portable]]. By compiling to an [[intermediate representation]], in this case portable C (as do [[Gambit (Scheme implementation)|Gambit]] and [[Bigloo]]), programs written in Chicken can be compiled for common popular [[operating system]]s such as [[Linux]], [[macOS]], other [[Unix-like]] systems, [[Windows]], [[Haiku (operating system)|Haiku]], and mobile platforms [[iOS]] and [[Android (operating system)|Android]].<ref>{{cite web |url=https://wiki.call-cc.org/portability |title=Portability |website=Chicken Scheme Wiki }}</ref> It also has built-in support for [[Cross compiler|cross-compiling]] programs and extensions,<ref>{{cite web |url=https://wiki.call-cc.org/man/5/Cross%20development |title=Cross development |last=Bex |first=Peter (sjamaan) |date=2016-05-28 |website=Chicken Scheme (Manual) |access-date=2019-02-26}}</ref> which allows it to be used on various [[embedded system]] platforms.


==Design==
==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.
Like many Scheme compilers, Chicken uses standard C as an [[intermediate representation]]. 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<ref>Baker, Henry {{cite web |url=http://home.pipeline.com/~hbaker1/CheneyMTA.html |title=''CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A.''}}</ref> by [[Henry Baker (computer scientist)|Henry Baker]] that outlined an innovative strategy for Scheme compilation into C. A Scheme program is compiled into C [[subroutine|functions]]. These C functions never reach the ''return'' [[statement (programming)|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.
Chicken's design was inspired by a 1994 paper<ref>{{cite web |url=http://home.pipeline.com/~hbaker1/CheneyMTA.html |title=CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A. |last=Baker |first=Henry |date=1994 |archive-url=https://web.archive.org/web/20060303155622/http://home.pipeline.com/~hbaker1/CheneyMTA.html |archive-date=2006-03-03 |url-status=dead }}</ref> by [[Henry Baker (computer scientist)|Henry Baker]] that outlined an innovative strategy to compile Scheme into C. A Scheme program is compiled into C [[subroutine|functions]]. These C functions never reach the ''return'' [[Statement (computer science)|statement]]; instead, they call a new [[continuation]] 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|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 (computer science)|garbage collection]] can be initiated. The design used is a [[Cheney's algorithm|copying garbage collector]] originally devised by C.J. Cheney, which copies all live continuations and other live objects to the heap.<ref>Cheney, C.J. "A Nonrecursive List Compacting Algorithm". CACM 13,11 (Nov. 1970), 677-678.</ref> Despite this, the C code does not copy C stack frames, only Scheme objects, so it does not require knowledge of the C implementation.
So far, this is the essence of [[continuation-passing style]]. Baker's novel idea is to use the C [[call 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 (computer science)|garbage collection]] can be initiated. The design used is a [[Cheney's algorithm|copying garbage collector]] originally devised by C. J. Cheney, which copies all live continuations and other live objects to the heap.<ref>Cheney, C.J. "A Nonrecursive List Compacting Algorithm". CACM 13,11 (Nov. 1970), 677-678.</ref> 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''.
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''.


==Limitations and deviations from the standard==
==Limitations and deviations from the standard==
Chicken Scheme is mostly R5RS-compliant, with a few notable limitations and deviations.<ref>{{cite web |url=https://wiki.call-cc.org/man/5/Deviations%20from%20the%20standard |title=Confirmed deviations (Chicken manual) |last=Bex |first=Peter (sjamaan) |last2=Winkelmann |first2=Felix |date=2016-05-28 |website=Chicken Scheme |access-date=2019-02-28}}</ref> R7RS compatibility is supplied as an extension library.<ref name="r7rs" />


The core system has basic support for [[UTF-8]] 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.<ref>{{cite web |url=https://wiki.call-cc.org/eggref/5/utf8 |title=utf8 (Chicken manual) |last=Bex |first=Peter (sjamaan) |author2=kooda |author3=mario |author4=svnwiki |author5=wasamasa |author6=kon |author7=mario |date=2018-08-11 |website=Chicken Scheme |access-date=2019-02-28}}</ref>
CHICKEN Scheme is mostly R5RS-compliant, with a few notable limitations and deviations.<ref>The CHICKEN Team, {{cite web |url=https://wiki.call-cc.org/man/4/Deviations%20from%20the%20standard |title=''Deviations from the standard''}}, the CHICKEN manual</ref>

There is no support for the full [[numeric tower]] in the core system. However, [https://wiki.call-cc.org/eggref/4/numbers an extension library] exists which adds support for the full numeric tower. The next major version will remove this limitation.<ref>The CHICKEN Team, {{cite web |url=https://wiki.call-cc.org/chicken-5-roadmap#integrating-the-full-numeric-tower |title=''CHICKEN 5 roadmap''}}</ref>

The core system has basic support for UTF-8 characters, however the string indexing and manipulation procedures are not UTF-8 aware. Here again there is an [https://wiki.call-cc.org/eggref/4/utf8 extension library] which adds support for full UTF-8 awareness.


==Add-on software==
==Add-on software==
Chicken has a large [[software repository]] of added libraries and programs, termed ''eggs''.<ref>{{cite web |url=https://eggs.call-cc.org/ |title=Chicken eggs |author=<!-- Unstated --> |date=<!-- Unstated --> |website=Chicken Scheme }}</ref> This system is very similar to [[RubyGems]].<ref>{{cite web |url=https://rubygems.org/ |title=RubyGems |author=<!-- Unstated --> |date=<!-- Unstated --> |website=RubyGems.org |access-date=2019-02-26}}</ref>


Initially, these eggs were developed in one central svn repository,<ref>{{cite web |url=https://www.more-magic.net/posts/vcs-independent-distribution.html |title=VCS-independent distribution of language extensions |last=Bex |first=Peter (sjamaan) }}, blogpost on More magic</ref> 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.<ref>{{cite web |url=https://wiki.call-cc.org/releasing-your-egg#instructions-for-popular-code-hosting-methods-and-vcses |title=Instructions for popular code hosting methods and VCSes |website=Chicken wiki }}</ref> 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.
CHICKEN has a large repository of additional libraries and programs called "[https://wiki.call-cc.org/chicken-projects/egg-index-4.html eggs]". This eggs system is quite similar to [[RubyGems]].{{or|date=July 2015}}


For all released eggs, the latest version is tested automatically as part of a [[continuous integration]] process. A canonical test [[Server (computing)|server]] exists,<ref>{{cite web |url=https://tests.call-cc.org/ |title=Chicken automated tests |author=<!-- Unstated --> |date=<!-- Unstated --> |website=Chicken Scheme |access-date=2019-02-28}}</ref> 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.
Initially, these eggs were developed in one central svn repository,<ref>Bex, Peter {{cite web |url=http://www.more-magic.net/posts/vcs-independent-distribution.html |title=''VCS-independent distribution of language extensions''}}, blogpost on More magic</ref> 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.<ref>The CHICKEN wiki, {{cite web |url=https://wiki.call-cc.org/releasing-your-egg#instructions-for-popular-code-hosting-methods-and-vcses |title=''Instructions for popular code hosting methods and VCSes''}}</ref> 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 he or she likes, and could even choose to avoid public version control altogether and distribute only plain tarballs.

For all released eggs, the latest version is tested automatically as part of a [[continuous integration]] process. Anyone can volunteer to supply additional testing capacity (on different hardware, or different operating systems or on different core releases), but there's also a canonical [https://tests.call-cc.org test server] where the core system and all eggs will be tested daily against the most recent development version (to catch regressive bugs) as well as the most recent stable version (to ensure that everything works for users of the stable system).


==Features==
==Features==
Chicken supports most of R5RS standard [[Scheme (programming language)|Scheme]], but it also adds a few nonstandard features which are not available in all Scheme implementations.

CHICKEN supports most of R5RS standard [[Scheme (programming language)|Scheme]], but it also adds a few nonstandard features which are not available in all Scheme implementations.


===Foreign function interface===
===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 (programming language)|Python]],<ref>{{cite web |url=https://wiki.call-cc.org/eggref/4/pyffi |title=pyffi |author=iraikov |date=2016-06-11 |website=Chicken Scheme Wiki |access-date=2019-03-03}}</ref> [[Lua (programming language)|Lua]],<ref>{{cite web |url=https://wiki.call-cc.org/eggref/4/lua |title=Lua |last=Bex |first=Peter (sjamaan) |author2=iraikov |date=2012-03-11 |website=Chicken Scheme Wiki |access-date=2019-03-03}}</ref> and [[Java (programming language)|Java]], via [[Java Native Interface]] (JNI)<ref>{{cite web |url=https://wiki.call-cc.org/eggref/4/jni |title=JNI |author=mario |author2=svnwiki |date=2013-06-04 |website=Chicken Scheme Wiki |access-date=2019-03-03}}</ref> or a bridge.<ref>{{cite web |url=https://wiki.call-cc.org/eggref/4/javahack |title=Javahack |last=Winkelmann |first=Felix |author2=mario |date=2013-06-04 |website=Chicken Scheme Wiki |access-date=2019-03-03}}</ref>
As mentioned above, CHICKEN compiles to C, which makes it possible to "inject" custom C code into the compiled result, which eases integration with C libraries. Its [[Foreign function interface]] supports converting back and forth between most built-in C types and corresponding Scheme objects.

There are also extension libraries for interfacing to [https://wiki.call-cc.org/eggref/4/pyffi Python], [https://wiki.call-cc.org/eggref/4/lua Lua], and Java via [https://wiki.call-cc.org/eggref/4/jni JNI] or through [https://wiki.call-cc.org/eggref/4/javahack a bridge].

===Cross-compilation===


===Cross-compiling===
It is relatively easy to [[cross-compile]] Scheme code to another platform (for example for embedded use on a device).
It is relatively easy to [[cross-compile]] Scheme code to another platform (for example for embedded use on a device).


In order to make cross-compilation possible for Scheme code, CHICKEN imposes a model of separate compilation: 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.
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 itself 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.
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===
===Modules and macros===
Since version 4, Chicken has a built-in module system and support for low-level [[hygienic macro]]s through ''explicit renaming'' macros<ref>{{cite web |url=https://wiki.call-cc.org/man/5/Module%20(chicken%20syntax)#explicit-renaming-macros |title=Module (Chicken syntax) |last=Bex |first=Peter (sjamaan) |last2=Winkelmann |first2=Felix |author3=mario |date=2018-09-23 |website=Chicken Scheme |access-date=2019-02-28}}</ref> (before version 4, this was available through an add-on library). Standard ''syntax-rules'' macros are also supported, and ''implicit renaming'' macros,<ref>{{cite web |url=https://wiki.call-cc.org/man/5/Module%20(chicken%20syntax)#implicit-renaming-macros |title=Module (Chicken syntax) |last=Bex |first=Peter (sjamaan) |last2=Winkelmann |first2=Felix |author3=mario |date=2018-09-23 |website=Chicken Scheme |access-date=2019-02-28}}</ref> 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.
Since version 4, CHICKEN has a built-in module system and support for low-level [[hygienic macros]] through [https://wiki.call-cc.org/man/4/Macros#explicit-renaming-macros ''explicit renaming''] (prior to CHICKEN 4 this was available through an add-on library). Standard ''syntax-rules'' macros are also supported, as well as [https://wiki.call-cc.org/man/4/Macros#implicit-renaming-macros ''implicit renaming''] macros, which is basically a "reversed" version of explicit renaming.


===Remote debugger===
This mechanism trades in performance for convenience. Each identifier not explicitly "injected" as unhygienic will be automatically renamed to avoid name capture. The performance cost lies in the fact that this "implicit" renaming requires the macro-expander to traverse the expressions an additional two times. This cost is paid at expansion time, so a macro author must consider whether longer compilation times are acceptable.
Since version 4.11, Chicken comes shipped with a debugger named ''Feathers''.<ref>{{cite web |url=https://wiki.call-cc.org/man/5/Debugging |title=Debugging |last=Bex |first=Peter (sjamaan) |date=2018-11-25 |website=Chicken Scheme }}</ref> 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===
===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).
More recently, support was added for 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.


==History==
This "scrutinizer" does not allow cross-module flow analysis, so it can only be used to optimize code that's part of one compilation unit (or module).
CHICKEN Scheme was originally developed by Felix Winkelmann on [[Cygwin]]/gcc and later [[Visual C++ 5.0]] on [[Windows 98]].<ref name="googlegroups"/> 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 [[The Wrong Trousers|Feathers McGraw]] on his desk. As the project matured, he decided not to change the name out of superstition.<ref>{{Cite web |last=Croisant |first=John |date=2013-06-19 |title=Behind the Scenes with CHICKEN Scheme and SPOCK (Part 2) |url=https://spin.atomicobject.com/2013/06/19/chicken-scheme-spock-part-2/ |access-date=2023-02-17 |website=Atomic Spin |language=en-US}}</ref>


==See also==
==See also==
Line 86: Line 96:
* [[Tail recursion]]
* [[Tail recursion]]
* [[Cheney's algorithm]]
* [[Cheney's algorithm]]
* "[[M.T.A. (song)|M.T.A.]]", a song reference in Baker's 1994 paper
* "[[M.T.A. (song)]]", a song reference in Baker's 1994 paper
* [[Gambit (Scheme implementation)|Gambit]]
* [[Gambit (Scheme implementation)]]
* [[Stalin (Scheme implementation)|Stalin]]
* [[Stalin (Scheme implementation)]]
{{Clear}}


==References==
==References==

{{Reflist}}
{{Reflist}}


==External links==
==External links==
* {{Official website}}
* [https://www.call-cc.org/ CHICKEN Scheme website]
* {{GitHub|alaricsp/Chicken-scheme|Chicken}}
* [https://wiki.call-cc.org The CHICKEN Wiki]

{{Lisp programming language}}


{{DEFAULTSORT:Chicken}}
{{DEFAULTSORT:Chicken}}

Revision as of 06:35, 16 July 2024

Chicken Scheme
Logo for Chicken Scheme
Chicken 5.0.0 interpreter running on macOS
ParadigmsMulti-paradigm: functional, imperative, meta
FamilyLisp
Designed byFelix Winkelmann
DeveloperThe Chicken Team
First appeared20 July 2000; 24 years ago (2000-07-20)[1]
Stable release
5.4.0 / 16 July 2024; 3 months ago (2024-07-16)
Typing disciplineDynamic, latent, strong
ScopeLexical
Implementation languageScheme, C
PlatformIA-32, x86-64, ARM, MIPS, SPARC64, PowerPC
OSCross-platform: Windows, Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris, AIX, Haiku, Android, iOS
LicenseBSD
Filename extensions.scm
Websitewww.call-cc.org Edit this at Wikidata
Influenced by
Lisp, Scheme

Chicken (stylized as CHICKEN) is a programming language, specifically a compiler and interpreter which implement a dialect of the programming language Scheme, and which compiles Scheme source code 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.[2] Chicken is free and open-source software available under a BSD license. 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 curricula and programming language experimentation, but it has seen little use in business and industry.[3] Chicken's community has produced a large set of libraries 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.[4]

Chicken's other goal is to be portable. By compiling to an intermediate representation, in this case portable C (as do Gambit and Bigloo), programs written in Chicken can be compiled for common popular operating systems such as Linux, macOS, other Unix-like systems, Windows, Haiku, and mobile platforms iOS and Android.[5] It also has built-in support for cross-compiling programs and extensions,[6] which allows it to be used on various embedded system platforms.

Design

Like many Scheme compilers, Chicken uses standard C as an intermediate representation. 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[7] 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 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 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.[8] 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.

Limitations and deviations from the standard

Chicken Scheme is mostly R5RS-compliant, with a few notable limitations and deviations.[9] R7RS compatibility is supplied as an extension library.[2]

The core system has basic support for UTF-8 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.[10]

Add-on software

Chicken has a large software repository of added libraries and programs, termed eggs.[11] This system is very similar to RubyGems.[12]

Initially, these eggs were developed in one central svn repository,[13] 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.[14] 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 exists,[15] 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,[16] Lua,[17] and Java, via Java Native Interface (JNI)[18] or a bridge.[19]

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[20] (before version 4, this was available through an add-on library). Standard syntax-rules macros are also supported, and implicit renaming macros,[21] 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.[22] 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.[1] 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.[23]

See also

References

  1. ^ a b Winkelmann, Felix. "Announcing the Chicken Scheme-to-C compiler". Google Groups (comp.lang.scheme).
  2. ^ a b evhan (2018-11-09). "r7rs (Chicken manual)". Chicken Scheme. Retrieved 2019-02-28.
  3. ^ "Scheme FAQ"., section "what is Scheme used for?"
  4. ^ Bex, Peter (sjamaan) (2018-08-16). "Software written in Chicken Scheme". Chicken Scheme. Retrieved 2019-02-26.
  5. ^ "Portability". Chicken Scheme Wiki.
  6. ^ Bex, Peter (sjamaan) (2016-05-28). "Cross development". Chicken Scheme (Manual). Retrieved 2019-02-26.
  7. ^ Baker, Henry (1994). "CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A." Archived from the original on 2006-03-03.
  8. ^ Cheney, C.J. "A Nonrecursive List Compacting Algorithm". CACM 13,11 (Nov. 1970), 677-678.
  9. ^ Bex, Peter (sjamaan); Winkelmann, Felix (2016-05-28). "Confirmed deviations (Chicken manual)". Chicken Scheme. Retrieved 2019-02-28.
  10. ^ Bex, Peter (sjamaan); kooda; mario; svnwiki; wasamasa; kon; mario (2018-08-11). "utf8 (Chicken manual)". Chicken Scheme. Retrieved 2019-02-28.
  11. ^ "Chicken eggs". Chicken Scheme.
  12. ^ "RubyGems". RubyGems.org. Retrieved 2019-02-26.
  13. ^ Bex, Peter (sjamaan). "VCS-independent distribution of language extensions"., blogpost on More magic
  14. ^ "Instructions for popular code hosting methods and VCSes". Chicken wiki.
  15. ^ "Chicken automated tests". Chicken Scheme. Retrieved 2019-02-28.
  16. ^ iraikov (2016-06-11). "pyffi". Chicken Scheme Wiki. Retrieved 2019-03-03.
  17. ^ Bex, Peter (sjamaan); iraikov (2012-03-11). "Lua". Chicken Scheme Wiki. Retrieved 2019-03-03.
  18. ^ mario; svnwiki (2013-06-04). "JNI". Chicken Scheme Wiki. Retrieved 2019-03-03.
  19. ^ Winkelmann, Felix; mario (2013-06-04). "Javahack". Chicken Scheme Wiki. Retrieved 2019-03-03.
  20. ^ Bex, Peter (sjamaan); Winkelmann, Felix; mario (2018-09-23). "Module (Chicken syntax)". Chicken Scheme. Retrieved 2019-02-28.
  21. ^ Bex, Peter (sjamaan); Winkelmann, Felix; mario (2018-09-23). "Module (Chicken syntax)". Chicken Scheme. Retrieved 2019-02-28.
  22. ^ Bex, Peter (sjamaan) (2018-11-25). "Debugging". Chicken Scheme.
  23. ^ Croisant, John (2013-06-19). "Behind the Scenes with CHICKEN Scheme and SPOCK (Part 2)". Atomic Spin. Retrieved 2023-02-17.