Changes in / [e6f1a4b:31f4837]


Ignore:
Location:
doc
Files:
1 deleted
3 edited

Legend:

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

    re6f1a4b r31f4837  
    4545Statically initialized identifiers may appear in any constant-expression context, \eg @case@.
    4646Dynamically initialized identifiers may appear as array dimensions in @g++@, which allows variable-sized arrays on the stack.
    47 Again, this form of aliasing is not an enumeration.
     47Again, this form of aliasing to primary constant is not an enumeration.
    4848
    4949
  • doc/theses/jiada_liang_MMath/intro.tex

    re6f1a4b r31f4837  
    11\chapter{Introduction}
    22
    3 All types in a programming language have a set of constants (symbols), and these constants represent values, \eg integer types have constants @-1@, @17@, @0xff@ representing whole numbers, floating-point types have constants @5.3@, @2.3E-5@, @0xff.ffp0@ representing  real numbers, character types have constants @'a'@, @"abc\n"@, \mbox{\lstinline{u8"}\texttt{\guillemotleft{na\"{i}ve}\guillemotright}\lstinline{"}} representing (human readable) text, \etc.
    4 Constants can be overloaded among types, \eg @0@ is a null pointer for all pointer types, and the value zero for integer and floating-point types.
    5 (In \CFA, the constants @0@ and @1@ can be overloaded for any type.)
    6 A constant's symbolic name is dictated by language syntax related to types.
    7 In general, the representation of a constant's value is \newterm{opaque}, so the internal representation can be chosen arbitrarily.
    8 In theory, there are an infinite set of constant names per type representing an infinite set of values.
    9 
    10 It is common in mathematics, engineering and computer science to alias new constants to existing constants so they have the same value, \eg $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), K(k), M, G, T for powers of 2\footnote{Overloaded with SI powers of 10.} often prefixing bits (b) or bytes (B), \eg Gb, MB, and in general situations, \eg specific times (noon, New Years), cities (Big Apple), flowers (Lily), \etc.
    11 An alias can bind to another alias, which transitively binds it to the specified constant.
    12 Multiple aliases can represent the same value, \eg eighth note and quaver, giving synonyms.
    13 
    14 Many programming languages capture this important software-engineering capability through a mechanism called \newterm{constant} or \newterm{literal} naming, where a new constant is aliased to an existing constant.
    15 Its purpose is for readability, replacing a constant name that directly represents a value with a name that is more symbolic and meaningful in the context of the program.
    16 Thereafter, changing the aliasing of the new constant to another constant automatically distributes the rebinding, preventing errors.
    17 % and only equality operations are available, \eg @O_RDONLY@, @O_WRONLY@, @O_CREAT@, @O_TRUNC@, @O_APPEND@.
    18 Because an aliased name is a constant, it cannot appear in a mutable context, \eg \mbox{$\pi$ \lstinline{= 42}} is meaningless, and a constant has no address, \ie it is an \newterm{rvalue}\footnote{
     3All types in a programming language must have a set of constants, and these constants have \newterm{primary names}, \eg integral types have constants @-1@, @17@, @0xff@, floating-point types have constants @5.3@, @2.3E-5@, @0xff.ffp0@, character types have constants @'a'@, @"abc\n"@, \mbox{\lstinline{u8"}\texttt{\guillemotleft{na\"{i}ve}\guillemotright}\lstinline{"}}, \etc.
     4Con\-stants can be overloaded among types, \eg @0@ is a null pointer for all pointer types, and the value zero for integral and floating-point types.
     5(In \CFA, the primary constants @0@ and @1@ can be overloaded for any type.)
     6Hence, each primary constant has a symbolic name referring to its internal representation, and these names are dictated by language syntax related to types.
     7In theory, there are an infinite set of primary constant names per type.
     8
     9\newterm{Secondary naming} is a common practice in mathematics, engineering and computer science, \eg $\pi$, $\tau$ (2$\pi$), $\phi$ (golden ratio), MB (megabyte, 1E6), and in general situations, \eg specific times (noon, New Years), cities (Big Apple), flowers (Lily), \etc.
     10Many programming languages capture this important software-engineering capability through a mechanism called \newterm{constant} or \newterm{literal} naming, where a secondary name is aliased to a primary name.
     11Its purpose is for readability and to eliminate duplication of the primary constant throughout a program.
     12For example, a meaningful secondary name replaces a primary name throughout a program;
     13thereafter, changing the binding of the secondary to primary name automatically distributes the rebinding, preventing errors.
     14In some cases, secondary naming is \newterm{opaque}, where the matching internal representation can be chosen arbitrarily, and only equality operations are available, \eg @O_RDONLY@, @O_WRONLY@, @O_CREAT@, @O_TRUNC@, @O_APPEND@.
     15Because a secondary name is a constant, it cannot appear in a mutable context, \eg \mbox{$\pi$ \lstinline{= 42}} is meaningless, and a constant has no address, \ie it is an \newterm{rvalue}\footnote{
    1916The term rvalue defines an expression that can only appear on the right-hand side of an assignment expression.}.
    20 In theory, there are an infinite set of possible aliasing, in practice, the number of aliasing per program is finite and small.
    21 
    22 Aliased constants can form an (ordered) set, \eg days of a week, months of a year, floors of a building (basement, ground, 1st), colours in a rainbow, \etc.
    23 In this case, the binding between a constant name and value can be implicit, where the values are chosen to support any set operations.
    24 Many programming languages capture the aliasing and ordering through a mechanism called an \newterm{enumeration}.
     17
     18Secondary names can form an (ordered) set, \eg days of a week, months of a year, floors of a building (basement, ground, 1st), colours in a rainbow, \etc.
     19Many programming languages capture these groupings through a mechanism called an \newterm{enumeration}.
    2520\begin{quote}
    2621enumerate (verb, transitive).
     
    2924to specify as in a list or catalogue.~\cite{OEDenumerate}
    3025\end{quote}
    31 Within an enumeration set, the enumeration names (aliases) must be unique, and instances of an enumerated type are \emph{often} restricted to hold only these names.
    32 
    33 It is possible to enumerate among set names without having an ordering among the set values.
     26Within an enumeration set, the enumeration names must be unique, and instances of an enumerated type are \emph{often} restricted to hold only the secondary names.
     27It is possible to enumerate among set names without having an ordering among the set elements.
    3428For example, the week, the weekdays, the weekend, and every second day of the week.
    3529\begin{cfa}[morekeywords={in}]
     
    3933for ( cursor in Mon, Wed, Fri, Sun } ...                $\C{// every second day of week}\CRT$
    4034\end{cfa}
     35This independence from internal representation allows multiple names to have the same representation (eighth note, quaver), giving synonyms.
    4136A set can have a partial or total ordering, making it possible to compare set elements, \eg Monday is before Friday and Friday is after.
    4237Ordering allows iterating among the enumeration set using relational operators and advancement, \eg:
     
    4439for ( cursor = Monday; cursor @<=@ Friday; cursor = @succ@( cursor ) ) ...
    4540\end{cfa}
    46 Here the values for the set names are logically \emph{generated} rather than listing a subset of names.
     41Here the internal representation for the secondary names are logically \emph{generated} rather than listing a subset of names.
    4742
    4843Hence, the fundamental aspects of an enumeration are:
     
    5045\item
    5146\begin{sloppypar}
    52 It provides a finite set of new constants, which are implicitly or explicitly assigned values that must be appropriate for any set operations.
    53 This aspect differentiates an enumeration from general types with an infinite set of constants.
     47It provides a finite set of secondary names, which become its primary constants.
     48This differentiates an enumeration from general types with an infinite set
     49of primary constants.
    5450\end{sloppypar}
    5551\item
    56 The alias names are constants, which follows transitively from their binding to other constants.
     52The secondary names are constants, which follows transitively from their binding (aliasing) to primary names, which are constants.
    5753\item
    5854Defines a type for generating instants (variables).
    5955\item
    60 For safety, an enumeration instance should be restricted to hold only its constant names.
    61 \item
    62 There is a mechanism for \emph{enumerating} over the enumeration names, where the ordering can be implicit from the type, explicitly listed, or generated arithmetically.
     56For safety, an enumeration instance should be restricted to hold only its type's secondary names.
     57\item
     58There is a mechanism for \emph{enumerating} over the secondary names, where the ordering can be implicit from the type, explicitly listed, or generated arithmetically.
    6359\end{enumerate}
    6460
     
    6763\label{s:Terminology}
    6864
    69 The term \newterm{enumeration} defines a type with a set of new constants, and the term \newterm{enumerator} represents an arbitrary alias name \see{\VRef{s:CEnumeration} for the name derivation}.
     65The term \newterm{enumeration} defines a type with a set of secondary names, and the term \newterm{enumerator} represents an arbitrary secondary name \see{\VRef{s:CEnumeration} for the name derivation}.
    7066As well, an enumerated type can have three fundamental properties, \newterm{label}, \newterm{order}, and \newterm{value}.
    7167\begin{cquote}
     
    8076\end{tabular}
    8177\end{cquote}
    82 Here, the enumeration @Week@ defines the enumerator constant @Mon@, @Tue@, @Wed@, @Thu@, @Fri@, @Sat@ and @Sun@.
     78Here, the enumeration @Week@ defines the enumerator labels @Mon@, @Tue@, @Wed@, @Thu@, @Fri@, @Sat@ and @Sun@.
    8379The implicit ordering implies the successor of @Tue@ is @Mon@ and the predecessor of @Tue@ is @Wed@, independent of any associated enumerator values.
    84 The value is the implicitly/explicitly assigned constant to support any enumeration operations;
    85 the value may be hidden (opaque) or visible.
     80The value is the constant represented by the secondary name, which can be implicitly or explicitly set.
    8681
    8782Specifying complex ordering is possible:
     
    9994Many programming languages provide an enumeration-like mechanism, which may or may not cover the previous five fundamental enumeration aspects.
    10095Hence, the term \emph{enumeration} can be confusing and misunderstood.
    101 Furthermore, some languages conjoin the enumeration with other type features, making it difficult to tease apart which feature is being used.
     96Furthermore, some languages conjoin the enumeration with other type features, making it difficult to tease apart which featuring is being used.
    10297This section discusses some language features that are sometimes called an enumeration but do not provide all enumeration aspects.
    10398
     
    106101\label{s:Aliasing}
    107102
    108 Some languages provide simple aliasing (renaming), \eg:
     103Some languages provide simple secondary aliasing (renaming), \eg:
    109104\begin{cfa}
    110105const Size = 20, Pi = 3.14159, Name = "Jane";
    111106\end{cfa}
    112 The alias name is logically replaced in the program text by its matching constant.
    113 It is possible to compare aliases, if the constants allow it, \eg @Size < Pi@;
    114 whereas \eg @Pi < Name@ might be disallowed depending on the language.
     107The secondary name is logically replaced in the program text by its corresponding primary name.
     108Therefore, it is possible to compare the secondary names, \eg @Size < Pi@, only because the primary constants allow it, whereas \eg @Pi < Name@ might be disallowed depending on the language.
    115109
    116110Aliasing is not macro substitution, \eg @#define Size 20@, where a name is replaced by its value \emph{before} compilation, so the name is invisible to the programming language.
    117 With aliasing, each new name is part of the language, and hence, participates fully, such as name overloading in the type system.
     111With aliasing, each secondary name is part of the language, and hence, participates fully, such as name overloading in the type system.
    118112Aliasing is not an immutable variable, \eg:
    119113\begin{cfa}
     
    127121
    128122Aliasing does provide readability and automatic resubstitution.
    129 It also provides simple enumeration properties, but with effort.
     123It also provides simple enumeration properties, but with extra effort.
    130124\begin{cfa}
    131125const Mon = 1, Tue = 2, Wed = 3, Thu = 4, Fri = 5, Sat = 6, Sun = 7;
     
    154148the ADT has three variants (constructors), @A@, @B@, @C@ with associated types @Int@, @Double@, and @S@.
    155149The constructors create an initialized value of the specific type that is bound to the immutable variables @foo@, @bar@, and @baz@.
    156 Hence, the ADT @Foo@ is like a union containing values of the associated types, and a constructor name is used to intialize and access the value using dynamic pattern-matching.
     150Hence, the ADT @Foo@ is like a union containing values of the associated types, and a constructor name is used to access the value using dynamic pattern-matching.
    157151\begin{cquote}
    158152\setlength{\tabcolsep}{15pt}
     
    181175\end{tabular}
    182176\end{cquote}
    183 For safety, most languages require all associated types to be listed or a default case with no field accesses.
     177For safety, most languages require all assocaited types to be listed or a default case with no field accesses.
    184178
    185179A less frequent case is multiple constructors with the same type.
     
    194188Note, the term \newterm{variant} is often associated with ADTs.
    195189However, there are multiple languages with a @variant@ type that is not an ADT \see{Algol68~\cite{Algol68} or \CC \lstinline{variant}}.
    196 In these languages, the variant is often a union using RTTI tags for discrimination, which cannot be used to simulate an enumeration.
     190In these languages, the variant is often a union using RTTI tags, which cannot be used to simulate an enumeration.
    197191Hence, in this work the term variant is not a synonym for ADT.
    198192
     
    214208data Week = Mon | Tue | Wed | Thu | Fri | Sat | Sun deriving(Enum, Eq, Show)
    215209\end{haskell}
    216 the default type for each constructor is the unit type, and deriving from @Enum@ enforces no other associated types, @Eq@ allows equality comparison, and @Show@ is for printing.
     210the default type for each constructor is the unit type, and deriving from @Enum@ enforces no other type, @Eq@ allows equality comparison, and @Show@ is for printing.
    217211The nullary constructors for the unit types are numbered left-to-right from $0$ to @maxBound@$- 1$, and provides enumerating operations @succ@, @pred@, @enumFrom@ @enumFromTo@.
    218212\VRef[Figure]{f:HaskellEnumeration} shows enumeration comparison and iterating (enumerating).
     
    252246
    253247The key observation is the dichotomy between an ADT and enumeration: the ADT uses the associated type resulting in a union-like data structure, and the enumeration does not use the associated type, and hence, is not a union.
    254 While the enumeration is constructed using the ADT mechanism, it is so restricted it is not an ADT.
     248While the enumeration is constructed using the ADT mechanism, it is so restricted it is not really an ADT.
    255249Furthermore, a general ADT cannot be an enumeration because the constructors generate different values making enumerating meaningless.
    256250While functional programming languages regularly repurpose the ADT type into an enumeration type, this process seems contrived and confusing.
  • doc/theses/jiada_liang_MMath/relatedwork.tex

    re6f1a4b r31f4837  
    423423
    424424\section{Golang}
    425 \label{s:Golang}
    426425
    427426Golang has a no enumeration.
     
    10691068
    10701069Python is a dynamically-typed reflexive programming language with multiple versions, and hence, it is possible to extend existing or build new language features within the language.
    1071 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.
    1072 Nevertheless, the following is a discuss of the core enumeration features that come with Python 3.13.
     1070As a result, discussing Python enumerations is a moving target, because if a features does not exist, if can often be created with varying levels of complexity.
     1071Nevertheless, an attempt has been made to discuss core enumeration features that come with Python 3.13.
    10731072
    10741073A Python enumeration type is a set of ordered scoped identifiers (enumerators) bound to \emph{unique} values.
     
    10821081class Week(Enum): Mon = 1; Tue = 2; Wed = 3; Thu = 10; Fri = @auto()@; Sat = 4; Sun = @auto()@
    10831082\end{python}
    1084 where @auto@ increments by 1 from the previous enumerator value \see{Golang \lstinline[language=Go]{iota}, \VRef{s:Golang}}.
     1083where @auto@ increments by 1 from the previous enumerator value.
    10851084Object initialization and assignment are restricted to the enumerators of this type.
    10861085An enumerator initialized with same value is an alias and invisible at the enumeration level, \ie the alias it substituted for its aliasee.
     
    11091108\end{cquote}
    11101109
    1111 An enumeration \lstinline[language=python]{class} can have methods.
     1110As an enumeration is a \lstinline[language=python]{class}, its own methods.
    11121111\begin{python}
    11131112class Week(Enum):
Note: See TracChangeset for help on using the changeset viewer.