# \#eval

**URL:** https://discourse.julialang.org/tag/eval/382.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Programmatically defining a global variable in a new module](https://discourse.julialang.org/t/programmatically-defining-a-global-variable-in-a-new-module/133188)

<div class="topic-metadata">

**Author:** [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Replies:** 17\
**Last updated:** [October 21, 2025, 5:10pm UTC](https://discourse.julialang.org/t/programmatically-defining-a-global-variable-in-a-new-module/133188 "2025-10-21T17:10:59Z")

</div>

I need to be able to programmatically define a new global variable in a module. Till Julia v1.11 I was able to do this as function define\_global() m = Module(:MyModule) Core.eval(m, :(global data)) setglobal…

---

## [Versioninfo not defined in Main](https://discourse.julialang.org/t/versioninfo-not-defined-in-main/123969)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 4\
**Last updated:** [December 20, 2024, 12:22am UTC](https://discourse.julialang.org/t/versioninfo-not-defined-in-main/123969 "2024-12-20T00:22:05Z")

</div>

I was debugging some issues I had using versioninfo() on an HPC, specifically that I would get the following error: ERROR: UndefVarError: \`versioninfo\` not defined in \`Main\` Suggestion: check for spelling errors or miss…

---

## [Retrieve unevaluated symbol inside \`@eval\`](https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 1\
**Last updated:** [September 3, 2024, 9:23am UTC](https://discourse.julialang.org/t/retrieve-unevaluated-symbol-inside-eval/118978 "2024-09-03T09:23:56Z")

</div>

In one of my packages I use @eval to define a list of functions in a loop based on symbols. I would also like to use the symbol without evaluating it, but I can’t figure out how. Maybe it’s an XY problem? julia\> for s i…

---

## [Evaluation into closed module - what's wrong?](https://discourse.julialang.org/t/evaluation-into-closed-module-whats-wrong/114526)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 3\
**Last updated:** [May 22, 2024, 5:05am UTC](https://discourse.julialang.org/t/evaluation-into-closed-module-whats-wrong/114526 "2024-05-22T05:05:26Z")

</div>

Hi metaprogramming afficionados, The package SparseConnectivityTracer.jl works by operator overloading, like ForwardDiff.jl or Measurements.jl. We overload operations on new number types called ConnectivityTracer, Gradi…

---

## [Is there a better way to write this macro?](https://discourse.julialang.org/t/is-there-a-better-way-to-write-this-macro/110610)

<div class="topic-metadata">

**Author:** [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Replies:** 35\
**Last updated:** [February 24, 2024, 7:09pm UTC](https://discourse.julialang.org/t/is-there-a-better-way-to-write-this-macro/110610 "2024-02-24T19:09:51Z")

</div>

I’m working on a VM, of the classic dispatch-on-value sort, and the last step (which I’m bearing down on) will be to make it type stable. The current implementation uses a multimethod for dispatch, but the Vector holding…

---

## [\`eval\` scope problem and \`println\` problem for multithreading](https://discourse.julialang.org/t/eval-scope-problem-and-println-problem-for-multithreading/109333)

<div class="topic-metadata">

**Author:** [@ccestbon](https://discourse.julialang.org/u/ccestbon)\
**Replies:** 13\
**Last updated:** [January 28, 2024, 9:17am UTC](https://discourse.julialang.org/t/eval-scope-problem-and-println-problem-for-multithreading/109333 "2024-01-28T09:17:55Z")

</div>

Update 1: Thanks for all the suggesions. I have modifed the code as follows: using Sockets # server server = listen(2000) errormonitor( @async begin sock = accept(server) ex = quote my() = println("aa") end …

---

## [Evaluate a formula inside a dataframes to create a new column](https://discourse.julialang.org/t/evaluate-a-formula-inside-a-dataframes-to-create-a-new-column/103208)

<div class="topic-metadata">

**Author:** [@gaspardelanuit](https://discourse.julialang.org/u/gaspardelanuit)\
**Replies:** 15\
**Last updated:** [August 27, 2023, 10:49pm UTC](https://discourse.julialang.org/t/evaluate-a-formula-inside-a-dataframes-to-create-a-new-column/103208 "2023-08-27T22:49:24Z")

</div>

I have a dataset that includes a column which has a formula. The formula is a recipe to get a new column from existing columns. Essentially the data looks like the following \> df = DataFrame(l=1:8, a=\[1, 1, 1, 2, 2, 1…

---

## [Can I make Julia eval a variable before using it as a kwargs?](https://discourse.julialang.org/t/can-i-make-julia-eval-a-variable-before-using-it-as-a-kwargs/99322)

<div class="topic-metadata">

**Author:** [@bertulli](https://discourse.julialang.org/u/bertulli)\
**Replies:** 10\
**Last updated:** [May 27, 2023, 9:53pm UTC](https://discourse.julialang.org/t/can-i-make-julia-eval-a-variable-before-using-it-as-a-kwargs/99322 "2023-05-27T21:53:48Z")

</div>

Hi! I’m building a DataFrame with the column names stored in some variables (both as symbols and strings): adc\_I\_title = "Arc ADC Current (A)" adc\_V\_title = "Arc ADC Voltage (V)" adc\_I\_symbol = Symbol(adc\_I\_title) adc\_V…

---

## [Using @eval in a function](https://discourse.julialang.org/t/using-eval-in-a-function/89488)

<div class="topic-metadata">

**Author:** [@vitaminace33](https://discourse.julialang.org/u/vitaminace33)\
**Replies:** 17\
**Last updated:** [October 29, 2022, 10:40pm UTC](https://discourse.julialang.org/t/using-eval-in-a-function/89488 "2022-10-29T22:40:23Z")

</div>

Hi! I am trying to extend the methods of a collection of functions programmatically with no partial success. foo(x::Real) = x for f in (:foo,) @eval ($f)(x::Complex) = x' end function fun() foo(x::Real) = x …

---

## [Differences of Core.eval vs. running the code directly in other modules then Main](https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489)

<div class="topic-metadata">

**Author:** [@sfuerst](https://discourse.julialang.org/u/sfuerst)\
**Replies:** 4\
**Last updated:** [June 9, 2022, 9:27pm UTC](https://discourse.julialang.org/t/differences-of-core-eval-vs-running-the-code-directly-in-other-modules-then-main/82489 "2022-06-09T21:27:47Z")

</div>

While writing the documentation of a package I’m currently developing, I did ran into a problem with Documenter.jl which I could track down to the sandboxing mechanism of Documenter in combination with Core.eval. Withou…

---

## [Using eval within a function](https://discourse.julialang.org/t/using-eval-within-a-function/82487)

<div class="topic-metadata">

**Author:** [@flobe](https://discourse.julialang.org/u/flobe)\
**Replies:** 7\
**Last updated:** [June 9, 2022, 2:31pm UTC](https://discourse.julialang.org/t/using-eval-within-a-function/82487 "2022-06-09T14:31:52Z")

</div>

I’m trying to build a statement for an if case within a function. Something like: function build\_string(test\_value, comparator, value) if eval(Meta.parse("test\_value" \* "comparator" \* "value")) \[...\] end … I ge…

---

## [Using eval to evaluate a variable inside an expression when string interpolation is not ok](https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356)

<div class="topic-metadata">

**Author:** [@mikeliux](https://discourse.julialang.org/u/mikeliux)\
**Replies:** 5\
**Last updated:** [June 8, 2022, 5:56am UTC](https://discourse.julialang.org/t/using-eval-to-evaluate-a-variable-inside-an-expression-when-string-interpolation-is-not-ok/82356 "2022-06-08T05:56:24Z")

</div>

I am learning Julia and I am trying to create a function to shuffle an n-dimensional array X along a desired dimension. This same strategy will be used later to split an array into 2 subarrays along a desired dimension. …

---

## [Dynamically Create and Destroy Modules (to avoid memory leaks in program synthesis)](https://discourse.julialang.org/t/dynamically-create-and-destroy-modules-to-avoid-memory-leaks-in-program-synthesis/39729)

<div class="topic-metadata">

**Author:** [@zennatavares](https://discourse.julialang.org/u/zennatavares)\
**Replies:** 6\
**Last updated:** [May 5, 2022, 2:52pm UTC](https://discourse.julialang.org/t/dynamically-create-and-destroy-modules-to-avoid-memory-leaks-in-program-synthesis/39729 "2022-05-05T14:52:17Z")

</div>

I’m trying to do some program synthesis in Julia. This means generating a lot of programs (Julia Exprs) evaluating them, and scoring them. These Expressions can create new types, structs, functions, etc. The most reas…

---

## [\[SOLVED\] How can I evaluate in Main from a module?](https://discourse.julialang.org/t/solved-how-can-i-evaluate-in-main-from-a-module/74908)

<div class="topic-metadata">

**Author:** [@emmettgb](https://discourse.julialang.org/u/emmettgb)\
**Replies:** 8\
**Last updated:** [January 21, 2022, 10:37am UTC](https://discourse.julialang.org/t/solved-how-can-i-evaluate-in-main-from-a-module/74908 "2022-01-21T10:37:32Z")

</div>

Hello! I am trying to make a macro, @each, which will take each value and compare the falsehood of it to a certain condition. The problem is, while it works fine so long as the macro is globally defined, i.e. in a noteb…

---

## [How to get the name of the current function](https://discourse.julialang.org/t/how-to-get-the-name-of-the-current-function/51223)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 5\
**Last updated:** [September 3, 2021, 10:29am UTC](https://discourse.julialang.org/t/how-to-get-the-name-of-the-current-function/51223 "2021-09-03T10:29:51Z")

</div>

I want to meta-program functions that include messages with their names. This works: fname = :foo @eval $fname() = "This function is \`$(fname)\`" julia\> foo() "This function is \`foo\`" But this doesn’t: for fname in (:…

---

## [How to avoid evaluation into the global space when the expression is not know in advance](https://discourse.julialang.org/t/how-to-avoid-evaluation-into-the-global-space-when-the-expression-is-not-know-in-advance/67342)

<div class="topic-metadata">

**Author:** [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Replies:** 31\
**Last updated:** [August 30, 2021, 3:05pm UTC](https://discourse.julialang.org/t/how-to-avoid-evaluation-into-the-global-space-when-the-expression-is-not-know-in-advance/67342 "2021-08-30T15:05:00Z")

</div>

input = Dict("x"=\>ones(10),"y"=\>2\*ones(10),"z"=\>3\*ones(10)) expr\_list = DataFrame(var=\["v1","v2","v3"\],expr = \["x\*y","y/z","x+y+z"\]) output = Dict() I have a dictionary of input storing the values of some variables x,…

---

## [Transforming arbitrary Julia code to lazy evaluation](https://discourse.julialang.org/t/transforming-arbitrary-julia-code-to-lazy-evaluation/66239)

<div class="topic-metadata">

**Author:** [@tbenst](https://discourse.julialang.org/u/tbenst)\
**Replies:** 4\
**Last updated:** [August 12, 2021, 3:51am UTC](https://discourse.julialang.org/t/transforming-arbitrary-julia-code-to-lazy-evaluation/66239 "2021-08-12T03:51:01Z")

</div>

I’ve been experimenting with methods for transforming arbitrary Julia code for lazy evaluation (repo at https://github.com/tbenst/Thunks.jl). Here’s an example of what I’d like to be able to do in a fraction of a second: …

---

## [Local expr with local variables - aka metaprogramming C++](https://discourse.julialang.org/t/local-expr-with-local-variables-aka-metaprogramming-c/62501)

<div class="topic-metadata">

**Author:** [@sapo](https://discourse.julialang.org/u/sapo)\
**Replies:** 18\
**Last updated:** [June 9, 2021, 8:32am UTC](https://discourse.julialang.org/t/local-expr-with-local-variables-aka-metaprogramming-c/62501 "2021-06-09T08:32:31Z")

</div>

Hi all, I am trying to use a C++ library by creating C++ code dynamically (i.e. meta-programming C++). I’m using Cxx package for this. In Cxx there’s a macro-string named icxx\_str which basically wraps the code inside …

---

## [How to call the original function when overriding it](https://discourse.julialang.org/t/how-to-call-the-original-function-when-overriding-it/56865)

<div class="topic-metadata">

**Author:** [@NightMachinary](https://discourse.julialang.org/u/NightMachinary)\
**Replies:** 8\
**Last updated:** [March 12, 2021, 11:22am UTC](https://discourse.julialang.org/t/how-to-call-the-original-function-when-overriding-it/56865 "2021-03-12T11:22:43Z")

</div>

I want to override Unitful.Base.show to make it first simplify the quantity’s unit before showing it. I don’t know how to call the original overriden function though. What I have tried: @defonce origShow = Unitful.Base.…

---

## [Dynamically Create a Function - Initial Idea with eval failed due to World Age Issue](https://discourse.julialang.org/t/dynamically-create-a-function-initial-idea-with-eval-failed-due-to-world-age-issue/49139)

<div class="topic-metadata">

**Author:** [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Replies:** 19\
**Last updated:** [October 28, 2020, 2:51pm UTC](https://discourse.julialang.org/t/dynamically-create-a-function-initial-idea-with-eval-failed-due-to-world-age-issue/49139 "2020-10-28T14:51:42Z")

</div>

Hey all, I’m struggling to implement a certain problem. My current situation is the following: Some parts of my project consist of using Tullio functions. Since my arrays can be of arbitrary dimensions and I want to ap…

---

## [Best performance for eval of expressions with parameters](https://discourse.julialang.org/t/best-performance-for-eval-of-expressions-with-parameters/43443)

<div class="topic-metadata">

**Author:** [@oheil](https://discourse.julialang.org/u/oheil)\
**Replies:** 2\
**Last updated:** [July 28, 2020, 2:07pm UTC](https://discourse.julialang.org/t/best-performance-for-eval-of-expressions-with-parameters/43443 "2020-07-28T14:07:40Z")

</div>

I try to achieve better/best performance for eval(expression). Up to now I found 5 more or less different possibilities (in respect to my code logic) to eval an expression. It’s best, to see it in code. The following MW…

---

## [How do you evaluate a parameter/variable if you are not in Main eval or Core.Eval do not work?](https://discourse.julialang.org/t/how-do-you-evaluate-a-parameter-variable-if-you-are-not-in-main-eval-or-core-eval-do-not-work/42343)

<div class="topic-metadata">

**Author:** [@cbasile21](https://discourse.julialang.org/u/cbasile21)\
**Replies:** 4\
**Last updated:** [July 1, 2020, 3:44pm UTC](https://discourse.julialang.org/t/how-do-you-evaluate-a-parameter-variable-if-you-are-not-in-main-eval-or-core-eval-do-not-work/42343 "2020-07-01T15:44:19Z")

</div>

Hello, I would really appreciate your help with the following problem. I will want to learn how evaluate a variable outside of Main, and I could not find a way to do that yet. Expected: Eval will work for #println(Core…

---

## [How to nest splicing contexts (i.e. @eval inside quote block)](https://discourse.julialang.org/t/how-to-nest-splicing-contexts-i-e-eval-inside-quote-block/38752)

<div class="topic-metadata">

**Author:** [@zachmatson](https://discourse.julialang.org/u/zachmatson)\
**Replies:** 5\
**Last updated:** [May 5, 2020, 10:33pm UTC](https://discourse.julialang.org/t/how-to-nest-splicing-contexts-i-e-eval-inside-quote-block/38752 "2020-05-05T22:33:59Z")

</div>

I am trying to make a macro that needs to evaluate an arbitrary (not known at parse time) amount of iterations of some code, which will change each time. I am trying to figure out how you would separately splice into the…

---

## [Metaprogramming using eval and struct: BUG getting UndefVarError: not defined](https://discourse.julialang.org/t/metaprogramming-using-eval-and-struct-bug-getting-undefvarerror-not-defined/37937)

<div class="topic-metadata">

**Author:** [@JosephPollacco](https://discourse.julialang.org/u/JosephPollacco)\
**Replies:** 22\
**Last updated:** [May 1, 2020, 3:22am UTC](https://discourse.julialang.org/t/metaprogramming-using-eval-and-struct-bug-getting-undefvarerror-not-defined/37937 "2020-05-01T03:22:04Z")

</div>

I am trying to read parameters from a .csv file for which the name of parameter and its values are given in the .csv file. For that I am trying to simply evaluate a simple expression involving putting the value of the …
