# Struct initialization error

**URL:** <https://discourse.julialang.org/t/struct-initialization-error/71582>\
**Category:** General Usage\
**Tags:** struct\
**Created:** [November 16, 2021, 12:37pm UTC](https://discourse.julialang.org/t/struct-initialization-error/71582 "2021-11-16T12:37:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![emanuellima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emanuellima/32/25505_2.png) [@emanuellima](https://discourse.julialang.org/u/emanuellima)\
**Post date:** [November 16, 2021, 12:37pm UTC](https://discourse.julialang.org/t/struct-initialization-error/71582/1 "2021-11-16T12:37:52Z")

</div>

I am having an error that I don’t understand. The code works on the REPL but it doesn’t when called from the terminal (after being compiled with Comonicon):

 ![image](https://global.discourse-cdn.com/julialang/original/3X/7/f/7f12e126b0b6229cf2c02c340ca5be020437d55b.png)

There is this struct called State, and it’s constructor that accepts keyword arguments. I am able to initialize and use it on the REPL, but on the terminal it throws this error, which is crazy because it is complaining that a method does not exist when it exists (as it shows me it exists). What am I missing? Can it be a world age bug?

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 16, 2021, 12:43pm UTC](https://discourse.julialang.org/t/struct-initialization-error/71582/2 "2021-11-16T12:43:28Z")

</div>

> [@emanuellima](#):
>
> What am I missing?

An MWE.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![emanuellima](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/emanuellima/32/25505_2.png) [@emanuellima](https://discourse.julialang.org/u/emanuellima)\
**Post date:** [November 16, 2021, 12:49pm UTC](https://discourse.julialang.org/t/struct-initialization-error/71582/3 "2021-11-16T12:49:20Z")

</div>

The code is rather big and on a private repo, so I will try to put the corresponding parts here, but I don’t know if it is going to be enough.

```julia
function state_factory(initial_conditions::NamedTuple)
    state_signature = generate_state_signature(initial_conditions)

    fields = map(x -> Meta.parse(x), split(state_signature))

    return quote
        struct State
            $(fields...)
            timestep::Int64
            substep::Int64

            function State($(fields...), timestep::Int64, substep::Int64)
                new($(fields...), timestep::Int64, substep::Int64)
            end

            State(; $(fields...), timestep::Int64 = 1, substep::Int64 = 1) = State($(fields...), timestep::Int64, substep::Int64)
        end
    end
end

function generate_state_signature(initial_conditions::NamedTuple)
    state_signature = ""

    for (variable, value) in pairs(initial_conditions)
        type = typeof(value)
        state_signature *= "$variable::$type "
    end

    return state_signature
end

```

This functions gets eval’d based on the named tuple. The constructor should accept keyword arguments, and it does on the REPL, but not on the terminal.
