4. Prozedurales Programmieren
4. Prozedurales Programmieren
4. Prozedurales Programmieren
Sie wollen auch ein ePaper? Erhöhen Sie die Reichweite Ihrer Titel.
YUMPU macht aus Druck-PDFs automatisch weboptimierte ePaper, die Google liebt.
Für obiges Transformationsbeispiel (Folie <strong>4.</strong>88)<br />
ergibt sich mit der Regel:<br />
p ≡ maxlrep ,<br />
T1 ≡ int, x1 ≡ aktmax,<br />
T2 ≡ IntList , x2 ≡ il,<br />
B ≡ isempty(il)<br />
C ≡ res = aktmax;<br />
D ≡ // leere Anweisung<br />
A1 ≡ max(aktmax,head(il))<br />
A2 ≡ tail(il)<br />
A1, A2 und B sind seiteneffektfrei;<br />
C und D enthalten keinen Aufruf von maxlrep;<br />
die Regel ist also auf maxlrep anwendbar und<br />
liefert:<br />
void maxlrep( int y1, IntList y2) {<br />
int aktmax = y1;<br />
IntList il = y2;<br />
while( !isempty(il) ) {<br />
aktmax = max(aktmax,head(il));<br />
il = tail(il);<br />
}<br />
res = aktmax;<br />
}<br />
Durch konsistente Parameterumbenennung erhält<br />
man die Prozedur von Folie <strong>4.</strong>89.<br />
0<strong>4.</strong>12.08 © A. Poetzsch-Heffter, TU Kaiserslautern<br />
93