Skip to content
Little Schemer in JS - fully functional!
JavaScript Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Little Funky JavaScripter

alt image

This is an implementation of the operations described in the Little Schemer (well, with the exception of chapter 10). It uses only crisp clear JavaScript binary tree lists; no JS arrays whatsoever in the way. Everything is a function.

Here are the tests.

Why is all this relevant? Because it's ALL FUNCTIONAL.

Please note that e.g. the Little JavaScripter of Douglas Crockford is NOT fully functional, for example:

function cons(car, cdr) { return [car, cdr]; } <-- This gives back a mutable JS array

whereas in this case (read later about the companion project) we have:

function cons(car, cdr) { return function(op) { return op(car, cdr); }; }

which freezes car(*) and cdr(**) inside a closure, waiting for some operator to come and do something using them as arguments for its own execution.

The catch of using only functions is that JS is not optimized for recurring on closures(***). That's what makes all this an insightful albeit fruitless exercise.

Download the whole lot, double click on the HTML file and let mocha do the talking. Whilst debugging, the method <cons>.c shows a pretty print of the current list.

This project is presented at my blog.

Companion project - GEIESLISTS

The engine behind all this is contained in the companion repository:


I know this JavaScript code is just a bunch of global stuff, but it's not meant to be used in any other way than as a study aid.

I am in debt of course with Daniel P. Friedman, Matthias Felleisen and Duane Bibby (the last one for all those cute elephants...)

Every feedback is welcome.

(*) itself a number, a string or a function

(**) itself certainly a function

(***) see - please compare:

  • allocating small structures -> 1M (int, int) pairs as array literals
  • allocating small structures -> 1M (int, int) pairs as binary CPS closures
  • accessing small structures -> 1M (int, int) pairs as array literals
  • accessing small structures -> 1M (int, int) pairs as binary CPS closures
You can’t perform that action at this time.