Lisp for the Arduino
Version 1.3 released
uLisp Version 1.3 adds setf, allowing you to modify lists in place. It provides a way to perform operations using lists as index-addressible arrays, and use association lists for efficient data storage. The other in-place operations push, pop, incf, and decf have also been extended in the same way. For more details see Language reference.
There are also fixes for two bugs that affected append with null arguments, and with-spi.
uLisp™ is a version of the Lisp programming language designed for the ATmega-based Arduino boards. Because it's an interpreter you can type commands in, and see the effect immediately, without having to compile and download your program. This makes it an ideal environment for learning to program, or for setting up simple electronic devices based on the Arduino.
Lisp is a rich language, with many advanced features that make it easier to program in than C or C++, so it's ideal for learning about fundamental programming concepts. It's also an ideal language for expressing complex ideas, such as teaching a robot to solve mazes or finding the shortest route on a map. As well as supporting a core set of Lisp functions uLisp includes Arduino extensions, making it ideal as a control language for the Arduino.
RAM: 2 Kbytes to 32 Kbytes.
Program memory: At least 32 Kbytes (the program currently uses about 22 Kbytes of program memory).
EEPROM memory: Used for saving and loading the uLisp workspace.
I don't currently recommend the ATmega32U4-based boards as there an unresolved problem interfacing uLisp via the serial interface with these boards.
The language is generally a subset of Common Lisp, and uLisp programs should also run under Common Lisp.
Types supported: list, symbol, and integer.
An integer is a sequence of digits, optionally prefixed with "+" or "-". Integers can be between -32768 and 32767. You can enter numbers in hexadecimal, octal, or binary with the notations #x2A, #o52, or #b101010, all of which represent 42.
User-defined symbol names can have up to three characters consisting of a-z and 0-9. Any sequence that isn't an integer can be used as a symbol; so, for example, 12a is a valid symbol.
There is one namespace for functions and variables; in other words, you cannot use the same name for a function and a variable.
uLisp includes a mark and sweep garbage collector. Garbage collection takes under 1 msec on an Arduino Uno or under 3 msec on an Arduino Mega 2560.
The following example illustrates how you might use uLisp.
After uploading uLisp to your Arduino board or ATmega chip you communicate it via the Serial Monitor. For more information see Using uLisp.
Suppose you have a red LED connected to the analogue output pin 9 on an Arduino Uno. Then you can type in the Lisp command:
(analogwrite 9 128)
to set the LED to 128, which corresponds to half brightness.
To save having to write this command every time you want to set the red LED you can define a function called red:
(defun red (x) (analogwrite 9 x))
Now you can achieve the same effect simply by writing:
In each case the LED changes immediately, as soon as you type in the command.
Suppose you've got a potentiometer connected to vary the voltage on the analogue input A0. You could define a function dim to make the potentiometer adjust the brightness of the LED with:
(defun dim () (loop (red (/ (analogread 0) 4)))
and run it by typing:
Finally, you could save the uLisp image to EEPROM, and specify that dim should be run on load, by entering:
When you reset the Arduino dim will now load and run automatically.
This is a simple example showing how uLisp allows you to build up complex programs from simpler components, testing each of the components as you go along.