- Timestamp:
- Apr 30, 2024, 12:08:24 PM (7 months ago)
- Branches:
- master
- Children:
- 69867ad9
- Parents:
- f632117
- Location:
- doc/theses/jiada_liang_MMath
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/theses/jiada_liang_MMath/CFAenum.tex
rf632117 rcaaf424 24 24 \label{s:EnumeratorUnscoping} 25 25 26 In C, unscoped enumerators presents a \ Newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.26 In C, unscoped enumerators presents a \newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names. 27 27 There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible. 28 28 … … 265 265 266 266 \VRef[Figure]{f:PlanetExample} shows an archetypal enumeration example illustrating most of the \CFA enumeration features. 267 Enumeration @Planet@ is a typedenumeration of type @MR@.267 @Planet@ is an enumeration of type @MR@. 268 268 Each of the planet enumerators is initialized to a specific mass/radius, @MR@, value. 269 The unnamed enumeration projects the gravitational-constant enumerator @G@. 270 The program main iterates through the planets computing the weight on each planet for a given earth weight. 269 The unnamed enumeration provides the gravitational-constant enumerator @G@. 270 Function @surfaceGravity@ uses the @with@ clause to remove @p@ qualification from fields @mass@ and @radius@. 271 The program main uses @SizeE@ to obtain the number of enumerators in @Planet@, and safely converts the random value into a @Planet@ enumerator. 272 The resulting random orbital body is used in a @choose@ statement. 273 The enumerators in the @case@ clause use position for testing. 274 The prints use @labelE@ to print the enumerators label. 275 Finally, a loop iterates through the planets computing the weight on each planet for a given earth weight. 276 The print statement does an equality comparison with an enumeration variable and enumerator. 271 277 272 278 \begin{figure} 279 \small 273 280 \begin{cfa} 274 281 struct MR { double mass, radius; }; 275 enum( MR) Planet {282 enum( @MR@ ) Planet { 276 283 // mass (kg) radius (km) 277 284 MERCURY = { 0.330_E24, 2.4397_E6 }, … … 285 292 NEPTUNE = { 102.4_E24, 24.746_E6 }, 286 293 }; 287 enum( double ) { G = 6.6743E-11 }; $\C{// universal gravitational constant (m3 kg-1 s-2)}$ 288 289 static double surfaceGravity( Planet p ) with( p ) { 290 return G * mass / ( radius * radius ); 294 enum( double ) { G = 6.6743_E-11 }; $\C{// universal gravitational constant (m3 kg-1 s-2)}$ 295 static double surfaceGravity( Planet p ) @with( p )@ { 296 return G * mass / ( radius \ 2u ); $\C{// exponentiation}$ 291 297 } 292 298 static double surfaceWeight( Planet p, double otherMass ) { … … 297 303 double earthWeight = convert( argv[1] ); 298 304 double mass = earthWeight / surfaceGravity( EARTH ); 299 for ( p; Planet ) { 300 sout | "Your weight on" | labelE(p) | "is" | wd(1,1, surfaceWeight( p, mass )) | "kg"; 305 306 Planet p = @fromInt@( prng( @SizeE@(Planet) ) ); $\C{// select a random orbiting body}$ 307 @choose( p )@ { 308 case MERCURY, VENUS, EARTH, MARS: 309 sout | @labelE( p )@ | "is a rocky planet"; 310 @case JUPITER, SATURN, URANUS, NEPTUNE:@ 311 sout | labelE( p ) | "is a gas-giant planet"; 312 default: 313 sout | labelE( p ) | "is not a planet"; 301 314 } 302 } 303 315 for ( @p; Planet@ ) { 316 sout | "Your weight on" | (@p == MOON@ ? "the" : "") | labelE(p) 317 | "is" | wd(1,1, surfaceWeight( p, mass )) | "kg"; 318 } 319 } 304 320 $\$$ planet 100 321 JUPITER is a gas-giant planet 305 322 Your weight on MERCURY is 37.7 kg 306 323 Your weight on VENUS is 90.5 kg 307 324 Your weight on EARTH is 100.0 kg 308 Your weight on MOON is 16.6 kg325 Your weight on the MOON is 16.6 kg 309 326 Your weight on MARS is 37.9 kg 310 327 Your weight on JUPITER is 252.8 kg -
doc/theses/jiada_liang_MMath/background.tex
rf632117 rcaaf424 78 78 Here, the aliased constants are: 20, 10, 20, 21, and -7. 79 79 Direct initialization is by a compile-time expression generating a constant value. 80 An enumerator without initialization is \ Newterm{auto-initialized}: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.80 An enumerator without initialization is \newterm{auto-initialized}: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@. 81 81 Because multiple independent enumerators can be combined, enumerators with the same values can occur. 82 82 The enumerators are rvalues, so assignment is disallowed. 83 Finally, enumerators are \ Newterm{unscoped}, \ie enumerators declared inside of an @enum@ are visible (projected) into the enclosing scope of the @enum@ type.83 Finally, enumerators are \newterm{unscoped}, \ie enumerators declared inside of an @enum@ are visible (projected) into the enclosing scope of the @enum@ type. 84 84 For unnamed enumeration this semantic is required because there is no type name for scoped qualification. 85 85 -
doc/theses/jiada_liang_MMath/intro.tex
rf632117 rcaaf424 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. -
doc/theses/jiada_liang_MMath/relatedwork.tex
rf632117 rcaaf424 12 12 The definition of member types and their constructors are from the outer lexical scope. 13 13 14 In general, an \ Newterm{algebraic data type} (ADT) is a composite type, \ie, a type formed by combining other types.15 Three common classes of algebraic types are \ Newterm{array type}, \ie homogeneous types, \Newterm{product type}, \ie heterogeneous tuples and records (structures), and \Newterm{sum type}, \ie tagged product-types (unions).14 In general, an \newterm{algebraic data type} (ADT) is a composite type, \ie, a type formed by combining other types. 15 Three common classes of algebraic types are \newterm{array type}, \ie homogeneous types, \newterm{product type}, \ie heterogeneous tuples and records (structures), and \newterm{sum type}, \ie tagged product-types (unions). 16 16 Enumerated types are a special case of product/sum types with non-mutable fields, \ie initialized (constructed) once at the type's declaration, possible restricted to compile-time initialization. 17 17 Values of algebraic types are access by subscripting, field qualification, or type (pattern) matching. … … 51 51 \section{Ada} 52 52 53 An Ada enumeration type is a set of ordered unscoped identifiers (enumerators) bound to \emph{unique} \ Newterm{literals}.\footnote{%53 An Ada enumeration type is a set of ordered unscoped identifiers (enumerators) bound to \emph{unique} \newterm{literals}.\footnote{% 54 54 Ada is \emph{case-insensitive} so identifiers may appear in multiple forms and still be the same, \eg \lstinline{Mon}, \lstinline{moN}, and \lstinline{MON} (a questionable design decision).} 55 55 \begin{ada} … … 2177 2177 Here, function @take_class@ has a @weekday@ parameter, and returns @"CS442"@, if the weekday value is @Mon@ or @Wed@, @"CS343"@, if the value is @Tue@ or @Thu@, and @"Tutorial"@ for @Fri@. 2178 2178 The ``@_@'' is a wildcard matching any @weekday@ value, so the function returns @"Take a break"@ for values @Sat@ or @Sun@, which are not matched by the previous cases. 2179 Since the variant has no type, it has a \ Newterm{0-arity constructor}, \ie no parameters.2180 Because @weekday@ is a union of values @Mon@ to @Sun@, it is a \ Newterm{union type} in turns of the functional-programming paradigm.2179 Since the variant has no type, it has a \newterm{0-arity constructor}, \ie no parameters. 2180 Because @weekday@ is a union of values @Mon@ to @Sun@, it is a \newterm{union type} in turns of the functional-programming paradigm. 2181 2181 2182 2182 Each variant can have an associated heterogeneous type, with an n-ary constructor for creating a corresponding value. … … 2202 2202 type @stringList@ = Empty | Pair of string * @stringList@ 2203 2203 \end{ocaml} 2204 which is a recursive sum of product of types, called an \ Newterm{algebraic data-type}.2204 which is a recursive sum of product of types, called an \newterm{algebraic data-type}. 2205 2205 A recursive function is often used to pattern match against a recursive variant type. 2206 2206 \begin{ocaml} -
doc/theses/jiada_liang_MMath/uw-ethesis-frontpgs.tex
rf632117 rcaaf424 30 30 \normalsize 31 31 A thesis \\ 32 presented to the University of Waterloo \\ 32 presented to the University of Waterloo \\ 33 33 in fulfillment of the \\ 34 34 thesis requirement for the degree of \\ … … 63 63 The following served on the Examining Committee for this thesis. The decision of the Examining Committee is by majority vote. 64 64 \bigskip 65 66 \noindent 67 \begin{tabbing} 68 Internal-External Member: \= \kill % using longest text to define tab length 69 External Examiner: \> Bruce Bruce \\ 65 66 \noindent 67 \begin{tabbing} 68 Internal-External Member: \= \kill % using longest text to define tab length 69 External Examiner: \> Bruce Bruce \\ 70 70 \> Professor, Dept. of Philosophy of Zoology, University of Wallamaloo \\ 71 \end{tabbing} 72 \bigskip 73 71 \end{tabbing} 72 \bigskip 73 74 74 \noindent 75 75 \begin{tabbing} … … 81 81 \end{tabbing} 82 82 \bigskip 83 83 84 84 \noindent 85 85 \begin{tabbing} … … 89 89 \end{tabbing} 90 90 \bigskip 91 91 92 92 \noindent 93 93 \begin{tabbing} … … 97 97 \end{tabbing} 98 98 \bigskip 99 99 100 100 \noindent 101 101 \begin{tabbing} … … 114 114 \addcontentsline{toc}{chapter}{Author's Declaration} 115 115 \begin{center}\textbf{Author's Declaration}\end{center} 116 116 117 117 \noindent 118 118 I hereby declare that I am the sole author of this thesis. This is a true copy of the thesis, including any required final revisions, as accepted by my examiners. 119 119 120 120 \bigskip 121 121 122 122 \noindent 123 123 I understand that my thesis may be made electronically available to the public. … … 182 182 \phantomsection % allows hyperref to link to the correct page 183 183 184 \begin{comment} 184 185 % L I S T O F A B B R E V I A T I O N S 185 186 % --------------------------- … … 189 190 \phantomsection % allows hyperref to link to the correct page 190 191 191 \begin{comment}192 192 % L I S T O F S Y M B O L S 193 193 % --------------------------- -
doc/theses/jiada_liang_MMath/uw-ethesis.tex
rf632117 rcaaf424 112 112 \newsavebox{\myboxB} 113 113 114 \newcommand{\newtermFont}{\emph}115 \newcommand{\Newterm}[1]{\newtermFont{#1}}116 %\renewcommand{\newterm}[1]{\newtermFont{#1}}117 114 \newcommand{\uC}{$\mu$\CC} 118 115 \newcommand{\PAB}[1]{{\color{red}PAB: #1}} … … 157 154 \urlstyle{sf} 158 155 159 \usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package160 \renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}156 %\usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package 157 %\renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}} 161 158 % If glossaries-extra is not in your LaTeX distribution, get it from CTAN (http://ctan.org/pkg/glossaries-extra), 162 159 % although it's supposed to be in both the TeX Live and MikTeX distributions. There are also documentation and … … 199 196 200 197 % Define Glossary terms (This is properly done here, in the preamble and could also be \input{} from a separate file...) 201 \usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package202 \renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}203 \input{glossary}204 \makeglossaries198 %\usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package 199 %\renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}} 200 %\input{glossary} 201 %\makeglossaries 205 202 206 203 %====================================================================== … … 276 273 % GLOSSARIES (Lists of definitions, abbreviations, symbols, etc. provided by the glossaries-extra package) 277 274 % ----------------------------- 278 \printglossary279 \cleardoublepage280 \phantomsection % allows hyperref to link to the correct page275 %\printglossary 276 %\cleardoublepage 277 %\phantomsection % allows hyperref to link to the correct page 281 278 282 279 %----------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.