Node:Starting and controlling the interpreter, Next:Error messages, Previous:Data types and constants defined by gh, Up:GH
In almost every case, your first gh_
call will be:
void gh_enter (int argc, char *argv[], void (*main_prog)()) | Function |
Starts up a Scheme interpreter with all the builtin Scheme primitives.
gh_enter() never exits, and the user's code should all be in the
main_prog() function. argc and argv will be
passed to main_prog.
Note that you can use |
A convenience routine which enters the Guile interpreter with the standard Guile read-eval-print loop (REPL) is:
void gh_repl (int argc, char *argv[]) | Function |
Enters the Scheme interpreter giving control to the Scheme REPL.
Arguments are processed as if the Guile program guile were being
invoked.
Note that Also note that when you use |
You will typically use gh_enter
and gh_repl
when you
want a Guile interpreter enhanced by your own libraries, but otherwise
quite normal. For example, to build a Guile-derived program that
includes some random number routines GSL (GNU Scientific Library),
you would write a C program that looks like this:
#include <guile/gh.h> #include <gsl_ran.h> /* random number suite */ SCM gw_ran_seed(SCM s) { gsl_ran_seed(gh_scm2int(s)); return SCM_UNSPECIFIED; } SCM gw_ran_random() { SCM x; x = gh_ulong2scm(gsl_ran_random()); return x; } SCM gw_ran_uniform() { SCM x; x = gh_double2scm(gsl_ran_uniform()); return x; } SCM gw_ran_max() { return gh_double2scm(gsl_ran_max()); } void init_gsl() { /* random number suite */ gh_new_procedure("gsl-ran-seed", gw_ran_seed, 1, 0, 0); gh_new_procedure("gsl-ran-random", gw_ran_random, 0, 0, 0); gh_new_procedure("gsl-ran-uniform", gw_ran_uniform, 0, 0, 0); gh_new_procedure("gsl-ran-max", gw_ran_max, 0, 0, 0); } void main_prog (int argc, char *argv[]) { init_gsl(); gh_repl(argc, argv); } int main (int argc, char *argv[]) { gh_enter (argc, argv, main_prog); }
Then, supposing the C program is in guile-gsl.c
, you could
compile it with gcc -o guile-gsl guile-gsl.c -lguile -lgsl.
The resulting program guile-gsl
would have new primitive
procedures gsl-ran-random
, gsl-ran-gaussian
and so forth.