ZetCode

Introduction to Scheme

last modified November 24, 2026 Guile 3.0

Scheme is a small, dynamically typed programming language from the Lisp family. Programs are written as nested lists in parentheses, procedures are ordinary values that can be passed around and returned, and loops are usually written as recursion. The language has a short definition and a handful of powerful ideas, which made it a favourite for teaching programming and for research into programming languages. This article describes where Scheme came from, lists its standards and implementations, installs GNU Guile, and runs the first programs.

What is Scheme

Scheme was created in 1975 by Gerald Jay Sussman and Guy L. Steele Jr. at the MIT Artificial Intelligence Laboratory. It started as a small Lisp interpreter written to explore the actor model of computation, and its authors discovered that a few well-chosen features were enough to express most control structures. A series of papers from that time, known as the Lambda Papers, showed how procedure calls could replace loops, jumps, and other special constructs.

Scheme differs from older Lisps in several ways that later spread to many languages. It uses lexical scope: a name refers to the binding that is visible where the code is written, not where it is called. Procedures are first-class values, so they can be stored in variables, passed as arguments, and created at run time. Every implementation must perform proper tail calls, which lets a recursive procedure run in constant space when the recursive call is its last action. Scheme also exposes continuations through call/cc and provides hygienic macros that extend the syntax of the language safely.

The language became widely known through the textbook Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman, used for decades in the introductory programming course at MIT. Today Scheme is used for teaching, for language research, as an extension language embedded in larger programs, and for general programming.

The Scheme standards

Scheme is defined by a series of reports called the Revisedn Report on the Algorithmic Language Scheme, abbreviated RnRS. Each report is short compared with the definition of most languages. The three reports that matter for current implementations are R5RS, R6RS, and R7RS.

StandardYearNotable features
R4RS1991the basis of the IEEE 1178 standard; macros only in an appendix
R5RS1998hygienic macros with syntax-rules, multiple values, dynamic-wind, eval
R6RS2007libraries, records, exceptions, Unicode, bytevectors, a much larger standard library
R7RS small2013a compact language close to R5RS, with libraries, records, exceptions, and bytevectors

R6RS was large and was not adopted by every implementation, so R7RS split the work in two: a small language, finished in 2013, and a large language built on top of it, which is still in progress. Implementations also share extensions through SRFIs (Scheme Requests for Implementation), numbered documents that specify libraries such as list operations (SRFI 1), records (SRFI 9), or unit tests (SRFI 64).

Implementations

Scheme has many implementations, and they differ in performance, in the standards they support, and in their libraries. Some widely used ones are listed below.

Racket started as a Scheme implementation, PLT Scheme, but has since grown into a separate language. This series uses GNU Guile 3.0. Guile implements most of R7RS small and R6RS, ships many SRFIs, and has its own modules for files, regular expressions, processes, threads, and objects. Where an example relies on a Guile extension rather than on standard Scheme, the text says so.

Installing Guile

On Debian and Ubuntu, Guile 3.0 is installed from the distribution packages. The package provides the guile command, which runs scripts and starts the interactive interpreter.

sudo apt install guile-3.0

Other systems have Guile in their package managers as well, usually under the name guile. The installation used for this series reports:

$ guile --version
guile (GNU Guile) 3.0.7
Packaged by Debian (3.0.7-deb+3.0.7-1)
Copyright (C) 2021 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

The first program

A Scheme program is a sequence of expressions that are evaluated one after another. Each expression in parentheses is a call: the first element names the procedure, and the remaining elements are its arguments. The first program calls two procedures.

hello.scm
(display "Hello there!")
(newline)

display writes its argument to the standard output, and newline ends the line. Unlike many languages, Scheme has no statement terminator and no main function; the top-level expressions of the file run in order. Source files usually have the .scm extension, and the program is run by passing the file name to guile.

$ guile hello.scm
Hello there!

Auto-compilation

Guile does not interpret the source text directly. The first time it runs a file, it compiles the file to bytecode, stores the result in a cache in the home directory, and runs the compiled code. It reports this on the standard error output, so the very first run of hello.scm prints notes before the program's own output, as shown below.

The paths in the notes depend on where the file is saved. Later runs reuse the cached .go file and print only the program output, until the source file is edited; then Guile notes that the source is newer than the compiled file and compiles it again. The notes are harmless, and they can be switched off with the --no-auto-compile option or by setting GUILE_AUTO_COMPILE=0. The compiler also prints warnings, for example about misspelled names, so the notes are worth reading. The outputs in this series show what the program prints once it has been compiled.

$ guile hello.scm
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/user/scheme/hello.scm
;;; compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.5/home/user/scheme/hello.scm.go
Hello there!

A second program

A program may contain any number of expressions. The arguments of a call can be calls themselves, and an inner call is evaluated first, so its result becomes the argument of the outer one.

facts.scm
(display "Scheme is a dialect of Lisp.")
(newline)
(display "It was created at MIT in 1975.")
(newline)
(display "Six times seven is ")
(display (* 6 7))
(newline)

The expression (* 6 7) multiplies the two numbers, and display prints the result, 42. Arithmetic in Scheme uses the same prefix form as every other call: the operator comes first, followed by its operands. display does not end the line, so the text and the number appear on the same line until newline is called.

$ guile facts.scm
Scheme is a dialect of Lisp.
It was created at MIT in 1975.
Six times seven is 42

The REPL

Started without a file, guile opens a REPL (read-eval-print loop). It reads an expression, evaluates it, prints the value, and waits for the next one. The REPL is the usual way to try out a procedure or check a small piece of code. The -q option skips the personal start-up file.

The prompt shows the current module, guile-user. Each value is printed and saved in a numbered variable such as $1, which can be used in later expressions. A definition and a display call return no useful value, so the REPL prints nothing for them; the text written by display appears directly before the next prompt because no newline was written. Commands that start with a comma control the REPL itself: ,help lists them and ,q quits.

$ guile -q
GNU Guile 3.0.7
Copyright (C) 1995-2021 Free Software Foundation, Inc.

Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
This program is free software, and you are welcome to redistribute it
under certain conditions; type `,show c' for details.

Enter `,help' for help.
scheme@(guile-user)> (+ 1 2)
$1 = 3
scheme@(guile-user)> (define x 5)
scheme@(guile-user)> (* x x)
$2 = 25
scheme@(guile-user)> (display "Hello there!")
Hello there!scheme@(guile-user)> ,q

Executable scripts

A Scheme file can be made into an executable script with a #! line. Guile treats everything from #! to a line containing only !# as a comment, so the header can carry options for the interpreter without disturbing the Scheme code.

greet.scm
#!/usr/bin/env -S guile --no-auto-compile -s
!#
(display "Hello there from a script!")
(newline)

The env -S form splits the rest of the line into separate arguments, so guile receives --no-auto-compile and -s. The -s option tells Guile that a script file follows, and --no-auto-compile keeps the compilation notes out of the output. The file needs the execute permission before it can be started directly.

$ chmod +x greet.scm
$ ./greet.scm
Hello there from a script!

Next steps

The Scheme basics article continues with expressions, printing, comments, definitions, and the first procedures. The expressions and evaluation article explains how Scheme evaluates a program, and the data types article introduces the values that programs work with.

Source

R7RS: the Revised7 Report on Scheme

GNU Guile Reference Manual

Scheme Requests for Implementation

Scheme on Wikipedia

In this article we have introduced Scheme, surveyed its standards from R4RS to R7RS, installed GNU Guile, and run the first programs as files, in the REPL, and as executable scripts. The next article covers the everyday parts of the language.

Author

I am Jan Bodnar, a programmer and technical writer. I have been writing programming tutorials at ZetCode since 2007 and have published eight e-books. See about the author.

List all Scheme tutorials.