# How do I concatenate symbols containing curly brackets into a single symbol?

**URL:** <https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759>\
**Category:** General Usage\
**Tags:** metaprogramming\
**Created:** [April 6, 2025, 2:46pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759 "2025-04-06T14:46:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [April 6, 2025, 2:46pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759/1 "2025-04-06T14:46:04Z")

</div>

I’d like to obtain the code

```julia
struct S{𝒯<:Real}
end

```

programmatically. Method 1 below works, but I’d like to be able to feed in the variable name (here `S`) automatically (e.g. by passing a variable `x` containing `:S`) and hence to construct a single symbol out of the concatenation of `x` and `{𝒯<:Real}`. How do I accomplish this? The curlies appear to be the culprit here; see methods 2 through 4 below.

```julia
name₁ = :(S₁{𝒯<:Real})
name₂ = Symbol( :S₂, :({𝒯<:Real}) )
name₃ = Symbol( :S₃, :T )
name₄ = Symbol( "S₄{𝒯<:Real}" )

e₁ = Expr( :struct, false, name₁, Expr( :block ) )
e₂ = Expr( :struct, false, name₂, Expr( :block ) )
e₃ = Expr( :struct, false, name₃, Expr( :block ) )
e₄ = Expr( :struct, false, name₄, Expr( :block ) )

eval( e₁ )
eval( e₂ )
eval( e₃ )
eval( e₄ )

dump( e₁ )
dump( e₂ )
dump( e₃ )
dump( e₄ )

names( Main )

```

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [April 6, 2025, 3:06pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759/2 "2025-04-06T15:06:44Z")

</div>

Figured it out… I can do

```julia
Expr( :curly, Symbol( :S, x), Expr( :(<:), :𝒯, :Real) )

```

---

<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:** [April 6, 2025, 7:06pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759/3 "2025-04-06T19:06:57Z")

</div>

Probably easier to just use interpolation, e.g. `:($S{𝒯<:Real})` if you have a variable `S` containing the desired symbol, or

```julia
:($(Symbol(:S, x)){𝒯<:Real})

```

to interpolate `Symbol(:S, x)`.

---

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [April 6, 2025, 7:52pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759/4 "2025-04-06T19:52:06Z")

</div>

> [@Joris\_Pinkse](#):
>
> I’d like to obtain the code
> 
> ```julia
> struct S{𝒯<:Real}
> end
> 
> ```
> 
> programmatically.

I think the easiest way is to use `@eval` to interpolate the symbol into the code:

```julia-repl
julia> x = :S
:S

julia> @eval struct $x{𝒯<:Real}
       end

julia> S{Rational}()
S{Rational}()

```

Or if you need to store the full `struct` expression in a variable, interpolate into a `quote` block instead:

```julia-repl
julia> y = :T
:T

julia> expr = quote
           struct $y{𝒯<:Real}
           end
       end
quote
    #= REPL[9]:2 =#
    struct T{𝒯 <: Real}
        #= REPL[9]:2 =#
    end
end

julia> eval(expr)

julia> T{AbstractFloat}()
T{AbstractFloat}()

```

---

<div class="post-metadata">

**Author:** ![Joris\_Pinkse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joris_pinkse/32/216398_2.png) [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Post date:** [April 6, 2025, 9:18pm UTC](https://discourse.julialang.org/t/how-do-i-concatenate-symbols-containing-curly-brackets-into-a-single-symbol/127759/5 "2025-04-06T21:18:28Z")

</div>

> [@stevengj](#):
>
> `:($(Symbol(:S, x)){𝒯<:Real})`

Thank you. Syntax is everything!
