# Generating @enum from string array

**URL:** <https://discourse.julialang.org/t/generating-enum-from-string-array/22796>\
**Category:** New to Julia\
**Tags:** enum\
**Created:** [April 5, 2019, 12:59pm UTC](https://discourse.julialang.org/t/generating-enum-from-string-array/22796 "2019-04-05T12:59:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 5, 2019, 12:59pm UTC](https://discourse.julialang.org/t/generating-enum-from-string-array/22796/1 "2019-04-05T12:59:07Z")

</div>

Hey guys, I am rather new to Julia, but will try to do my best to explain my question. So basically I am making an enum (array?) called “Cat” which following variables:

```julia
@enum Cat begin
        Points
        Idp
        Vel
        Rhop
        Mass
        Press
        Vol
        Ace
        Vor
        Typ #Typ, since "Type" is illegal to assign
        Mk
    end

```

Where the integer values are non important since I use two different dicts like this:

```julia
    const searchString = Dict(Points => "POINTS ",Idp=>"POINT_DATA ",Vel=>"Vel ",Rhop=>"Rhop ",Mass=>"Mass ",Press => "Press ",Vol => "Vol ",Ace => "Ace ",Vor => "Vor ",Typ=>"Type ",Mk => "Mk ")
    const catType = Dict(Points => Float32,Idp=>Int32,Vel=>Float32,Rhop=>Float32,Mass=>Float32,Press =>Float32,Vol=>Float32,Ace=>Float32,Vor=>Float32,Typ=>Int8,Mk=>Int8)

```

So this works fine, but I want to improve it. So basically my question is:

Can I generate my enum Cat by using a String Array initially? If yes, how would I do that?

So in pseudo code code:

“Points” =\> enum Cat

Cat = Points

I hope it makes sense.

Kind regards

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [April 5, 2019, 7:25pm UTC](https://discourse.julialang.org/t/generating-enum-from-string-array/22796/2 "2019-04-05T19:25:37Z")

</div>

Welcome to Julia-discourse!

I’m a bit confused by your two dicts. To get the string, just do `string(Rhop)` (that `Points` translates to `"POINTS"` seems a bit arbitrary). Then why do you associate types with your item? It they are needed, then maybe use a `struct` instead?

You could use eval, but that does not seem good. If you need to dynamically create an entity, use something which is made for this, like e.g. a Dict.

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 6, 2019, 1:53pm UTC](https://discourse.julialang.org/t/generating-enum-from-string-array/22796/3 "2019-04-06T13:53:12Z")

</div>

Thanks for the explanation, didn’t know structs existed.

I just hoped that it would be possible to dynamically make @enums since I like to work that way, but dict might be the best alternative

Kind regards
