10 Minute Vim!

Lisp REPL

· Read in about 1 min · (182 Words)

So, working through the Land of Lisp book, getting the hang of it.

Chapter Six, the author starts off by talking a little about the Common Lisp REPL, or Read-Eval-Print-Loop that you use as sort of the "command line" for interacting with lisp. It is pretty cool, you type in code, and it executes. And then he opens the hood a little:

(defun repl ()
    (loop (print (eval (read)))))

WHAAAAAAAAAAAAAAA??!?!?!

I just about spit my drink all over the monitor laughing. The function eval() evaluates whatever text is passed in as code, in this case, from the command line via the obviously named read and after executing it, print() prints the result, and it just does that forever till you quit.

That means, you could make one of these for any language that can evaluate strings into code. I know python has one built-in. Php can evaluate code with eval, and a quick search shows a highly nifty (and robust from the looks of it) REPL for php complements of facebook. Sweet. Or, you can use php -a for the interactive mode.

steve shogren

software developer, manager, author, speaker

books:

posts for: