[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Q] units and macros in MzScheme
> Can one define a macro inside a unit and then export/import it to
another
> unit or into the global namespace?
>
> thanks,
> -- Leo
>
> Good question.
>
> Short answer: no.
>
Although Matthias is exactly right about defining the *macro* in a unit, one
can define the *implementation* of the macro in a unit. Perhaps this isn't
what you want, we we do use this pattern fairly often to define macros in
drscheme's source code:
(require-library "invoke.ss")
(define-values/invoke-unit
(thunk)
(unit (import)
(export thunk)
(define (thunk x) `(lambda () ,x))))
(define-macro thunk thunk)
Hope that helps,
Robby