Changeset caaf424 for doc


Ignore:
Timestamp:
Apr 30, 2024, 12:08:24 PM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
69867ad9
Parents:
f632117
Message:

remove glossary macros, switch back to newterm marco from Newterm, update Planet example

Location:
doc/theses/jiada_liang_MMath
Files:
6 edited

Legend:

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

    rf632117 rcaaf424  
    2424\label{s:EnumeratorUnscoping}
    2525
    26 In C, unscoped enumerators presents a \Newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.
     26In C, unscoped enumerators presents a \newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.
    2727There is no mechanism in C to resolve these naming conflicts other than renaming one of the duplicates, which may be impossible.
    2828
     
    265265
    266266\VRef[Figure]{f:PlanetExample} shows an archetypal enumeration example illustrating most of the \CFA enumeration features.
    267 Enumeration @Planet@ is a typed enumeration of type @MR@.
     267@Planet@ is an enumeration of type @MR@.
    268268Each 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.
     269The unnamed enumeration provides the gravitational-constant enumerator @G@.
     270Function @surfaceGravity@ uses the @with@ clause to remove @p@ qualification from fields @mass@ and @radius@.
     271The program main uses @SizeE@ to obtain the number of enumerators in @Planet@, and safely converts the random value into a @Planet@ enumerator.
     272The resulting random orbital body is used in a @choose@ statement.
     273The enumerators in the @case@ clause use position for testing.
     274The prints use @labelE@ to print the enumerators label.
     275Finally, a loop iterates through the planets computing the weight on each planet for a given earth weight.
     276The print statement does an equality comparison with an enumeration variable and enumerator.
    271277
    272278\begin{figure}
     279\small
    273280\begin{cfa}
    274281struct MR { double mass, radius; };
    275 enum( MR ) Planet {
     282enum( @MR@ ) Planet {
    276283        //                      mass (kg)   radius (km)
    277284        MERCURY = { 0.330_E24, 2.4397_E6 },
     
    285292        NEPTUNE  = { 102.4_E24, 24.746_E6 },
    286293};
    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 );
     294enum( double ) { G = 6.6743_E-11 }; $\C{// universal gravitational constant (m3 kg-1 s-2)}$
     295static double surfaceGravity( Planet p ) @with( p )@ {
     296        return G * mass / ( radius \ 2u ); $\C{// exponentiation}$
    291297}
    292298static double surfaceWeight( Planet p, double otherMass ) {
     
    297303        double earthWeight = convert( argv[1] );
    298304        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";
    301314        }
    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}
    304320$\$$ planet 100
     321JUPITER is a gas-giant planet
    305322Your weight on MERCURY is 37.7 kg
    306323Your weight on VENUS is 90.5 kg
    307324Your weight on EARTH is 100.0 kg
    308 Your weight on MOON is 16.6 kg
     325Your weight on the MOON is 16.6 kg
    309326Your weight on MARS is 37.9 kg
    310327Your weight on JUPITER is 252.8 kg
  • doc/theses/jiada_liang_MMath/background.tex

    rf632117 rcaaf424  
    7878Here, the aliased constants are: 20, 10, 20, 21, and -7.
    7979Direct 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@.
     80An enumerator without initialization is \newterm{auto-initialized}: from left to right, starting at zero or the next explicitly initialized constant, incrementing by @1@.
    8181Because multiple independent enumerators can be combined, enumerators with the same values can occur.
    8282The 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.
     83Finally, enumerators are \newterm{unscoped}, \ie enumerators declared inside of an @enum@ are visible (projected) into the enclosing scope of the @enum@ type.
    8484For unnamed enumeration this semantic is required because there is no type name for scoped qualification.
    8585
  • doc/theses/jiada_liang_MMath/intro.tex

    rf632117 rcaaf424  
    11\chapter{Introduction}
    22
    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.
     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.
    44Con\-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.
    55(In \CFA, the primary constants @0@ and @1@ can be overloaded for any type.)
     
    77In theory, there are an infinite set of primary constant names per type.
    88
    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.
     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.
    1111Its purpose is for readability and to eliminate duplication of the primary constant throughout a program.
    1212For example, a meaningful secondary name replaces a primary name throughout a program;
    1313thereafter, 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{
     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{
    1616The term rvalue defines an expression that can only appear on the right-hand side of an assignment expression.}.
    1717
    1818Secondary 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}.
     19Many programming languages capture these groupings through a mechanism called an \newterm{enumeration}.
    2020\begin{quote}
    2121enumerate (verb, transitive).
     
    6363\label{s:Terminology}
    6464
    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}.
     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}.
     66As well, an enumerated type can have three fundamental properties, \newterm{label}, \newterm{order}, and \newterm{value}.
    6767\begin{cquote}
    6868\sf\setlength{\tabcolsep}{3pt}
     
    116116foo( Size ); // take the address of (reference) Size
    117117\end{cfa}
    118 Taking the address of an immutable variable makes it an \Newterm{lvalue}, which implies it has storage.
     118Taking the address of an immutable variable makes it an \newterm{lvalue}, which implies it has storage.
    119119With separate compilation, it is necessary to choose one translation unit to perform the initialization.
    120120If aliasing does require storage, its address and initialization are opaque (compiler only), similar to \CC rvalue reference @&&@.
     
    185185Here, 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.
    186186
    187 Note, the term \Newterm{variant} is often associated with ADTs.
     187Note, the term \newterm{variant} is often associated with ADTs.
    188188However, there are multiple languages with a @variant@ type that is not an ADT \see{Algol68~\cite{Algol68} or \CC \lstinline{variant}}.
    189189In 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  
    1212The definition of member types and their constructors are from the outer lexical scope.
    1313
    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).
     14In general, an \newterm{algebraic data type} (ADT) is a composite type, \ie, a type formed by combining other types.
     15Three 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).
    1616Enumerated 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.
    1717Values of algebraic types are access by subscripting, field qualification, or type (pattern) matching.
     
    5151\section{Ada}
    5252
    53 An Ada enumeration type is a set of ordered unscoped identifiers (enumerators) bound to \emph{unique} \Newterm{literals}.\footnote{%
     53An Ada enumeration type is a set of ordered unscoped identifiers (enumerators) bound to \emph{unique} \newterm{literals}.\footnote{%
    5454Ada 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).}
    5555\begin{ada}
     
    21772177Here, 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@.
    21782178The ``@_@'' 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.
     2179Since the variant has no type, it has a \newterm{0-arity constructor}, \ie no parameters.
     2180Because @weekday@ is a union of values @Mon@ to @Sun@, it is a \newterm{union type} in turns of the functional-programming paradigm.
    21812181
    21822182Each variant can have an associated heterogeneous type, with an n-ary constructor for creating a corresponding value.
     
    22022202type @stringList@ = Empty | Pair of string * @stringList@
    22032203\end{ocaml}
    2204 which is a recursive sum of product of types, called an \Newterm{algebraic data-type}.
     2204which is a recursive sum of product of types, called an \newterm{algebraic data-type}.
    22052205A recursive function is often used to pattern match against a recursive variant type.
    22062206\begin{ocaml}
  • doc/theses/jiada_liang_MMath/uw-ethesis-frontpgs.tex

    rf632117 rcaaf424  
    3030        \normalsize
    3131        A thesis \\
    32         presented to the University of Waterloo \\ 
     32        presented to the University of Waterloo \\
    3333        in fulfillment of the \\
    3434        thesis requirement for the degree of \\
     
    6363The following served on the Examining Committee for this thesis. The decision of the Examining Committee is by majority vote.
    6464  \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}
     68Internal-External Member: \=  \kill % using longest text to define tab length
     69External Examiner: \>  Bruce Bruce \\
    7070\> Professor, Dept. of Philosophy of Zoology, University of Wallamaloo \\
    71 \end{tabbing} 
    72   \bigskip
    73  
     71\end{tabbing}
     72  \bigskip
     73
    7474  \noindent
    7575\begin{tabbing}
     
    8181\end{tabbing}
    8282  \bigskip
    83  
     83
    8484  \noindent
    8585  \begin{tabbing}
     
    8989\end{tabbing}
    9090  \bigskip
    91  
     91
    9292  \noindent
    9393\begin{tabbing}
     
    9797\end{tabbing}
    9898  \bigskip
    99  
     99
    100100  \noindent
    101101\begin{tabbing}
     
    114114 \addcontentsline{toc}{chapter}{Author's Declaration}
    115115 \begin{center}\textbf{Author's Declaration}\end{center}
    116  
     116
    117117 \noindent
    118118I 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.
    119119
    120120  \bigskip
    121  
     121
    122122  \noindent
    123123I understand that my thesis may be made electronically available to the public.
     
    182182\phantomsection         % allows hyperref to link to the correct page
    183183
     184\begin{comment}
    184185% L I S T   O F   A B B R E V I A T I O N S
    185186% ---------------------------
     
    189190\phantomsection         % allows hyperref to link to the correct page
    190191
    191 \begin{comment}
    192192% L I S T   O F   S Y M B O L S
    193193% ---------------------------
  • doc/theses/jiada_liang_MMath/uw-ethesis.tex

    rf632117 rcaaf424  
    112112\newsavebox{\myboxB}
    113113
    114 \newcommand{\newtermFont}{\emph}
    115 \newcommand{\Newterm}[1]{\newtermFont{#1}}
    116 %\renewcommand{\newterm}[1]{\newtermFont{#1}}
    117114\newcommand{\uC}{$\mu$\CC}
    118115\newcommand{\PAB}[1]{{\color{red}PAB: #1}}
     
    157154\urlstyle{sf}
    158155
    159 \usepackage[automake,toc,abbreviations]{glossaries-extra} % Exception to the rule of hyperref being the last add-on package
    160 \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}}
    161158% If glossaries-extra is not in your LaTeX distribution, get it from CTAN (http://ctan.org/pkg/glossaries-extra),
    162159% although it's supposed to be in both the TeX Live and MikTeX distributions. There are also documentation and
     
    199196
    200197% 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 package
    202 \renewcommand*{\glstextformat}[1]{\textcolor{black}{#1}}
    203 \input{glossary}
    204 \makeglossaries
     198%\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
    205202
    206203%======================================================================
     
    276273% GLOSSARIES (Lists of definitions, abbreviations, symbols, etc. provided by the glossaries-extra package)
    277274% -----------------------------
    278 \printglossary
    279 \cleardoublepage
    280 \phantomsection         % allows hyperref to link to the correct page
     275%\printglossary
     276%\cleardoublepage
     277%\phantomsection                % allows hyperref to link to the correct page
    281278
    282279%----------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.