Allow calling impure functions in clocked equations/statements
In 12.3 Pure Modelica Functions there is a list of situations where it's allowed to call an impure function, it doesn't mention clocked equations/statements. Shouldn't it be allowed there as well?
model M
Clock c = Clock(1);
Real x;
Real y;
equation
x = sample(time, c);
y = impureFunction(x);
end M;
Feels a bit unnecessary to require the y = ... to be wrapped with when Clock() then.
On one hand I see that point, but on the other hand I see a problem with usability and diagnostics.
Consider:
model M
input Real x;
output Real y;
equation
y = impureFunction(x);
end M;
model A
M m(x=sample(time, Clock(1));
end A;
Here the call is ok in A - but in M it would not be legal as it is not clocked. Assuming we want to allow the first model, the question is what to do with M:
- Say that it is illegal and have some weird rule that it must be clocked in the same model. (Not clear how.)
- Say that it is legal in
Aand give diagnostics forMignoring that possibility. (Users of the feature will complain.) - Say that it is legal in
Aand give diagnostics forMincluding that possibility, which will mean that every use of impure functions we have to include it.
Based on that I find the idea of explicitly making it clocked
model M
input Real x;
output Real y;
equation
when Clock() then
y = impureFunction(x);
end when;
end M;
an acceptable way of writing to avoid all of that.
As follow-up, having some other way of making models/blocks clocked is also something we could consider, but we would then need to differentiate between a model being clocked, vs. clocked with one clock.
I your example I would say M is illegal therefore A is also illegal.
I your example I would say
Mis illegal thereforeAis also illegal.
But if they are illegal, I find it difficult to say that the equations are legal "just" because it is part of the same model (I realize that the discussion would benefit from having different names for the different models :-)