You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using @mtkmodel macro syntax to describe a system that includes a component that uses a function, I cannot pass its function as a positional arg with -> anonymous syntax:
I expected two things here — one is that TimeVaryingFunction is documented with its argument as positional, not kwarg — and the positional syntax works as I expected in the @component macro. The other is that the anonymous function syntax gives a bad error message.
This does work if I use a kwarg, but I didn't understand why without looking at what the macro was doing:
julia>@mtkmodel Example begin@componentsbegin
x =TimeVaryingFunction(f=x->x^2)
endend
ModelingToolkit.Model{typeof(__Example__), Dict{Symbol, Any}}(__Example__, Dict{Symbol, Any}(:components=> Any[Union{Expr, Symbol}[:x, :TimeVaryingFunction]], :independent_variable=> t), false)
The equivalent model with the @component macro works as I naively expected, and the docstring also led me to believe this should work:
help?> TimeVaryingFunction
search: TimeVaryingFunction
TimeVaryingFunction(f; name)
Outputs f(t).
The input variable t can be changed by passing a different variable as the keyword argument t.
Environment (please complete the following information):
Describe the bug 🐞
When using
@mtkmodel
macro syntax to describe a system that includes a component that uses a function, I cannot pass its function as a positional arg with->
anonymous syntax:I also cannot pass named functions directly:
Expected behavior
I expected two things here — one is that
TimeVaryingFunction
is documented with its argument as positional, not kwarg — and the positional syntax works as I expected in the@component
macro. The other is that the anonymous function syntax gives a bad error message.This does work if I use a kwarg, but I didn't understand why without looking at what the macro was doing:
The equivalent model with the
@component
macro works as I naively expected, and the docstring also led me to believe this should work:Environment (please complete the following information):
using Pkg; Pkg.status()
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
versioninfo()
The text was updated successfully, but these errors were encountered: