diff --git a/doc/chibi.scrbl b/doc/chibi.scrbl index 943d159e..d496a5cc 100755 --- a/doc/chibi.scrbl +++ b/doc/chibi.scrbl @@ -136,6 +136,8 @@ documentation system described in build this manual. \ccode{chibi-ffi} is a tool to build wrappers for C libraries, described in the FFI section below. +See the examples directory for some sample programs. + \section{Default Language} \subsection{Scheme Standard} @@ -231,6 +233,15 @@ These forms perform basic selection and renaming of individual identifiers from the given module. They may be composed to perform combined selection and renaming. +Note while the repl provides default bindings as a convenience, +programs have strict semantics as in R7RS and must start with at least +one import, e.g. + +\schemeblock{ +(import (scheme base)) +(write-string "Hello world!\n") +} + Some modules can be statically included in the initial configuration, and even more may be included in image files, however in general modules are searched for in a module load path. The definition of the diff --git a/eval.c b/eval.c index fbe5b2b5..d71e7df4 100644 --- a/eval.c +++ b/eval.c @@ -45,7 +45,9 @@ void sexp_warn (sexp ctx, const char *msg, sexp x) { if (sexp_oportp(out)) { sexp_write_string(ctx, strictp ? "ERROR: " : "WARNING: ", out); sexp_write_string(ctx, msg, out); - sexp_write(ctx, x, out); + if (x != SEXP_UNDEF) { + sexp_write(ctx, x, out); + } sexp_write_char(ctx, '\n', out); if (strictp) sexp_stack_trace(ctx, out); } @@ -1100,8 +1102,13 @@ static sexp analyze (sexp ctx, sexp object, int depth, int defok) { } else if (sexp_idp(sexp_car(x))) { if (! cell) { res = analyze_app(ctx, x, depth); - if (sexp_exceptionp(res)) + if (sexp_exceptionp(res)) { sexp_warn(ctx, "exception inside undefined operator: ", sexp_car(x)); + /* the common case of no imports */ + if (!sexp_env_parent(sexp_context_env(ctx))) { + sexp_warn(ctx, "did you forget to import a language? e.g. (import (scheme base))", SEXP_UNDEF); + } + } } else { op = sexp_cdr(cell); if (sexp_corep(op)) { diff --git a/examples/hello.scm b/examples/hello.scm new file mode 100644 index 00000000..461b8899 --- /dev/null +++ b/examples/hello.scm @@ -0,0 +1,3 @@ +(import (scheme base)) + +(write-string "Hello world!\n")