[plt-scheme] Implementing an embedded mini-language

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Apr 12 11:50:55 EDT 2004

This message seems to have fallen through the cracks. In case an answer
is still useful...

At Wed, 31 Mar 2004 07:44:01 -0800, Don wrote:
> 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.

The `#%app' form is implicitly used when an expression would otherwise
parse as an application form. To allow Scheme application in your
namespace, use `namespace-require':

  (namespace-require '(rename mzscheme #%app #%app))

> 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.

In fact, `namespace-variable-value', `namespace-set-variable-value!',
`namespace-undefine', and `namespace-mapped-symbols' do accept an
optional namespace argument. The docs are wrong.


Posted on the users mailing list.