# Extends existed module?

**URL:** <https://racket.discourse.group/t/extends-existed-module/1117>\
**Category:** Questions & Answers\
**Created:** [July 2, 2022, 8:08am UTC](https://racket.discourse.group/t/extends-existed-module/1117 "2022-07-02T08:08:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [July 2, 2022, 8:08am UTC](https://racket.discourse.group/t/extends-existed-module/1117/1 "2022-07-02T08:08:02Z")

</div>

I'm unsure how to express this problem precisely. Thus, I give some examples.

In Racket, a `stx` module in `syntax` module can be imported like

```scheme
(require syntax/stx)

```

If I make something related to `syntax`, and named it `a`, can I make others import it like `(require syntax/a)`?

If could, how to do that?

---

<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:** [July 2, 2022, 8:18am UTC](https://racket.discourse.group/t/extends-existed-module/1117/2 "2022-07-02T08:18:07Z")

</div>

The collection `syntax` lives here:

```
https://github.com/racket/racket/tree/master/racket/collects/syntax

```

So you'd have to lobby to get your module `a` included in this collection.

---

<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:** [July 2, 2022, 8:34am UTC](https://racket.discourse.group/t/extends-existed-module/1117/3 "2022-07-02T08:34:20Z")

</div>

Yes, take a look at [multi-collection package](https://docs.racket-lang.org/pkg/Package_Concepts.html#%28tech._multi._collection._package%29). Here’s an example multi-collection package:

[https://github.com/lexi-lambda/racket-collections/tree/master/collections-lib](https://github.com/lexi-lambda/racket-collections/tree/master/collections-lib)

The main thing is that in `info.rkt`, `collection` must be defined as `'multi`.

Since the directory for the package contains `data/collection.rkt`, you can write `(require data/collection)` to require the module.

---

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [July 2, 2022, 12:56pm UTC](https://racket.discourse.group/t/extends-existed-module/1117/4 "2022-07-02T12:56:17Z")

</div>

I think a single collection package would work too, if you use `syntax` as collection and then just have a file `a.rkt` in that package.

Single/Multi-Collection is orthogonal to Single/Multi-Package, this comment goes into more detail:

> [@How to Organize Your Racket Library \[blog\]](https://racket.discourse.group/t/how-to-organize-your-racket-library-blog/717/4):
>
> I like your post a lot, I think starting out with racket it would have helped me to get up to speed in understanding that package organization strategy. The only thing I would like to state explicitly — because I am unsure that it is conveyed 100% to the reader — is that single-collection vs multi-collection is orthogonal to single-package vs multi-package. You can use them in any combination you like, e.g. in my [define-attributes](https://github.com/SimonLSchlee/define-attributes) package I use single-collection with multiple-package. Sometime…

---

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [July 2, 2022, 4:47pm UTC](https://racket.discourse.group/t/extends-existed-module/1117/5 "2022-07-02T16:47:50Z")

</div>

I guess @sorawee's would also correct, but I have trouble with multi-collection in mindset.  
@simonls's suggestion is correct, one can write the following "info.rkt"

```scheme
(define collection "syntax")

```

Then it would simply seem the package as `syntax`, the most interesting part is the `main.rkt` left here will not affect existing code, so the original import part still works.

---

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [July 2, 2022, 6:10pm UTC](https://racket.discourse.group/t/extends-existed-module/1117/6 "2022-07-02T18:10:59Z")

</div>

I don't know what `main.rkt` you are referring to, the one from the original package?

From my experiments a while back, it seemed as if only one of the packages can contain a `main.rkt` that corresponds to a particular collection-path `syntax` or `syntax/parse` etc..  
If the packages have files with the same name I always got errors, so it seems be "append-only" where you need to be careful to avoid conflicts.

For your addition I would try to only have a `info.rkt` and a `a.rkt`, but no `main.rkt`.

---

<div class="post-metadata">

**Author:** ![dannypsnl](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dannypsnl/32/917_2.png) [@dannypsnl](https://racket.discourse.group/u/dannypsnl)\
**Post date:** [July 2, 2022, 9:24pm UTC](https://racket.discourse.group/t/extends-existed-module/1117/7 "2022-07-02T21:24:02Z")

</div>

Yes, for example, let's have a directory `a-ext` trying to extend module `a`.  
Having `a-ext/main.rkt` is fine(but I only check if it's empty), this is because from my experience(imprecisely), missing `main.rkt` cannot get compiled?

---

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [July 2, 2022, 9:53pm UTC](https://racket.discourse.group/t/extends-existed-module/1117/8 "2022-07-02T21:53:09Z")

</div>

> [@dannypsnl](#):
>
> Having `a-ext/main.rkt` is fine(but I only check if it's empty), this is because from my experience(imprecisely), missing `main.rkt` cannot get compiled?

I don't understand what you mean by check if it's empty, or why you want another `main.rkt` there.  
Are empty `main.rkt` files handled differently?

The way I see it collection `a` needs to be resolved to one package that contains `main.rkt`, if multiple packages have this file, I have seen errors in the past about conflicts/ambiguity, I am not sure what tool/step was complaining about that (I think it was raco setup).

Well I tried to do it again now, and it doesn't complain about the two `main.rkt`, so now I am not exactly sure what the issue was. Or if racket tooling behaves different with newer versions. But my `define-attributes` package only has a `main.rkt` in its `-lib` package and seems to work.

Because I can't reproduce my previous experiences anymore, I am not entirely sure what is the best thing to do, so I can't recommend confidently, so I guess do what works for you and test.  
If I re-encounter the issue I will write a comment.
