Skip to content

Instantly share code, notes, and snippets.

@tonyarkles
Created January 17, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonyarkles/a21fc33d5ce9c86be59b2c454e55cd35 to your computer and use it in GitHub Desktop.
Save tonyarkles/a21fc33d5ce9c86be59b2c454e55cd35 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include "ecl/ecl.h"
cl_object foo() {
return ecl_make_integer(42);
}
cl_object bar(cl_object x) {
int lx = fixint(x) * 42;
return ecl_make_int(lx);
}
int main(int argc, char* argv[]) {
char* lisp_args[] = {
argv[0],
NULL
};
cl_boot(1, lisp_args);
atexit(cl_shutdown);
cl_object exit_obj = c_string_to_object(":EXIT");
cl_object result = Cnil;
ecl_def_c_function(c_string_to_object("foo"), (cl_objectfn_fixed)foo, 0);
ecl_def_c_function(c_string_to_object("bar"), (cl_objectfn_fixed)bar, 1);
while (cl_equal(exit_obj, result) == Cnil) {
printf("\n> ");
fflush(stdout);
cl_object form = cl_safe_eval(c_string_to_object("(read)"), Cnil, Cnil);
result = cl_safe_eval(form, Cnil, Cnil);
cl_print(1, result);
}
putchar('\n');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment