Getting Started with Chicken (Scheme)

Screenshot 2018-05-04 20.14.24

Introduction

Chicken is an implementation of the Scheme programming language that compiles into C code. It is one of several existing Scheme implementations. Chicken, unlike some others of its family, also comes with a library management system similar to RubyGems or NPM where modules are called Eggs.

Installing Chicken

Most Linux systems either come with or have pre-existing packages.

For MacOS X, both MacPorts and Homebrew have packages.

There are also binary releases for Windows. However, as of this, writing, the only recommended build is available from Chocolatey, which will require additionally installing that package manager software.

Example


; A simple "Hello, World!"
(print "Hello, World!")

view raw

hello.scm

hosted with ❤ by GitHub

Using Chicken as a Scripting Language

Chicken comes with a Chicken Script Interpreter (CSI) that can be run using its initial: csi. Without any other arguments, it will open a read-eval-print loop (REPL) where code can be written and executed line-by-line. More usefully to most situations, it can be run with its “-s” (to interpret and run) or “-ss” (which expects a defined ‘main’ to which it will pass arguments sent to it).

With the above file saved as “hello.scm”, it can be run as an interpreted language using

csi -s hello.scm

This will display the results of “Hello, World”.

The manual goes into greater depth on different options.

Using Chicken as a Compiled Language

A compiler* is also part of the Chicken installation. Named “csc”, it can be accessed through the same name. By default, it will compile the

csc hello.scm

*Binary installations of Chicken will require that a C compiler also be installed on the system in order to run properly. This will also be required for the use of Eggs.

The manual also goes into greater depth on different options for compiling modules or creating code to be dynamically loaded.

Installing and Using Eggs

Additional modules, called “eggs” in Chicken, can be installed using the “chicken-install” command-line tool.

chicken-install egg-name

Once installed, Eggs can be used through the “require-extentsion” procedure. Before using any of the named procedures or symbols, include an egg like the following:

(require-extension egg-name)