Skip to content

Commit

Permalink
Clarify that each can be inside an array.
Browse files Browse the repository at this point in the history
  • Loading branch information
HansOlsson committed Dec 13, 2022
1 parent 00abf66 commit c646156
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion chapters/inheritance.tex
Expand Up @@ -459,7 +459,7 @@ \subsection{Modifiers for Array Elements}\label{modifiers-for-array-elements}
The following rules apply to modifiers:
\begin{itemize}
\item
The \lstinline!each!\indexinline{each} keyword on a modifier requires that it is applied in an array declaration/modification, and the modifier is applied individually to each element of the enclosing array (with regard to the position of \lstinline!each!).
The \lstinline!each!\indexinline{each} keyword on a modifier requires that it is applied inside an array declaration or modification of an array, and the modifier is applied individually to each element of the enclosing array (with regard to the position of \lstinline!each!).
In case of nested modifiers this implies it is applied individually to each element of each element of the enclosing array; see example.
If the modified element is a vector and the modifier does not contain the \lstinline!each! prefix, the modification is split such that the first element in the vector is applied to the first element of the vector of elements, the second to the second element, until the last element of the vector is applied to the last element of the array; it is an error if these sizes do not match.
Matrices and general arrays of elements are treated by viewing those as vectors of vectors etc.
Expand Down Expand Up @@ -508,6 +508,15 @@ \subsection{Modifiers for Array Elements}\label{modifiers-for-array-elements}
Real[2] work2(each start = 2); // Legal
end F;
\end{lstlisting}
Note that the array is not necessarily the closest enclosing identifier.
\begin{lstlisting}[language=modelica]
model G
C c[2]( each a = {1, 2, 3}, d(start={4, 5}, each fixed=true));
// The second each relies on c being an array,
// without the second each we would have to write:
C c2[2]( each a = {1, 2, 3}, d(start={4, 5}, fixed=fill(true, 2)));
end G;
\end{lstlisting}
\end{example}

\subsection{Final Element Modification Prevention}\label{final-element-modification-prevention}
Expand Down

0 comments on commit c646156

Please sign in to comment.