[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Compiled S-Expressions



When an s-expression has a side effect, such as

"(display "foo")"

and it is compiled using the C API's scheme_compile
function, are the side effects still generated when
the resulting compiled expression is evaluated?

Second, how does one get access to the actual syntax
form to compile?

For example, if you do something like:

Scheme_Object* s_expr = scheme_make_string("(+ 1 2)");
Scheme_Object* cpld = scheme_compile(s_expr, env, 0);

Simply compiles the string as a symbol, so a later
call to:

Scheme_Object* v = scheme_eval_compiled(cpld, env);

Just returns v = the Scheme String "(+ 1 2)".

To evaluate properly, you need to create a syntax form,
which (drawing from eval.c):

Scheme_Object* port = scheme_make_string_input_port("(+ 1 2)");
Scheme_Object* expr = scheme_read_syntax(port, scheme_false);
Scheme_Object* cpld = scheme_compile(expr, env, 0);
Scheme_Object* v = scheme_eval_compiled(thnk, env);

However, this doesn't compile because scheme_read_syntax is
not exported in scheme.h.

Should this be a publicly-accessible method?  I suppose I
could kludge around it by declaring it "extern", but there's
probably a good reason it's not accessible.

How can I create compiled S-expressions from arbitrary text
files so I can cache them for later reuse?

Thanks,

-Brent