Skip to main content

What is Lisp and Scheme?

Lisp cycle

Lisp is the second-oldest programming language (after Fortran) that is still in use. Lisp is an acronym for LISt Processing. It was invented by John McCarthy in 1958 at MIT. The main feature of Lisp is its lack of syntax. The idea for Lisp language came from mathematics, to be exact Lambda Calculus defined by Alonzo Church, which was invented or discovered to prove that the halting problem is unsolvable.

The most distinguishing things about lisp is a notion that code and data are represented using the same data structures, in lisp they are lists. This is a very important characteristic, and it's called Homoiconicity.

S-Expressions

In Lisp, everything is written as S-Expression, which is a list wrapped in parentheses with space between elements.

(+ 1 2 3)

This is basic lisp expression. The difference between Scheme and other programming languages that often write the same expression as:

1 + 2 + 3

Is that in Lisp there are no operators. The above expression is just procedure application (function call).

NOTE: We will use procedure and function interchangeably in this tutorial.

Plus is not an operator, only a symbol that point into an addition procedure that is executed. So in fact in other programming languages this should be written as:

+(1, 2, 3)

This is obviously invalid syntax (in most languages).

Nesting expressions

The S-Expressions can be nested:

(+ (* 3 (/ 1 2)) (+ 1 2))

But you can't add parentheses randomly to wrap expressions, like in other languages. Parentheses are always procedure application (or special form that will be described later).

S-Expression is the most efficient way to write function application, and you can form with it any nested trees.

What is Scheme

So now what is Scheme. Scheme is a dialect of Lisp, there are other well known dialects of Lisp, like Common Lisp, Racket, Clojure. They all have one in common, they all use S-Expressions for syntax (or lack of).

Scheme was designed by Guy L. Steele and Gerald Jay Sussman in a 1970s. They were playing with an idea called the actor model and trying to understand it by creating a simple implementation. That implementation later led to Scheme programming languages.

REPL

REPL or Read-Eval-Print Loop, is a way to interact with interpreter in an interactive way. Most modern interpreted programming languages that some kind of REPL, but it was first introduced in 1964 by L. Peter Deutsch and Edmund Berkele for Lisp implementation on PDP-1.

To run REPL you often need to run scheme or lisp executable. It's often called from the terminal interface. When the scheme or lisp system runs you will get a prompt that may look like this:

scheme>

And you can type your scheme code and press enter to execute it (it's often called evaluation of the expression).

NOTE: you can run LIPS bookmarklet while reading this tutorial. But note that it doesn't yet support continuations and TCO (Tail Call Optimization).

Standards

Scheme is standardized in form of RnRS documents. Revisedn Report on the Algorithmic Language Scheme. Where power indicate how many times it was revisited. Power of 2 means Revisited Revisited.

The latest standard is R7RS Small, and there is version large in the making.

Scheme Implementations

You can find different implementations of the programming language that re more or less compatible with specification.

Example implementations:

The official website for Scheme programming language is scheme.org, which contains more up to date list of Scheme implementations.

SRFI Documents

SRFI stands for Scheme Requests for Implementations. And are official documents that add new features to the languages. Some of the SRFI may land in new version of RnRS specification. The website for SRFI documents is located at srfi.schemers.org.