Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Swap the order of 'type-specifier' and 'array-subscripts'
This fixes the non-intuitive order when appending array dimensions in Modelica: ``` model ModelicaAppendDimensions type Arr = Real[3, 4]; Arr[1, 2] x = fill(0.0, 1, 2, 3, 4); /* Note: (Real[k, l])[m, n] is not the same as Real[k, l, m, n]. */ end ModelicaAppendDimensions; ``` With the order swapped, we get this instead: ``` model NaturalAppendDimensions type Arr = [3, 4] Real; [1, 2] Arr x = fill(0.0, 1, 2, 3, 4); /* Note: [k, l]([m, n]Real) is the same as Real[k, l, m, n]. */ end NaturalAppendDimensions; ```
- Loading branch information
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having dimension before the type, the handling inside the compiler might be some kind of natural, but from the user point of view I find it unusual and somehow very ugly.
Especially, in your example, I think you made a mistake:
should be
And this is, what it makes the handling somehow unnatural.
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also making such changes, the syntax of Flat Modelica diverges from Modelica to much, without real benefit.
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree.
And regarding examples I believe it is more helpful to say what something is the same as - and not what it isn't.
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gkurzbach, I think you missed the negation in the comment of
ModelicaAppendDimensions
(which is probably what @HansOlsson meant).The examples show what is the same as what by giving a
fill
call with the resulting dimensions. In this way, the negative example (ModelicaAppendDimensions
) shows that(Real[3, 4])[1, 2]
is the same asReal[1, 2, 3, 4]
— notReal[3, 4, 1, 2]
as one may naively think. I don't think I've ever met a person that doesn't find this counter-intuitive, which is why I wanted to give fixing it a try.The reason why I think this matters more for Modelica than some other popular languages is that one quite often encounters these nested arrays that have to be thought of as multidimensional, especially when creating modifiers.
Now that we've had some discussion around it, I'm expecting that we can decide what to do during tomorrow's meeting.
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for that, you are right.
So I'm even more in favor of removing dimensions on types at all. Also, we are defining FlatModelica and dimensions on types introduce some kind of hierarchical structure, which is against the aim to have a flat language, e.g.:
Are T3 and T4 equivalent? To answer such questions, the compiler has to flatten the hierarchy of declarations and that's what we want to avoid in the language.
4f01282
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposals:
in contrast to:
Using records to work around a lack of array type abstraction:
If we need of records of arrays anyways, then there is no relaxation in terms of complexity not supporting this abstraction.
To be revisited.
Next meeting Thursday Jan. 30, 9.00AM.