by Joshua Branson ? May 14, 2026
For quite some time, I have been inspired by the GNU project and Richard Stallman (1). His writings and talks convinced me to use Emacs and the Scheme programming language. Scheme is essentially programming language nirvana. If you have never tried learning any lisp-like language, then give Scheme a try. It is weird and cool, and the Scheme family of languages, in particular, encourage you to use functional programming. Note that the best way to learn any lisp like language, is to use a good editor like Emacs with paredit and aggressive indent or Dr. Racket. The Little Schemer, spritely institute's scheme primer, and SICP are all scheme resources. If you are just getting started and want minimal configuration pain, then try Dr. Racket. If you are interested in pure function programming then take a look at Haskell, standard ML, or owl lisp.
I've been interested in the functional programming paradigm for a while, but I've yet to write any practical code in that style. I recently wanted to learn what is functional programming. This is the first blog post that gives a quick and easy overview of functional programming. If you like this quick introduction, then be sure to read the later more in depth blog posts.
Let's start with giving a quick look at imperative programming and object oriented programming, which functional programming is not. Let's examine imperative programming first.
Imperative programming is like talking to a robot. You tell the robot to first clean the kitchen, then take out the trash, next rob the bank?the usual things. Imperative programming is giving the computer a list of commands to be completed in sequence. Here's a simple example of imperative programming to find the prime numbers less than 10.
int is_prime (int n) {
for (i = 2; i <= (sqrt n); i++) {
if (n % i == 0) {
return 0;
}
}
return i;
}
for (i = 2; i <= 10; i++) {
if (is_prime (i))
printf ("%d ", i);
}
If you choose to write a program in C, then you are usually writing in the imperative style. There are no objects. A good programmer developing imperatively will avoid mutable global variables, use good data structures, and have sensibly named procedures. I believe a good portion of the Linux kernel is written this way.
Now let's consider object oriented programming. Most people are familiar with this style of coding. The programmer creates multiple objects. Each object has methods which manipulate data. It's a really nice abstraction. Java really popularized object oriented coding. Here's a object oriented coding style featuring java.
import java.util.Scanner;
public class PrimeNumberExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number to check: ");
int num = scanner.nextInt();
scanner.close();
if (isPrime(num)) {
System.out.println(num + " is a prime number.");
} else {
System.out.println(num + " is not a prime number.");
}
}
/**
* Checks if a positive integer is a prime number.
* @return true if the number is prime, false otherwise.
*/
public static boolean isPrime(int number) {
// Numbers less than or equal to 1 are not prime
if (number <= 1) {
return false;
}
// Check for factors from 2 up to the square root of the number
for (int i = 2; i * i <= number; i++) {
if (number % i == 0) {
return false; // Found a divisor, so it's not prime
}
}
return true; // No divisors found, so it's prime
}
}
Object Oriented coding is typically the norm. It just makes sense for the average coder to code this way. If you mutate a variable, you are normally only modifying one isolated object's variable. Object Oriented programming tries to minimize global variables, by grouping variables to objects. This way you can mutate state of an object and not mutate global state.
If you are not a programmer, just know that having lots of global variables that you can change at anytime is a recipe for disaster. Don't do it!
Now that we've considered the other styles of coding, let's consider functional programming. Let's start by defining it. Functional programming does not have loops (like while or for) and does not change the value of variables. All variables are constant or immutable. It feels odd the first time you try it, but once you wrap your head around it, recursion is so much easier to use! Most algorithms are easier to write via recursion. Additionally, in the functional programming jargon a function is defined as a subroutine that is written in the functional style. A procedure is any subroutine that is written in any style: functional or not. With our first bit of jargon out of the way, let's compare loops vs. recursion.
First, let's imperatively sum all the numbers 1 - 10 first, in scheme. This is a procedure.
(define (??-imperatively number)
"Sum the numbers 1 - n. ?? or sigma is the mathmatical symbol for sum of numbers. I just wanted to show that scheme procedures can have pretty much any arbitrary utf-8 character in them. Cool right?"
(define i 1)
(define sum 0)
(while (<= i number)
(set! sum (+ sum i))
(set! i (+ i 1)))
sum)
(??-imperatively 10)
This procedure uses a while loop to sum up the numbers, and it violates both principles of functional programming. It uses a loop and it changes the value of variables. Let's write the same program, but this time use recursion via a named let. The following is a function.
(define (??-via-recursion n)
(let loop ([i n] [sum 0])
(if (> i 0)
(loop (- i 1) (+ sum i))
sum)))
(??-via-function 10)
At this point, the reader may be wondering, what is the point of functional programming ? Why should one use it? You should use functional programming because, it allows you to craft deterministic programs. For example, junior programmers may write a program that uses lots of mutable global variables, which is an easy way to create a buggy program, especially if you use threads. This is not possible in a functional program. A purely functional program can use threads without fear of data races (you will still have logic bugs of course).
Still not convinced? I actually recently read a blog post that really sold functional programming well. It said that functionally programming removes all the un-needed features of programming languages. For example, the C programming language has the goto keyword. It allows you to precisely control your program control flow. When I was being taught C in college our professor had this to say about the goto keyword:
C has this "goto" keyword. Never use it.And then he never talked about it ever again! goto ends up creating more headache for the developer. It is so easily mis-used. Languages that do not have goto force the developer to create programs that are easier to reason about. Rust, for example, does not have goto.
Other "footgun" features are null pointers and the return keyword. In functional languages, there is usually no return keyword. Instead the last expression that is evaluated is what is returned from the function. This felt weird to me when I first used emacs-lisp. In C you can return a value and end a procedure whenever you want. In lisp like languages the last expression that you evaluate is the procedure's result.
If you decide to learn the scheme programming language, which you can learn enough to be competent in a half an hour, you can ensure that your code is functional by avoiding any function that ends in !. By convention, scheme functions that end in ! are not functional. For example, the function !set changes the value of a variable, ergo not functional.
I'll end this blog post by mentioning that functional programming is super cool, but this blog post is more conceptual than practical. There's not quite enough information here to allow the reader to start making any useful functional programs. You will have to wait until the next blog post, or perhaps dive into Structure and Interpretation of Programs or The Little Schemer. However, if you can wrap your head around recursion, it'll really help you simplify your algorithms in whatever programming language you use.
Some people have complained that Richard Stallman is not the best leader for the GNU project. While I largely agree that the free software movement deserves a better leader (and Stallman can be odd and maybe even weird or occasionally a "creepy old man"), I still find myself admiring the man that created the GNU project and wrote much of its early software. He's an atheist, and I'm a Christian. He votes Democrat, and I usually vote Republican. I invite you to make up your own mind: In Support of Richard Stallman vs. The Stallman Report