|
@@ -10732,7 +10732,8 @@ Figure~\ref{fig:Lvec-concrete-syntax} defines the concrete syntax for
|
|
tuple with the square bracket notation, i.e., \code{t[n]} returns
|
|
tuple with the square bracket notation, i.e., \code{t[n]} returns
|
|
the nth element of the tuple \code{t}, 3) the \code{is} comparison
|
|
the nth element of the tuple \code{t}, 3) the \code{is} comparison
|
|
operator, and 4) obtaining the number of elements (the length) of a
|
|
operator, and 4) obtaining the number of elements (the length) of a
|
|
- tuple.}
|
|
|
|
|
|
+ tuple. In this chapter, we restrict access indices to constant
|
|
|
|
+ integers.}
|
|
%
|
|
%
|
|
The program below shows an example use of tuples. It creates a 3-tuple
|
|
The program below shows an example use of tuples. It creates a 3-tuple
|
|
\code{t} and a 1-tuple that is stored at index $2$ of the 3-tuple,
|
|
\code{t} and a 1-tuple that is stored at index $2$ of the 3-tuple,
|
|
@@ -10779,13 +10780,13 @@ print( t[0] + t[2][0] if t[1] else 44 )
|
|
\newcommand{\LtupGrammarPython}{
|
|
\newcommand{\LtupGrammarPython}{
|
|
\begin{array}{rcl}
|
|
\begin{array}{rcl}
|
|
\itm{cmp} &::= & \key{is} \\
|
|
\itm{cmp} &::= & \key{is} \\
|
|
- \Exp &::=& \Exp \key{,} \ldots \key{,} \Exp \MID \CGET{\Exp}{\Exp} \MID \CLEN{\Exp}
|
|
|
|
|
|
+ \Exp &::=& \Exp \key{,} \ldots \key{,} \Exp \MID \CGET{\Exp}{\Int} \MID \CLEN{\Exp}
|
|
\end{array}
|
|
\end{array}
|
|
}
|
|
}
|
|
\newcommand{\LtupASTPython}{
|
|
\newcommand{\LtupASTPython}{
|
|
\begin{array}{lcl}
|
|
\begin{array}{lcl}
|
|
\itm{cmp} &::= & \code{Is()} \\
|
|
\itm{cmp} &::= & \code{Is()} \\
|
|
-\Exp &::=& \TUPLE{\Exp^{+}} \MID \GET{\Exp}{\Exp} \\
|
|
|
|
|
|
+\Exp &::=& \TUPLE{\Exp^{+}} \MID \GET{\Exp}{\INT{\Int}} \\
|
|
&\MID& \LEN{\Exp}
|
|
&\MID& \LEN{\Exp}
|
|
\end{array}
|
|
\end{array}
|
|
}
|
|
}
|
|
@@ -11060,7 +11061,8 @@ Figure~\ref{fig:type-check-Lvec}, we use the
|
|
start and end parentheses. \index{subject}{unquote-slicing}}
|
|
start and end parentheses. \index{subject}{unquote-slicing}}
|
|
%
|
|
%
|
|
\python{records the type of each tuple expression in a new field
|
|
\python{records the type of each tuple expression in a new field
|
|
- named \code{has\_type}.}
|
|
|
|
|
|
+ named \code{has\_type}. As the type checker has to compute the type
|
|
|
|
+ of each tuple access, the index must be a constant.}
|
|
|
|
|
|
|
|
|
|
\begin{figure}[tp]
|
|
\begin{figure}[tp]
|