# How to use the binding space?

**URL:** <https://racket.discourse.group/t/how-to-use-the-binding-space/1717>\
**Category:** Questions & Answers\
**Tags:** question, space\
**Created:** [February 16, 2023, 11:12am UTC](https://racket.discourse.group/t/how-to-use-the-binding-space/1717 "2023-02-16T11:12:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Antigen-11](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/antigen-11/32/1813_2.png) [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Post date:** [February 16, 2023, 11:12am UTC](https://racket.discourse.group/t/how-to-use-the-binding-space/1717/1 "2023-02-16T11:12:16Z")

</div>

According to the racket reference,

> A space’s scope is accessed indirectly by using [make-interned-syntax-introducer](https://docs.racket-lang.org/reference/stxtrans.html#%28def._%28%28quote._~23~25kernel%29._make-interned-syntax-introducer%29%29)...... The [require](https://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) and [provide](https://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._provide%29%29) forms include support for bindings spaces through subforms like [for-space](https://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-space%29%29) and [only-space-in](https://docs.racket-lang.org/reference/require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._only-space-in%29%29). No other forms provided by the [racket](https://docs.racket-lang.org/reference/index.html) module bind or reference identifier in a specified space

So I first tried running this in the repl:

```scheme
> (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

```scheme
> (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`

```scheme
> 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:

```scheme
> (version)
"8.8.0.8"

```

---

<div class="post-metadata">

**Author:** ![sorawee](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sorawee](https://racket.discourse.group/u/sorawee)\
**Post date:** [February 16, 2023, 5:09pm UTC](https://racket.discourse.group/t/how-to-use-the-binding-space/1717/2 "2023-02-16T17:09:10Z")

</div>

You can create a macro `ref-in-space` that does the same thing as `bind-in-space`, but for referencing.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [February 16, 2023, 5:31pm UTC](https://racket.discourse.group/t/how-to-use-the-binding-space/1717/3 "2023-02-16T17:31:37Z")

</div>

You might be interested in how Qi uses binding spaces to create (and permit creation of) Qi-specific macros.

---

<div class="post-metadata">

**Author:** ![Antigen-11](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/antigen-11/32/1813_2.png) [@Antigen-11](https://racket.discourse.group/u/Antigen-11)\
**Post date:** [February 17, 2023, 1:18am UTC](https://racket.discourse.group/t/how-to-use-the-binding-space/1717/4 "2023-02-17T01:18:08Z")

</div>

Thank you very much. I'll try this.
