Index: doc/theses/jiada_liang_MMath/relatedwork.tex
===================================================================
--- doc/theses/jiada_liang_MMath/relatedwork.tex	(revision f9da7618922cfffae1c2df08c6aebb72d2ded799)
+++ doc/theses/jiada_liang_MMath/relatedwork.tex	(revision 38f5006ef2bee7ba7cdf8bc8ef954804e0243166)
@@ -2,14 +2,14 @@
 \label{s:RelatedWork}
 
-Enumerations exist in many popular programming languages, e.g., Pascal~\cite{Pascal}, Ada~\cite{Ada}, \Csharp, \CC, Go~\cite{Go}, Java~\cite{Java}, Modula-3~\cite{Modula-3}, Rust~\cite{Rust}, Swift~\cite{Swift}, Python~\cite{Python}, and the algebraic data-type in functional programming.
-There are a large set of overlapping features among these languages, but each language has its own unique restrictions and extensions.
-
-
-\section{(Free) Pascal}
+Enumerations exist in many popular programming languages, \eg Pascal~\cite{Pascal}, Ada~\cite{Ada}, \Csharp~\cite{Csharp}, \CC, Go~\cite{Go}, Java~\cite{Java}, Modula-3~\cite{Modula-3}, Rust~\cite{Rust}, Swift~\cite{Swift}, Python~\cite{Python}, and the algebraic data-type in functional programming.
+There are a large set of overlapping features among these languages, but each language has its own unique extensions and restrictions.
+
+
+\section{Pascal}
 
 \lstnewenvironment{pascal}[1][]{% necessary
 \lstset{
 language=pascal,
-escapechar=\$,				% LaTeX escape in CFA code
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
@@ -17,6 +17,14 @@
 }{}
 
-Free Pascal is a modern object-oriented version of the classic Pascal programming language.
-It allows a C-style enumeration type, where enumerators must be in assigned in ascending numerical order with a constant expression and the range can be non-consecutive.
+Classic Pascal has the \lstinline[language=pascal]{const} declaration binding a name to a constant literal/expression.
+\begin{pascal}
+const one = 0 + 1;   Vowels = set of (A,E,I,O,U);   NULL = NIL;
+		 PI = 3.14159;   Plus = '+';   Fred = 'Fred';
+\end{pascal}
+The enumerator type is inferred from the constant-expression type.
+There is no notion of an ordered set, modulo the \lstinline[language=pascal]{set of} type.
+
+Free Pascal is a modern, object-oriented version of classic Pascal, with a C-style enumeration type.
+Enumerators must be in assigned in ascending numerical order with a constant expression and the range can be non-consecutive.
 \begin{pascal}
 Type EnumType = ( one, two, three, forty @= 40@, fortyone );
@@ -24,5 +32,5 @@
 Pseudo-functions @Pred@ and @Succ@ can only be used if the range is consecutive.
 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.
-The size underlying integral type can be explicitly specified using compiler directive @$PACKENUM@~$N$, where $N$ is the number of bytes, e.g.:
+The size underlying integral type can be explicitly specified using compiler directive @$PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
 \begin{pascal}
 Type @{$\color{red}\$$PACKENUM 1}@ SmallEnum = ( one, two, three );
@@ -37,6 +45,6 @@
 \lstnewenvironment{ada}[1][]{% necessary
 \lstset{
-language=ada,
-escapechar=\$,				% LaTeX escape in CFA code
+language=[2005]Ada,
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
@@ -44,38 +52,43 @@
 }{}
 
-An enumeration type is defined as a list of possible values:
-\begin{ada}
-type RGB is (Red, Green, Blue);
-\end{ada}
-Like for numeric types, where e.g., 1 is an integer literal, @Red@, @Green@ and @Blue@ are called the literals of this type.
-There are no other values assignable to objects of this type.
-
-\paragraph{Operators and attributes} ~\newline
-Apart from equality (@"="@), the only operators on enumeration types are the ordering operators: @"<"@, @"<="@, @"="@, @"/="@, @">="@, @">"@, where the order relation is given implicitly by the sequence of literals:
-Each literal has a position, starting with 0 for the first, incremented by one for each successor.
-This position can be queried via the @'Pos@ attribute; the inverse is @'Val@, which returns the corresponding literal. In our example:
-\begin{ada}
-RGB'Pos (Red) = 0
-RGB'Val (0)   = Red
-\end{ada}
-There are two other important attributes: @Image@ and @Value@.
-@Image@ returns the string representation of the value (in capital letters), @Value@ is the inverse:
-\begin{ada}
-RGB'Image ( Red ) = "RED"
-RGB'Value ("Red") =  Red
-\end{ada}
-These attributes are important for simple IO (there are more elaborate IO facilities in @Ada.Text_IO@ for enumeration types).
-Note that, since Ada is case-insensitive, the string given to @'Value@ can be in any case.
-
-\paragraph{Enumeration literals} ~\newline
-Literals are overloadable, i.e. you can have another type with the same literals.
-\begin{ada}
-type Traffic_Light is (Red, Yellow, Green);
-\end{ada}
-Overload resolution within the context of use of a literal normally resolves which @Red@ is meant.
-Only if you have an unresolvable overloading conflict, you can qualify with special syntax which @Red@ is meant:
-\begin{ada}
-RGB'(Red)
-\end{ada}
+An Ada enumeration type is an ordered list of constants, called \Newterm{literals} (enumerators) of the type.
+\begin{ada}
+type RGB is ( @Red@, @Green@, Blue ); -- 3 literals (enumerators)
+\end{ada}
+No other enumerators are assignable to objects of this type.
+Enumerators without an explicitly designated constant value are auto-initialized: from left to right, starting at zero or the next explicitly initialized constant, incrementing by 1.
+Like C, Ada enumerators are unscoped, \ie enumerators declared inside of an enum are visible (projected) into the enclosing scope.
+Note, Ada is case-insensitive so names may appear in multiple forms and still be the same name (a questionable design decision).
+The only operators on enumeration types are the ordering operators, @=@, @<@, @<=@, @=@, @/=@, @>=@, @>@, where the ordering relation is given implicitly by the sequence of enumerators.
+
+Ada enumerators are overloadable.
+\begin{ada}
+type Traffic_Light is ( @Red@, Yellow, @Green@ );
+\end{ada}
+Like \CFA, Ada uses an advanced type-resolution algorithm, including the left-hand side of assignment, to disambiguate among overloaded names.
+Figure~\VRef{f:AdaEnumeration} shows how ambiguities are handled using a cast, \eg @RGB'(Red)@.
+
+\begin{figure}
+\begin{ada}
+with Ada.Text_IO; use Ada.Text_IO;
+procedure test is
+   type RGB is ( Red, Green, Blue );
+   type Traffic_Light is ( Red, Yellow, Green );
+   procedure @Print@( Colour : RGB ) is begin
+       Put_Line( "Colour is " & RGB'Image( Colour ) );
+   end Print;
+   procedure @Print@( TL : Traffic_Light ) is begin
+       Put_Line( "Light is " & Traffic_Light'Image( TL ) );
+   end Print;
+begin
+    Print( Blue );				$\C[2in]{-- RGB}$
+    Print( Yellow );			$\C{-- Traffic\_Light}$
+    Print( @RGB'(Red)@ );		$\C{-- ambiguous without cast}\CRT$
+end test;
+\end{ada}
+\caption{Ada Enumeration Overload Resolution} 
+\label{f:AdaEnumeration} 
+\end{figure}
+
 Like many other declarative items, enumeration literals can be renamed.
 In fact, such a literal is actually a function, so it has to be renamed as such:
@@ -86,4 +99,19 @@
 Renaming makes @Red@ directly visible without necessity to resort the use-clause.
 
+There are four enumeration pseudo functions (attributes): @'Pos@, @'Val@, @'Image@, and @'Value@.
+Function @Pos@ returns the enumerator position; the inverse function @Val@ returns the corresponding enumerator.
+\begin{ada}
+RGB'Pos(Red) = 0  -- '=' => equality
+RGB'Val(0) = Red
+\end{ada}
+Funcion @Image@ returns enumerator label (in capital letters); the inverse function @Value@ returns the corresponding enumerator.
+\begin{ada}
+RGB'Image( Red ) = "RED"
+RGB'Value("Red") =  Red
+\end{ada}
+These attributes are important for simple IO (there are more elaborate IO facilities in @Ada.Text_IO@ for enumeration types).
+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 intuitively result based on the attribute name.
+
+
 Note that redeclaration as a function does not affect the staticness of the literal.
 
@@ -109,35 +137,22 @@
 See Ada Programming/Libraries/Standard.
 
-\paragraph{Booleans as enumeration literals} ~\newline
-Also Booleans are defined as enumeration types:
-\begin{ada}
-type Boolean is (False, True);
-\end{ada}
-There is special semantics implied with this declaration in that objects and expressions of this type can be used as conditions.
-Note that the literals @False@ and @True@ are not Ada keywords.
-
-Thus it is not sufficient to declare a type with these literals and then hope objects of this type can be used like so:
-\begin{ada}
-type My_Boolean is (False, True);
-Condition: My_Boolean;
-
-if Condition then -- wrong, won't compile
-\end{ada}
-
-If you need your own Booleans (perhaps with special size requirements), you have to derive from the predefined Boolean:
-\begin{ada}
-type My_Boolean is new Boolean;
-Condition: My_Boolean;
-
-if Condition then -- OK
-\end{ada}
-
-\paragraph{Enumeration subtypes} ~\newline
-You can use range to subtype an enumeration type:
-\begin{ada}
-subtype Capital_Letter is Character range 'A' .. 'Z';
-type Day_Of_Week is (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday);
-subtype Working_Day is Day_Of_Week range Monday .. Friday;
-\end{ada}
+The boolean type is defined as an enumeration:
+\begin{ada}
+type Boolean is (False, True); -- False / True not keywords
+@Flag@ : Boolean;
+\end{ada}
+which can be used in conditions.
+\begin{ada}
+if @Flag@ then ...
+\end{ada}
+Since only types derived from @Boolean@ can be a conditional, @Boolean@ is essentially  a builtin type.
+
+Ada provides a simple \emph{consecutive} subset (subtype) of an enumeration using \lstinline[language=ada]{range}.
+\begin{ada}
+type BW  is ( Cyan, Megenta, Yellow, Red, Green, Blue );
+type CMY is new BW @range@ Cyan .. Yellow;
+type RGB is new BW @range@ Red .. Blue;
+\end{ada}
+Hence, the ordering of the enumerators is crucial to provide the necessary ranges.
 
 \paragraph{Using enumerations} ~\newline
@@ -175,16 +190,4 @@
 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.
 
-\paragraph{Attributes of Enumeration Types} ~\newline
-An enumeration type, @T@, has the following attributes: @T'First@, @T'Last@, @T'Range@, @T'Pred@, @T'Succ@, @T'Min@, @T'Max@, @T'Image@, @T'Wide_Image@, @T'Value@, @T'Wide_Value@, @T'Pos@, and @T'Val@ (pronounced "T tick first", "T tick last", etc.).
-Most of these are illustrated in the example program given below, and most of them produce what you would intuitively expect based on their names.
-
-@T'Image@ and @T'Value@ form a complementary pair of attributes.
-The former takes a value in @T@ and returns a String representation of that value.
-The latter takes a @String@ that is a representation of a value in @T@ and returns that value.
-
-@T'Pos@ and @T'Val@ form another complementary pair.
-The former takes a value in @T@ and returns its position number.
-The latter takes a position number and returns the corresponding value of type @T@.
-
 
 \section{C\raisebox{-0.7ex}{\LARGE$^\sharp$}\xspace} % latex bug: cannot use \relsize{2} so use \LARGE
@@ -193,5 +196,5 @@
 \lstset{
 language=[Sharp]C,
-escapechar=\$,				% LaTeX escape in CFA code
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
@@ -320,6 +323,6 @@
 \lstnewenvironment{c++}[1][]{% necessary
 \lstset{
-language=C++,
-escapechar=\$,				% LaTeX escape in CFA code
+language=[GNU]C++,
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
@@ -329,5 +332,6 @@
 \CC is backwards compatible with C, so it inherited C's enumerations.
 However, the following non-backwards compatible changes have been made.
-\begin{quote}
+
+\begin{cquote}
 7.2 Change: \CC objects of enumeration type can only be assigned values of the same enumeration type.
 In C, objects of enumeration type can be assigned values of any integral type. \\
@@ -341,6 +345,7 @@
 \textbf{Difficulty of converting}: Syntactic transformation. (The type error produced by the assignment can be automatically corrected by applying an explicit cast.) \\
 \textbf{How widely used}: Common.
-\end{quote}
-\begin{quote}
+\end{cquote}
+
+\begin{cquote}
 7.2 Change: In \CC, the type of an enumerator is its enumeration.
 In C, the type of an enumerator is @int@. \\
@@ -357,5 +362,6 @@
 \textbf{How widely used}: Seldom. The only time this affects existing C code is when the size of an enumerator is taken.
 Taking the size of an enumerator is not a common C coding practice.
-\end{quote}
+\end{cquote}
+
 Hence, the values in a \CC enumeration can only be its enumerators (without a cast).
 While the storage size of an enumerator is up to the compiler, there is still an implicit cast to @int@.
@@ -392,10 +398,10 @@
 
 
-\section{Go}
+\section{Golang}
 
 \lstnewenvironment{Go}[1][]{% necessary
 \lstset{
 language=Go,
-escapechar=\$,				% LaTeX escape in CFA code
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
@@ -403,83 +409,37 @@
 }{}
 
-What Is an Enum in Golang?
-
-An enumerator, or enum, is a data type in Golang that consists of a set of named, constant values. While Golang doesn't support enums, it can be implemented using the identifier iota with constants.
-
-However, in Golang, they're implemented quite differently than most other programming languages. Golang doesn't support enums directly, however, we can implement it using iota and constants.
-
-In order to implement enums in Golang, let's first understand what iota is and how it is used.
-
- 
-What Is Iota in Golang?
-
-iota is an identifier that is used with constant and can simplify constant definitions that use auto-increment numbers. The iota keyword represents integer constant starting from zero.
-
-The iota keyword represents successive integer constants 0, 1, 2, \ldots.
-It resets to 0 whenever the word const appears in the source code and increments after each const specification.
+The Golang enumeration is similar to classical Pascal \lstinline[language=pascal]{const}, where the type of a \lstinline[language=Golang]{const} name is the type of its constant.
+Constant names are unscoped and must be unique (no overloading).
+The first enumerator \emph{must} be explicitly initialized;
+subsequent enumerators can be implicitly or explicitly initialized.
+Implicit initialization is the previous (left) enumerator value.
 \begin{Go}
-package main
-
-import "fmt"
-
-const (
-	c0 = iota
-	c1 = iota
-	c2 = iota
-)
-func main() {
-	fmt.Println(c0, c1, c2) //Print : 0 1 2
-}
+const ( R = 0; G; B )					$\C{// implicit: 0 0 0}$
+const ( Fred = "Fred"; Mary = "Mary"; Jane = "Jane" ) $\C{// explicit: Fred Mary Jane}$
+const ( H = 0; Jack = "Jack"; J, K = 3; I )	$\C{// type change, implicit/explicit: 0 Jack Jack 3 3}$
 \end{Go}
-You can avoid writing successive iota in front of every constant. This can be simplified as in the below code listing:
+
+Auto-incrementing is supported by the keyword \lstinline[language=Go]{iota}, available only in the \lstinline[language=Go]{const} declaration.
+The \lstinline[language=Go]{iota} is a \emph{per \lstinline[language=golang]{const} declaration} integer counter, starting at zero and implicitly incremented by one for each \lstinline[language=golang]{const} identifier.
 \begin{Go}
-package main
-
-import "fmt"
-
-const (
-	c0 = iota
-	c1
-	c2
-)
-
-func main() {
-	fmt.Println(c0, c1, c2) //Print : 0 1 2
-}
+const ( R = @iota@; G; B )				$\C{// implicit: 0 1 2}$
+const ( C = @iota + B + 1@; G; Y )		$\C{// implicit: 3 4 5}$
 \end{Go}
-To start a list of constants at 1 instead of 0, you can use iota in an arithmetic expression.
+An underscore \lstinline[language=golang]{const} identifier advances \lstinline[language=Go]{iota}.
 \begin{Go}
-package main
-
-import "fmt"
-
-const (
-	c0 = iota + 1
-	c1
-	c2
-)
-
-func main() {
-	fmt.Println(c0, c1, c2) // Print : 1 2 3
-}
+const ( O1 = iota + 1; @_@; O3; @_@; O5 ) // 1, 3, 5 
 \end{Go}
-You can use the blank identifier to skip a value in a list of constants.
+Auto-incrementing stops after an explicit initialization.
 \begin{Go}
-package main
-
-import "fmt"
-
-const (
-	c1 = iota + 1
-	_
-	c3
-	c4
-)
-
-func main() {
-	fmt.Println(c1, c3, c4) // Print : 1 3 4
-}
+const ( Monday = iota; Tuesday; Wednesday; // 0, 1, 2
+	 @Thursday = 10@; Friday; Saturday; Sunday ) // 10, 10, 10, 10
 \end{Go}
-
+Auto-incrementing can be restarted with an expression containing \emph{one} \lstinline[language=Go]{iota}.
+\begin{Go}
+const ( V1 = iota; V2; @V3 = 7;@ V4 = @iota@; V5 ) // 0 1 7 3 4
+const ( Monday = iota; Tuesday; Wednesday; // 0, 1, 2
+	 @Thursday = 10;@ Friday = @iota - Wednesday + Thursday - 1@; Saturday; Sunday ) // 10, 11, 12, 13
+\end{Go}
+Note, \lstinline[language=Go]{iota} is advanced for the explicitly initialized enumerator, like the underscore @_@ identifier.
 
 \section{Java}
@@ -495,5 +455,5 @@
 \lstset{
 language=Swift,
-escapechar=\$,				% LaTeX escape in CFA code
+escapechar=\$,							% LaTeX escape in code
 moredelim=**[is][\color{red}]{@}{@},	% red highlighting @...@
 }% lstset
