Changeset 11cced6


Ignore:
Timestamp:
Aug 8, 2024, 6:12:21 PM (3 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
c1c0efdb
Parents:
c4aca65
Message:

grammar update and section moved

File:
1 edited

Legend:

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

    rc4aca65 r11cced6  
    1919
    2020Enumeration-like features exist in many popular programming languages, both past and present, \eg Pascal~\cite{Pascal}, Ada~\cite{Ada}, \Csharp~\cite{Csharp}, OCaml~\cite{OCaml} \CC, Go~\cite{Go}, Haskell~\cite{Haskell}, Java~\cite{Java}, Rust~\cite{Rust}, Swift~\cite{Swift}, Python~\cite{Python}.
    21 Among theses languages, there are a large set of overlapping features, but each language has its own unique extensions and restrictions.
     21Among these languages, there is a large set of overlapping features, but each language has its own unique extensions and restrictions.
    2222
    2323
     
    3939\end{pascal}
    4040Object initialization and assignment are restricted to the enumerators of this type.
    41 Enumerators are auto-initialized from left to right, starting at zero, incrementing by 1.
     41Enumerators are auto-initialized from left to right, starting at zero and incrementing by 1.
    4242Enumerators \emph{cannot} be explicitly initialized.
    4343Pascal provides a predefined type \lstinline[language=Pascal]{Boolean} defined as:
     
    6666\end{pascal}
    6767Hence, the ordering of the enumerators is crucial to provide the necessary ranges.
    68 There is bidirectional assignment between the enumeration and its subranges.
     68There is a bidirectional assignment between the enumeration and its subranges.
    6969\begin{pascal}
    7070day := Sat;
     
    7777day := wend;                    $\C{\{ no check \}}\CRT$
    7878\end{pascal}
    79 There should be a static/dynamic range check to verify values assigned to subtypes.
     79A static/dynamic range check should be performed to verify the values assigned to subtypes.
    8080(Free Pascal does not check and aborts in certain situations, like writing an invalid enumerator.)
    8181
     
    125125\end{tabular}
    126126\end{cquote}
    127 Note, subtype @Weekday@ and @Weekend@ cannot be used to define a case or loop range.
     127Note that subtypes @Weekday@ and @Weekend@ cannot be used to define a case or loop range.
    128128
    129129An enumeration type can be used as an array dimension and subscript.
     
    149149\end{pascal}
    150150
    151 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.
     151The 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.
    152152The integral size can be explicitly specified using compiler directive \$@PACKENUM@~$N$, where $N$ is the number of bytes, \eg:
    153153\begin{pascal}
     
    172172type Traffic_Light is ( @Red@, Yellow, @Green@ );
    173173\end{ada}
    174 Like \CFA, Ada uses a type-resolution algorithm including the left-hand side of assignmente to disambiguate among overloaded identifiers.
     174Like \CFA, Ada uses a type-resolution algorithm, including the left-hand side of the assignment, to disambiguate among overloaded identifiers.
    175175\VRef[Figure]{f:AdaEnumeration} shows how ambiguity is handled using a cast, \ie \lstinline[language=ada]{RGB'(Red)}.
    176176
     
    203203for Week use ( Mon => 0, Tue => 1, Wed => 2, Thu => @10@, Fri => 11, Sat => 14, Sun => 15 );
    204204\end{ada}
    205 The enumeration operators are the equality and relational operators, @=@, @/=@, @<@, @<=@, @=@, @/=@, @>=@, @>@, where the ordering relationship is given implicitly by the sequence of acsending enumerators.
     205The enumeration operators are the equality and relational operators, @=@, @/=@, @<@, @<=@, @=@, @/=@, @>=@, @>@, where the ordering relationship is given implicitly by the sequence of ascending enumerators.
    206206
    207207Ada provides an alias mechanism, \lstinline[language=ada]{renames}, for aliasing types, which is useful to shorten package identifiers.
     
    259259if @Flag@ then ...    -- conditional
    260260\end{ada}
    261 Since only types derived from @Boolean@ can be a conditional, @Boolean@ is essentially  a builtin type.
     261Since only types derived from @Boolean@ can be conditional, @Boolean@ is essentially a built-in type.
    262262
    263263Ada provides \emph{consecutive} subtyping of an enumeration using \lstinline[language=ada]{range}.
     
    325325\label{s:C++RelatedWork}
    326326
    327 \CC enumeration is largely backwards compatible with C, so it inherited C's enumerations with some modifications and additions.
     327\CC enumeration is largely backward compatible with C, so it inherited C's enumerations with some modifications and additions.
    328328
    329329\CC has aliasing using @const@ declarations, like C \see{\VRef{s:Cconst}}, with type inferencing, plus static/dynamic initialization.
     
    440440% However, there is no mechanism to iterate through an enumeration without an unsafe cast and it does not understand the enumerator values.
    441441\CC enumerators are not relational: the only comparator defined for \CC is the value comparison. The define order of enumerator has no
    442 impact on its behaviour. As a consequnce, \CC has no meaningful enumerating mechanism.
     442impact on its behaviour. As a consequence, \CC has no meaningful enumerating mechanism.
    443443\begin{c++}
    444444enum Week { Mon, Tue, Wed, Thu = 10, Fri, Sat, Sun };
     
    447447\end{c++}
    448448An approximation of enumerating an enum in \CC is to use the last enumerator value as a range. But it inevitably
    449 fails the enumeration value does not assemble auto-initialization.
     449fails, the enumeration value does not assemble auto-initialization.
    450450
    451451An enumeration type cannot declare an array dimension but an enumerator can be used as a subscript.
     
    460460% https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/enums
    461461
    462 \Csharp is a dynamically-typed programming-language with a scoped, integral enumeration similar to \CC \lstinline[language=C++]{enum class}.
     462\Csharp is a dynamically-typed programming language with a scoped, integral enumeration similar to \CC \lstinline[language=C++]{enum class}.
    463463\begin{csharp}
    464464enum Week : @long@ { Mon, Tue, Wed, Thu@ = 10@, Fri, Sat, Sun }
    465465enum RGB { Red, Green, Blue }
    466466\end{csharp}
    467 The default underlying integral type is @int@ (no @char@), with auto-incrementing, implicit/explicit initialization.
     467The default underlying integral type is @int@ (no @char@), with auto-incrementing and implicit/explicit initialization.
    468468A method cannot be defined in an enumeration type (extension methods are possible).
    469469There is an explicit bidirectional conversion between an enumeration and its integral type, and an implicit conversion to the enumerator label in display contexts.
     
    479479% Relational and arithmetic operators are defined in terms of its numeric value only.
    480480% Therefore, enumerators are not ordered and not enumerable like \CC.
    481 Like \CC, \Csharp defines enumeration relational and arithemtic operators in terms of value.
    482 Enumerators has no defined positional meaning.
     481Like \CC, \Csharp defines enumeration relational and arithmetic operators in terms of value.
     482Enumerators have no defined positional meaning.
    483483\begin{csharp}
    484484day = day++ - 5;                                        $\C{// unsafe}$
     
    555555const V = 3.1;  const W = 3.1;
    556556\end{Go}
    557 Since these declarations are unmutable variables, they are unscoped and Golang has no overloading.
     557Since these declarations are immutable variables, they are unscoped, and Golang has no overloading.
    558558
    559559Golang provides an enumeration-like feature to group together @const@ declaration into a block and introduces a form of auto-initialization.
     
    592592                @Thu = 10;@ Fri = @iota - Wed + Thu - 1@; Sat; Sun ) // 10, 11, 12, 13
    593593\end{Go}
    594 Here, @V4@ and @Fri@ restart auto-incrementing from \lstinline[language=Go]{iota} and reset \lstinline[language=Go]{iota} to 4 and 11, respectively, because of the intialization expressions containing \lstinline[language=Go]{iota}.
     594Here, @V4@ and @Fri@ restart auto-incrementing from \lstinline[language=Go]{iota} and reset \lstinline[language=Go]{iota} to 4 and 11, respectively, because of the initialization expressions containing \lstinline[language=Go]{iota}.
    595595Note, because \lstinline[language=Go]{iota} is incremented for an explicitly initialized identifier or @_@,
    596596at @Fri@ \lstinline[language=Go]{iota} is 4 requiring the minus one to compute the value for @Fri@.
     
    640640Week day = Week.Sat;
    641641\end{Java}
    642 The enumerators members are scoped and cannot be made \lstinline[language=java]{public}, hence require qualification.
     642The enumerator's members are scoped and cannot be made \lstinline[language=java]{public}, hence requiring qualification.
    643643The value of an enumeration instance is restricted to its enumerators.
    644644
     
    649649\end{Java}
    650650Since @day@ has no value, it prints its label (name).
    651 The member @valueOf@ is the inverse of @name@ converting a string to enumerator.
     651The member @valueOf@ is the inverse of @name@, converting a string to an enumerator.
    652652\begin{Java}
    653653day = Week.valueOf( "Wed" );
     
    703703Notice enumerators in the @switch@ statement do not require qualification.
    704704
    705 There are no arithemtic operations on enumerations, so there is no arithmetic way to iterate through an enumeration without making the implementation type \lstinline[language=Java]{public}.
     705There are no arithmetic operations on enumerations, so there is no arithmetic way to iterate through an enumeration without making the implementation type \lstinline[language=Java]{public}.
    706706Like \Csharp, looping over an enumeration is done using method @values@, which returns an array of enumerator values (expensive operation).
    707707\begin{Java}
     
    801801Through this integral tag, it is possible to enumerate, and when all tags represent the unit type, it behaves like \CC \lstinline[language=C++]{enum class}.
    802802When tags represent non-unit types, Rust largely precludes accessing the tag because the semantics become meaningless.
    803 Hence, the two mechanisms are largely disjoint, and ony the enumeration component is discussed.
    804 
    805 In detail, the @enum@ type has an implicit integer tag (discriminant), with a unique value for each variant type.
    806 Direct initialization is by a compile-time expression generating a constant value.
     803Hence, the two mechanisms are largely disjoint, and only the enumeration component is discussed.
     804
     805In detail, the @enum@ type has an implicit integer tag (discriminant) with a unique value for each variant type.
     806Direct initialization is achieved by a compile-time expression that generates a constant value.
    807807Indirect initialization (without initialization, @Fri@/@Sun@) is auto-initialized: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.
    808808There is an explicit cast from the tag to integer.
     
    966966The @enum.allCases@ property returns a collection of all the cases for looping over an enumeration type or variable (expensive operation).
    967967
    968 A typed enumeration is accomplished by inheriting from any Swift type, and accessing the underlying enumerator value is done with attribute @rawValue@.
    969 Type @Int@ has auto-incrementing from previous enumerator;
     968A typed enumeration is accomplished by inheriting from any Swift type, and accessing the underlying enumerator value is done with the attribute @rawValue@.
     969Type @Int@ has auto-incrementing from the previous enumerator;
    970970type @String@ has auto-incrementing of the enumerator label.
    971971\begin{cquote}
     
    996996\end{cquote}
    997997
    998 There is a bidirectional conversion from typed enumerator to @rawValue@ and vise versa.
     998There is a bidirectional conversion from typed enumerator to @rawValue@ and vice versa.
    999999\begin{swift}
    10001000var weekInt : WeekInt = WeekInt.Mon;
     
    10111011% https://docs.python.org/3/howto/enum.html
    10121012
    1013 Python is a dynamically-typed reflexive programming language with multiple incompatible versions.
    1014 The generality of the language makes it is possible to extend existing or build new language features.
    1015 As a result, discussing Python enumerations is a moving target, because if a features does not exist, it can often be created with varying levels of complexity within the language.
     1013Python is a dynamically typed reflexive programming language with multiple incompatible versions.
     1014The generality of the language makes it possible to extend existing or build new language features.
     1015As a result, discussing Python enumerations is a moving target because if a feature does not exist, it can often be created with varying levels of complexity within the language.
    10161016Therefore, the following discussion is (mostly) restricted to the core enumeration features in Python 3.13.
    10171017
    10181018A Python enumeration is not a basic type;
    10191019it is a @class@ inheriting from the @Enum@ class.
    1020 The @Enum@ class presents a set of scoped enumerators, where each enumerator is a pair object with a \emph{constant} string name and arbitrary value.
     1020The @Enum@ class presents a set of scoped enumerators, where each enumerator is a pair object with a \emph{constant} string name and an arbitrary value.
    10211021Hence, an enumeration instance is a fixed type (enumeration pair), and its value is the type of one of the enumerator pairs.
    10221022
     
    10251025class Week(!Enum!): Mon = 1; Tue = 2; Wed = 3; Thu = 4; Fri = 5; Sat = 6; Sun = 7
    10261026\end{python}
    1027 and/or explicitly auto initialized, \eg:
     1027and/or explicitly auto-initialized, \eg:
    10281028\begin{python}
    10291029class Week(Enum): Mon = 1; Tue = 2; Wed = 3; Thu = 10; Fri = !auto()!; Sat = 4; Sun = !auto()!
     
    10381038\end{python}
    10391039
    1040 There is no direct concept of restricting the enumerators in an enumeration \emph{instance} because the dynamic typing changes the type.
     1040There is no direct concept of restricting the enumerators in an enumeration \emph{instance} because dynamic typing changes the type.
    10411041\begin{python}
    10421042class RGB(Enum): Red = 1; Green = 2; Blue = 3
     
    11471147class WeekEnd(WeekE): Sat = 6; Sun = 7
    11481148\end{python}
    1149 Here, type @WeekE@ is an abstract type because the dynamic typing never uses it.
     1149Here, type @WeekE@ is an abstract type because dynamic typing never uses it.
    11501150\begin{cquote}
    11511151\setlength{\tabcolsep}{25pt}
     
    11751175@Flag@ is the same as @IntFlag@ but cannot be combined with, nor compared against, any other @Flag@ enumeration, nor @int@.
    11761176Auto increment for @IntFlag@ and @Flag@ is by powers of 2.
    1177 Enumerators that are a combinations of single bit enumerators are aliases, and hence, invisible.
     1177Enumerators that are combinations of single-bit enumerators are aliases and, hence, invisible.
    11781178The following is an example for @Flag@.
    11791179\begin{python}
     
    12581258\end{cquote}
    12591259(Note, after an @adtv@'s type is know, the enumerator is inferred without qualification, \eg @I(3)@.)
    1260 The type names are independent from the type value, and mapped to an opaque, ascending, integral tag, starting from 0, supporting relational operators @<@, @<=@, @>@, and @>=@.
     1260The type names are independent of the type value and mapped to an opaque, ascending, integral tag, starting from 0, supporting relational operators @<@, @<=@, @>@, and @>=@.
    12611261\begin{cquote}
    12621262\setlength{\tabcolsep}{10pt}
     
    12991299
    13001300% Enumerating is accomplished by deriving from @enumerate@.
    1301 OCaml enumerators has an ordering following the definition order, but they are not enumerable.
    1302 To iterate over all enumerators, an OCaml type needs to derive @enumerate@ proprocessor, which appends a list of all enumerators to the program
    1303 abstract syntax tree (AST). The list of value may not persist the define ordering. Given that it needs tools that is outside of the native language to facilate,
     1301OCaml enumerators have an ordering following the definition order, but they are not enumerable.
     1302To iterate over all enumerators, an OCaml type needs to derive the @enumerate@ preprocessor, which appends a list of all enumerators to the program
     1303abstract syntax tree (AST). The list of values may not persist in the defined ordering. Given that it needs tools that are outside of the native language to facilitate,
    13041304we claim it has no capability of enumerating.
    13051305
     
    15331533
    15341534\VRef[Table]{t:FeatureLanguageComparison} shows a comparison of enumeration features and programming languages with the explaination of categories below.
    1535 The features are high level and may not capture nuances within a particular language.
     1535The features are high-level and may not capture nuances within a particular language.
    15361536
    15371537\begin{table}
     
    15771577\item Typed: The type of value. H: heterogeneous type; values from the same enum need not be the same type.
    15781578U: uni-type; value must have the same type.
    1579 \item Safe: A enumeration variable can only hold a value from its defined enumerators.
    1580 \item Posn ordered: enumerators have defined ordering based on enuemrator declaration order.
     1579\item Safe: An enumeration variable can only hold a value from its defined enumerators.
     1580\item Posn ordered: enumerators have defined ordering based on enumerator declaration order.
    15811581It is implied position ordered if its enumerator value must be strictly increasingly ordered.
    1582 \item Unique value: enumerators must have unique value.
    1583 \item Auto-init: Value are auto initializable by language specification, often being the "+1" of the predecessor.
    1584 \item (Un)Scoped: U: unscoped enuemrators and does not need qualification; S: Scoped enumerators and requires qualification.
    1585 \item Overload: An enumerator label can be used without type qualification in a context where the label has defined by multiple enumerations.
     1582\item Unique value: enumerators must have a unique value.
     1583\item Auto-init: Values are auto-initializable by language specification, often being the "+1" of the predecessor.
     1584\item (Un)Scoped: U: unscoped enumerators and did not need qualification; S: Scoped enumerators and requires qualification.
     1585\item Overload: An enumerator label can be used without type qualification in a context where multiple enumerations have defined the label.
    15861586\item Loop: Enumerate enum members without the need to convert an enumeration to another data structure
    1587 \item Arr. dim: An enumeration can be used directly as array dimension and enumerators can be mapped to an array element (not a conversion to integer type).
     1587\item Arr. dim: An enumeration can be used directly as an array dimension, and enumerators can be mapped to an array element (not a conversion to integer type).
    15881588\item Subset: Name a subset of enumerators as a new type.
    1589 \item Superset: Create a new enumeration that contains all enumerators from pre-defined enuemrations.
     1589\item Superset: Create a new enumeration that contains all enumerators from pre-defined enumerations.
    15901590\end{enumerate}
Note: See TracChangeset for help on using the changeset viewer.