[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dumping guile's state and registering variables.
From: |
Brett Viren |
Subject: |
Re: Dumping guile's state and registering variables. |
Date: |
Wed, 7 Mar 2001 10:11:59 -0500 (EST) |
Bill Schottstaedt writes:
> > 1) Keep track of any user defined functions so I can dump them out as
> > scheme code to allow them to be reloaded at a later execution.
>
> I don't know how complex your situation is, but in the CVS guile you
> can run through the module's "obarray" and see what's been defined.
Ahh, I was not using a module. All symbols I made were just going
into the global space.
> I do this for a Tab-completion feature (abstracted code below);
> if I remember right there's a way to find the procedure body as
> a string, using the info the debugger keeps around -- scm_procedure_source
> perhaps. It might be cleaner to define a macro (in Scheme) that
> does both the function definition and save.
I did find the guile procedure: procedure-source and wrote the
following:
// Return source to procedure proc as a string
string scm_source(SCM proc)
{
// run once
static SCM result = gh_eval_str("(define (proc2string proc)
(call-with-output-string (lambda (p) (display (caddr (procedure-source proc))
p))))");
char * proc_name = gh_symbol2newstr(proc,0);
string cmd = "(proc2string ";
cmd += proc_name;
cmd += ")";
SCM src = gh_eval_str(cmd.c_str());
char* cptr = gh_scm2newstr(src,0);
string s(cptr);
cptr[0] = '0';
free (proc_name);
free (cptr);
return s;
}
This is a little tortured, because even though procedure-source
returns a list, (list->string (procedure-source proc)) failed. Also
because I'm only 50% sure what I am doing....
> static int scan_tab(SCM tab, char *text, int len, int matches)
Thanks, I'll study this.
-Brett.