( ( ( λ ) ) )

Intro to Scheme

Think different. Parentheses, recursion, and the beauty of functional programming.

1

The Story of Scheme

One of the most influential programming languages ever created, born at MIT in 1975. Scheme is small, elegant, and powerful. It changed how generations of computer scientists think about code.

1958
John McCarthy creates Lisp at MIT. It is the second-oldest programming language still in use, after Fortran (1957). Lisp introduces ideas that will shape all of computing: garbage collection, tree data structures, and the idea that code and data are the same thing.
1975
Guy Steele and Gerald Sussman create Scheme at MIT. They wanted a small, clean dialect of Lisp to explore ideas about computation. Scheme strips Lisp down to its essentials: functions, recursion, and lists.
1985
MIT publishes "Structure and Interpretation of Computer Programs" (SICP), a textbook that uses Scheme to teach computer science from the ground up. It becomes one of the most famous CS textbooks of all time.
1985+
Scheme's ideas spread everywhere. Brendan Eich is influenced by Scheme when he creates JavaScript in 1995. Ruby, Python, and many modern languages borrow concepts like closures, first-class functions, and lexical scoping from Scheme.
"Scheme demonstrates that a very small number of rules for forming expressions, with no restrictions on how they are composed, suffice to form a practical and efficient programming language."
- R5RS (Revised Report on the Algorithmic Language Scheme)
2

Hello, World!

Scheme looks different from most languages. Everything is wrapped in parentheses, and operations come first. This is called prefix notation.

> (display "Hello, World!")
Hello, World!

> (newline)

;; Math uses prefix notation: operator first, then operands
> (+ 1 2)
=> 3

> (* 4 5)
=> 20

;; Nesting works naturally
> (+ (* 2 3) (* 4 5))
=> 26
Most Languages Scheme
1 + 2 (+ 1 2)
3 * (4 + 5) (* 3 (+ 4 5))
print("Hi") (display "Hi")
if (x > 0) { ... } (if (> x 0) ...)

The parentheses might look strange at first. But they give Scheme its greatest power: because every expression has the same shape, the language has almost no special syntax to memorize.

3

Lists and Recursion

Lists are the heart of Scheme. Everything is built from lists, and you process them with recursion instead of loops.

;; A list
> '(1 2 3 4 5)
=> (1 2 3 4 5)

;; car: get the first element
> (car '(1 2 3))
=> 1

;; cdr: get everything except the first
> (cdr '(1 2 3))
=> (2 3)

;; cons: prepend an element
> (cons 0 '(1 2 3))
=> (0 1 2 3)

Instead of loops, Scheme uses recursion. A function calls itself, processing one element at a time until the list is empty.

;; Factorial using recursion
(define (factorial n)
  (if (= n 0)
    1
    (* n (factorial (- n 1)))))

> (factorial 5)
=> 120

;; How it works:
;; (factorial 5)
;; (* 5 (factorial 4))
;; (* 5 (* 4 (factorial 3)))
;; (* 5 (* 4 (* 3 (* 2 (* 1 1)))))
;; (* 5 (* 4 (* 3 (* 2 1))))
;; => 120
"In Scheme, you don't loop. You recurse."
4

Lambda and Higher-Order Functions

In Scheme, functions are values. You can store them in variables, pass them to other functions, and create them on the fly with lambda.

;; lambda creates an anonymous function
> (lambda (x) (* x x))
=> #<procedure>

;; Use it immediately
> ((lambda (x) (* x x)) 5)
=> 25

;; Give it a name
> (define square (lambda (x) (* x x)))
> (square 7)
=> 49

Higher-order functions take other functions as arguments. This is where things get interesting.

;; map: apply a function to every element
> (map square '(1 2 3 4))
=> (1 4 9 16)

;; filter: keep elements that pass a test
> (filter (lambda (x) (> x 3)) '(1 2 3 4 5))
=> (4 5)

;; apply: spread a list as arguments
> (apply + '(1 2 3 4))
=> 10

Functions as Values

A function is just another piece of data. You can put it in a list, return it from another function, or store it in a variable.

Closures

A lambda "remembers" the variables from where it was created. This is called a closure, and it is one of Scheme's most powerful features.

Composition

Build complex behavior by combining simple functions. Small pieces, loosely joined. Each function does one thing well.

5

What Makes Scheme Special

Scheme is not just another programming language. It is a way of thinking. Here is what sets it apart.

( )
Minimal Syntax

The entire syntax fits on an index card. Parentheses and atoms. That is it. No curly braces, no semicolons, no operator precedence rules to memorize. The simplicity is the point.

=/=
Homoiconic: Code IS Data

A Scheme program is literally a list. The expression (+ 1 2) is a list of three elements. This means you can write programs that generate, analyze, and transform other programs. This is one of the deepest ideas in all of computing.

TCO
Tail Call Optimization

Scheme guarantees that tail-recursive functions run in constant stack space. This means recursion is not just a style choice; it is genuinely efficient. You never have to worry about stack overflows with properly written Scheme code.

fn
Forces You to Think Recursively

Without for-loops or while-loops, you must learn to decompose problems into base cases and recursive steps. This is hard at first, but it trains a way of thinking that makes you better at every language you touch.

*
The "Mind-Expanding" Language

Programmers who learn Scheme almost universally report that it changed how they think. If you understand Scheme, every other language makes more sense. Closures, map, filter, reduce, first-class functions: Scheme had them all in 1975.

"A language that doesn't affect the way you think about programming is not worth knowing."
- Alan Perlis, first recipient of the Turing Award
6

Try It Yourself

The terminal has a Scheme interpreter built in. Install it and start experimenting.

$ apt install scheme
1 package(s) installed successfully.

$ scheme
BiwaScheme REPL
Type expressions and press Enter to evaluate.

;; Define a variable
biwa> (define greeting "Hello from Scheme!")
biwa> (display greeting)
Hello from Scheme!

;; Define a function
biwa> (define (double x) (* x 2))
biwa> (double 21)
=> 42

;; Try recursion
biwa> (define (sum-to n)
  (if (= n 0) 0
    (+ n (sum-to (- n 1)))))
biwa> (sum-to 100)
=> 5050

;; Lambda and map
biwa> (map (lambda (x) (* x x)) '(1 2 3 4 5))
=> (1 4 9 16 25)

You can also write Scheme in files. Create a file with nano hello.scm, write your code, then run it with scheme hello.scm.

Scheme will change how you think about programming, even if you never use it professionally. The concepts you learn here, like recursion, closures, and higher-order functions, are the foundations of modern software engineering. Every hour you spend with Scheme makes you a better programmer in every language.

Scheme Thinker!

You have explored one of the most influential programming languages ever created. Scheme will change how you see code.

0
Sections Explored
0
Time Exploring

Everything Is an Expression

In Scheme, there are no statements. Every piece of code returns a value. (+ 1 2) returns 3, (if true 1 0) returns 1. Code is always producing something.

Recursion Over Loops

Scheme has no for or while loops. Instead, you solve problems by having functions call themselves. It sounds strange at first, but it leads to elegant solutions.

Code Is Data

Scheme is homoiconic: programs are lists, and lists are data. You can write programs that write programs. This is one of the most powerful ideas in computer science.

It Teaches You to Think Differently

Learning Scheme rewires how you approach problems. Concepts like recursion, higher-order functions, and immutability carry into every other language you use.

Ready to Create?

Put your new knowledge into practice!

Suggest a Correction