I’m trying out lisp and working through the book Practical Common Lisp at http://www.gigamonkeys.com/book/.
Is there a command which can print a function which was previously defined at the REPL in a way that can later be read? I’ve tried
(print #'function-name)
but this results in output enclosed in #<> which can’t be read back in (and if is set to *print-readably*T I just get an error). I get the same results using princ or prin1 instead of print.
I’m a bit surprised this isn’t easy to find. Several of the things I’ve read on lisp encourage experimentation at the REPL, but if you can’t save your functions after you’ve entered them, you’re forced to write them in a separate file before entering them, which partly defeats the point.
Function objects can’t be read back.
1) You can use the function DRIBBLE, which causes the REPL input to be saved into a file.
2) Evaluating from an editor into the REPL is common. You don’t need to type to the REPL, you can type into a editor text buffer and send the expressions from there to the REPL.
3) Common Lisp has the FUNCTION-LAMBDA-EXPRESSION, which under some circumstance might be able to recover the source code (or what the Lisp system has recorded as source):