Changeset 66d92e3


Ignore:
Timestamp:
Nov 20, 2023, 10:34:26 AM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
634cb80
Parents:
8c13ca8
Message:

proofread enumeration proposal

Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • doc/proposals/enum.tex

    r8c13ca8 r66d92e3  
    1414\renewcommand\paragraph{\@startsection{paragraph}{4}{\z@}{-2.0ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries}}
    1515\renewcommand\subparagraph{\@startsection{subparagraph}{4}{\z@}{-1.5ex \@plus -1ex \@minus -.2ex}{-1em}{\normalfont\normalsize\bfseries\itshape}}
     16
     17% Denote newterms in particular font and index them without particular font and in lowercase, e.g., \newterm{abc}.
     18% The option parameter provides an index term different from the new term, e.g., \newterm[\texttt{abc}]{abc}
     19% The star version does not lowercase the index information, e.g., \newterm*{IBM}.
     20\newcommand{\newtermFontInline}{\emph}
     21\newcommand{\newterm}{\protect\@ifstar\@snewterm\@newterm}
     22\newcommand{\@newterm}[2][\@empty]{\lowercase{\def\temp{#2}}{\newtermFontInline{#2}}\ifx#1\@empty\index{\temp}\else\index{#1@{\protect#2}}\fi}
     23\newcommand{\@snewterm}[2][\@empty]{{\newtermFontInline{#2}}\ifx#1\@empty\index{#2}\else\index{#1@{\protect#2}}\fi}
    1624\makeatother
    1725
     
    3846\newcommand{\CFAIcon}{\textsf{C\raisebox{\depth}{\rotatebox{180}A}}} % Cforall icon
    3947\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
     48\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
     49\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    4050\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
    4151
     
    5868    captionpos=b,                   
    5969    keepspaces=true,                 
     70        escapechar=\$,                                                  % LaTeX escape in CFA code
    6071%    numbers=left,                   
    6172%    numbersep=5pt,                 
     
    8394\begin{abstract}
    8495An enumeration is a type that defines a list of named constant values in C (and other languages).
    85 C uses an integral type as the underlying representation of an enumeration.
     96C and \CC use an integral type as the underlying representation of an enumeration.
    8697\CFA extends C enumerations to allow all basic and custom types for the inner representation.
    8798\end{abstract}
     
    92103\begin{lstlisting}[label=lst:weekday]
    93104enum Weekday { Monday, Tuesday, Wednesday, Thursday=10, Friday, Saturday, Sunday };
    94 \end{lstlisting}
    95 The example defines an @enum@ type @Weekday@ with ordered enumerators @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
     105                $\(\uparrow\)$                                                                      $\(\uparrow\)$
     106    ${\rm \newterm{enumeration name}}$                                        ${\rm \newterm{enumerator names}}
     107\end{lstlisting}
     108The example defines an enumeration type @Weekday@ with ordered enumerators @Monday@, @Tuesday@, @Wednesday@, @Thursday@, @Friday@, @Saturday@ and @Sunday@.
    96109The successor of @Tuesday@ is @Monday@ and the predecessor of @Tuesday@ is @Wednesday@.
    97 A C enumeration has an integral type, with consecutive enumerator values assigned by the compiler starting at zero or explicitly initialized by the programmer.
    98 For example, @Monday@ to @Wednesday@ have values 0--2, @Thursday@ is set to @10@, and after it, @Friday@ to @Sunday@ have values 11--13.
    99 
    100 There are 3 attributes for an enumeration: position, label, and value:
     110A C enumeration is an integral type, with consecutive enumerator values assigned by the compiler starting at zero or the next explicitly initialized value by the programmer.
     111For example, @Monday@ to @Wednesday@ have values 0--2 implicitly set by the compiler, @Thursday@ is explicitly set to @10@ by the programmer, and @Friday@ to @Sunday@ have values 11--13 implicitly set by the compiler.
     112
     113There are 3 attributes for an enumeration: \newterm{position}, \newterm{label}, and \newterm{value}:
    101114\begin{cquote}
    102 \small\sf
     115\small\sf\setlength{\tabcolsep}{3pt}
    103116\begin{tabular}{rccccccccccc}
    104 enum Weekday \{ & Monday,       & Tuesday,      & Wednesday,    & Thursday=10,  & Friday,       & Saturday,     & Sunday \}; \\
    105 position                & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
    106 label                   & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
    107 value                   & 0                     & 1                     & 2                             & 10                    & 11            & 12            & 13
     117@enum@ Weekday \{       & Monday,       & Tuesday,      & Wednesday,    & Thursday=10,  & Friday,       & Saturday,     & Sunday \}; \\
     118\it position            & 0                     & 1                     & 2                             & 3                             & 4                     & 5                     & 6                     \\
     119\it label                       & Monday        & Tuesday       & Wednesday             & Thursday              & Friday        & Saturday      & Sunday        \\
     120\it value                       & 0                     & 1                     & 2                             & 10                    & 11            & 12            & 13
    108121\end{tabular}
    109122\end{cquote}
    110123
    111 The enumerators of an enum are unscoped, i.e., enumerators declared inside of an enum are visible in the enclosing scope of the enum class.
     124The enumerators of an enumeration are unscoped, i.e., enumerators declared inside of an @enum@ are visible in the enclosing scope of the @enum@ type.
    112125\begin{lstlisting}[label=lst:enum_scope]
    113126{
    114         enum RGB { R, G, B };
    115         int i = R  // i == 0
    116 }
    117 int j = G; // ERROR! G is not declared in this scope
     127        enum Weekday { ... };   // enumerators implicitly projected into local scope
     128        Weekday weekday = Monday;
     129        weekday = Friday;
     130        int i = Sunday  // i == 13
     131}
     132int j = Wednesday; // ERROR! Wednesday is not declared in this scope
    118133\end{lstlisting}
    119134
     
    121136
    122137A \CFA enumeration is parameterized by a type, which specifies the type for each enumerator.
    123 \CFA allows any object type for the enumerators, and values assigned to enumerators must be in the declared type.
     138\CFA allows any object type for the enumerators, and values assigned to enumerators must be from the declared type.
    124139\begin{lstlisting}[label=lst:color]
    125140enum Colour( @char *@ ) { Red = "R", Green = "G", Blue = "B"  };
    126141\end{lstlisting}
    127142The type of @Colour@ is @char *@ and each enumerator is initialized with a C string.
    128 Only types have define an ordering can be automatically initialized (see Section~\ref{s:AutoInitializable}).
    129 
     143Only types with a defined ordering can be automatically initialized (see Section~\ref{s:AutoInitializable}).
    130144
    131145% An instance of \CFA-enum (denoted as @<enum_instance>@) is a label for the defined enum name.
     
    133147% Similarly, the @value()@ function returns the value used to initialize the \CFA-enum.
    134148
    135 A \CFA-enum is scoped: enumeration constants are not automatically exposed to the global scope.
    136 Enumeration constant can be referenced using qualified expressions like an aggregate that supports qualified references to its fields. The syntax of $qualified\_expression$ for \CFA-enum is the following:
    137 $$<qualified\_expression> := <enum\_type>.<enumerator>$$
    138 
    139 
    140 \subsection{enumeration instance}
    141 \begin{lstlisting}[label=lst:sample_cforall_enum_usage]
    142 Colour green = Colour.Green;
    143 \end{lstlisting}
    144 The ~\ref{lst:sample_cforall_enum_usage} example declares a $enumeration\ instance$ named @red@ and initializes it with $enumeration\ constant$ @Color.Red@.
    145 An enumeration instance is a data structure that captures attributes of an enumeration constant, which can be retrieved by functions $position( enumeration\ instance )$, $value( enumeration\ instance )$, and $label( enumeration\ instance )$.
    146 \begin{lstlisting}
    147 int green_pos = position( green ); // 1
    148 char * green_value = value( green ); // "G"
    149 char * green_label = label( green ); // "Green"
    150 \end{lstlisting}
    151 An enumeration instance can be assigned to a variable or used as its position with type integer, its value with declared type T, or its label with type char *, and the compiler will resolve the usage as a type fits the context.
     149\subsection{Enumerator Scoping}
     150
     151A \CFA-enum can be scoped, meaning the enumerator constants are not projected into the enclosing scope.
     152\begin{lstlisting}
     153enum Colour( char * ) @!@ { ... };
     154\end{lstlisting}
     155where the @'!'@ implies the enumerators are \emph{not} projected.
     156The enumerators of a scoped enumeration are accessed using qualification, like the fields of an aggregate.
     157% The syntax of $qualified\_expression$ for \CFA-enum is the following:
     158% $$<qualified\_expression> := <enum\_type>.<enumerator>$$
     159\begin{lstlisting}
     160Colour colour = @Colour.@Red;   // qualification
     161colour = @Colour.@Blue;
     162\end{lstlisting}
     163
     164\subsection{Enumerator Attributes}
     165
     166The attributes of an enumerator are accessed by pseudo-functions @position@, @value@, and @label@, i.e., like @sizeof@.
     167\begin{lstlisting}
     168int green_pos = @position@( Colour.Green );     // 1
     169char * green_value = @value@( Colour.Green );   // "G"
     170char * green_label = @label@( Colour.Green );   // "Green"
     171\end{lstlisting}
     172There are implicit conversions from an enumerator to its attributes.
    152173\begin{lstlisting}[label=lst:enum_inst_assign_int]
    153 int green_pos = green; // equivalent to position( green );
    154 \end{lstlisting}
    155 A resolution of an enumeration constant is $unambigious$ if only one of the attributes has the resolvable type.
    156 In example~\ref{lst:enum_inst_assign_int}, the right-hand side of the assignment expression expects integer type.
    157 The position of an enumeration is @int@, while the other two cannot be resolved as integers.
    158 The expression unambiguously returns the position of @green@.
    159 \begin{lstlisting}[label=lst:enum_inst_assign_string]
    160 char * green_value = green; // equivalent to value( green );
    161 \end{lstlisting}
    162 On the other hand, the resolution of an enumeration constant is $ambigious$ if multiple attributes have the expected type.
    163 In example~\ref{lst:enum_inst_assign_string}, both value and label have the expected type @char *@.
     174int green_pos = Colour.Green;  // 1
     175char * green_value = Colour.Green;  // ambiguous
     176char * green_label = Colour.Green;  // ambiguous
     177\end{lstlisting}
     178where a conversion is ambiguous, if the enumerator's type is same as an attribute's type.
     179For example, @value( Colour.Green )@ and @label( Colour.Green )@ both have type @char *@.
     180Further examples are:
     181\begin{cquote}
     182\begin{tabular}{ll}
     183\begin{lstlisting}
     184int monday_pos = Monday;  // ambiguous
     185int monday_value = Monday;  // ambiguous
     186char * monday_label = Monday;  // "Monday"
     187
     188\end{lstlisting}
     189&
     190\begin{lstlisting}
     191enum(double) Math { PI = 3.14159, E = 2.718 };
     192int pi_pos = PI;  // 0
     193double pi_value = PI;  // 3.14159
     194char * pi_label = PI;  // "PI"
     195\end{lstlisting}
     196\end{tabular}
     197\end{cquote}
     198Here, @position( Monday )@ and @value( Monday )@ both have type @int@, while all attribute types are unique for enumerator @PI@.
     199
    164200When a resolution is ambiguous, a \textit{resolution precedence} applies: $$value > position > label$$
    165201\CFA uses resolution distance to describe if one type can be used as another. While \CFA calculates the resolution distance between the expected type and types of all three attributes, it would not choose the attribute with the closest distance. Instead, when resolving an enumeration constant, \CFA always chooses value whenever it is a possible resolution (resolution distance is not infinite), followed by position, then label.
     
    170206In the example~\ref{lst:enum_inst_precedence}, while $position( Bar )$ has the closest resolution among the three attributes, $Foo.Bar$ is resolved as $value( Bar )$ because of the resolution precedence.
    171207
    172 Although \CFA enumeration captures three different attributes, an instance of enumeration does not occupy extra memory.
    173 The @sizeof@ \CFA enumeration instance is always 4 bytes, the same amount of memory to store a C enumeration instance.
     208\PAB{Not sure this is going to work.}
     209
     210\subsection{Enumerator Storage}
     211
     212Although \CFA enumeration captures three different attributes, an enumeration instance does not store all this information.
     213The @sizeof@ a \CFA enumeration instance is always 4 bytes, the same size as a C enumeration instance (@sizeof( int )@).
    174214It comes from the fact that:
    175215\begin{enumerate}
     
    179219it is always resolved as one of its attributes in terms of real usage.
    180220\end{enumerate}
    181 When creating the enumeration instance green and assigns it with the enumeration constant @Color.Green@, the compilers essentially allocate an integer variables and store the position 1.
     221When creating an enumeration instance @colour@ and assigning it with the enumerator @Color.Green@, the compiler allocates an integer variable and stores the position 1.
    182222The invocations of $positions()$, $value()$, and $label()$ turn into calls to special functions defined in the prelude:
    183223\begin{lstlisting}[label=lst:companion_call]
     
    195235
    196236\begin{lstlisting}[caption={Enum Type Functions}, label=lst:cforall_enum_functions]
    197 forall( T )  {
    198         struct Companion {
    199                 const T * const values;
    200                 const char** const labels;
    201                         int length;
    202         };
    203 }
    204 \end{lstlisting}
    205 \CFA creates an object of Companion for every \CFA-enumeration. A companion object has the same name as the enumeration is defined for.
     237forall( T )
     238struct Companion {
     239        const T * const values;
     240        const char ** const labels;
     241        int length;
     242};
     243\end{lstlisting}
     244\CFA creates a @Companion@ object for every \CFA enumeration.
     245A companion object has the same name as the enumeration is defined for.
    206246A companion object stores values and labels of enumeration constants, in the order of the constants defined in the enumeration.
    207247
    208 \CFA generates the definition of companion functions. Because \CFA implicitly stores enumeration instance as its position, the companion function $position$ does nothing but returns the position it passes it.
    209 Companions function $value$ and $label$ return the array item at the given position of $values$ and $labels$, respectively.
     248\CFA generates the definition of companion functions.
     249Because \CFA implicitly stores enumeration instance as its position, the companion function @position@ does nothing but return the position it is passed.
     250Companions function @value@ and @label@ return the array item at the given position of @values@ and @labels@, respectively.
    210251\begin{lstlisting}[label=lst:companion_definition]
    211252int position( Companion o, int pos ) { return pos; }
     
    213254char * label( Companion o, int pos ) { return o.labels[ pos ]; }
    214255\end{lstlisting}
    215 Notably, the Companion structure definition, and all companion objects, are visible to the users.
    216 A user can retrieve values and labels defined in an enumeration by accessing the values and labels directly, or indirectly by calling Companion functions $values$ and $labels$
     256Notably, the @Companion@ structure definition, and all companion objects, are visible to users.
     257A user can retrieve values and labels defined in an enumeration by accessing the values and labels directly, or indirectly by calling @Companion@ functions @values@ and @labels@
    217258\begin{lstlisting}[label=lst:companion_definition_values_labels]
    218259Colour.values; // read the Companion's values
    219 values( Colour ); // Same as Colour.values
     260values( Colour ); // same as Colour.values
    220261\end{lstlisting}
    221262
    222263\subsection{User Define Enumeration Functions}
    223264
    224 The Companion objects make extending features for \CFA enumeration easy.
    225 
     265Companion objects make extending features for \CFA enumeration easy.
    226266\begin{lstlisting}[label=lst:companion_user_definition]
    227267char * charastic_string( Companion o, int position ) {
    228         return sprintf("Label: %s; Value: %s", label( o, position ), value( o, position) );
     268        return sprintf( "Label: %s; Value: %s", label( o, position ), value( o, position) );
    229269}
    230270printf( charactic_string ( Color, 1 ) );
    231 >>> Label: G; Value: G
     271>>> Label: Green; Value: G
    232272\end{lstlisting}
    233273Defining a function takes a Companion object effectively defines functions for all \CFA enumeration.
     
    236276Therefore, a user can use the syntax with a user-defined enumeration function call:
    237277\begin{lstlisting}[label=lst:companion_user_definition]
    238 charactic_string ( Color.Green ); // equivalent to charactic_string ( Color, 1 )
    239 >>> Label: G; Value: G
     278charactic_string( Color.Green ); // equivalent to charactic_string( Color, 1 )
     279>>> Label: Green; Value: G
    240280\end{lstlisting}
    241281Similarly, the user can work with the enumeration type itself: (see section ref...)
     
    251291\subsection{Runtime Enumeration}
    252292
    253 The Companion structure definition is visible to users, and users can create an instance of Companion object themselves, which effectively constructs a \textit{Runtime Enumeration}.
     293The companion structure definition is visible to users, and users can create an instance of companion object themselves, which effectively constructs a \textit{Runtime Enumeration}.
    254294\begin{lstlisting}[ label=lst:runtime_enum ]
    255 const char values[] = { "Hello", "World" };
    256 const char labels[] = { "First", "Second" };
    257 Companion (char *) MyEnum = { .values: values, .labels: labels, .length: 2 };
     295const char values[$\,$] = { "Hello", "World" };
     296const char labels[$\,$] = { "First", "Second" };
     297Companion(char *) MyEnum = { .values: values, .labels: labels, .length: 2 };
    258298\end{lstlisting}
    259299A runtime enumeration can be used to call enumeration functions.
     
    267307                                    // and MyEnum.First is not recognizable
    268308\end{lstlisting}
    269 During the compilation, \CFA adds enumeration declarations to an enumeration symbol table and creates specialized function definitions for \CFA enumeration. \CFA does not recognize runtime enumeration during compilation and would not add them to the enumeration symbol table, resulting in a lack of supports for runtime enumeration.
     309During the compilation, \CFA adds enumeration declarations to an enumeration symbol table and creates specialized function definitions for \CFA enumeration.
     310\CFA does not recognize runtime enumeration during compilation and would not add them to the enumeration symbol table, resulting in a lack of supports for runtime enumeration.
     311
     312\PAB{Not sure how useful this feature is.}
    270313
    271314\section{Enumeration Features}
    272315
    273 A trait is a collection of constraints in \CFA, which can be used to describe types.
     316A trait is a collection of constraints in \CFA that can be used to describe types.
    274317The \CFA standard library defines traits to categorize types with related enumeration features.
    275318
     
    279322TODO: make the initialization rule a separate section.
    280323
    281 If no explicit initializer is given to an enumeration constant, C initializes the first enumeration constant with value 0, and the other enumeration constant has a value equal to its $predecessor+1$.
     324If no explicit initializer is given to an enumeration constant, C initializes the first enumeration constant with value 0, and the next enumeration constant has a value equal to its $predecessor + 1$.
    282325\CFA enumerations have the same rule in enumeration constant initialization.
    283 However, not all types can be automatically initialized by \CFA because the meaning of $zero$, $one$, and addition operator may not be well-defined.
    284 
    285 A type is auto-Initializable if it has defined @zero_t@, @one_t@, and an addition operator.
     326However, only \CFA types that have defined traits for @zero_t@, @one_t@, and an addition operator can be automatically initialized by \CFA.
     327
     328Specifically, a type is auto-initializable only if it satisfies the trait @AutoInitializable@:
    286329\begin{lstlisting}
    287330forall(T)
     
    292335};
    293336\end{lstlisting}
    294 An example of user-defined @AutoInitializable@ would look like the following:
     337An example of a user-defined @AutoInitializable@ is:
    295338\begin{lstlisting}[label=lst:sample_auto_Initializable]
    296339struct Odd { int i; };
    297340void ?()( Odd & t, zero_t ) { t.i = 1; };
    298341void ?()( Odd & t, one_t ) { t.i = 2; };
    299 Odd ?+?( Odd t1, Odd t2 )
    300         { return Odd( t1.i + t2.i); };
    301 \end{lstlisting}
    302 When an enumeration declares an AutoInitializable as its type, no explicit initialization is necessary.
     342Odd ?+?( Odd t1, Odd t2 ) { return Odd( t1.i + t2.i); };
     343\end{lstlisting}
     344When the type of an enumeration is @AutoInitializable@, implicit initialization is available.
    303345\begin{lstlisting}[label=lst:sample_auto_Initializable_usage]
    304346enum AutoInitUsage(Odd) {
    305         A, B, C = 6, D
    306 };
    307 \end{lstlisting}
    308 
    309 In the example~\ref{lst:sample_auto_Initializable_usage_gen}, because no initializer is specified for the first enumeration constant @A@, \CFA initializes it with the value of @zero_t@, which is 1.
    310 @B@ and @D@ have the values of their $predecessor + one_t$, while @one_t@ has the value 2.
    311 Therefore, the enumeration is initialized as the following:
     347        A, B, C = 7, D
     348};
     349\end{lstlisting}
     350In the example, there is no initializer specified for the first enumeration constant @A@, so \CFA initializes it with the value of @zero_t@, which is 1.
     351@B@ and @D@ have the values of their $predecessor + one_t$, where @one_t@ has the value 2.
     352Therefore, the enumeration is initialized as follows:
    312353\begin{lstlisting}[label=lst:sample_auto_Initializable_usage_gen]
    313354enum AutoInitUsage(Odd) {
    314         A=1, B=3, C = 6, D=8
    315 };
    316 \end{lstlisting}
    317 In \CFA, integral types, float types, and imaginary numbers are example types that are AutoInitialiable.
     355        A = 1, B = 3, C = 7, D = 9
     356};
     357\end{lstlisting}
     358Note, there is no mechanism to prevent an even value for the direct initialization, such as @C = 6@.
     359
     360In \CFA, character, integral, float, and imaginary types are all @AutoInitialiable@.
    318361\begin{lstlisting}[label=lst:letter]
    319 enum Alphabet(int) {
    320         A='A', B, C, D, E, F, G, H, I, J, K, L, M,
    321         N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
    322         a='a', b, c, d, e, f, g, h, i, j, k, l, m,
    323         n, o, p, q, r, s, t, u, v, w, x, y, z
    324 };
    325 print( "%c, %c, %c", Alphabet.F, Alphabet.o, Alphabet.o );
    326 >>> F, o, o
     362enum Alphabet( int ) {
     363        A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z,
     364        a = 'a', b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
     365};
     366print( "%c, %c, %c", Alphabet.F, Alphabet.o, Alphabet.z );
     367>>> F, o, z
    327368\end{lstlisting}
    328369
    329370\subsection{Iteration and Range}
    330371
    331 It is convenient to iterate over a \CFA enumeration.
    332 Here is the basic usage:
     372It is convenient to iterate over a \CFA enumeration, e.g.:
    333373\begin{lstlisting}[label=lst:range_functions]
    334 for ( Alphabet ah; Alphabet; ) {
    335         printf( "%d ", ah );
    336 }
    337 >>> A B C (...omit the rest)
    338 \end{lstlisting}
    339 The for-loop uses the enumeration type @Alphabet@ as range.
    340 When that happens, \CFA iterates all enumerators in the order they defined in the enumeration.
    341 @'ch'@ is the iterating enumerator, and it returns the value of an Alphabet in this context according to the precedence rule.
     374for ( Alphabet alph; Alphabet ) {
     375        printf( "%d ", alph );
     376}
     377>>> A B C ...
     378\end{lstlisting}
     379The for-loop uses the enumeration type @Alphabet@ its range, and iterates through all enumerators in the order defined in the enumeration.
     380@alph@ is the iterating enumeration object, which returns the value of an @Alphabet@ in this context according to the precedence rule.
    342381
    343382\CFA offers a shorthand for iterating all enumeration constants:
    344383\begin{lstlisting}[label=lst:range_functions]
    345 for ( Alphabet ch ) {
    346         printf( "%d ", ch );
    347 }
    348 >>> A B C (...omit the rest)
    349 \end{lstlisting}
    350 
    351 Enumeration supports the \CFA loop control syntax for for-loop.
     384for ( Alphabet alph ) {
     385        printf( "%d ", alph );
     386}
     387>>> A B C ...
     388\end{lstlisting}
     389The following different loop-control syntax is supported:
    352390\begin{lstlisting}[label=lst:range_functions]
    353391for ( Alphabet.D )
    354 for ( ch; Alphabet.g ~ Alphabet.z )
    355 for ( Alphabet ch; Alphabet.R ~ Alphabet.X ~ 2 )
    356 \end{lstlisting}
    357 Notably, the meaning of "step" of iteration has changed for enumeration.
     392for ( alph; Alphabet.g ~ Alphabet.z )
     393for ( Alphabet alph; Alphabet.R ~ Alphabet.X ~ 2 )
     394\end{lstlisting}
     395\PAB{Explain what each loop does.}
     396Notably, the meaning of ``step'' for an iteration has changed for enumeration.
    358397Consider the following example:
    359398\begin{lstlisting}[label=lst:range_functions]
     
    364403        printf( "%d ", s );
    365404}
    366 
    367405>>> 10 12 14
    368406
     
    378416It is also possible to iterate over an enumeration's labels, implicitly or explicitly:
    379417\begin{lstlisting}[label=lst:range_functions_label_implicit]
    380 for ( char * ch; Alphabet )
     418for ( char * alph; Alphabet )
    381419\end{lstlisting}
    382420This for-loop implicitly iterates every label of the enumeration, because a label is the only valid resolution to the ch with type @char *@ in this case.
     
    399437During the $Validation$ pass, the compiler links the type declaration to the type's definition.
    400438It ensures that the name of an enumerator is unique within the enumeration body, and checks if all values of the enumerator have the declaration type.
    401 If the declared type is not @Auto Initializable@, \CFA rejects the enumeration definition.
     439If the declared type is not @AutoInitializable@, \CFA rejects the enumeration definition.
    402440Otherwise, it attempts to initialize enumerators with the enumeration initialization pattern. (a reference to a future initialization pattern section)
    403441
     
    429467But the result is computed at run time, and the compiler ensures the @values@ are not changed.
    430468
    431 \subsection{qualified expression}
     469\subsection{Qualified Expression}
    432470
    433471\CFA uses qualified expression to address the scoping of \CFA-enumeration.
     
    441479If the @aggregation_name@ is identified as a \CFA enumeration, the compiler checks if @field@ presents in the declared \CFA enumeration.
    442480
    443 \subsection{\lstinline{with} statement/statement}
     481\subsection{\lstinline{with} Statement}
    444482
    445483\emph{Work in Progress}
    446484
    447 Instead of qualifying an enumeration expression every time, one can use the @with@ to expose enumerators to the current scope so that they are directly accessible.
     485Instead of qualifying an enumeration expression every time, the @with@ can be used to expose enumerators to the current scope, making them directly accessible.
    448486
    449487\subsection{Instance Declaration}
Note: See TracChangeset for help on using the changeset viewer.