[toronto-lisp] Fwd: Development helpers

Leo Zovic leo.zovic at gmail.com
Thu Oct 7 14:48:27 UTC 2010


>
> 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
#<FUNCTION 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/toronto-lisp/attachments/20101007/accf3790/attachment.html>


More information about the toronto-lisp mailing list