# How to interface between functional and macro syntax in MTK

**URL:** https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501
**Category:** Modelling & Simulations
**Created:** [April 28, 2025, 7:32pm UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501 "2025-04-28T19:32:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Matthew1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthew1/32/215134_2.png) [@Matthew1](https://discourse.julialang.org/u/Matthew1)
#### Post date: [April 28, 2025, 7:32pm UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501/1 "2025-04-28T19:32:42Z")

</div>

How does one pass structural parameters from a @mtkmodel to a @component function? Is it possible to sort of convert between the positional syntax of @component function to the keyword syntax of @mtkmodel (for structural parameters)? As an example, how would one do the following?

```julia
@component function Subsystem(B; d, name)

    vars = @variables begin
        (y(t))[1:B]
    end

    eqs = [
        D(y) ~ d*y
    ]

    ODESystem(eqs, t, vars, eqs; name)
end

@mtkmodel Example2 begin
    
    @structural_parameters begin
        A = 1
        B = 2
    end

    @parameters begin
        c
        d
    end

    @components begin
        subsystem = Subsystem(B; d=d)
    end
end

A = 10
B = 20
c = 4.67
d = 2.34

@mtkbuild correct_method = Example2(A=A, B=B, c=c, d=d)

```

MethodError: no method matching Subsystem(; B::Int64, name::Symbol, d::Num)  
The function `Subsystem` exists, but no method is defined for this combination of argument types.

Closest candidates are:  
Subsystem(::Any; d, name) got unsupported keyword argument “B”  
@ Main C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2461

Stacktrace:  
[1] macro expansion  
@ C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2295 [inlined]  
[2] **Example2** (; name::Symbol, A::Int64, B::Int64, c::Float64, d::Float64, subsystem\_\_d::Nothing, subsystem\_\_B::Nothing)  
@ Main C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\model\_parsing.jl:1203  
[3] (::ModelingToolkit.Model{typeof( **Example2** ), Dict{Symbol, Any}})(; kw::@Kwargs{name::Symbol, A::Int64, B::Int64, c::Float64, d::Float64})  
@ ModelingToolkit C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\model\_parsing.jl:25  
[4] top-level scope  
@ C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2295

---

<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: [April 29, 2025, 8:22am UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501/2 "2025-04-29T08:22:34Z")

</div>

> [@Matthew1](#):
>
> MethodError: no method matching Subsystem(; B::Int64, name::Symbol, d::Num)  
> The function `Subsystem` exists, but no method is defined for this combination of argument types.
> 
> Closest candidates are:  
> Subsystem(::Any; d, name) got unsupported keyword argument “B”

You have `B` as a positional argument, not a keyword argument. The macro requires it to be a keyword argument.

---

<div class="post-metadata">

### Author: ![Matthew1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthew1/32/215134_2.png) [@Matthew1](https://discourse.julialang.org/u/Matthew1)
#### Post date: [April 29, 2025, 9:39am UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501/3 "2025-04-29T09:39:23Z")

</div>

But B needs to be a positional argument in Subsystem, so that it is defined as a non-symbolic parameter, right? So how to have B (non-symbolic parameter) as positional for @component function Subsystem, but keyword when calling it in macro?

Also being discussed here: [Interpolations component cannot be used within @mtkmodel macro · Issue #340 · SciML/ModelingToolkitStandardLibrary.jl · GitHub](https://github.com/SciML/ModelingToolkitStandardLibrary.jl/issues/340)

---

<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: [April 29, 2025, 9:49am UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501/4 "2025-04-29T09:49:42Z")

</div>

Why not just make it a keyword argument?

---

<div class="post-metadata">

### Author: ![Matthew1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matthew1/32/215134_2.png) [@Matthew1](https://discourse.julialang.org/u/Matthew1)
#### Post date: [April 29, 2025, 12:56pm UTC](https://discourse.julialang.org/t/how-to-interface-between-functional-and-macro-syntax-in-mtk/128501/5 "2025-04-29T12:56:25Z")

</div>

Thank you Chris.
