manpagez: man pages & more
info guile-tut
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.4 More interesting programming with libguile

The learn0 program shows how you can invoke Scheme commands from a C program. This is not such a great achievement: the same could have been done by opening a pipe to SCM or any other Scheme interpreter.

A true extension language must allow callbacks. Callbacks allow you to write C routines that can be invoked as Scheme procedures, thus adding new primitive procedures to Scheme. This also means that a Scheme procedure can modify a C data structure.

Guile allows you to define new Scheme procedures in C, and provides a mechanism to go back and forth between C and Scheme data types.

Here is a second program, learn1, which demonstrates these features. It is split into three source files: learn1.c, c_builtins.h and c_builtins.c. I am including the code here.

Notice that learn1 uses a Scheme master world, and the C routines in c_builtins.c are simply adding new primitives to Scheme.


© manpagez.com 2000-2024
Individual documents may contain additional copyright information.