|
@@ -14536,9 +14536,9 @@ mainconclusion:
|
|
|
\index{subject}{lambda}
|
|
|
\index{subject}{lexical scoping}
|
|
|
|
|
|
-This chapter studies lexically scoped functions, that is, functions
|
|
|
-whose body may refer to variables that are bound 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 lexically scoped functions
|
|
@@ -14586,7 +14586,6 @@ produces \code{20} whereas applying \code{h} to \code{15} produces
|
|
|
\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
|
|
@@ -14745,10 +14744,10 @@ a type annotation for the variable on the left-hand side.}
|
|
|
\gray{\LvarGrammarPython{}} \\ \hline
|
|
|
\gray{\LifGrammarPython{}} \\ \hline
|
|
|
\gray{\LwhileGrammarPython} \\ \hline
|
|
|
- \gray{\LtupGrammarPython} \\ \hline
|
|
|
- \gray{\LfunGrammarPython} \\ \hline
|
|
|
+ \gray{\LtupGrammarPython} \\ \hline
|
|
|
+ \gray{\LfunGrammarPython} \\ \hline
|
|
|
\LlambdaGrammarPython \\
|
|
|
- \begin{array}{rcl}
|
|
|
+ \begin{array}{lcl}
|
|
|
\LangFunM{} &::=& \Def\ldots \Stmt\ldots
|
|
|
\end{array}
|
|
|
\end{array}
|
|
@@ -14777,7 +14776,7 @@ a type annotation for the variable on the left-hand side.}
|
|
|
\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}
|
|
|
\]
|
|
@@ -14785,16 +14784,16 @@ a type annotation for the variable on the left-hand side.}
|
|
|
{\if\edition\pythonEd
|
|
|
\[
|
|
|
\begin{array}{l}
|
|
|
- \gray{\LintASTPython{}} \\ \hline
|
|
|
+ \gray{\LintASTPython} \\ \hline
|
|
|
\gray{\LvarASTPython{}} \\ \hline
|
|
|
\gray{\LifASTPython{}} \\ \hline
|
|
|
- \gray{\LwhileASTPython} \\ \hline
|
|
|
- \gray{\LtupASTPython} \\ \hline
|
|
|
+ \gray{\LwhileASTPython{}} \\ \hline
|
|
|
+ \gray{\LtupASTPython{}} \\ \hline
|
|
|
\gray{\LfunASTPython} \\ \hline
|
|
|
\LlambdaASTPython \\
|
|
|
-\begin{array}{rcl}
|
|
|
- \LangFunM{} &::=& \PROGRAM{}{\LS \Def \ldots \Stmt \ldots \RS}
|
|
|
-\end{array}
|
|
|
+ \begin{array}{lcl}
|
|
|
+ \LangLamM{} &::=& \PROGRAM{}{\LS \Def \ldots \Stmt \ldots \RS}
|
|
|
+ \end{array}
|
|
|
\end{array}
|
|
|
\]
|
|
|
\fi}
|