# How do you make anonymous module w/ variables?

**URL:** <https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 3, 2017, 4:21am UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068 "2017-06-03T04:21:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 3, 2017, 4:21am UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/1 "2017-06-03T04:21:35Z")

</div>

Doing some real hacky stuff.

I want to make an anonymous module with variables.

Kind of pseudocode, I want:

```julia
module ()
    foo = 404
end

```

Where I’m at (in real code) is:

```julia
cur_anon = Module()

```

// this returns: `anonymous`

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 3, 2017, 4:29am UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/2 "2017-06-03T04:29:09Z")

</div>

`eval(cur_anon, :(....................))`

Note that not everything will work in such a module (serialization etc) it shouldn’t segfault though if you are just defining variables and running “simple” code in it. It might also not be GC’d.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 4, 2017, 8:24pm UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/3 "2017-06-04T20:24:03Z")

</div>

Playing devil’s advocate, what work would need to be done to get serialization and GC working?

Also, are there ways to manually add items to the GC stack?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 4, 2017, 8:47pm UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/4 "2017-06-04T20:47:51Z")

</div>

> [@djsegal](#):
>
> GC working

GC will work. There will just be a lot of things cached referencing to it that keep it alive.

> [@djsegal](#):
>
> Also, are there ways to manually add items to the GC stack?

Unclear what do you mean or want.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 4, 2017, 8:58pm UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/5 "2017-06-04T20:58:56Z")

</div>

> [@yuyichao](#):
>
> GC will work. There will just be a lot of things cached referencing to it that keep it alive.

Is this true for all modules?

> [@yuyichao](#):
>
> Unclear what do you mean or want.

I meant how do you go about forcing a clear/deregister/unassign (whatever the word is for deallocating disk space) towards an anon module

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 4, 2017, 9:11pm UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/6 "2017-06-04T21:11:49Z")

</div>

> [@djsegal](#):
>
> Is this true for all modules?

Yes.

> [@djsegal](#):
>
> I meant how do you go about forcing a clear/deregister/unassign (whatever the word is for deallocating disk space) towards an anon module

FWIW, adding things to the GC stack preserves it. (And it was what you want to preserve that I was asking about). No you cannot lie to the GC.

---

<div class="post-metadata">

**Author:** ![djsegal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/djsegal/32/13752_2.png) [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Post date:** [June 4, 2017, 9:21pm UTC](https://discourse.julialang.org/t/how-do-you-make-anonymous-module-w-variables/4068/7 "2017-06-04T21:21:55Z")

</div>

Alright. Thanks for the info!

I was just seeing how far I could go with the idea
