# Runtime initializaion of parametric type in package from input

**URL:** https://discourse.julialang.org/t/runtime-initializaion-of-parametric-type-in-package-from-input/99080
**Category:** General Usage
**Tags:** question, macros, staticarrays, environment-variable
**Created:** [May 18, 2023, 6:33pm UTC](https://discourse.julialang.org/t/runtime-initializaion-of-parametric-type-in-package-from-input/99080 "2023-05-18T18:33:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![FireCrumb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/firecrumb/32/35370_2.png) [@FireCrumb](https://discourse.julialang.org/u/FireCrumb)
#### Post date: [May 18, 2023, 6:33pm UTC](https://discourse.julialang.org/t/runtime-initializaion-of-parametric-type-in-package-from-input/99080/1 "2023-05-18T18:33:37Z")

</div>

Hi,

I have a package, where I want to define `MyStaticVectorType` type, as an alias to `SVector{MEM_SIZE,Int}` (from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl)).

Where `MEM_SIZE` is loaded from environment variable when the program runs, so it’s available _before_ I call `import MyPackage` but _after_ the package is precompiled/built.

To load a constant from environment variable, I created this macro:

```julia
macro const_from_env(const_name::Symbol, const_type::Symbol, default_value)
    esc(quote
        const $(const_name) = parse($(const_type), get(ENV, $("$const_name"), $("$default_value")))
        export $(const_name)
    end)
end

```

It works like this:

```julia
@const_from_env MEM_SIZE Int 16

```

So it would load from `ENV["MEM_SIZE"]` with a default value of 16.  
If I run `MEM_SIZE=4 julia`

However, sometimes **it gets stuck on the default value during package compilation**.

Question is **how to make it read the value (and define types) from current environment**?

In other words, anything that depends on this parameter should _not_ be procompiled and cached, but rather be evaluated when the package is imported.

Hope the question is clear, thanks in advance for any help!
