# Resolving/expanding syntax object in context of specific module

**URL:** <https://racket.discourse.group/t/resolving-expanding-syntax-object-in-context-of-specific-module/3954>\
**Category:** Questions & Answers\
**Tags:** macro, rhombus\
**Created:** [September 22, 2025, 11:17pm UTC](https://racket.discourse.group/t/resolving-expanding-syntax-object-in-context-of-specific-module/3954 "2025-09-22T23:17:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimmyg](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kimmyg/32/2448_2.png) [@kimmyg](https://racket.discourse.group/u/kimmyg)\
**Post date:** [September 22, 2025, 11:17pm UTC](https://racket.discourse.group/t/resolving-expanding-syntax-object-in-context-of-specific-module/3954/1 "2025-09-22T23:17:28Z")

</div>

I am defining a macro in a `rhombus` module that produces legal `shplait` syntax and is intended to be accessed by a module written in `shplait`.

What is the most direct and/or preferred way to associate the `shplait` language module's lexical information with the produced syntax object so that its bindings (particularly for implicit forms) resolve to those exported by `shplait` during expansion?

To be concrete, I have `def.rhm` as

```scheme
#lang rhombus/and_meta
meta: def stx = `add1(42)`
expr.macro 'add1_42': stx
export add1_42

```

and `use.rhm` defined as

```scheme
#lang shplait
import: open: "def.rhm"
add1_42

```

which fails at expansion time with `add1` unbound.

I presume the solution is a use of `replace_scopes`. I have tried

1. `'add1(42)'.replace_scopes('sub1')` where `sub1` is exported by `shplait`, and
2. `'add1(42)'.replace_scopes(ctx)` where `ctx` is bound to a `Syntax.local_literal` in the scope of all of `shplait`'s bindings.

Where am I going wrong?

---

<div class="post-metadata">

**Author:** ![mflatt](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/mflatt/32/6_2.png) [@mflatt](https://racket.discourse.group/u/mflatt)\
**Post date:** [September 22, 2025, 11:41pm UTC](https://racket.discourse.group/t/resolving-expanding-syntax-object-in-context-of-specific-module/3954/2 "2025-09-22T23:41:50Z")

</div>

You could locally import and open `shplait` around the compile-time definition of `stx`. That way, `shaplit` is in the environment of `'add1(42)'`. I'm using `meta -1` here to reverse the phase shift from being inside `meta`:

```scheme
#lang rhombus/and_meta
meta:
  import:
    meta -1: shplait open
  def stx = 'add1(42)'
expr.macro 'add1_42': stx
export add1_42

```

Using `'add1(42)'.replace_scopes('sub1')` doesn't help, because `'add(42)'` and `'sub1'` both have the same environment / scopes.

If you really just wanted `add1`, then you could more simply use

```scheme
#lang rhombus/and_meta
import:
  shplait.add1
meta:
  def stx = 'add1("42")'
expr.macro 'add1_42': stx
export add1_42

```

But I imagine you're trying to get more bindings from `shplait`.

---

<div class="post-metadata">

**Author:** ![kimmyg](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/kimmyg/32/2448_2.png) [@kimmyg](https://racket.discourse.group/u/kimmyg)\
**Post date:** [September 23, 2025, 1:31am UTC](https://racket.discourse.group/t/resolving-expanding-syntax-object-in-context-of-specific-module/3954/3 "2025-09-23T01:31:24Z")

</div>

Oops, I meant to say `stx.replace_scopes(…)` as the syntax object is patched together and I end up with a reference to it.

In any case, the `meta -1:` did the trick.

Thanks for your help!
