# Plural macros (e.g. @variables) should return collection of the defined objects

**URL:** <https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [December 20, 2021, 7:38pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397 "2021-12-20T19:38:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinBonde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinbonde/32/33200_2.png) [@MartinBonde](https://discourse.julialang.org/u/MartinBonde)\
**Post date:** [December 20, 2021, 7:38pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397/1 "2021-12-20T19:38:22Z")

</div>

When working on a large model it is extremely useful to be able to manipulate large groups of variables or constraints.

To avoid repeating long lists of variable names or equations, it would be very useful if the the ‘plural macros’ (e.g. @variables and @constraints), returned collections of the newly defined objects.

For example I would like for

```julia
vars = @variables model begin
  x
  y[1:2]
end

```

to be equivalent to writing

```julia
@variables model begin
  x
  y[1:2]
end
vars = [x, y]

```

and

```julia
eqs = @NLconstraints model begin
  E_x, x == 1
  E_y[i ∈ 1:2], y[i] == x
end

```

should be equivalent to writing

```julia
@NLconstraints model begin
  E_x, x == 1
  E_y[i ∈ 1:2], y[i] == x
end
eqs = [E_x, E_y]

```

Note that this is not just a matter of laziness, but that repeating long lists of items is prone to hard-to-debug errors. I.e. spotting which item is missing in a large collection of variables or constraints can take a long time.

Has this feature been discussed before?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 21, 2021, 7:36pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397/2 "2021-12-21T19:36:26Z")

</div>

This seems reasonable.

Want to open an issue with this in the JuMP.jl GitHub repository? [https://github.com/jump-dev/JuMP.jl/issues](https://github.com/jump-dev/JuMP.jl/issues)

---

<div class="post-metadata">

**Author:** ![MartinBonde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinbonde/32/33200_2.png) [@MartinBonde](https://discourse.julialang.org/u/MartinBonde)\
**Post date:** [December 21, 2021, 7:46pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397/3 "2021-12-21T19:46:32Z")

</div>

Absolutely. I was about to open a “feature request” issue yesterday, but the documentation suggested that it might be worth discussing here first.

I have no experience with meta programming in Julia yet, but glancing at the source code it looks pretty manageable as all the plural versions of the macros are already implemented together in one place rather than for each macro.

---

<div class="post-metadata">

**Author:** ![MartinBonde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/martinbonde/32/33200_2.png) [@MartinBonde](https://discourse.julialang.org/u/MartinBonde)\
**Post date:** [December 21, 2021, 7:52pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397/4 "2021-12-21T19:52:15Z")

</div>

I have opened an issue here: [https://github.com/jump-dev/JuMP.jl/issues/2837](https://github.com/jump-dev/JuMP.jl/issues/2837)

This would also serve as a work-around for the issue where _list\_of\_constraint\_types_ and hence _all\_constraints_ do not work for non-linear constraints.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [December 21, 2021, 8:08pm UTC](https://discourse.julialang.org/t/plural-macros-e-g-variables-should-return-collection-of-the-defined-objects/73397/5 "2021-12-21T20:08:42Z")

</div>

I added `all_nl_constraints` which will be in the next JuMP release.
