# Providing name only to sub-module?

**URL:** <https://racket.discourse.group/t/providing-name-only-to-sub-module/3918>\
**Category:** Questions & Answers\
**Tags:** macro, testing\
**Created:** [August 24, 2025, 3:32am UTC](https://racket.discourse.group/t/providing-name-only-to-sub-module/3918 "2025-08-24T03:32:38Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [October 11, 2025, 10:43pm UTC](https://racket.discourse.group/t/providing-name-only-to-sub-module/3918/11 "2025-10-11T22:43:10Z")

</div>

> [@pcn](#):
>
> But at the moment, I don't know where to get the context to assign to the `body ...` of the macro, so that I can both preserve the original source locations (for precise error reporting), and get the bindings from `(submod "..")`:

The scope “on the parentheses” of the `(submod "..")` form is used for the imported bindings. This distinction is important so that the binding for `submod` still comes from the macro definition site, in case the usual binding isn't available at the use site.

Here's a worked-out example:

```scheme
#lang racket

(require syntax/parse/define)

(define-syntax-parser with-examples
  [(_ body ...)
   #:with racket/base (datum->syntax this-syntax #'racket/base)
   #:with submod.. (datum->syntax this-syntax (list #'submod #'".."))
   #'(module* all-defns #f
       (provide (all-from-out submod..))
       (module* compile-time-exec #f
         (require (for-syntax racket/base
                              submod..))
         (begin-for-syntax
           body ...)))])

(define n 42)

(with-examples
 (displayln n))

```

I also changed to use `this-syntax` instead of binding and using `#'with-examples`: that would allow some other macro that would expand to `with-examples` to work like the `(submod "..")` case.

> [@pcn](#):
>
> potentially giving up the arrows if that's infeasible

I'm not sure if there's a way to do this or not, and I've only skimmed the rest of this thread (so I'm likewise not getting into whether it should check `syntax-local-context` or `syntax-local-lift-module-end-declaration` or something to work multiple times).

But one thing to note is that `(require (submod ".."))` imports the identifiers exported by the parent module, potentially shadowing un-exported identifiers with the same names. The most common example is contracts:

```scheme
#lang racket
(define (buggy-generate-string)
  'not-a-string)
(provide (contract-out
          [buggy-generate-string
           (-> string?)]))
(module* implicit #f
  (provide implicit)
  (define (implicit)
    (buggy-generate-string)))
(module* explicit #f
  (require (submod ".."))
  (provide explicit)
  (define (explicit)
    (buggy-generate-string)))
(module* main racket
  (require (submod ".." implicit))
  (require (submod ".." explicit))
  `([implicit ,(implicit)]
    [explicit ,(with-handlers ([exn:fail? values])
                 (explicit))]))

```

---

_[View the full topic](https://racket.discourse.group/t/providing-name-only-to-sub-module/3918)._
