[toronto-lisp] Fwd: Development helpers

Justin Giancola justin.giancola at gmail.com
Thu Oct 7 15:27:09 UTC 2010

The short answer is that by default a standard Common Lisp REPL does
not preserve either a textual or sexp representation of function/macro
definitions you enter. A long time ago I remember reading about a hack
whereby someone had hooked into defun so as to store the original
definition in some property (maybe 'source-code or some such). That
way after calling

(defun foo () ... ) ; => FOO

you could later do

(get 'foo 'source-code) ; => (defun FOO () ... )

But having said that, these sorts of tricks are not very common.
Developers typically compose code in files or scratch buffers and lean
on their editors/IDEs to keep track of definitions.


On Thu, Oct 7, 2010 at 10:48 AM, Leo Zovic <leo.zovic at gmail.com> wrote:
>> Hi there,
>> first of all Paul and Dave, thanks for replying!!  The question can
>> perhaps
>> be best explained
>> with an example:
>> repl=> (defun doit-3 (x)
>> (* 3 x))
>> repl=> '(some more cool stuff)
>> repl=>'(and more and more)
>> i keep testing and playing around with functions
>> more and more
>> I can certainly run my doit-3 function
>> repl=>(doit-3 4)
>> 12
>> repl=>
>> and now, I say to myself, - how the heck did I write that doit-3, I
>> forgot,
>> because,
>> I wrote it 20 minutes ago, it obviously exists inside REPL because I can
>> execute it...
>> So, how do I view [dump??] the contents of doit-3 to the screen, or to a
>> file on the
>> disk, so I can invoke an editor and modify doit-3 and then reload it??
>> I am just interested in learning how to be more productive in a standard
>> software
>> development cycle.
>> Thanks, Alex.
> If you typed the function in recently enough, you can hit Ctrl+up (or
> similar depending on what kind of prompt you're using) to see previous
> definitions you entered, but there's sometimes a limit to how much history
> you can access that way.
> If the only place you've typed the function is into the REPL, and you can't
> get far enough up using REPL history, then there isn't really a way of
> backing the definition out. With your example above:
> => (defun doit-3 (x) (* 3 x))
> DOIT-3
> => (doit-3 4)
> 12
> [some time later your typing history runs out and you forgot how doit-3 was
> defined]
> => #'doit-3
> If you're used to JavaScript, this seems asinine; why doesn't it just print
> out the function text? The reason is that when you define a function, it's
> compiled into some form of byte-code and the REPL throws away the initial
> representation (in JavaScript that doesn't happen so you can easily get the
> definition given a function name).
> The sure way to have access to functions you've written earlier is to record
> them in a file, as opposed to just the REPL. You've gotten some LispWorks
> pointers already (which I assume are correct, I don't use it myself). In
> Emacs/slime, the way you'd do this is
> 1. split your window [default binding C-x 2 or C-x 3 for a vertical split]
> 2. open a lisp file in one, and slime in the other [M-x slime]
> 3. type your definitions out in the lisp file, and use Emacs keystrokes to
> send individual definitions into the prompt [default binding C-M-x]
> C-M-x will send the definition closest your pointer to the SLIME prompt as
> though you typed it there, but you'll still have access to the initial
> definition. If you need to redefine it, just make the changes and hit C-M-x
> again with your pointer somewhere in the definition.
> -Leo
> _______________________________________________
> toronto-lisp mailing list
> toronto-lisp at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/toronto-lisp

More information about the toronto-lisp mailing list