[plt-scheme] A macro to signify Scheme

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Apr 23 17:56:14 EDT 2004

At Fri, 23 Apr 2004 02:07:50 -0400, "Mike T. Machenry" wrote:
> I am try to write a module language which will not provide mzscheme but
> instead a macro that will allow its body access to mzscheme. 

The only solution that I can see (for now) manipulates the marks on
syntax objects in a fairly direct way.

Since you control `#%module-begin', you can introduce a `(require
mzscheme)' that is marked such that it will capture bindings only in
expressions that another macro marks later.

The modules below illustrate this strategy. The "mylang.ss" language
omits `cons', `car', and `cdr' from `mzscheme', but it provides a
`to-scheme' form whose expression sees `mzscheme' exports.



(module mylang-utils mzscheme
  (provide introduce-for-mz)

  (define introducer (make-syntax-introducer))

  (define (introduce-for-mz stx)
      (syntax-local-introduce stx)))))


(module mylang mzscheme
  (require-for-syntax "mylang-utils.ss")

  (define-syntax (mylang-module-begin stx)
    (syntax-case stx ()
      [(_ e ...)
          (require #,(introduce-for-mz (datum->syntax-object
          e ...)]))

  ;; Form that goes back to scheme:
  (define-syntax (to-scheme stx)
    (syntax-case stx ()
      [(_ e) (introduce-for-mz #'e)]))

  (provide (all-from-except mzscheme #%module-begin 
                            ;; arbitrary omissions:
                            cons car cdr lambda)
           (rename mylang-module-begin #%module-begin)


(module l "mylang.ss"
  ; This won't work:
  ; (printf "~a~n" (car '(1 2)))
  ; This works:
  (printf "~a~n" ((to-scheme car) '(1 2))))

Posted on the users mailing list.