|
@@ -20895,7 +20895,7 @@ casts the return value from \CANYTY{} to \INTTY{}.
|
|
|
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
%
|
|
|
-There are further complications regarding casts on mutable data
|
|
|
+There are further complications regarding casts on mutable data,
|
|
|
such as the \code{list} type introduced in
|
|
|
the challenge assignment of section~\ref{sec:arrays}.
|
|
|
%
|
|
@@ -21262,9 +21262,9 @@ class InterpLcast(InterpLany):
|
|
|
|
|
|
Recall that when we added support for arrays in
|
|
|
section~\ref{sec:arrays}, the syntax for the array operations were the
|
|
|
-same as for tuple operations (for example, accessing an element, getting the
|
|
|
-length). So we performed overload resolution, with a pass named
|
|
|
-\code{resolve}, to separate the array and tuple operations. In
|
|
|
+same as for tuple operations (for example, accessing an element and
|
|
|
+getting the length). So we performed overload resolution, with a pass
|
|
|
+named \code{resolve}, to separate the array and tuple operations. In
|
|
|
particular, we introduced the primitives \code{array\_load},
|
|
|
\code{array\_store}, and \code{array\_len}.
|
|
|
|
|
@@ -21393,8 +21393,8 @@ A cast between two tuple types can be handled in a similar manner. We
|
|
|
create a proxy with the \code{TupleProxy} AST node. Tuples are
|
|
|
immutable, so there is no need for a function to cast the value during
|
|
|
a write. Because there is a separate element type for each slot in
|
|
|
-the tuple, we need not just one function for casting during a read,
|
|
|
-but instead a tuple of functions.
|
|
|
+the tuple, we need more than one function for casting during a read:
|
|
|
+we need a tuple of functions.
|
|
|
%
|
|
|
Also, as we show in the next section, we need to differentiate these
|
|
|
tuples from the user-created ones, so we recommend using a new AST
|
|
@@ -21403,7 +21403,7 @@ tuples of functions.
|
|
|
%
|
|
|
Figure~\ref{fig:map-bang-lower-cast} shows the output of
|
|
|
\code{lower\_casts} on the example given in figure~\ref{fig:map-bang}
|
|
|
-that involved casting an array of integers to an array of \CANYTY{}.
|
|
|
+that involves casting an array of integers to an array of \CANYTY{}.
|
|
|
|
|
|
\fi}
|
|
|
|
|
@@ -21598,8 +21598,8 @@ Next we describe each of the new primitive operations.
|
|
|
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
%
|
|
|
-A tuple proxy is represented by a tuple containing 1) the underlying
|
|
|
-tuple and 2) a tuple of functions for casting elements that are read
|
|
|
+A tuple proxy is represented by a tuple containing (1) the underlying
|
|
|
+tuple and (2) a tuple of functions for casting elements that are read
|
|
|
from the tuple. The \LangPVec{} language includes the following AST
|
|
|
classes and primitive functions.
|
|
|
|
|
@@ -21630,9 +21630,9 @@ classes and primitive functions.
|
|
|
|
|
|
\end{description}
|
|
|
|
|
|
-An array proxy is represented by a tuple containing 1) the underlying
|
|
|
-array, 2) a function for casting elements that are read from the
|
|
|
-array, and 3) a function for casting elements that are written to the
|
|
|
+An array proxy is represented by a tuple containing (1) the underlying
|
|
|
+array, (2) a function for casting elements that are read from the
|
|
|
+array, and (3) a function for casting elements that are written to the
|
|
|
array. The \LangPVec{} language includes the following AST classes
|
|
|
and primitive functions.
|
|
|
|
|
@@ -21642,10 +21642,10 @@ and primitive functions.
|
|
|
|
|
|
\item[\code{InjectListProxy}]\ \\
|
|
|
%
|
|
|
- This AST node brands a array proxy as value of the \PARRAYTYNAME{} type.
|
|
|
+ This AST node brands an array proxy as a value of the \PARRAYTYNAME{} type.
|
|
|
\item[\code{is\_array\_proxy}]\ \\
|
|
|
%
|
|
|
- Returns true if the value is a array proxy and false if it is an
|
|
|
+ Returns true if the value is an array proxy and false if it is an
|
|
|
array.
|
|
|
\item[\code{project\_array}]\ \\
|
|
|
%
|
|
@@ -21654,11 +21654,11 @@ and primitive functions.
|
|
|
|
|
|
\item[\code{proxy\_array\_len}]\ \\
|
|
|
%
|
|
|
- Given a array proxy, returns the length of the underlying array.
|
|
|
+ Given an array proxy, returns the length of the underlying array.
|
|
|
|
|
|
\item[\code{proxy\_array\_load}]\ \\
|
|
|
%
|
|
|
- Given a array proxy, returns the $i$th element of the underlying
|
|
|
+ Given an array proxy, returns the $i$th element of the underlying
|
|
|
array.
|
|
|
|
|
|
\item[\code{proxy\_array\_store}]\ \\
|
|
@@ -21777,7 +21777,7 @@ the target type is \code{PVector}. Instead of using
|
|
|
%
|
|
|
{\if\edition\pythonEd\pythonColor
|
|
|
Recall that the $\itm{tagof}$ function determines the bits used to
|
|
|
-identify values of different types and it is used in the \code{reveal\_casts}
|
|
|
+identify values of different types, and it is used in the \code{reveal\_casts}
|
|
|
pass in the translation of \code{Project}. The \PTUPLETYNAME{} and
|
|
|
\PARRAYTYNAME{} types can be mapped to $010$ in binary ($2$ is
|
|
|
decimal), just like the tuple and array types.
|
|
@@ -21985,20 +21985,20 @@ and \code{proxy\_vector\_length} functions.
|
|
|
new programs, test your compiler on all the tests for \LangLam{}
|
|
|
and for \LangDyn{}.
|
|
|
%
|
|
|
- \racket{Sometimes you may get a type checking error on the
|
|
|
+ \racket{Sometimes you may get a type-checking error on the
|
|
|
\LangDyn{} programs, but you can adapt them by inserting a cast to
|
|
|
the \CANYTY{} type around each subexpression that has caused a type
|
|
|
error. Although \LangDyn{} does not have explicit casts, you can
|
|
|
induce one by wrapping the subexpression \code{e} with a call to
|
|
|
an unannotated identity function, as follows: \code{((lambda (x) x) e)}.}
|
|
|
%
|
|
|
- \python{Sometimes you may get a type checking error on the
|
|
|
- \LangDyn{} programs but you can adapt them by inserting a
|
|
|
+ \python{Sometimes you may get a type-checking error on the
|
|
|
+ \LangDyn{} programs, but you can adapt them by inserting a
|
|
|
temporary variable of type \CANYTY{} that is initialized with the
|
|
|
troublesome expression.}
|
|
|
\end{exercise}
|
|
|
|
|
|
-\begin{figure}[p]
|
|
|
+\begin{figure}[t]
|
|
|
\begin{tcolorbox}[colback=white]
|
|
|
{\if\edition\racketEd
|
|
|
\begin{tikzpicture}[baseline=(current bounding box.center),scale=0.85]
|