From 8a5d6ef4a0a8f09d1a3a995484bc36d892687bd7 Mon Sep 17 00:00:00 2001 From: Henrik Tidefelt Date: Tue, 8 Jul 2025 09:02:19 +0200 Subject: [PATCH] Update purity exception for Streams.print Reformulating to match the current MSL where 'print' is declared impure. --- chapters/functions.tex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chapters/functions.tex b/chapters/functions.tex index 1438010f0..0685fcdfa 100644 --- a/chapters/functions.tex +++ b/chapters/functions.tex @@ -290,11 +290,13 @@ \section{Pure Modelica Functions}\label{pure-modelica-functions} Binding equations for external objects. \end{itemize} +An exception is made for \lstinline!Modelica.Utilities.Streams.print!, for which none of the impure function restrictions apply. + It is an error if an impure function call is part of a systems of equations (including linear systems), even if called in agreement with the restrictions above. The reason is that solving systems of equations generally requires expressions to be evaluated an unknown number of times. This includes the special handling of \lstinline!when initial()! during initialization. -There are two ways in which an impure function could be called in a system of equations, namely in the deprecated case of external functions assumed to be impure, and when using \lstinline!pure($\ldots$)! to call an impure function from within a pure function. +There are three ways in which an impure function could be called in a system of equations, namely in the deprecated case of external functions assumed to be impure, when using \lstinline!pure($\ldots$)! to call an impure function from within a pure function, and the exception for \lstinline!Modelica.Utilities.Streams.print!. The side-effect semantics of the function call are then undefined. Specifically, the number of calls with external side-effects is unspecified. However, for impure functions where the outputs only depend on the inputs the system of equations should be solved correctly.