Thursday, February 02, 2012

A Simple Example

Occasionally, people make far fetched claims about the flexibility offered by lisp. Here is a simple example: editing the source code of a running program.

(defun foo () t) ;; foo returns true when called
(loop (when (not (foo)) (return))) ;; call foo repeatedly, until it is false.

This is of course a simple while true do nothing loop. But then we evaluate this little bit on the same system in a separate interaction session/slime buffer.

(defun foo () nil) ;; foo returns nil/false when called.

Amazingly, our loop exits, returns nil, and we are back in business. This is of course a contrived example, but not so far from the mark in expressing the simple idea that editing a program at runtime can yield a lot of power.

No comments: