I hope I understand your question!: the first example using "+" could be:

static s7_pointer make_f(s7_scheme *sc, s7_pointer args)
{
  s7_pointer x = s7_car(args);
  char buf[256];
  snprintf(buf, 256, "(let ((x %ld)) (lambda (y) (+ x y)))",
           s7_integer(x));
  return(s7_eval_c_string(sc, buf));
}

The same idea using a C function in place of "+":

static int64_t fadd(int64_t x, int64_t y) {return(x + y);}

static s7_pointer g_fadd(s7_scheme *sc, s7_pointer args)
{
  return(s7_make_integer(sc,
           fadd(s7_integer(s7_car(args)), s7_integer(s7_cadr(args)))));
}

static s7_pointer make_fadd(s7_scheme *sc, s7_pointer args)
{
  s7_pointer x = s7_car(args);
  char buf[256];
  snprintf(buf, 256, "(let ((x %ld)) (lambda (y) (fadd x y)))",
           s7_integer(x));
  return(s7_eval_c_string(sc, buf));
}

  s7_scheme *s7 = s7_init();
  s7_define_function(s7, "make-f", make_f, 1, 0, false, NULL);
  s7_define_function(s7, "make-fadd", make_fadd, 1, 0, false, NULL);
  s7_define_function(s7, "fadd", g_fadd, 2, 0, false, NULL);
 ...

I haven't brought out to s7.h the lambda call above (as s7_lambda or
something), and need to think about whether there's currently a reasonable
way to do it with the existing s7.h functions -- will mull it over.


_______________________________________________
Cmdist mailing list
[email protected]
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to