Copyright (C) 2000-2012 |
GNU Info (guile-tut.info)What learn1 is doingWhat learn1 is doing -------------------- If you compare learn1 to learn0, you will find that learn1 uses a new Guile construct: the function `gh_new_procedure()', and its siblings: /* now try to define some new builtins, coded in C, so that they are available in Scheme. */ gh_new_procedure1_0("c-factorial", c_factorial); gh_new_procedure1_0("c-sin", c_sin); gh_new_procedure1_0("v-t", vector_test); It is clear that `gh_new_procedure()' adds a new builtin routine written in C which can be invoked from Scheme. We can now revise our checklist for programming with libguile, so it includes adding callbacks. 1. `#include <guile/gh.h>' 2. You need to invoke the initialization routine `gh_enter()'. This starts up a Scheme interpreter, handling many details. 3. Your main() function should be almost empty: the real main program goes in a separate function main_prog() which is passed to gh_enter(). This rather arcane convention is due to the way Guile's garbage collector works: the whole program has to run in the dynamic context of `gh_enter()'. 4. You pass strings to the Scheme interpreter with the `gh_eval_str()' routine. 5. *[new]* You can now define new builtin Scheme functions; i.e. define new builtin Scheme functions, with the `gh_new_procedure()' routine. 6. You pass strings to the Scheme interpreter with the `gh_eval_str()' routine. 7. You link your program with `-lguile'. I breezed by the issue of how to write your C routines that are registered to be called from Scheme. This is non-trivial, and is discussed at length in the `Guile Programmer's Manual'. automatically generated by info2www version 1.2.2.9 |