Simple Package Manager


#1

This is a simple package manager for use on any uLisp board with an SD Card interface. It was written by @apiarian as part of his ulisp-fruit-jam project – thank you @apiarian for permission to share it! I’ve added a couple of minor changes after experience of using it myself.

Here’s the whole package manager as a Lisp Library: Package Manager.

Introduction

Each package corresponds to a file on the SD Card containing the source of each function or variable assigned to that package. A list of the currently loaded packages and their symbols is maintained in the global variable *pkgs*.

A typical workflow is as follows:

To define a new package, and add some functions/variables to it, call package-add:

(package-add file symbol …)

For example, suppose you are making a package of vector functions for a ray tracer:

(defun v+ (a b) (mapcar #'+ a b))
(defun v- (a b) (mapcar #'- a b))
(defun v* (v s) (mapcar (lambda (x) (* x s)) v))
(defun dot (a b) (apply #'+ (mapcar #'* a b)))

you could create a package vectors.lsp for them with:

> (package-add "vectors.lsp" 'v+ 'v- 'v* 'dot)
(v+ v- v* dot)

You can also remove a function/variable from a package, and optionally remove it from memory, with package-remove.

To save the current definitions of all the functions/variables in the package to the SD Card call:

(package-save file )

For example:

> (package-save "vectors.lsp")
"vectors.lsp"

Next time you power up the board you can load all the functions/variables in the package with:

(package-load file )

For example:

> (package-load "vectors.lsp")
(v+ v- v* dot)

This also adds the package and its symbols to *pkgs* .

If you’re starting on a different project you can remove all the functions/variables in a package from memory with:

(package-unload file )

This also removes it from *pkgs* .

Finally, to see all the symbols in a package call package-symbols, and to see the packages you have loaded call package-list.

To save typing you can use a global variable for the package filename:

(defvar *vectors* "vectors.lsp")

Remember to add it to the package!

(package-add *vectors* '*vectors*)

Installing the package manager

Obviously you can’t use the package manager to install itself, so the best option is to define it as a Lisp Library so its loaded automatically at startup:

  • Download the Package Manager and save it as PackageManager.h .
  • Put this in the same Arduino project folder as the uLisp source file.
  • Change the definition of LispLibrary[] at the start of the uLisp source to:
// Lisp Library
const char LispLibrary[] PROGMEM =
#include "PackageManager.h"
;
  • Uncomment:
#define lisplibrary
  • Compile and upload uLisp to the board.