Skip to content

Commit

Permalink
Clarify variability of functions.
Browse files Browse the repository at this point in the history
Closes #2538
  • Loading branch information
HansOlsson committed Apr 30, 2021
1 parent 4103f30 commit c8b5039
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions chapters/functions.tex
Expand Up @@ -116,6 +116,29 @@ \subsection{Inheritance of Functions}\label{inheritance-of-functions}
For example, it is possible to modify and extend a \lstinline!function! class to add default values for input variables.
\end{nonnormative}

A special case is defining a \lstinline!function! as a short-class definition with modifiers for inputs inside a model.
These default values, unless overridden in the function call, will then be considered for variability similarly as if they were given in the function call.

\begin{example}
Demonstrating the variability implications.
Note that functions cannot directly use non-constants in enclosing scopes, so we cannot write \lstinline!input Real x1=x;! directly in \lstinline!foo!.
\begin{lstlisting}[language=modelica]
model M
function foo
input Real x1;
input Real x2=2;
output Real y;
algorithm
y:=x1+x2;
end foo;
Real x=time;
function f1=foo(x1=x);
constant Real z=f1(x2=1); // Illegal since 'x' is seen as argument
constant Real z2=f1(x1=2); // Legal, since 'x1' has a new value.
end M;
\end{lstlisting}
\end{example}

\section{Function as a Specialized Class}\label{function-as-a-specialized-class}

The function concept in Modelica is a specialized class (\cref{specialized-classes}).
Expand Down

0 comments on commit c8b5039

Please sign in to comment.