Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Least and greatest value of empty enumeration #3647

Open
henrikt-ma opened this issue Feb 6, 2025 · 3 comments
Open

Least and greatest value of empty enumeration #3647

henrikt-ma opened this issue Feb 6, 2025 · 3 comments
Assignees

Comments

@henrikt-ma
Copy link
Collaborator

The grammar allows an enumeration to not have any literals (by making the enum-list optional), but why?

short-class-specifier :
   IDENT "=" base-prefix type-specifier [ array-subscripts ]
   [ class-modification ] description
   | IDENT "=" enumeration "(" ( [ enum-list ] | ":" ) ")" description

As long as it is allowed we have a problem with models like this, where the greatest value of the enumeration is needed:

model EmptyEnumeration
  type E = enumeration();
  parameter Integer n = 0;
  Integer k = Integer(min({ E(i) for i in 1:n }));
end EmptyEnumeration;
@perost
Copy link
Collaborator

perost commented Feb 6, 2025

OpenModelica doesn't follow the grammar here and gives a syntax error for the empty enumeration. But I guess that just confirms that there shouldn't be any issue with making enum-list required.

@HansOlsson
Copy link
Collaborator

As I recall one issue with enumerations was sub/super-typing, and there were some discussions about being able to add enumeration members later. That was then restricted to just using enumeration(:) as constraining type - and one guess would be that enumeration() was an early variant of that.

@HansOlsson
Copy link
Collaborator

I realized that with replaceable enumerations there might be a use-case:

  model M
    replaceable type E=enumeration(:);
    Real x[E](each start=0);
  equation 
    der(x)=ones(size(x,1))-x;
  end M;
  M m1(redeclare type E=enumeration());
  M m2(redeclare type E=enumeration(A, B));

For examples, if someone wants to have trace-products with names it might make sense to allow none as well.

For some reason Dymola generates 0 as minimum for the missing enumeration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants