Changeset 022bce0


Ignore:
Timestamp:
Feb 25, 2024, 6:13:37 PM (2 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
1bb76ad, a4da45e
Parents:
6c68893
Message:

more proofreading on enumeration thesis

Location:
doc
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • doc/LaTeXmacros/common.sty

    r6c68893 r022bce0  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Feb 13 15:39:51 2024
    14 %% Update Count     : 634
     13%% Last Modified On : Sun Feb 25 17:37:46 2024
     14%% Update Count     : 640
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4040\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
    4141\newcommand{\CFL}{\textrm{Cforall}\xspace}                              % Cforall non-icon name
    42 \newcommand{\Celeven}{\textrm{C11}\xspace}                              % C11 symbolic name
     42\newcommand{\Celeven}{\textrm{C1\!1}\xspace}                    % C11 symbolic name
     43
    4344\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    44 \newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    45 \newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
    4645% numbers disallowed in latex variables names => use number names
    47 \newcommand{\CCeleven}{\protect\CCIcon{11}\xspace}              % C++11 symbolic name
     46\newcommand{\CCeleven}{\protect\CCIcon{1\!1}\xspace}    % C++11 symbolic name
    4847\newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace}    % C++14 symbolic name
    4948\newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace}   % C++17 symbolic name
    5049\newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace}              % C++20 symbolic name
     50\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     51\newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
     52
    5153\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    5254
     
    303305literate=
    304306%  {-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
    305   {-}{\raisebox{-1pt}{\texttt{-}}}1
     307  {-}{\raisebox{-1pt}{\ttfamily-}}1
    306308  {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    307309  {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1
     310  {'}{\ttfamily'\!}1
    308311  {`}{\ttfamily\upshape\hspace*{-0.3ex}`}1
    309312  {<-}{$\leftarrow$}2
  • doc/LaTeXmacros/common.tex

    r6c68893 r022bce0  
    1111%% Created On       : Sat Apr  9 10:06:17 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Tue Feb 13 13:38:58 2024
    14 %% Update Count     : 599
     13%% Last Modified On : Sun Feb 25 18:11:56 2024
     14%% Update Count     : 614
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    4040\newcommand{\CFA}{\protect\CFAIcon\xspace}                              % CFA symbolic name
    4141\newcommand{\CFL}{\textrm{Cforall}\xspace}                              % Cforall non-icon name
    42 \newcommand{\Celeven}{\textrm{C11}\xspace}                              % C11 symbolic name
     42\newcommand{\Celeven}{\textrm{C1\!1}\xspace}                    % C11 symbolic name
     43
    4344\newcommand{\CCIcon}{\textrm{C}\kern-.1em\hbox{+\kern-.25em+}} % C++ icon
    44 \newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
    45 \newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
    4645% numbers disallowed in latex variables names => use number names
    47 \newcommand{\CCeleven}{\protect\CCIcon{11}\xspace}              % C++11 symbolic name
     46\newcommand{\CCeleven}{\protect\CCIcon{1\!1}\xspace}    % C++11 symbolic name
    4847\newcommand{\CCfourteen}{\protect\CCIcon{14}\xspace}    % C++14 symbolic name
    4948\newcommand{\CCseventeen}{\protect\CCIcon{17}\xspace}   % C++17 symbolic name
    5049\newcommand{\CCtwenty}{\protect\CCIcon{20}\xspace}              % C++20 symbolic name
     50\newcommand{\CC}[1][]{\protect\CCIcon{#1}\xspace}               % C++ symbolic name
     51\newcommand{\Cpp}[1][]{\CC{#1}}                                                 % C++ synonym
     52
    5153\newcommand{\Csharp}{C\raisebox{-0.7ex}{\relsize{2}$^\sharp$}\xspace} % C# symbolic name
    5254
     
    307309literate=
    308310%  {-}{\makebox[1ex][c]{\raisebox{0.4ex}{\rule{0.75ex}{0.1ex}}}}1
    309   {-}{\raisebox{-1pt}{\texttt{-}}}1
     311  {-}{\raisebox{-1pt}{\ttfamily-}}1
    310312  {^}{\raisebox{0.6ex}{$\scriptstyle\land\,$}}1
    311313  {~}{\raisebox{0.3ex}{$\scriptstyle\sim\,$}}1
     314  {'}{\ttfamily'\!}1
    312315  {`}{\ttfamily\upshape\hspace*{-0.3ex}`}1
    313316  {<-}{$\leftarrow$}2
  • doc/bibliography/pl.bib

    r6c68893 r022bce0  
    37423742    month       = jul, year = 1987,
    37433743    volume      = 4, number = 4, pages = {9-16}
     3744}
     3745
     3746@manual{FreePascal,
     3747    keywords    = {Pascal, object oriented},
     3748    contributer = {pabuhr@plg},
     3749    author      = {Micha\"{e}l Van Canneyt},
     3750    title       = {{F}ree {P}ascal Reference Guide, version 3.2.2},
     3751    month       = may,
     3752    year        = 2021,
     3753    note        = {\url{http://downloads.freepascal.org/fpc/docs-pdf/ref.pdf}},
    37443754}
    37453755
  • doc/theses/jiada_liang_MMath/intro.tex

    r6c68893 r022bce0  
    33Naming values is a common practice in mathematics and engineering, \eg $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MHz (1E6), etc.
    44Naming is also commonly used to represent many other numerical phenomenon, such as days of the week, months of a year, floors of a building (basement), specific times (noon, New Years).
    5 Many programming languages capture this important software-engineering capability through a mechanism called an \Newterm{enumeration}.
     5Many programming languages capture this important software engineering capability through a mechanism called an \Newterm{enumeration}.
    66An enumeration is similar to other programming-language types by providing a set of constrained values, but adds the ability to name \emph{all} the values in its set.
    77Note, all enumeration names must be unique but different names can represent the same value (eight note, quaver), which are synonyms.
  • doc/theses/jiada_liang_MMath/relatedwork.tex

    r6c68893 r022bce0  
    2525There is no notion of an ordered set, modulo the \lstinline[language=pascal]{set of} type.
    2626
    27 Free Pascal is a modern, object-oriented version of classic Pascal, with a C-style enumeration type.
    28 Enumerators must be in assigned in ascending numerical order with a constant expression and the range can be non-consecutive.
     27Free Pascal~\cite[\S~3.1.1]{FreePascal} is a modern, object-oriented version of classic Pascal, with a C-style enumeration type.
     28Enumerators must be assigned in ascending numerical order with a constant expression and the range can be non-consecutive.
    2929\begin{pascal}
    3030Type EnumType = ( one, two, three, forty @= 40@, fortyone );
    3131\end{pascal}
    3232Pseudo-functions @Pred@ and @Succ@ can only be used if the range is consecutive.
    33 The underlying type is an implementation-defined integral type large enough to hold all enumerated values; it does not have to be the smallest possible type.
    34 The size underlying integral type can be explicitly specified using compiler directive @$PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
     33The underlying type is an implementation-defined integral-type large enough to hold all enumerated values; it does not have to be the smallest possible type.
     34The integral size can be explicitly specified using compiler directive @$PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
    3535\begin{pascal}
    3636Type @{$\color{red}\$$PACKENUM 1}@ SmallEnum = ( one, two, three );
     
    6464@for RGB use ( Red => 10, Green => 20, Blue => 30 );@ -- ascending order
    6565\end{ada}
     66Hence, the position, value, label tuples are:
     67\begin{ada}
     68(0, 10, RED)  (1, 20, GREEN)  (2, 30, BLUE)
     69\end{ada}
    6670
    6771Like C, Ada enumerators are unscoped, \ie enumerators declared inside of an enum are visible (projected) into the enclosing scope.
     
    7478\end{ada}
    7579Like \CFA, Ada uses an advanced type-resolution algorithm, including the left-hand side of assignment, to disambiguate among overloaded names.
    76 Figure~\VRef{f:AdaEnumeration} shows how ambiguities are handled using a cast, \eg \lstinline[language=ada]{RGB'(Red)}.
     80\VRef[Figure]{f:AdaEnumeration} shows how ambiguity is handled using a cast, \eg \lstinline[language=ada]{RGB'(Red)}.
    7781
    7882\begin{figure}
     
    8185procedure test is
    8286   type RGB is ( @Red@, Green, Blue );
    83    type Traffic_Light is ( @Red@, Yellow, Green );
    84    procedure @Red@( Colour : RGB ) is begin
     87   type Traffic_Light is ( @Red@, Yellow, Green );         -- overload
     88   procedure @Red@( Colour : RGB ) is begin            -- overload
    8589       Put_Line( "Colour is " & RGB'Image( Colour ) );
    8690   end Red;
    87    procedure @Red@( TL : Traffic_Light ) is begin
     91   procedure @Red@( TL : Traffic_Light ) is begin       -- overload
    8892       Put_Line( "Light is " & Traffic_Light'Image( TL ) );
    8993   end Red;
     
    98102\end{figure}
    99103
    100 Ada provides an alias mechanism called \lstinline[language=ada]{renames} for aliasing types, especially to shorten package type names.
     104Ada provides an alias mechanism, \lstinline[language=ada]{renames}, for aliasing types, which is useful to shorten package names.
    101105\begin{ada}
    102106OtherRed : RGB renames Red;
    103107\end{ada}
    104 which suggests the \CFA extension to @typedef@.
     108which suggests a possible \CFA extension to @typedef@.
    105109\begin{cfa}
    106110typedef RGB.Red OtherRed;
    107111\end{cfa}
    108112
    109 There are four enumeration pseudo functions (attributes): @'Pos@, @'Val@, @'Image@, and @'Value@.
    110 Function @Pos@ returns the enumerator position; the inverse function @Val@ returns the corresponding enumerator.
    111 \begin{ada}
    112 RGB'Pos(Red) = 0  -- '=' => equality
    113 RGB'Val(0) = Red
    114 \end{ada}
    115 Funcion @Image@ returns the enumerator label (in capital letters); the inverse function @Value@ returns the corresponding enumerator.
    116 \begin{ada}
    117 RGB'Image( Red ) = "RED"
    118 RGB'Value("Red") =  Red
    119 \end{ada}
    120 These attributes are important for simple IO (there are more elaborate IO facilities in @Ada.Text_IO@ for enumeration types).
    121 As well, an enumeration type @T@ has the additional attributes, @T'First@, @T'Last@, @T'Range@, @T'Pred@, @T'Succ@, @T'Min@, and @T'Max@, producing an intuitive result based on the attribute name.
    122 
    123 Ada leverages enumerations as the bases for character and boolean types.
    124 Rather unique to Ada is the use of character literals as enumeration literals:
    125 \begin{ada}
    126 type ABC is ('A', 'B', 'C');
    127 \end{ada}
    128 This literal @'A'@ has nothing in common with the literal @'A'@ of the predefined type @Character@ (or @Wide_Character@).
    129 
    130 Every type that has at least one character literal is a character type.
    131 For every character type, string literals and the concatenation operator @"&"@ are also implicitly defined.
    132 \begin{ada}
    133 type My_Character is (No_Character, 'a', Literal, 'z');
    134 type My_String is array (Positive range <>) of My_Character;
    135 
    136 S: My_String := "aa" & Literal & "za" & 'z';
    137 T: My_String := ('a', 'a', Literal, 'z', 'a', 'z');
    138 \end{ada}
    139 In this example, @S@ and @T@ have the same value.
    140 
    141 Ada's @Character@ type is defined that way.
    142 See Ada Programming/Libraries/Standard.
    143 
    144 The boolean type is defined as an enumeration:
     113There are three pairs of inverse enumeration pseudo-functions (attributes): @'Pos@ and @'Val@, @'Enum_Rep@ and @'Enum_Val@, and @'Image@ and @'Value@,
     114\begin{cquote}
     115\lstDeleteShortInline@
     116\setlength{\tabcolsep}{15pt}
     117\begin{tabular}{@{}ll@{}}
     118\begin{ada}
     119RGB'Pos( Red ) = 0;
     120RGB'Enum_Rep( Red ) = 10;
     121RGB'Image( Red ) = "RED";
     122\end{ada}
     123&
     124\begin{ada}
     125RGB'Val( 0 ) = Red
     126RGB'Enum_Val( 10 ) =  Red
     127RGB'Value( "Red" ) =  Red
     128\end{ada}
     129\end{tabular}
     130\lstMakeShortInline@
     131\end{cquote}
     132These attributes are important for IO.
     133An enumeration type @T@ also has the following attributes: @T'First@, @T'Last@, @T'Range@, @T'Pred@, @T'Succ@, @T'Min@, and @T'Max@, producing an intuitive result based on the attribute name.
     134
     135Ada allows the enumerator label to be a character constant.
     136\begin{ada}
     137type Operator is ( '+', '-', '*', '/' );
     138Op : Operator;
     139\end{ada}
     140which is syntactic sugar for the label and not character literals from the predefined type @Character@.
     141The purpose is readability using character literals rather than names.
     142\begin{ada}
     143Op := '+';
     144case Op is                    -- all enumerators must appear
     145        when '+' => ... ;
     146        when '-' => ... ;
     147        when '*' => ... ;
     148        when '/' => ... ;
     149end case;
     150\end{ada}
     151Arrays of character enumerators can be treated as strings.
     152\begin{ada}
     153Ops : array( 0..3 ) of Operator;
     154Ops := @"+-*/"@;            -- string assignment to array elements
     155Ops := @"+-" & "*/"@;   -- string concatenation and assignment
     156for Op of Ops loop
     157        Put_Line( Operator'Image( Op ) );
     158end loop;
     159\end{ada}
     160Ada's @Character@ type is defined as a character enumeration across all Latin-1 characters.
     161
     162Ada's boolean type is defined as a special enumeration, which can be used in conditions.
    145163\begin{ada}
    146164type Boolean is (False, True); -- False / True not keywords
    147165@Flag@ : Boolean;
    148 \end{ada}
    149 which can be used in conditions.
    150 \begin{ada}
    151 if @Flag@ then ...
     166if @Flag@ then ...    -- conditional
    152167\end{ada}
    153168Since only types derived from @Boolean@ can be a conditional, @Boolean@ is essentially  a builtin type.
    154169
    155 Ada provides a simple \emph{consecutive} subset (subtype) of an enumeration using \lstinline[language=ada]{range}.
    156 \begin{ada}
    157 type BW  is ( Cyan, Megenta, Yellow, Red, Green, Blue );
    158 type CMY is new BW @range@ Cyan .. Yellow;
    159 type RGB is new BW @range@ Red .. Blue;
     170Ada provides \emph{consecutive} subtyping of an enumeration using \lstinline[language=ada]{range}.
     171\begin{ada}
     172type Week is ( Mon, Tue, Wed, Thu, Fri, Sat, Sun );
     173subtype Weekday is Week @range Mon .. Fri@;
     174subtype Weekend is Week @range Sat .. Sun@;
     175Day : Week;
    160176\end{ada}
    161177Hence, the ordering of the enumerators is crucial to provide the necessary ranges.
    162178
    163 \begin{ada}
    164 type Subtype_Name is (Id1, Id2, Id3 ... );
    165 \end{ada}
    166 where @Id1@, @Id2@, etc. are identifiers or characters literals.
    167 In either case, the legal values of the type are referred to as "enumeration literals."
    168 Each of these values has a "position number" corresponding to its position in the list such that @Id1@ has position 0, @Id2@ has position 1, and the Nth value has position N-1.
    169 
    170 The enumeration attributes @First@ and @Succ@ allow stepping through a subsequence of the values.
    171 \begin{ada}
    172 case Day_Of_Week'First is
    173         when Sunday =>
    174            ISO (False);
    175         when Day_Of_Week'Succ(Sunday) =>
    176            ISO (True);
    177         when Tuesday .. Saturday =>
    178            raise Program_Error;
     179An enumeration type can be used in the Ada \lstinline[language=ada]{case} (switch) and iterating constructs.
     180\begin{cquote}
     181\lstDeleteShortInline@
     182\setlength{\tabcolsep}{15pt}
     183\begin{tabular}{@{}ll@{}}
     184\begin{ada}
     185case Day is
     186        when @Mon .. Fri@ => ... ;
     187        when @Sat .. Sun@ => ... ;
    179188end case;
    180189\end{ada}
    181 A loop will automatically step through the values of the subtype's range.
    182 Filtering week days to include only working days with an even position number:
    183 \begin{ada}
    184         for Day in Working_Day loop
    185                 if Day_Of_Week'Pos(Day) mod 2 = 0 then
    186                         Work_In_Backyard;
    187                 end if;
    188         end loop;
    189 \end{ada}
    190 Enumeration types can be used as array index subtypes, yielding a table feature:
    191 \begin{ada}
    192 type Officer_ID is range 0 .. 50;
    193 type Schedule is array (Working_Day) of Officer_ID;
     190&
     191\begin{ada}
     192case Day is
     193        when @Weekday@ => ... ;  -- subtype ranges
     194        when @Weekend@ => ... ;
     195end case;
     196\end{ada}
     197\end{tabular}
     198\end{cquote}
     199
     200\begin{cquote}
     201\setlength{\tabcolsep}{12pt}
     202\begin{tabular}{@{}lll@{}}
     203\begin{ada}
     204for Day in @Mon .. Sun@ loop
     205        ...
     206end loop;
     207\end{ada}
     208&
     209\begin{ada}
     210for Day in @Weekday@ loop
     211        ...
     212end loop;
     213\end{ada}
     214&
     215\begin{ada}
     216for Day in @Weekend@ loop
     217        ...
     218end loop;
     219\end{ada}
     220\end{tabular}
     221\lstMakeShortInline@
     222\end{cquote}
     223
     224An enumeration type can be used as an array dimension and subscript.
     225\begin{ada}
     226Lunch : array( @Week@ ) of Time;
     227for Day in Week loop
     228        Lunch( @Day@ ) := ... ;       -- set lunch time
     229end loop;
    194230\end{ada}
    195231
     
    248284int i = A;   i = e;                                             $\C{// implicit casts to int}$
    249285\end{c++}
    250 \CC{11} added a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), so the enumerators are local to the enumeration and must be accessed using type qualification.
     286\CC{11} added a scoped enumeration, \lstinline[language=c++]{enum class} (or \lstinline[language=c++]{enum struct}), where the enumerators are accessed using type qualification.
    251287\begin{c++}
    252288enum class E { A, B, C };
     
    254290e = B;                                                                  $\C{// B not in scope}$
    255291\end{c++}
    256 \CC{20} supports unscoped access with a \lstinline[language=c++]{using enum} declaration.
     292\CC{20} supports explicit unscoping with a \lstinline[language=c++]{using enum} declaration.
    257293\begin{c++}
    258294enum class E { A, B, C };
     
    261297e = B;                                                                  $\C{// direct access}$
    262298\end{c++}
    263 \CC{11} added the ability to explicitly declare the underlying integral type for \lstinline[language=c++]{enum class}.
     299\CC{11} added the ability to explicitly declare the underlying \emph{integral} type for \lstinline[language=c++]{enum class}.
    264300\begin{c++}
    265301enum class RGB @: long@ { Red, Green, Blue };
     
    292328enum Weekday : byte { Monday, Tuesday, Wednesday, Thursday@ = 10@, Friday, Saturday, Sunday@,@ };
    293329\end{csharp}
    294 The default underlying type is @int@, with auto-incrementing, implicit/explicit intialization, terminator comma, and optional integral typing (default @int@)
     330The default underlying type is @int@, with auto-incrementing, implicit/explicit initialization, terminator comma, and optional integral typing (default @int@)
    295331A method cannot be defined in an enumeration type.
    296332As well, there is an explicit bidirectional conversion between an enumeration and its integral type, and an implicit conversion to the enumerator label in display contexts.
Note: See TracChangeset for help on using the changeset viewer.