# Syntax-case, require, file

**URL:** <https://racket.discourse.group/t/syntax-case-require-file/687>\
**Category:** Questions & Answers\
**Created:** [February 13, 2022, 10:10am UTC](https://racket.discourse.group/t/syntax-case-require-file/687 "2022-02-13T10:10:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [February 13, 2022, 10:10am UTC](https://racket.discourse.group/t/syntax-case-require-file/687/1 "2022-02-13T10:10:56Z")

</div>

Why

```scheme
(define-syntax (require-file stx)
  (syntax-case stx ()
    [(_ x)
     #'(require (file x))]))

```

doesn't work (it compiles, but doesn't import identifiers)?

```scheme
(define-syntax (require-file* stx)
  (syntax-case stx ()
    [(_ x)
      #`(require #,(datum->syntax #'x (list #'file #'x)))]))

```

works fine.

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [February 13, 2022, 12:47pm UTC](https://racket.discourse.group/t/syntax-case-require-file/687/2 "2022-02-13T12:47:01Z")

</div>

Hygienic expansion. When a macro defines identifiers (like via `require`), the expander scopes them to the macro’s generated code — unless the programmer explicitly dictates the macro system that the identifiers should be scoped to the use of the macro.

---

<div class="post-metadata">

**Author:** ![Kalimehtar](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kalimehtar/32/394_2.png) [@Kalimehtar](https://racket.discourse.group/u/Kalimehtar)\
**Post date:** [February 13, 2022, 1:04pm UTC](https://racket.discourse.group/t/syntax-case-require-file/687/3 "2022-02-13T13:04:24Z")

</div>

> unless the programmer explicitly dictates the macro system that the identifiers should be scoped to the use of the macro

Thank you! Now I understand, why first version wrong (correct one should be wrapped into syntax-local-introduce).  
But now I don't understand, why second version defines identifiers outside the macro. How I "explicitly dictated the macro system that the identifiers should be scoped to the use of the macro"?

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [February 13, 2022, 3:10pm UTC](https://racket.discourse.group/t/syntax-case-require-file/687/4 "2022-02-13T15:10:53Z")

</div>

The question is which context the imported identifiers get.

The documentation for require, states that in `(require module-path)`:

 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/5f6171a9482146e6f8c07fab0a0687cbed972c01.png)

This explains why your second version worked - you changed the context of the module path.

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [February 13, 2022, 3:16pm UTC](https://racket.discourse.group/t/syntax-case-require-file/687/5 "2022-02-13T15:16:35Z")

</div>

datum-\>syntax transfers scope context to the file spec in the require, and since you chose a part of the macro’s INPUT from which to transfer scope information, the imported identifiers get the scope of where the `x` comes from.
