Skip to content

Commit

Permalink
Use comments instead of text escape in array indexing listing
Browse files Browse the repository at this point in the history
This makes the example more aligned with other examples, and thereby easier to read and understand.
  • Loading branch information
henrikt-ma committed Dec 28, 2020
1 parent 61bc454 commit d7fc47e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions chapters/arrays.tex
Original file line number Diff line number Diff line change
Expand Up @@ -969,15 +969,21 @@ \section{Array Indexing}\label{array-indexing}
\end{nonnormative}

\begin{example}
% henrikt-ma: This listing needs to be cleaned up from confusing punctuation.
\begin{lstlisting}[language=modelica, escapechar=!]
a[:, j] !\emph{is a vector of the j-th column of a,}!
a[j] !\emph{is a vector of the j-th row of a:}! a[j, :]
a[j : k] is {[a[j], a[j+1], ... , a[k]}
a[:,j : k] is [a[:,j], a[:,j+1], ... , a[:,k]],
v[2:2:8] = v[ {2,4,6,8} ] .
v[{j,k}] := {2,3}; // Same as v[j] := 2; v[k] := 3;
v[{1,1}] := {2,3}; // Same as v[1] := 3;
Array indexing expressions:
\begin{lstlisting}[language=modelica]
a[:, j] // Vector of the j-th column of a.
a[j] // Vector of the j-th row of a. Same as: a[j, :]
a[j : k] // Same as: {[a[j], a[j+1], $\ldots$, a[k]}
a[:, j : k] // Same as: [a[:, j], a[:, j+1], $\ldots$, a[:, k]]
\end{lstlisting}
The range vector operator is just a special case of a vector expression:
\begin{lstlisting}[language=modelica]
v[2 : 2 : 8] // Same as: v[{2, 4, 6, 8}]
\end{lstlisting}
Array indexing in assignment statements:
\begin{lstlisting}[language=modelica]
v[{j, k}] := {2, 3}; // Same as: v[j] := 2; v[k] := 3;
v[{1, 1}] := {2, 3}; // Same as: v[1] := 3;
\end{lstlisting}
If \lstinline!x! is a vector, \lstinline!x[1]! is a scalar, but the slice \lstinline!x[1:5]! is a vector
(a vector-valued or colon index expression causes a vector to be returned).
Expand Down

0 comments on commit d7fc47e

Please sign in to comment.