summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Shinn <alexshinn@gmail.com>2024-01-30 12:31:06 +0900
committerAlex Shinn <alexshinn@gmail.com>2024-01-30 12:31:06 +0900
commit29dd1a3b81e297033f687cbbf2b51319856647f4 (patch)
tree4fc77a90f98b17dc943ffa79b33d06feb7ef594e
parent97a04bd2fc68bc153008971f7656875b2861ad98 (diff)
Add more specific warning for error on no import, clarify docs.
-rwxr-xr-xdoc/chibi.scrbl11
-rw-r--r--eval.c11
-rw-r--r--examples/hello.scm3
3 files changed, 23 insertions, 2 deletions
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")