Преглед изворни кода

Access indices must be constants

This is needed to enable type checking of tuple accesses. Specialized
AST and mentioned in text.
Peter Thiemann пре 3 година
родитељ
комит
5893ebfc05
1 измењених фајлова са 6 додато и 4 уклоњено
  1. 6 4
      book.tex

+ 6 - 4
book.tex

@@ -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
   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
-  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
 \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}{
 \begin{array}{rcl}
   \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}
 }
 \newcommand{\LtupASTPython}{
 \begin{array}{lcl}
 \itm{cmp} &::= & \code{Is()} \\
-\Exp &::=& \TUPLE{\Exp^{+}} \MID \GET{\Exp}{\Exp} \\
+\Exp &::=& \TUPLE{\Exp^{+}} \MID \GET{\Exp}{\INT{\Int}} \\
      &\MID& \LEN{\Exp}
 \end{array}
 }
@@ -11060,7 +11061,8 @@ Figure~\ref{fig:type-check-Lvec}, we use the
 start and end parentheses. \index{subject}{unquote-slicing}}
 %
 \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]