# Is there any way to produce a Type by cat strings together?

**URL:** <https://discourse.julialang.org/t/is-there-any-way-to-produce-a-type-by-cat-strings-together/73961>\
**Category:** General Usage\
**Tags:** question, macros, metaprogramming\
**Created:** [January 3, 2022, 12:06pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-produce-a-type-by-cat-strings-together/73961 "2022-01-03T12:06:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timacro/32/32196_2.png) [@timacro](https://discourse.julialang.org/u/timacro)\
**Post date:** [January 3, 2022, 12:06pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-produce-a-type-by-cat-strings-together/73961/1 "2022-01-03T12:06:38Z")

</div>

To define a set of Regxx types，It would be OK with these pieces of code:

```julia
for (bits,t) in [(8,UInt8),(16,UInt16),(32,UInt32)]
    rname = Symbol("Reg",bits)
    @eval struct $rname
        addr::UInt32
        data::$t
    end
end

```

But I wonder if there is any way to define types like this:

```julia
for bits in [8,16,32]
    name = Symbol("D",bits)
    @eval struct $name
        addr::UInt32
        data:: ??? # needs to produce UInt8、UInt16、UInt32
    end
end

```

---

<div class="post-metadata">

**Author:** ![melonedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/melonedo/32/15503_2.png) [@melonedo](https://discourse.julialang.org/u/melonedo)\
**Post date:** [January 3, 2022, 12:30pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-produce-a-type-by-cat-strings-together/73961/2 "2022-01-03T12:30:20Z")

</div>

I think you have already posted the answer:

```julia
for bits in [8,16,32]
    name = Symbol("D",bits)
    t = Symbol("UInt", bits)
    @eval struct $name
        addr::UInt32
        data::$t
    end
end

```

---

<div class="post-metadata">

**Author:** ![timacro](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timacro/32/32196_2.png) [@timacro](https://discourse.julialang.org/u/timacro)\
**Post date:** [January 3, 2022, 12:44pm UTC](https://discourse.julialang.org/t/is-there-any-way-to-produce-a-type-by-cat-strings-together/73961/4 "2022-01-03T12:44:36Z")

</div>

You are right! 😂 😂 😂

I ran into a error when I tried the code like yours, excepted a statement:

```julia
for bits in [8,16,32]
    rname = Symbol("D",bits)
    @eval struct $rname
        addr::UInt32
        data::Symbol("UInt",$bits) # error! due to not understand @eval's usage
    end
end

```

Thanks a lot !
