[plt-scheme] If expressions in Embedded PLT Scheme
Clearly, I wasn't clear. So, let's try again:
(1) I've embedded PLT Scheme (previously MzScheme) in an application.
(2) The application is being used with a number of "legacy" Scheme
files, some of which I don't have permission to modify. (Others also
use the application, so I don't even know about all of the files.)
(3) Those "legacy" Scheme files often use the two-parameter (no-
alternative) if.
I'm trying to deal with #3 in the context of #2 and #1.
* Because of #2, I can't replace "if" by "when".
* Because of #2, I can't just put "#lang mzscheme" at the top of the
Scheme programs.
* In the embedded PLT Scheme application, there are also calls to
"inside PLT" C functions like scheme_apply and scheme_eval_string; I'm
not sure how to put "#lang mzscheme" in those.
I'm attaching a sample application (which is much simpler than the
real application; I can't just rewrite everything in Scheme). Are
there suggestions of what I could add/change to make it happily load
the "legacy" Scheme files, many of which use the "no-alternative" form
of "if"?
Note that I've tried making copies of the Scheme files and adding
"#lang mzscheme" to the top. However, then the embedded intepreter
does't seem to have access to the procedures defined in the file.
Thanks!
-- Sam Rebelsky
--- START OF PROGRAM CODE ---
/*
sample.c
Given a Scheme "program" with a main procedure, loads that program
and applies the procedure named 'main' to the values given on the
command line (including the name of the scheme program).
Compiling:
Requires -lmzscheme -lmzgc -ldl -lm
*/
#include <scheme.h>
#include <stdio.h>
#include <stdlib.h>
int
main (int argc, char **argv)
{
Scheme_Env *e;
mz_jmp_buf * volatile save, fresh;
scheme_set_stack_base (NULL, 1);
/* Set up the Scheme environment. */
e = scheme_basic_env ();
scheme_set_collects_path (scheme_make_path ("/usr/local/plt/lib/plt/
collects"));
scheme_init_collection_paths (e, scheme_null);
scheme_namespace_require (scheme_intern_symbol ("scheme/base"));
/* Set up application-specific stuff. */
/* Elided. */
/* Prepare to execute code. */
save = scheme_current_thread->error_buf;
scheme_current_thread->error_buf = &fresh;
if (scheme_setjmp (scheme_error_buf))
{
/* It failed. Give up. */
exit (1);
}
else
{
int i;
Scheme_Object **args;
Scheme_Object *result;
/* Load the Scheme file. */
scheme_load (argv[1]);
/* Build the list of actual parameters. */
args = malloc ((argc-1) * sizeof (Scheme_Object *));
for (i = 1; i < argc; i++)
{
args[i-1] = scheme_make_locale_string (argv[i]);
} /* for */
/* Apply the main procedure, and print the result. */
result = scheme_apply (scheme_eval_string ("main", e),
(argc-1), args);
printf ("%s\n", scheme_display_to_string (result, NULL));
}
exit (0);
} /* main */
---- END OF PROGRAM CODE ----
On Oct 8, 2008, at 12:14 PM, Carl Eastlund wrote:
> If you use "when" in place of "if", you'll get the one-clause if
> behavior, or you can use the legacy mzscheme behavior by putting
> "#lang mzscheme" at the top of your program (instead of "#lang
> scheme").
>
> --Carl