[plt-scheme] define-values/invoke-unit in an internal definition context

From: Noel Welsh (noelwelsh at gmail.com)
Date: Thu Oct 9 03:08:24 EDT 2008

I'm trying to abstract over both macros and normal values, but having
a problem that define-values/invoke-unit doesn't seem to work in a
local definition context.  A simple example is below.  Reading the
code is perhaps easier than explaining in words what I'm doing, so I
won't go into detail here.  Can anyone tell me how to get it working?

Thanks,
Noel


#lang scheme/base

(require (for-syntax scheme/base)
         scheme/unit
         (planet schematics/schemeunit:3))

(define-signature sig^ (a b c))

(define unit@
  (unit
    (import)
    (export sig^)

    (define a 0)
    (define b 1)
    (define c 2)))

(define-syntax macro1
  (syntax-rules ()
    [(_) (display "hello")]))

(define-syntax macro2
  (syntax-rules ()
    [(_) (display "o hai")]))

;; Here we abstract over macros and the unit
(define-syntax use-unit@
  (syntax-rules ()
    [(_ macro)
     ((lambda (unit)
        (define-values/invoke-unit unit (import) (export sig^))
        (macro) (printf " ~a ~a ~a\n" a b c)))]))

'((use-unit@ macro1) unit@)
((use-unit@ macro2) unit@)


Posted on the users mailing list.