chibi-scheme embedded: calling scheme function with multiple params from C

126 views Asked by At

The following site shows an sample of embedding chibi scheme into a c program:

http://synthcode.com/scheme/chibi/

/* construct a Scheme expression to eval */
obj1 = sexp_intern(ctx, "my-procedure", -1);
obj2 = sexp_cons(ctx, obj1, SEXP_NULL);
sexp_eval(ctx, obj2, NULL);

That snippet shows how to call a procedure. Now, I'm trying to call a procedure with an argument, but I'm not getting it to work.

I'm both new at scheme and at chibi. This is how I thought it would be:

obj1 = sexp_intern(ctx, "my-procedure", -1);
obj2 = sexp_make_fixnum(3); 
tmp  = sexp_cons(ctx, obj1, obj2);
sym  = sexp_cons(ctx, tmp, SEXP_NULL);
res  = sexp_eval(ctx, sym, NULL);

I get this error back from chibi: dotted list in source

How can I call a procedure with multiple params?

1

There are 1 answers

0
Dess On

This did it:

// (define (addValues a) (+ a 5))
obj1 = sexp_intern(ctx, "addValues", -1);
obj2 = sexp_make_fixnum(3); 
tmp  = sexp_list1(ctx, obj2);
tmp  = sexp_cons(ctx, obj1, tmp);
res  = sexp_eval(ctx, tmp, NULL);
if (sexp_numberp(res)) {
    auto x = sexp_unbox_fixnum(res);
    std::cout << "addValues:" << x << "\n"; 
}