[plt-scheme] Implementing an embedded mini-language

From: Don (dfelgar at rainier-infosys.com)
Date: Wed Mar 31 10:44:01 EST 2004

Greetings.

I want to implement a small, sexp-based language within a Scheme
program.  It needs to have a namespace that is disjoint with that of
the surrounding Scheme process.

Here is the closest I've come so far, for a language which consists
only of the variable some-var:

;; ---------- lang.scm
(module lang mzscheme (provide my-eval)
(define ns (make-namespace 'empty))
(define (my-eval expr)
  (eval expr ns))
(parameterize
 ((current-namespace ns))
 (namespace-set-variable-value! 'some-var
                                (lambda expr "some-var in lang\n"))))

;; ---------- use-lang.scm
(require "lang.scm")
(display (my-eval '(some-var)))

This produces the error, "compile: bad syntax; function application is
not allowed, because no #%app syntax transformer is bound in:
(some-var)".  The purpose of #%app has not come clear to me from the
docs.

I looked at the lambda-calculus example in the MzScheme manual section
12.5, but as stated I need to continue evaluating regular Scheme,
whereas this example perpetually limits the image namespace.

Also a question: why do namespace-set-variable-value! and its ilk
operate on the current namespace?  In my naive view it would be more
useful to pass a namespace argument to these procedures.

Thanks in advance.


Posted on the users mailing list.