# Do something when value is stated as top-level

**URL:** <https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427>\
**Category:** New to Julia\
**Created:** [December 7, 2020, 8:28pm UTC](https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427 "2020-12-07T20:28:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [December 7, 2020, 8:28pm UTC](https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427/1 "2020-12-07T20:28:46Z")

</div>

Is there any way to create a hook that is called when some values (say, values of a certain type) are stated as top-level? Perhaps by overloading the `eval` function?

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [December 7, 2020, 8:44pm UTC](https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427/2 "2020-12-07T20:44:49Z")

</div>

Do you mean when the values are displayed? For that you can overload the `display` function.

---

<div class="post-metadata">

**Author:** ![circonflexe](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@circonflexe](https://discourse.julialang.org/u/circonflexe)\
**Post date:** [December 7, 2020, 9:34pm UTC](https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427/3 "2020-12-07T21:34:55Z")

</div>

I mean not only in the REPL (sorry for not clarifying) but also when executing a file, e.g. in batch mode, or via embedding in a C program.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [December 7, 2020, 11:23pm UTC](https://discourse.julialang.org/t/do-something-when-value-is-stated-as-top-level/51427/4 "2020-12-07T23:23:24Z")

</div>

You can use the optional `mapexpr` argument of `include` to transform the parsed top-level expressions in the included file to do anything you want.
