Jeremy Siek пре 9 година
родитељ
комит
b9a57ecd9a
1 измењених фајлова са 30 додато и 0 уклоњено
  1. 30 0
      book.tex

+ 30 - 0
book.tex

@@ -533,6 +533,36 @@ translated to the following one.
 \end{array}
 \]
 
+We recommend implementing \textsf{flatten} as a recursive function
+that returns two things, 1) the newly flattened expression, and 2) a
+list of assignment statements, one for each of the new variables
+introduced while flattening the expression.
+
+Take special care for programs such as the following that initialize
+variables with integers or other variables.
+\[
+\LET{a}{42}{ \LET{b}{x}{ y }}
+\]
+This program should be translated to 
+\[
+\begin{array}{l}
+\ASSIGN{a}{42}
+\ASSIGN{b}{x}
+\RETURN{b}
+\end{array}
+\]
+and not the following, which could result from a naive implementation
+of \textsf{flatten}
+\[
+\begin{array}{l}
+\ASSIGN{x.1}{42}\\
+\ASSIGN{a}{x.1}\\
+\ASSIGN{x.2}{a}\\
+\ASSIGN{y}{x.2}\\
+\RETURN{y}
+\end{array}
+\]
+
 
 \section{Select Instructions}