Lazy forms in Common Lisp
Switch branches/tags
Nothing to show
Clone or download
Latest commit 939a7e9 May 6, 2016
Failed to load latest commit information.
.gitignore Initial commit. Apr 29, 2016 Initial commit. Apr 29, 2016
lazy.asd ASDF package file. May 5, 2016
lazy.lisp Fixed whitespace issue at top of file. Apr 29, 2016

Lazy Forms for Common Lisp

This is a simple lazy form evaluation package for Common Lisp.


A lazy form (or thunk) is simply a function wrapping a body of code that will only every be executed once, and the result remembered for future use.

To create a lazy form use the lazy macro:

(lazy &body form)  ;=> THUNK

Let's try it:

CL-USER > (lazy (+ 1 2))

Let's resolve it with the lazy-value function:

CL-USER > (lazy-value *)

Try it again, but with something that has side-effects:

CL-USER > (lazy (print 'hi) (+ 1 2))

Resolve it and get the value:

CL-USER > (lazy-value *)

Get the value again, and notice that the thunk isn't executed a second time:

CL-USER > (lazy-value **)

That's it!