Intro to Scheme
Think different. Parentheses, recursion, and the beauty of functional programming.
Think different. Parentheses, recursion, and the beauty of functional programming.
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.
Scheme looks different from most languages. Everything is wrapped in parentheses, and operations come first. This is called prefix notation.
| 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.
Lists are the heart of Scheme. Everything is built from lists, and you process them with recursion instead of loops.
Instead of loops, Scheme uses recursion. A function calls itself, processing one element at a time until the list is empty.
In Scheme, functions are values. You can store them in variables, pass them to other functions, and create them on the fly with lambda.
Higher-order functions take other functions as arguments. This is where things get interesting.
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.
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.
Build complex behavior by combining simple functions. Small pieces, loosely joined. Each function does one thing well.
Scheme is not just another programming language. It is a way of thinking. Here is what sets it apart.
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.
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.
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.
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.
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.
The terminal has a Scheme interpreter built in. Install it and start experimenting.
You can also write Scheme in files. Create a file with nano hello.scm, write your code, then run it with scheme hello.scm.
You have explored one of the most influential programming languages ever created. Scheme will change how you see code.
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.
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.
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.
Learning Scheme rewires how you approach problems. Concepts like recursion, higher-order functions, and immutability carry into every other language you use.
Put your new knowledge into practice!