modelica / ModelicaSpecification

Specification of the Modelica Language
https://specification.modelica.org
Creative Commons Attribution Share Alike 4.0 International
102 stars 41 forks source link

Shadowing time #1243

Open modelica-trac-importer opened 6 years ago

modelica-trac-importer commented 6 years ago

Reported by perost on 13 Aug 2013 09:22 UTC Is the built-in variable time allowed to be shadowed by another element? I.e. can you declare an element with the name time? The specification (3.6.7) only says that time is a built-in variable available in all models and blocks, which doesn't preclude declaring a local element with the name time. Allowing time to be shadowed causes some ambiguity though:

package P
  constant Real time = 1.0;

  model A
    Real x = time; // Which time is referenced here?
  end A;
end P;

Migrated-From: https://trac.modelica.org/Modelica/ticket/1243

henrikt-ma commented 3 years ago

Reopening, since I think this shows that the wording available in all models and blocks needs to be removed.

HansOlsson commented 2 years ago

Reopening, since I think this shows that the wording available in all models and blocks needs to be removed.

I don't see that we can just remove that; we could replace it by something else. I could see that we add the second sentence below:

The variable is a built-in variable available in all models and blocks, which is treated as an input variable. The name time is reserved and may not declared in any class.

henrikt-ma commented 2 years ago

Sounds good.

To me, it would make a lot of sense to give it keyword status, instead of ending up with the same sad situation as with Real and friends: things which are like keywords in every way except that the specification fails to give them full keyword status.

For example, things like this are trivially avoided if giving full keyword status:

type E = enumeration(one, more, time);
HansOlsson commented 2 years ago

Yes, having it as keyword would be best - because it doesn't fully work to view it as a variable.

Fully explanation: See https://github.com/modelica/ModelicaSpecification/pull/3090/files - that implies that each use time is sort of a separate variable. That was needed to fulfil the promise for clocked discretized partitions that any model can be discretized, so time in one such model can be clocked even though time in another partition is continuous. Normally the partitions are different model, but if you flatten the structure the same is needed in one model so it doesn't suffice to view time in different models as different variables - it must be each use of time, i.e., it is better to view it as a keyword and not a variable.