XKCD "Lisp Cycles" CCA Non-Commercial 2.5

A previous Adafruit Guide talks about using FORTH and LISP on SAMD51 based boards. The performance and memory provide the opportunity to get away from assembly language and C/C++ and use different styles of language. CircuitPython is a perfect example of this. But it does not have to stop there. 

A problem is the language implementations ran on the bare metal (the hardware), losing many of the advantages that a higher-level language like CircuitPython can provide. Maybe the most important of these is the ability to treat part of the board's flash storage as a USB drive and place source code there simply by editing files directly on the drive or copying them to it (including dragging and dropping).

This guide introduces an implementation of a Lisp dialect very similar to Scheme with an interesting feature: it's written in Python 3. It's called is CircuitScheme. The implementation is based on written some time ago by Peter Norvig who wrote the books Artificial Intelligence: A Modern Approach and Paradigms of AI Programming: Case Studies in Common Lisp . He is currently Director of Research at Google. TL;DR he knows his stuff.

Norvig authored two articles that describe the background and implementation of Lispy:

(How to Write a (Lisp) Interpreter (in Python))

(An ((Even Better) Lisp) Interpreter (in Python))

These provide a description of Lispy and a good introduction to the techniques and considerations of implementing another programming language in Python. This guide will not replicate the content of those papers. You may read them, then come back and see how we can use this in CircuitPython.

Python is a a good language for implementing Lisp as it already has a lot of the capabilities that are needed. Being able to leverage Python's garbage collection is especially useful. Lispy goes even further than some implementations in that lists are implemented directly by Python lists.

So we have a Lisp to program in with all the advantages of the CircuitPython infrastructure. It also means that it's easy to add functionality such as support for hardware interaction. We'll cover that later in the guide.

The goal of this guide isn't to teach you Scheme; there are various resources online for that. is a good central spot to find them. An excellent resource for learning Scheme is The Structure and Interpretation of Computer Programs which is a text that was used for first year computer science at MIT for many years. It was co-written by one of the creators of Scheme (and MIT professor), Gerald Sussman. MIT recorded the series of lectures from the course and has made them available, along with electronic versions of the book. In this guide, you will learn Scheme as a side effect of using it as the language used to explore concepts in computing.

Required Hardware

Lispy will run comfortably on any M4 Express board: Grand Central, Feather, or ItsyBitsy. Do not forget to also get a good USB cable to connect the board to your computer.

Top down shot of a Adafruit Grand Central M4 Express featuring the SAMD51.
Are you ready? Really ready? Cause here comes the Adafruit Grand Central featuring the Microchip ATSAMD51. This dev board is so big, it's not...
In Stock
Angled shot of a Adafruit Feather M4 Express.
It's what you've been waiting for, the Feather M4 Express featuring ATSAMD51. This Feather is fast like a swift, smart like an owl, strong like a ox-bird (it's half ox,...
In Stock
Adafruit ItsyBitsy M4 Express featuring ATSAMD51 connected to a small breadboard.
What's smaller than a Feather but larger than a Trinket? It's an Adafruit ItsyBitsy M4 Express featuring the Microchip ATSAMD51! Small,...
In Stock
USB cable - USB A to Micro-B - 3 foot long
This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your Metro, Feather, Raspberry Pi or other dev-board or...
In Stock

This guide was first published on Feb 14, 2019. It was last updated on May 24, 2024.

This page (Overview) was last updated on Mar 08, 2024.

Text editor powered by tinymce.