According to the racket reference,
A space’s scope is accessed indirectly by using make-interned-syntax-introducer...... The require and provide forms include support for bindings spaces through subforms like for-space and only-space-in. No other forms provided by the racket module bind or reference identifier in a specified space
So I first tried running this in the repl:
> (module t racket/base
(require (for-syntax racket/base))
(define-syntax (bind-in-space stx)
(syntax-case stx ()
((_ i v)
#'(begin
(define i v)
(provide (for-space tmp i))))))
(bind-in-space a 1))
string:9:17: provide: provided identifier is defined only outside the space
at: a
in: (provide (for-space tmp a))
[,bt for context]
Then I rewrote the program in the light of the discription of make-interned-syntax-introducer
procedure
> (module t racket/base
(require (for-syntax racket/base))
(define-syntax (bind-in-space stx)
(syntax-case stx ()
((_ i v)
(let ((add-space (lambda (i) ((make-interned-syntax-introducer 'tmp) i 'add))))
(with-syntax ((i (add-space #'i)))
#'(begin
(define i v)
(provide (for-space tmp i))))))))
(bind-in-space a 1))
The module
form was evaluated successfully, fortunatelly. But after importing the module with (require (only-space-in tmp 't))
, I failed to reference the identifier a
> a
a: undefined;
cannot reference an identifier before its definition
in module: top-level
[,bt for context]
> (module->exports ''t)
'(((0 . tmp) (a ())))
'()
What can I do to repair it?
PS:
> (version)
"8.8.0.8"