Peter Thiemann 3 rokov pred
rodič
commit
bda4b504b3
1 zmenil súbory, kde vykonal 43 pridanie a 4 odobranie
  1. 43 4
      book.tex

+ 43 - 4
book.tex

@@ -8070,12 +8070,22 @@ statements created by applying \code{create\_block} to the code
 generated for the \code{thn} and \code{els} branches. Let us
 illustrate this translation with an example.  Returning
 to the program with an \code{if} expression in tail position,
-we invoke \code{explicate\_pred} on its condition \code{(eq? x 0)}
+we invoke \code{explicate\_pred} on its condition
+\racket{\code{(eq? x 0)}}
+\python{\code{x == 0}}
 which happens to be a comparison operator.
+{\if\edition\racketEd
 \begin{lstlisting}
 (let ([x (read)])
   (if (eq? x 0) 42 777))
 \end{lstlisting}
+  \fi}
+{\if\edition\pythonEd
+\begin{lstlisting}
+x = input_int()
+42 if x == 0 else 777
+\end{lstlisting}
+  \fi}
 The two branches \code{42} and \code{777} were already compiled to \code{return}
 statements, from which we now create the following blocks.
 \begin{center}
@@ -8089,9 +8099,12 @@ block_2:
   \end{minipage}
 \end{center}
 %
-So \code{explicate\_pred} compiles the comparison \code{(eq? x 0)}
+So \code{explicate\_pred} compiles the comparison
+\racket{\code{(eq? x 0)}}
+\python{\code{x == 0}}
 to the following \code{if} statement.
 %
+{\if\edition\racketEd
 \begin{center}
 \begin{minipage}{\textwidth}
 \begin{lstlisting}
@@ -8102,12 +8115,25 @@ else
 \end{lstlisting}
 \end{minipage}
 \end{center}
-
+\fi}
+{\if\edition\pythonEd
+\begin{center}
+\begin{minipage}{\textwidth}
+\begin{lstlisting}
+if x == 0:
+   goto block_1;
+else
+   goto block_2;
+\end{lstlisting}
+\end{minipage}
+\end{center}
+\fi}
 Next consider the case for Boolean constants. We perform a kind of
 partial evaluation\index{subject}{partial evaluation} and output
 either the \code{thn} or \code{els} branch depending on whether the
 constant is \TRUE{} or \FALSE{}. Let us illustrate this with the
 following program.
+{\if\edition\racketEd
 \begin{center}
 \begin{minipage}{\textwidth}
 \begin{lstlisting}
@@ -8115,10 +8141,23 @@ following program.
 \end{lstlisting}
 \end{minipage}
 \end{center}
+\fi}
+{\if\edition\pythonEd
+\begin{center}
+\begin{minipage}{\textwidth}
+\begin{lstlisting}
+42 if True else 777
+\end{lstlisting}
+\end{minipage}
+\end{center}
+\fi}
 %
 Again, the two branches \code{42} and \code{777} were compiled to
 \code{return} statements, so \code{explicate\_pred} compiles the
-constant \code{\#t} to the code for the ``then'' branch.
+constant
+\racket{\code{\#t}}
+\python{\code{True}}
+to the code for the ``then'' branch.
 \begin{center}
 \begin{minipage}{\textwidth}
 \begin{lstlisting}