# Iterate over macros

**URL:** <https://discourse.julialang.org/t/iterate-over-macros/43493>\
**Category:** Tooling\
**Tags:** question, package, juliapro\
**Created:** [July 22, 2020, 2:03pm UTC](https://discourse.julialang.org/t/iterate-over-macros/43493 "2020-07-22T14:03:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![afazevedo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/afazevedo/32/16394_2.png) [@afazevedo](https://discourse.julialang.org/u/afazevedo)\
**Post date:** [July 22, 2020, 2:03pm UTC](https://discourse.julialang.org/t/iterate-over-macros/43493/1 "2020-07-22T14:03:06Z")

</div>

I’m using the Parameters package that uses a macro to define parameters. I wonder if there is any way to iterate by changing the struct information. An example:

```julia
using Parameters

    @with_kw struct params
        path::String = files_even[1]
        model::String = "dcmst"
        EPS::Float64 = 0.0001
        test::Bool = 1
        plot::Bool = 1
    end

g_params = params()

```

Here I have an array that has all the paths to instances that I want to test. I would like to iterate through the files\_even array by changing the value of the path parameter.  
When I implement a for to iterate, it issues the following error:

```julia
for i in 1:10
    @with_kw struct params
        path::String = files_even[i]
        model::String = "dcmst"
        EPS::Float64 = 0.0001
        test::Bool = 1
        plot::Bool = 1
    end
end

```

And the error:

```julia
ERROR: syntax: macro definition not allowed inside a local scope

```

Thanks in advance!

---

<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:** [July 22, 2020, 2:06pm UTC](https://discourse.julialang.org/t/iterate-over-macros/43493/2 "2020-07-22T14:06:20Z")

</div>

> [@afazevedo](#):
>
> ```julia
> for i in 1:10
> @with_kw struct params
> path::String = files_even[i]
> 
> ```

This doesn’t make sense. `struct params` declares a type. You can only declare a type once.

If you want to declare multiple types in a loop, you can use `@eval`, but it doesn’t sound like that’s what you want here. You don’t need to declare a new type just to change parameters, just call the constructor to create an instance. (The point of `@with_kw` is to declare _default_ values of the parameters, but you can override these in instances.)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 12, 2023, 4:41pm UTC](https://discourse.julialang.org/t/iterate-over-macros/43493/3 "2023-09-12T16:41:33Z")

</div>


