Jeremy Siek преди 3 години
родител
ревизия
2bc2474356
променени са 2 файла, в които са добавени 59 реда и са изтрити 10 реда
  1. 55 8
      book.tex
  2. 4 2
      defs.tex

+ 55 - 8
book.tex

@@ -25,7 +25,7 @@
 
 \def\racketEd{0}
 \def\pythonEd{1}
-\def\edition{0}
+\def\edition{1}
 
 % material that is specific to the Racket edition of the book
 \newcommand{\racket}[1]{{\if\edition\racketEd{#1}\fi}}
@@ -14405,10 +14405,9 @@ mainconclusion:
 \index{subject}{lambda}
 \index{subject}{lexical scoping}
 
-This chapter studies lexically scoped functions as they appear in
-functional languages such as Racket. By lexical scoping we mean that a
-function's body may refer to variables whose binding site is outside
-of the function, in an enclosing scope.
+This chapter studies lexically scoped functions. Lexical scoping means
+that a function's body may refer to variables whose binding site is
+outside of the function, in an enclosing scope.
 %
 Consider the example in Figure~\ref{fig:lexical-scoping} written in
 \LangLam{}, which extends \LangFun{} with anonymous functions using the
@@ -14455,7 +14454,6 @@ functions because they use different values for \code{x}. Applying
 \label{fig:lexical-scoping}
 \end{figure}
 
-
 The approach that we take for implementing lexically scoped functions
 is to compile them into top-level function definitions, translating
 from \LangLam{} into \LangFun{}.  However, the compiler must give
@@ -14471,7 +14469,9 @@ inside $e$ but does not have an enclosing binding that is also in
 $e$.\index{subject}{free variable}
 \end{definition}
 
-For example, in the expression \code{(+ x (+ y z))} the variables
+For example, in the expression
+\racket{\code{(+ x (+ y z))}}\python{\code{x + y + z}}
+the variables
 \code{x}, \code{y}, and \code{z} are all free.  On the other hand,
 only \code{x} and \code{y} are free in the following expression
 because \code{z} is bound by the \code{lambda}.
@@ -14568,6 +14568,17 @@ syntax for function application.
   \end{array}
 }
 
+\newcommand{\LlambdaGrammarPython}{
+  \begin{array}{lcl}
+  \Exp &::=& \CLAMBDA{\Var \code{,} \ldots}{\Exp} 
+  \end{array}
+}
+\newcommand{\LlambdaASTPython}{
+  \begin{array}{lcl}
+  \Exp &::=& \LAMBDA{\LS\Var\code{, }\ldots\RS}{\Exp}
+  \end{array}
+}
+
 % include AnnAssign in ASTPython
 
 \begin{figure}[tp]
@@ -14575,6 +14586,7 @@ syntax for function application.
 \fbox{
   \begin{minipage}{0.96\textwidth}
     \small
+{\if\edition\racketEd
 \[
 \begin{array}{l}
   \gray{\LintGrammarRacket{}} \\ \hline
@@ -14589,6 +14601,23 @@ syntax for function application.
   \end{array}
 \end{array}
 \]
+\fi}
+{\if\edition\pythonEd
+\[
+\begin{array}{l}
+  \gray{\LintGrammarPython{}} \\ \hline
+  \gray{\LvarGrammarPython{}} \\ \hline
+  \gray{\LifGrammarPython{}} \\ \hline
+  \gray{\LwhileGrammarPython} \\ \hline
+  \gray{\LtupGrammarPython} \\   \hline
+  \gray{\LfunGrammarPython} \\   \hline
+  \LlambdaGrammarPython \\
+  \begin{array}{lcl}
+  \LangLamM{} &::=& \Def^{*} \Stmt^{*}
+  \end{array}
+\end{array}
+\]
+\fi}
 \end{minipage}
 }
 \caption{The concrete syntax of \LangLam{}, extending \LangFun{} (Figure~\ref{fig:Rfun-concrete-syntax}) 
@@ -14601,6 +14630,7 @@ syntax for function application.
 \fbox{
   \begin{minipage}{0.96\textwidth}
     \small
+{\if\edition\racketEd
 \[
 \begin{array}{l}
   \gray{\LintOpAST} \\ \hline
@@ -14611,10 +14641,27 @@ syntax for function application.
   \gray{\LfunASTRacket} \\ \hline
   \LlambdaASTRacket \\
   \begin{array}{lcl}
-  \LangLamM{} &::=& \gray{ \PROGRAMDEFSEXP{\code{'()}}{\LP\Def\ldots\RP}{\Exp} }
+  \LangLamM{} &::=& \PROGRAMDEFSEXP{\code{'()}}{\LP\Def\ldots\RP}{\Exp}
   \end{array}
 \end{array}
 \]
+\fi}
+{\if\edition\pythonEd
+\[
+\begin{array}{l}
+  \gray{\LintASTPython} \\ \hline
+  \gray{\LvarASTPython{}} \\ \hline
+  \gray{\LifASTPython{}} \\ \hline
+  \gray{\LwhileASTPython{}} \\ \hline
+  \gray{\LtupASTPython{}} \\ \hline
+  \gray{\LfunASTPython} \\ \hline
+  \LlambdaASTPython \\
+  \begin{array}{lcl}
+  \LangLamM{} &::=& \PROGRAM{}{\LS \Def \ldots \Stmt \ldots \RS}
+  \end{array}
+\end{array}
+\]
+\fi}
 \end{minipage}
 }
 \caption{The abstract syntax of \LangLam{}, extending \LangFun{} (Figure~\ref{fig:Rfun-syntax}).}

+ 4 - 2
defs.tex

@@ -259,8 +259,6 @@
 \newcommand{\VOID}[1]{\key{(Void)}}
 \newcommand{\FUNREFARITY}[2]{\key{(FunRefArity}~#1~#2\code{)}}
 \newcommand{\CFUNREFARITY}[2]{\key{(fun-ref-arity}~#1~#2\code{)}}
-\newcommand{\LAMBDA}[3]{\key{(Lambda}~#1~#2~#3\code{)}}
-\newcommand{\CLAMBDA}[3]{\LP\key{lambda:}\,#1\,\key{:}\,#2~\Exp\RP}
 \newcommand{\CGLAMBDA}[3]{\LP\key{lambda:}\,#1\,#2~\Exp\RP}
 \newcommand{\INJECT}[2]{\LP\key{Inject}~#1~#2\RP}
 \newcommand{\PROJECT}[2]{\LP\key{Project}~#1~#2\RP}
@@ -269,6 +267,8 @@
 \newcommand{\VALUEOF}[2]{\LP\key{ValueOf}~#1~#2\RP}
 
 \if\edition\racketEd
+\newcommand{\LAMBDA}[3]{\key{(Lambda}~#1~#2~#3\code{)}}
+\newcommand{\CLAMBDA}[3]{\LP\key{lambda:}\,#1\,\key{:}\,#2~\Exp\RP}
 \newcommand{\TAILCALL}[2]{\key{(TailCall}~#1~#2\code{)}}
 \newcommand{\CASSIGN}[2]{#1~\key{=}~#2\key{;}}
 \newcommand{\ASSIGN}[2]{\key{(Assign}~#1~#2\key{)}}
@@ -280,6 +280,8 @@
 \newcommand{\FUNDEF}[5]{\key{(Def}~#1~#2~#3~#4~#5\code{)}}
 \fi
 \if\edition\pythonEd
+\newcommand{\LAMBDA}[2]{\key{Lambda}\LP#1\key{, }#2\RP}
+\newcommand{\CLAMBDA}[2]{\key{lambda}\,#1\,\key{:}\,#2}
 \newcommand{\TAILCALL}[2]{\key{TailCall}\LP#1\code{,}#2\RP}
 \newcommand{\CASSIGN}[2]{#1~\key{=}~#2}
 \newcommand{\ASSIGN}[2]{\key{Assign}\LP\LS #1\RS\key{, }#2\RP}