# \#metaprogramming

**URL:** https://discourse.julialang.org/tag/metaprogramming/68.md?page=1

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

**Page:** 2

---

## [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…

---

## [Code works when debugging but not otherwise in repl](https://discourse.julialang.org/t/code-works-when-debugging-but-not-otherwise-in-repl/118137)

<div class="topic-metadata">

**Author:** [@PeterCourcoux](https://discourse.julialang.org/u/PeterCourcoux)\
**Replies:** 1\
**Last updated:** [August 13, 2024, 4:49pm UTC](https://discourse.julialang.org/t/code-works-when-debugging-but-not-otherwise-in-repl/118137 "2024-08-13T16:49:31Z")

</div>

I have the following code: !/usr/bin/env julia …

---

## [Extending JuMP @variable](https://discourse.julialang.org/t/extending-jump-variable/118094)

<div class="topic-metadata">

**Author:** [@shawn\_T](https://discourse.julialang.org/u/shawn_T)\
**Replies:** 7\
**Last updated:** [August 13, 2024, 9:41am UTC](https://discourse.julialang.org/t/extending-jump-variable/118094 "2024-08-13T09:41:59Z")

</div>

Hi, I am planning to extend JuMP @variable macro by defining a new struct to replace the VariableInfo struct defined in JuMP, the code below is following the extension page: struct My\_var \<: JuMP.AbstractVariable …

---

## [How to code-gen unrolled loop over a tuple?](https://discourse.julialang.org/t/how-to-code-gen-unrolled-loop-over-a-tuple/117655)

<div class="topic-metadata">

**Author:** [@bremez](https://discourse.julialang.org/u/bremez)\
**Replies:** 28\
**Last updated:** [August 9, 2024, 8:58pm UTC](https://discourse.julialang.org/t/how-to-code-gen-unrolled-loop-over-a-tuple/117655 "2024-08-09T20:58:52Z")

</div>

I would like a function that accepts a tuple of functions, picks one at random based on provided relative weights, and passes it to a definite second function. Right now, I accomplish this as follows, for e.g. a tuple of…

---

## [Variable interpolation](https://discourse.julialang.org/t/variable-interpolation/117769)

<div class="topic-metadata">

**Author:** [@geoffD](https://discourse.julialang.org/u/geoffD)\
**Replies:** 5\
**Last updated:** [August 7, 2024, 2:30am UTC](https://discourse.julialang.org/t/variable-interpolation/117769 "2024-08-07T02:30:45Z")

</div>

Hi, everyone. New to Julia and trying to do something like the following: v1 = "m" function mat() return "I am a mat" end I would like to be able to issue the following command: ($v1)at and get back “I am a …

---

## [Expensive Code Generation for Functions for Reuse](https://discourse.julialang.org/t/expensive-code-generation-for-functions-for-reuse/117899)

<div class="topic-metadata">

**Author:** [@Ian\_L](https://discourse.julialang.org/u/Ian_L)\
**Replies:** 3\
**Last updated:** [August 6, 2024, 10:37pm UTC](https://discourse.julialang.org/t/expensive-code-generation-for-functions-for-reuse/117899 "2024-08-06T22:37:08Z")

</div>

Hello. I’m looking for some guidance on a design decision to make. I have an algorithm which makes use of 10 to 20 specialized function that are called repeatedly, however, none of the functions are known until the neces…

---

## [How one can evaluate @printf to be returned to a value](https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669)

<div class="topic-metadata">

**Author:** [@khaledharizb](https://discourse.julialang.org/u/khaledharizb)\
**Replies:** 7\
**Last updated:** [July 31, 2024, 6:16pm UTC](https://discourse.julialang.org/t/how-one-can-evaluate-printf-to-be-returned-to-a-value/117669 "2024-07-31T18:16:15Z")

</div>

Hi all, for a technical reason I would like to define functions as below. My problem is how to evaluate func(xx) to get a value function DeltaAI(z) return 1/(1+z) end function DeltaAII(z) return √(1-z^2) end if (F==0)…

---

## [Macro interpolation of Symbols without \`eval\`](https://discourse.julialang.org/t/macro-interpolation-of-symbols-without-eval/117603)

<div class="topic-metadata">

**Author:** [@joh](https://discourse.julialang.org/u/joh)\
**Replies:** 3\
**Last updated:** [July 30, 2024, 12:37pm UTC](https://discourse.julialang.org/t/macro-interpolation-of-symbols-without-eval/117603 "2024-07-30T12:37:57Z")

</div>

I am trying to write a macro for setting up a submodule in my package. Since this is called at precompile time, I cannot use eval (otherwise I get InitError: Evaluation into the closed module ImportEval breaks incrementa…

---

## [Macro with variable argument list combined with closure](https://discourse.julialang.org/t/macro-with-variable-argument-list-combined-with-closure/117623)

<div class="topic-metadata">

**Author:** [@nietzsche](https://discourse.julialang.org/u/nietzsche)\
**Replies:** 2\
**Last updated:** [July 30, 2024, 11:19am UTC](https://discourse.julialang.org/t/macro-with-variable-argument-list-combined-with-closure/117623 "2024-07-30T11:19:06Z")

</div>

Hi, i have a question about variable arguments in macros together with the scope of them. Function count\_test() should be a closure over the variable count and the lambda should be generated with a macro. It should b…

---

## [Code Generation with macro](https://discourse.julialang.org/t/code-generation-with-macro/117080)

<div class="topic-metadata">

**Author:** [@Andy\_Zhang](https://discourse.julialang.org/u/Andy_Zhang)\
**Replies:** 6\
**Last updated:** [July 22, 2024, 12:58pm UTC](https://discourse.julialang.org/t/code-generation-with-macro/117080 "2024-07-22T12:58:38Z")

</div>

Background I am writing a package that provides some structures of matrices, and I want them to have different properties. module MyModuleA export TypeA, properties # function interfaces properties(::Type{\<:Ab…

---

## [Metaprogramming: substitute the name of the argument](https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867)

<div class="topic-metadata">

**Author:** [@dmi3kno](https://discourse.julialang.org/u/dmi3kno)\
**Replies:** 20\
**Last updated:** [July 14, 2024, 8:08am UTC](https://discourse.julialang.org/t/metaprogramming-substitute-the-name-of-the-argument/116867 "2024-07-14T08:08:53Z")

</div>

I am writing a function factory that takes two functions and weighs them by some \_wt \\in (0,1). function fun\_mix(fun1::Function, fun2::Function; \_nm\_wt="\_wt") f = function (u::AbstractFloat, args...; \_wt=0.5) …

---

## [\[Ann\] MethodInspector.jl: Package to inspect method APIs](https://discourse.julialang.org/t/ann-methodinspector-jl-package-to-inspect-method-apis/116893)

<div class="topic-metadata">

**Author:** [@bluesmoon](https://discourse.julialang.org/u/bluesmoon)\
**Replies:** 0\
**Last updated:** [July 11, 2024, 8:31am UTC](https://discourse.julialang.org/t/ann-methodinspector-jl-package-to-inspect-method-apis/116893 "2024-07-11T08:31:33Z")

</div>

Bit late announcing this, but reminded by Michael Tiemann’s talk at JuliaCon. Announcing MethodInspector.jl Code at: GitHub - bluesmoon/MethodInspector.jl: Julia package to inspect the names and types of method argumen…

---

## [A macro for removing calls to Base.convert: @noconvert](https://discourse.julialang.org/t/a-macro-for-removing-calls-to-base-convert-noconvert/116651)

<div class="topic-metadata">

**Author:** [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Replies:** 2\
**Last updated:** [July 9, 2024, 9:41am UTC](https://discourse.julialang.org/t/a-macro-for-removing-calls-to-base-convert-noconvert/116651 "2024-07-09T09:41:13Z")

</div>

From the prior discussion on type annotations I was wondering what a macro that removed all calls to Base.convert would look like. Here’s my prototype via Cassette.jl: using Cassette Cassette.@context NoConvertCtx; Cas…

---

## [Using metaprogramming to combine multiple functions and construct a composite temporary function](https://discourse.julialang.org/t/using-metaprogramming-to-combine-multiple-functions-and-construct-a-composite-temporary-function/116647)

<div class="topic-metadata">

**Author:** [@chooron](https://discourse.julialang.org/u/chooron)\
**Replies:** 10\
**Last updated:** [July 7, 2024, 2:35am UTC](https://discourse.julialang.org/t/using-metaprogramming-to-combine-multiple-functions-and-construct-a-composite-temporary-function/116647 "2024-07-07T02:35:04Z")

</div>

I can identify the input and output variable names of the functions. Using this information, I want to combine these functions to construct a composite function. I hope to obtain the result with the specified variable na…

---

## [Macro for implicitly defined NamedTuples](https://discourse.julialang.org/t/macro-for-implicitly-defined-namedtuples/114685)

<div class="topic-metadata">

**Author:** [@pablosanjose](https://discourse.julialang.org/u/pablosanjose)\
**Replies:** 4\
**Last updated:** [May 24, 2024, 5:10pm UTC](https://discourse.julialang.org/t/macro-for-implicitly-defined-namedtuples/114685 "2024-05-24T17:10:32Z")

</div>

I want to write a macro imp that does this julia\> @imp(; a = 2, b = a^2, c = 3) (; a = 2, b = 4, c = 3) Not being any good with metaprogramming I turn to the Julia community: Is there any package that already achiev…

---

## [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…

---

## [Get the actual type from an Expr representing a type](https://discourse.julialang.org/t/get-the-actual-type-from-an-expr-representing-a-type/113848)

<div class="topic-metadata">

**Author:** [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Replies:** 2\
**Last updated:** [May 4, 2024, 11:42pm UTC](https://discourse.julialang.org/t/get-the-actual-type-from-an-expr-representing-a-type/113848 "2024-05-04T23:42:50Z")

</div>

I think this may be the question being asked here, but it wasn’t resolved. I am writing a macro that manipulates the signature of a function. I want to know if an argument is annotated with a subtype of a type owned by …

---

## [Parsing Julia code to separate symbols based on scoping and create a symbol table](https://discourse.julialang.org/t/parsing-julia-code-to-separate-symbols-based-on-scoping-and-create-a-symbol-table/113809)

<div class="topic-metadata">

**Author:** [@Akhil\_Akkapelli](https://discourse.julialang.org/u/Akhil_Akkapelli)\
**Replies:** 1\
**Last updated:** [May 3, 2024, 7:00pm UTC](https://discourse.julialang.org/t/parsing-julia-code-to-separate-symbols-based-on-scoping-and-create-a-symbol-table/113809 "2024-05-03T19:00:39Z")

</div>

I have a quote block in Julia containing functions, modules, and etc. Assuming that quote block is in Main module and Main module does not have these symbols with same names. I want to separate the symbols based on their…

---

## [CodeSculptor.jl: take AST's apart, play with them, and put them back together. A significant upgrade to MacroTools.splitdef() and splitarg()](https://discourse.julialang.org/t/codesculptor-jl-take-asts-apart-play-with-them-and-put-them-back-together-a-significant-upgrade-to-macrotools-splitdef-and-splitarg/113476)

<div class="topic-metadata">

**Author:** [@heyx3](https://discourse.julialang.org/u/heyx3)\
**Replies:** 0\
**Last updated:** [April 24, 2024, 9:13pm UTC](https://discourse.julialang.org/t/codesculptor-jl-take-asts-apart-play-with-them-and-put-them-back-together-a-significant-upgrade-to-macrotools-splitdef-and-splitarg/113476 "2024-04-24T21:13:34Z")

</div>

---

## [How to pass an arbitrary number of macro arguments from one macro to another? (a bit like splatting)](https://discourse.julialang.org/t/how-to-pass-an-arbitrary-number-of-macro-arguments-from-one-macro-to-another-a-bit-like-splatting/112288)

<div class="topic-metadata">

**Author:** [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Replies:** 7\
**Last updated:** [March 29, 2024, 11:27pm UTC](https://discourse.julialang.org/t/how-to-pass-an-arbitrary-number-of-macro-arguments-from-one-macro-to-another-a-bit-like-splatting/112288 "2024-03-29T23:27:05Z")

</div>

I have a macro which does stuff depending on how many inputs there are macro my\_macro(arg1) println("We got one argument.") sum = 1 if arg1 isa Int64 sum = sum + arg1 end sum end macro my\_mac…

---

## [Performance of persistent variables](https://discourse.julialang.org/t/performance-of-persistent-variables/112044)

<div class="topic-metadata">

**Author:** [@c\_sell](https://discourse.julialang.org/u/c_sell)\
**Replies:** 0\
**Last updated:** [March 24, 2024, 4:33pm UTC](https://discourse.julialang.org/t/performance-of-persistent-variables/112044 "2024-03-24T16:33:09Z")

</div>

Hello, I have a simple toy example in which I compare two methods of creating persistent variables. In my case, both methods exhibit identical performance. Are there any differences to consider regarding safety, compil…

---

## [Advanced Metaprogramming Uses of QuoteNode](https://discourse.julialang.org/t/advanced-metaprogramming-uses-of-quotenode/110708)

<div class="topic-metadata">

**Author:** [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Replies:** 1\
**Last updated:** [February 24, 2024, 10:28pm UTC](https://discourse.julialang.org/t/advanced-metaprogramming-uses-of-quotenode/110708 "2024-02-24T22:28:37Z")

</div>

Continuing the discussion from Is there a better way to write this macro?: Quoth The Manual: The parser yields QuoteNodes for simple quoted items like symbols. QuoteNode can also be used for certain advanced metapro…

---

## [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…

---

## [Metaprogramming: macro calling another macro making named variables](https://discourse.julialang.org/t/metaprogramming-macro-calling-another-macro-making-named-variables/109621)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 7\
**Last updated:** [February 20, 2024, 11:17pm UTC](https://discourse.julialang.org/t/metaprogramming-macro-calling-another-macro-making-named-variables/109621 "2024-02-20T23:17:24Z")

</div>

Ooof, I need some metaprogramming help… There is the macro @parameters x = 0.5. The macro, in a simplified sense, does the following: makes a named parameter with name :x and default value 0.5 and returns the container a…

---

## [Performance of \`Meta.parse\` and \`eval\`](https://discourse.julialang.org/t/performance-of-meta-parse-and-eval/52061)

<div class="topic-metadata">

**Author:** [@brucala](https://discourse.julialang.org/u/brucala)\
**Replies:** 11\
**Last updated:** [December 30, 2020, 6:39pm UTC](https://discourse.julialang.org/t/performance-of-meta-parse-and-eval/52061 "2020-12-30T18:39:10Z")

</div>

Hi all, I’m a relatively new and now enthusiastic Julia user. While exploring the metaprogramming capabilities I came to the question of this topic. Probably I am missing something or misinterpreting the use intention f…

---

## [Creating a method dynamically with keyword arguments](https://discourse.julialang.org/t/creating-a-method-dynamically-with-keyword-arguments/110108)

<div class="topic-metadata">

**Author:** [@Janis\_Erdmanis](https://discourse.julialang.org/u/Janis_Erdmanis)\
**Replies:** 4\
**Last updated:** [February 12, 2024, 6:25pm UTC](https://discourse.julialang.org/t/creating-a-method-dynamically-with-keyword-arguments/110108 "2024-02-12T18:25:33Z")

</div>

I have a context structure with many fields and want to mutate some by reinitialising, where I could do various validations. I know there is an excellent SetField.jl package, but I have only one structure, and thus, I wo…

---

## [Generate and evaluate functions programmatically](https://discourse.julialang.org/t/generate-and-evaluate-functions-programmatically/110083)

<div class="topic-metadata">

**Author:** [@VPBML](https://discourse.julialang.org/u/VPBML)\
**Replies:** 2\
**Last updated:** [February 12, 2024, 12:27pm UTC](https://discourse.julialang.org/t/generate-and-evaluate-functions-programmatically/110083 "2024-02-12T12:27:55Z")

</div>

Hi, I wonder what is the best way (performance-wise) to generate and evaluate functions programmatically. The functions I need are generated dynamically via a Genetic Programming algorithm (i.e., they are based on previ…

---

## [Why does Meta.parse ignores comments?](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 6\
**Last updated:** [January 31, 2024, 4:46pm UTC](https://discourse.julialang.org/t/why-does-meta-parse-ignores-comments/109523 "2024-01-31T16:46:02Z")

</div>

I am really surprised that Meta.parse seems to actively kick out some information julia\> Meta.parse(""" function hi() # comment end """) :(function hi() #= none:1 =# #= none:1 =# …

---

## [Array comprehension in a quote](https://discourse.julialang.org/t/array-comprehension-in-a-quote/108333)

<div class="topic-metadata">

**Author:** [@lstagner](https://discourse.julialang.org/u/lstagner)\
**Replies:** 4\
**Last updated:** [January 5, 2024, 4:33am UTC](https://discourse.julialang.org/t/array-comprehension-in-a-quote/108333 "2024-01-05T04:33:13Z")

</div>

I want to do an array comprehension from a list of ranges in a quote but I get a syntax error. loops = \[:(i=1:2), :(j=1:3)\] :(\[i+j for :(loops...)\]) # ideally maps to \[i+j for i=1:2, j=1:3\] syntax: invalid iteration spe…

---

## [How can I splat expressions into quote blocks?](https://discourse.julialang.org/t/how-can-i-splat-expressions-into-quote-blocks/108263)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 3\
**Last updated:** [January 2, 2024, 2:15pm UTC](https://discourse.julialang.org/t/how-can-i-splat-expressions-into-quote-blocks/108263 "2024-01-02T14:15:33Z")

</div>

ex1 = quote a = 1 a += 1 end ex2 = quote a \*= 2 a += 3 end quote $ex1... $ex2... end gives me quote #= REPL\[65\]:2 =# begin #= REPL\[61\]:2 =# a = 1 #= REPL\[61\]:3 =#…

[Previous page](https://discourse.julialang.org/tag/metaprogramming/68.md?match_all_tags=true&tags%5B%5D=metaprogramming)

[Next page](https://discourse.julialang.org/tag/metaprogramming/68.md?match_all_tags=true&page=2&tags%5B%5D=metaprogramming)
