No subject
Thu Mar 26 00:47:06 EDT 2009
George
To build:
* Save example as "foo.c"
* The comment at the end of the function shows how to compile and link
the code. You may need different include and library paths to
reflect where PLT is installed on your system. In emacs, you can
evaluate this expression, then compile and link the example using
"compile".
Running:
By default, the example executes a read-eval-print-loop. Given a '-c'
option, it evaluates the command line arguments that follow as scheme
expressions.
foo.c starts here:
#include <unistd.h>
#include "scheme.h"
static int
repl(void)
{
scheme_eval(scheme_apply(scheme_builtin_value("read-eval-print-loop"),
0,
NULL),
scheme_basic_env());
return 0;
}
// evaluate expressions in argv, snarfed from "Inside PLT MzScheme"
static int
eval_argv(int argc, char *argv[])
{
Scheme_Env *e = scheme_basic_env();
Scheme_Object *curout = scheme_get_param(scheme_config,
MZCONFIG_OUTPUT_PORT);
int i;
for (i = 0; i < argc; ++i) {
if (scheme_setjmp(scheme_error_buf))
return -1; // evaluation error
scheme_display(scheme_eval_string(argv[i], e), curout);
scheme_display(scheme_make_character('\n'), curout);
}
return 0;
}
int
main(int argc, char *argv[])
{
switch (getopt(argc, argv, "c")) { // parse command line look for "-c"
case -1:
return repl();
case 'c':
return eval_argv(argc - optind, argv + optind);
default:
return -1;
}
return 0;
}
/*
(set (make-local-variable 'compile-command)
(mapconcat #'identity
'("gcc -Wall -g"
"-I/usr/local/plt/include"
"-o foo"
"foo.c"
"/usr/local/plt/lib/libmzscheme.a"
"/usr/local/plt/lib/libmzgc.a"
"-ldl -lm") ; dynamic link loader and math libs
" "))
*/
More information about the plt-scheme
mailing list