# ArgMacros: How to use variables as defaults?

**URL:** <https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717>\
**Category:** General Usage\
**Tags:** command-line-options\
**Created:** [February 10, 2025, 3:24am UTC](https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717 "2025-02-10T03:24:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [February 10, 2025, 3:24am UTC](https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717/1 "2025-02-10T03:24:48Z")

</div>

How do you use variables within `@tuplearguments` of `ArgMacros`?

```julia
#!/usr/bin/env julia

const usage = "thisscript [--val1=<val1>] [--val2=<val2>]"
const val2_default = 9

args = @tuplearguments begin
  @helpusage Main.usage # -> no method matching var"@helpusage"( . . .
  @argumentdefault Int 3 val1 "--val1"
  @argumentdefault Int Main.val2_default val2 "--val2"
end
@show args

```

In the above, I tried to use two global variables within the macro call. One attempt fails: `Main.usage` causes a “no method” error. The other is _90% successful:_ `Main.val2_default` fetches the correct value (when `@helpusage` uses a String literal) but the help message shows

```julia
. . .
--val2
      (Type: Int, Default: Main.val2_default)

```

I’m sure that I’m not able to solve this problem only because I don’t know “these things” well enough.

---

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [February 10, 2025, 9:12am UTC](https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717/2 "2025-02-10T09:12:44Z")

</div>

Hi!

I’m not familiar with the ArgMacros.jl package, but by looking at its documentation, I’d say that you aren’t allowed to use variables and named constants in the macros for usage string and default values; you must inline these. I.e.,

```julia
args = @tuplearguments begin
  @helpusage "thisscript [--val1=<val1>] [--val2=<val2>]"
  @argumentdefault Int 3 val1 "--val1"
  @argumentdefault Int 9 val2 "--val2"
end
@show args

```

---

<div class="post-metadata">

**Author:** ![ryofurue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ryofurue/32/24531_2.png) [@ryofurue](https://discourse.julialang.org/u/ryofurue)\
**Post date:** [February 11, 2025, 12:07pm UTC](https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717/3 "2025-02-11T12:07:39Z")

</div>

> you aren’t allowed

Do you think that that represents 1) an inherent (insurmountable) restriction, 2) a deliberate design decision for some reason, 3) a complexity that would result if variables are allowed? Again I’m not at all familiar with how macro works . . .

---

<div class="post-metadata">

**Author:** ![HanD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hand/32/213908_2.png) [@HanD](https://discourse.julialang.org/u/HanD)\
**Post date:** [February 12, 2025, 10:34am UTC](https://discourse.julialang.org/t/argmacros-how-to-use-variables-as-defaults/125717/4 "2025-02-12T10:34:52Z")

</div>

I’d guess it is an inherent restriction, because the macro implementation relies on the fact that these values are known at parse time. Perhaps it would be possible to adjust the macro to accept variables/constants as well las literals, but it would certainly complicate things.

So it’s either 1 or 3, I’m not sure which without deeper investigation.
