Open baggepinnen opened 1 month ago
One must list all the args (parameter or variable), of a sub-component or a base-system, that should be added to the arglist of the main-component.
This will fix the issue:
@mtkmodel Outer begin
@extend () = v = Inner(; color, render)
@parameters begin
radius = 0.1, [description = "Radius of the sphere in animations"]
end
end
The component that is extended may have 10s-100s of parameters and variables, if we have to type them all out it kind-of defeats the purpose of extending something in the first place?
It was mainly to keep the syntax same in both cases. If it is more convenient, I can modify the case for extend
to automatically add all args.
I can modify the case for extend to automatically add all args.
That sounds good to me, and aligns with what I would expect from inheritance
The problem with adding the args explicitly after extending is that they are not optional anymore. You always have to provide color
argument, even though Inner
has defaults defined for it.
That might be a problem with the current implementation, it does not mean that we can't change the implementation to something better?
Note that, even now mtkmodel handles it gracefully. It adds nothing
as default value and internally checks if input is provided and updates suitably. So you would not have to always provide an input.
Extending all args to main component automatically, will also handle it the same way; all args will be available but remain optional. (I expect this to land soon)
It was mainly to keep the syntax same in both cases. If it is more convenient, I can modify the case for
extend
to automatically add all args.
Good.
Another @extend
issue, please see #2758:
Still in current version v9.46.1, when @extend
multiple times, only the last one takes effect,
that is, only the last extended component in the :extend
field of ModelingToolkit.Model
Thanks @ven-k
When using
@mtkmodel
and@extend
, the constructor does not know about the parameters of the extended system. MWE: