Changeset 35897fb for doc/theses/jiada_liang_MMath/intro.tex
- Timestamp:
- May 1, 2024, 1:36:04 PM (6 weeks ago)
- Branches:
- master
- Children:
- d414664
- Parents:
- de3a579 (diff), 69867ad9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/intro.tex
rde3a579 r35897fb 1 1 \chapter{Introduction} 2 2 3 All 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.3 All 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. 4 4 Con\-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 5 (In \CFA, the primary constants @0@ and @1@ can be overloaded for any type.) … … 7 7 In theory, there are an infinite set of primary constant names per type. 8 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.10 Many 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.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. 10 Many 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. 11 11 Its purpose is for readability and to eliminate duplication of the primary constant throughout a program. 12 12 For example, a meaningful secondary name replaces a primary name throughout a program; 13 13 thereafter, changing the binding of the secondary to primary name automatically distributes the rebinding, preventing errors. 14 In 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@.15 Because 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{14 In 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@. 15 Because 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{ 16 16 The term rvalue defines an expression that can only appear on the right-hand side of an assignment expression.}. 17 17 18 18 Secondary 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. 19 Many programming languages capture these groupings through a mechanism called an \ Newterm{enumeration}.19 Many programming languages capture these groupings through a mechanism called an \newterm{enumeration}. 20 20 \begin{quote} 21 21 enumerate (verb, transitive). … … 63 63 \label{s:Terminology} 64 64 65 The 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}.66 As well, an enumerated type can have three fundamental properties, \ Newterm{label}, \Newterm{order}, and \Newterm{value}.65 The 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}. 66 As well, an enumerated type can have three fundamental properties, \newterm{label}, \newterm{order}, and \newterm{value}. 67 67 \begin{cquote} 68 68 \sf\setlength{\tabcolsep}{3pt} … … 116 116 foo( Size ); // take the address of (reference) Size 117 117 \end{cfa} 118 Taking the address of an immutable variable makes it an \ Newterm{lvalue}, which implies it has storage.118 Taking the address of an immutable variable makes it an \newterm{lvalue}, which implies it has storage. 119 119 With separate compilation, it is necessary to choose one translation unit to perform the initialization. 120 120 If aliasing does require storage, its address and initialization are opaque (compiler only), similar to \CC rvalue reference @&&@. … … 185 185 Here, the constructor name gives different meaning to the values in the common \lstinline[language=Haskell]{Int} type, \eg the value @3@ has different interpretations depending on the constructor name in the pattern matching. 186 186 187 Note, the term \ Newterm{variant} is often associated with ADTs.187 Note, the term \newterm{variant} is often associated with ADTs. 188 188 However, there are multiple languages with a @variant@ type that is not an ADT \see{Algol68~\cite{Algol68} or \CC \lstinline{variant}}. 189 189 In these languages, the variant is often a union using RTTI tags, which cannot be used to simulate an enumeration.
Note: See TracChangeset
for help on using the changeset viewer.