# @variables parsing breaks on default value?

**URL:** https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970
**Category:** Modelling & Simulations
**Tags:** modelingtoolkit
**Created:** [June 18, 2022, 3:08pm UTC](https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970 "2022-06-18T15:08:39Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [June 18, 2022, 3:08pm UTC](https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970/1 "2022-06-18T15:08:39Z")

</div>

This code snippet:

```julia
sts = @variables begin
    m_flow(t), [connect=Flow],
    T(t)=T0, [connect=Stream]
end

```

Fails with:

```julia
LoadError: AssertionError: @variables expects a tuple of expressions or an expression of a tuple (`@variables x y z(t) v[1:3] w[1:2,1:4]` or `@variables x y z(t) v[1:3] w[1:2,1:4] k=1.0`)

```

This issue goes away when `=T0` is removed,

Note that:

```julia
@variables T(t)=T0, [connect=Stream]

```

also fails, but with a different error:

```julia
syntax: misplaced assignment statement in "[connect = Stream]" around In[2]:1

```

without the comma, works fine:

```julia
@variables T(t)=T0 [connect=Stream]

```

However, in this format (without the comma) doesn’t work in a multiline `@variables` declaration:

```julia
@variables begin
    m_flow(t) [connect=Flow]
    T(t)=T0 [connect=Stream]
end
# syntax: space before "[" not allowed in "m_flow(t) [" at In[3]:2

```

Is this a bug? or is there a _correct_ way to define these variables?

DD

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 18, 2022, 5:40pm UTC](https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970/2 "2022-06-18T17:40:17Z")

</div>

Those commas are all incorrect. That use of commas isn’t anywhere in the docs right?

The last one should work and looks like a parsing error. Open an issue on that one. We should make a multiline `@variables` with metadata and add it to the docs with a doctest in:

[https://mtk.sciml.ai/v8.14/basics/ContextualVariables/#Variable-metadata-[Experimental/TODO]](https://mtk.sciml.ai/v8.14/basics/ContextualVariables/#Variable-metadata-%5BExperimental/TODO%5D)

As the docs say, extensive use of the metadata is still a bit “Experimental/TODO”, but close enough to be in the uncanny valley.

---

<div class="post-metadata">

### Author: ![dodoplus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dodoplus/32/30148_2.png) [@dodoplus](https://discourse.julialang.org/u/dodoplus)
#### Post date: [June 18, 2022, 6:16pm UTC](https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970/3 "2022-06-18T18:16:24Z")

</div>

This is from the [docs](https://mtk.sciml.ai/dev/basics/Validation/#units)

```julia
@variables t [unit = u"s"] x(t) [unit = u"m"] g(t) w(t) [unit = "Hz"]

@variables(t, [unit = u"s"], x(t), [unit = u"m"], g(t), w(t), [unit = "Hz"])

```

and this is from a [test](https://github.com/SciML/ModelingToolkit.jl/blob/master/test/variable_parsing.jl)

```julia
@variables begin
    x = [1, 2], [connect = Flow, unit = u]
    y = 2
end

```

However, seems I’ve added an extra comma. That said, it doesn’t seem to matter:

```julia
sts = @variables begin
    m_flow(t), [connect=Flow]
    T(t)=T0, [connect=Stream]
end
#syntax: misplaced assignment statement in "[connect = Stream]" around In[5]:2

```

which is weird, since this is very similar to the test above.

---

<div class="post-metadata">

### Author: ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)
#### Post date: [June 18, 2022, 6:18pm UTC](https://discourse.julialang.org/t/variables-parsing-breaks-on-default-value/82970/4 "2022-06-18T18:18:39Z")

</div>

> [@dodoplus](#):
>
> This is from the [docs](https://mtk.sciml.ai/dev/basics/Validation/#units)

That’s just how Julia parses macros. If you do `@macro()` you have to put commas for the arguments, but if it’s not used as a function it’s done by space.

> [@dodoplus](#):
>
> which is weird, since this is very similar to the test above.

Yeah, looks like you found something the test didn’t. That’s worth an issue.
