Say I've played a bit with SBCL with no SLIME, no whatsoever, plain interpreter. Now I want to save couple of functions in a file. Not an core image, just a bits of code in a text form. How should I do that?
If you are using sb-readline or rlwrap you press up until you hit when it got defined and copy and paste itto a file. You might have it in the termial window history too.
If none of these works only compiled definitions are available then the only way to save them is by dumping core image.
For next time, you could make a macro that stores every definition source in a special variable so that you can easily retreive them.
C-r
. If you used Emacs shell, then it would be M-r
or M-s
. Might save you some key-presses :) –
Spirogyra There are two ways to do that: use DRIBBLE
and/or FUNCTION-LAMBDA-EXPRESSION
The first is to always use the Common Lisp function DRIBBLE
before experimenting:
rjmba:tmp joswig$ sbcl
This is SBCL 1.1.9, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
Dribble takes a pathname for a text file. Once called, the interactive IO will be written to that file.
* (dribble "/Lisp/tmp/2013-09-06-01.text")
* (defun foo (a) (1+ a))
FOO
* (foo 10)
11
* (quit)
See the file:
rjmba:tmp joswig$ cat 2013-09-06-01.text
* (defun foo (a) (1+ a))
FOO
* (foo 10)
11
* (quit)
From above you should be able to see if you have any interesting functions entered...
You could also set your SBCL (for example using the init file) to set up dribble always at start. Calling (dribble)
without arguments ends a dribble.
Next: FUNCTION-LAMBDA-EXPRESSION
:
* (defun foo (b) (1- b))
FOO
Now you can call FUNCTION-LAMBDA-EXPRESSION
to get the definition back. It might be slightly altered, but it should do the job to recover valuable ideas written as code:
* (function-lambda-expression #'foo)
(SB-INT:NAMED-LAMBDA FOO
(B)
(BLOCK FOO (1- B)))
NIL
FOO
function-lambda-expression
? I've got SBCL 1.0.49, and after evaluating your defun in the REPL, (function-lambda-expression #'foo)
just returns three values: NIL, T, FOO
. –
Kalevala If you are using sb-readline or rlwrap you press up until you hit when it got defined and copy and paste itto a file. You might have it in the termial window history too.
If none of these works only compiled definitions are available then the only way to save them is by dumping core image.
For next time, you could make a macro that stores every definition source in a special variable so that you can easily retreive them.
C-r
. If you used Emacs shell, then it would be M-r
or M-s
. Might save you some key-presses :) –
Spirogyra © 2022 - 2024 — McMap. All rights reserved.
(defun ...)
it is directly compiled into machine code. The original Lisp code is not stored anywhere by the compiler. – Committeewoman