8.18
top
← prev up next →

Chaining module languagesπŸ”— i

Suzanne Soy <racket@suzanne.soy>

This package is experimental. Later versions may break backward-compatibility.

syntax

( chain-module-begin lang. body)

This macro is intended to be used as the result of a #%module-begin macro. It chain-calls the #%module-begin of lang. This makes it possible for a #%module-begin to perform some changes on its body, and then chain-call the #%module-begin of a user-specified language.

As an example here is the definition for a no-op language, which simply takes a (possibly improper) list of languages to chain, and calls the next one:

(module the-meta-langracket/base
(provide (rename-out [new-#%module-begin#%module-begin ]))
(for-syntax racket/base
syntax/parse))
(define-syntax (new-#%module-beginstx)
(syntax-parsestx
[(_ {~ornext-lang:id(next-lang:id. chain₊)}. body)
(define maybe-chain₊(if (attributechain₊)
`(,#'chain₊)
'()))
(define new-form`(,#'chain-module-begin ,#'next-lang,@maybe-chain₊
. ,(transform-body#'body)))
(datum->syntax stxnew-formstxstx)]))
(define-for-syntax (transform-bodybody)
;identity transformation:
body))

This language could then be used as follows:

(module bthe-meta-langtyped/racket
(define x:Number123))

Given two other meta-language built in the same way and provided by meta-two and meta-three, it would be possible to chain the three languages as follows:

(module bthe-lang(meta-twometa-three. typed/racket)
(define x:Number123))

The chain-module-begin macro produces the following syntax:

(require lang)
(continue. internal-args))

where (continue. internal-args) fully expands (#%module-begin . body), where #%module-begin is the one provided by lang, and produces the following syntax:

(begin . expanded-body)

An extra scope is added to the whole (begin . expanded-body) form, so that a #%require form within the expanded-body may shadow bindings provided by lang, just as require forms normally have the possibility to shadow bindings provided by the #lang language.

top
← prev up next →

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /