| #include <stdio.h>
#include <guile/gh.h>
#include "c_builtins.h"
void main_prog(int argc, char *argv[]);
main(int argc, char *argv[])
{
gh_enter(argc, argv, main_prog);
}
void main_prog(int argc, char *argv[])
{
char input_str[200]; /* ugly hack: assume strlen(line) < 200 */
int done;
/* for fun, evaluate some simple Scheme expressions here */
gh_eval_str("(define (square x) (* x x))");
gh_eval_str("(define (fact n) (if (= n 1) 1 (* n (fact (- n 1)))))");
gh_eval_str("(square 9)");
gh_eval_str("(fact 100)");
/* 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);
/* now sit in a Scheme eval loop: I input the expressions, have
Guile evaluate them, and then get another expression. */
done = 0;
fputs("learn1> ", stdout);
while (!done) {
if (gets(input_str) == NULL) {
done = 1;
} else {
gh_eval_str(input_str);
fputs("learn1> ", stdout);
}
}
exit(0);
}
|