Lisp and Spreadsheets

Jul 27, 2022

Functional and event-driven programming – for the masses. Or how I once wrote a Kubernetes-based CI/CD system in Excel0.

Functional programming has been around forever. Lisp is the second oldest programming language1. Now that Excel is Turing Complete with the LAMBDA function, it might finally be the time that Excel and spreadsheet languages might be the trojan horse for introducing full lambda calculus to the masses.

Visual Basic and Excel built-in functions are limited in their expressiveness. You can't reuse off-the-shelf code in spreadsheets, version it, or treat it like normal code. While you can write spreadsheet extensions in languages like C#, it isn't user-friendly and not web-native.

What if you could use a Lisp inside a spreadsheet? Or another functional language? Or maybe even a general purpose language?

What if some functions ran natively in the browser while others were sent off to edge runtimes? What if functions were versioned, shareable, and packaged?  

You'd get fast and reactive execution. It would be easy to debug arbitrary DAGs since you could inspect the intermediate output of each step easily from the spreadsheet. Reusing the Excel calculation graph makes for a simple yet powerful build system.

Why now?

  • WebAssembly support in browsers means fast local runtimes in the browser like Pyodide for Python or QuickJS for sandboxed JavaScript. User-generated code (e.g., functions) can (mostly) be safely run.
  • Fast edge function runtimes like Cloudflare Workers or Fastly Lucet means execution time for remote functions measured in 10s of milliseconds, not 100s.
  • HTML and the DOM have always been a limitation in bringing performant rich GUI experiences into the browser (e.g., Spreadsheets). Now, canvas-based rendering makes these applications possible in the browser (e.g., Figma and Zoom in the browser).
  • Hardware performance makes execution times bearable for chains of dependent functions.

0 The throwaway code is at r2d4/sheets, but the idea: a C# extension for Excel that would register custom functions that ran as pods on Kubernetes and set the value as the pod's stdout. At the time (2018), there wasn't a C# client for Kubernetes, so I shimmed out to Go to run the pod and grab the logs after it terminated. You could do all sorts of interesting things – compile a program and use the output as a template for another program that was compiled, Unix tools as Excel functions (ran in alpine), and even a basic filesystem in Redis (that was also launched from a cell).

1 Fortran (1957) beat Lisp by one year (1958).