define-below/define-below.ss
(module define-below mzscheme

  (require (lib "unit.ss")
           ;;(lib "etc.ss")
           "rename-below.ss"
           "../private/planet.ss")

  (require-for-syntax (lib "unit-exptime.ss")
                      (lib "function.ss" "scheme"))
  (require-for-syntax-cce/scheme)

  (provide top/error rename-below
           import export
           define-values-below define-below
           define-values/invoke-unit/below)

  (define-syntax (top/error stx)
    (syntax-case stx ()
      [(t/e . id)
       (identifier? #'id)
       (raise-syntax-error #f "undefined" #'id)]))

  (define-syntax (define-values/invoke-unit/below stx)
    (syntax-case stx ( import export )
      [(d/i/b u@ (import i^ ...) (export e^ ...))
       (let*-values ([(exports) (syntax->list (syntax (e^ ...)))]
                     [(parents var-lists def-lists stx-lists)
                      (map/values 4
                                  (curryr signature-members stx)
                                  exports)])
         (with-syntax* ([((e^-orig ...) ...)
                         (map append var-lists def-lists stx-lists)]
                        [((e^-name ...) ...)
                         (map (lambda (names)
                                (map (lambda (id)
                                       (syntax-local-introduce
                                        (syntax-local-get-shadower id)))
                                     (syntax->list names)))
                              (syntax->list (syntax ((e^-orig ...) ...))))]
                        [((e^-temp ...) ...)
                         (map generate-temporaries
                              (syntax->list #'((e^-name ...) ...)))])
           (syntax/loc stx
             (begin
               (define-values/invoke-unit
                 u@
                 (import i^ ...)
                 (export (rename e^ [e^-temp e^-name] ...) ...))
               (rename-below [e^-temp e^-name] ... ...)))))]))

  (define-syntax (define-below stx)
    (syntax-case stx ()
      [(d-b (header . formals) . body)
       (syntax/loc stx (d-b header (lambda formals . body)))]
      [(d-b var body)
       (syntax/loc stx
         (define-values-below (var) body))]))

  (define-syntax (define-values-below stx)
    (syntax-case stx ()
      [(d-v-b (var ...) body)
       (with-syntax ([(hidden ...) (generate-temporaries #'(var ...))])
         (syntax/loc stx
           (begin
             (rename-below [hidden var] ...)
             (define-values (hidden ...) body))))]))

  )