From c646156ef5813ec771c4ee8f73be4cb7ffac7856 Mon Sep 17 00:00:00 2001 From: HOS Date: Tue, 13 Dec 2022 14:38:28 +0100 Subject: [PATCH] Clarify that each can be inside an array. Closes #3052 --- chapters/inheritance.tex | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/chapters/inheritance.tex b/chapters/inheritance.tex index 224f033f1..c162af59d 100644 --- a/chapters/inheritance.tex +++ b/chapters/inheritance.tex @@ -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. @@ -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}