Ignore:
Timestamp:
Aug 6, 2024, 9:49:56 AM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
efd055c
Parents:
c03af31
Message:

formatting, add section of enumeration subset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    rc03af31 r0c51c8b4  
    66
    77
    8 \section{Enumeration Syntax}
    9 
    10 \CFA extends the C enumeration declaration \see{\VRef{s:CEnumeration}} by parameterizing with a type (like a generic type), and adding Plan-9 inheritance \see{\VRef{s:EnumerationInheritance}} using an @inline@ to another enumeration type.
     8\section{Syntax}
     9
     10\CFA extends the C enumeration declaration \see{\VRef{s:CEnumeration}} by parameterizing with a type (like a generic type), and adding Plan-9 inheritance \see{\VRef{s:CFAInheritance}} using an @inline@ to another enumeration type.
    1111\begin{cfa}[identifierstyle=\linespread{0.9}\it]
    1212$\it enum$-specifier:
     
    2424
    2525
    26 \section{Enumeration Operations}
     26\section{Operations}
    2727
    2828\CFA enumerations have access to the three enumerations properties \see{\VRef{s:Terminology}}: label, order (position), and value via three overloaded functions @label@, @posn@, and @value@ \see{\VRef{c:trait} for details}.
     
    4343A A @0@ 3
    4444\end{cfa}
    45 Finally, there is an additional enumeration routine @countof@ (like @sizeof@, @typeof@) that returns the number of enumerators in an enumeration.
    46 \begin{cfa}
    47 enum(int) E { A, B, C, D };
    48 countof( E );  // 4
    49 \end{cfa}
    50 This auto-generated function replaces the C idiom for automatically computing the number of enumerators \see{\VRef{s:Usage}}.
     45Finally, there is an additional enumeration pseudo-function @countof@ (like @sizeof@, @typeof@) that returns the number of enumerators in an enumeration.
     46\begin{cfa}
     47enum(int) E { A, B, C, D } e;
     48countof( E );  // 4, type argument
     49countof( e );  // 4, variable argument
     50\end{cfa}
     51This buildin function replaces the C idiom for automatically computing the number of enumerators \see{\VRef{s:Usage}}.
    5152\begin{cfa}
    5253enum E { A, B, C, D, @N@ };  // N == 4
     
    197198
    198199
    199 \section{Enumeration Inheritance}
    200 \label{s:EnumerationInheritance}
     200\section{Subset}
     201
     202An enumeration's type can be another enumeration.
     203\begin{cfa}
     204enum( char ) Letter { A = 'A', ... };
     205enum( @Letter@ ) Greek { Alph = A, Beta = B, ... }; // alphabet intersection
     206\end{cfa}
     207Enumeration @Greek@ may have more or less enums than @Letter@, but the enum values \emph{must} be from @Letter@.
     208Therefore, @Greek@ enums are a subset of type @Letter@ and are type compatible with enumeration @Letter@, but @Letter@ enums are not type compatible with enumeration @Greek@.
     209
     210
     211\section{Inheritance}
     212\label{s:CFAInheritance}
    201213
    202214\CFA Plan-9 inheritance may be used with \CFA enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C).
    203215Containment is nominative: an enumeration inherits all enumerators from another enumeration by declaring an @inline statement@ in its enumerator lists.
    204216\begin{cfa}
    205 enum( char * ) Names { /* $\see{\VRef[Figure]{s:EnumerationInheritance}}$ */ };
     217enum( char * ) Names { /* $\see{\VRef[Figure]{f:EumeratorTyping}}$ */ };
    206218enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
    207219enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
     
    302314
    303315
    304 \section{Enumerator Control Structures}
     316\section{Control Structures}
    305317
    306318Enumerators can be used in multiple contexts.
     
    392404
    393405
    394 \section{Enumeration Dimension}
     406\section{Dimension}
    395407
    396408\VRef{s:EnumeratorTyping} introduces the harmonizing problem between an enumeration and secondary information.
     
    420432
    421433
    422 \section{Enumeration I/O}
     434\section{I/O}
    423435
    424436As seen in multiple examples, enumerations can be printed and the default property printed is the enumerator's label, which is similar in other programming languages.
     
    473485\label{f:EnumerationI/O}
    474486\end{figure}
    475 
    476487
    477488
Note: See TracChangeset for help on using the changeset viewer.