Changeset 0c51c8b4 for doc


Ignore:
Timestamp:
Aug 6, 2024, 9:49:56 AM (3 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
efd055c
Parents:
c03af31
Message:

formatting, add section of enumeration subset

Location:
doc/theses/jiada_liang_MMath
Files:
4 edited

Legend:

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

    rc03af31 r0c51c8b4  
    77
    88
    9 \section{Enumerator Visibility}
    10 \label{s:EnumeratorVisibility}
     9\section{Visibility}
     10\label{s:CVisibility}
    1111
    1212In C, unscoped enumerators present a \newterm{naming problem} when multiple enumeration types appear in the same scope with duplicate enumerator names.
     
    4242
    4343
    44 \section{Enumerator Scoping}
     44\section{Scoping}
    4545
    4646A C Enum can be scoped, using @'!'@, so the enumerator constants are not projected into the enclosing scope.
     
    6464}
    6565\end{cfa}
    66 As in Section~\ref{s:EnumeratorVisibility}, opening multiple scoped enumerations in a @with@ can result in duplicate enumeration names, but \CFA implicit type resolution and explicit qualification/casting handle this localized scenario.
     66As in Section~\ref{s:CVisibility}, opening multiple scoped enumerations in a @with@ can result in duplicate enumeration names, but \CFA implicit type resolution and explicit qualification/casting handle this localized scenario.
    6767
    6868A partially implemented extension to enumerator scoping is providing a combination of scoped and unscoped enumerators, using individual denotations, where @'^'@ means unscoped.
  • doc/theses/jiada_liang_MMath/CFAenum.tex

    rc03af31 r0c51c8b4  
    66
    77
    8 \section{Enumeration Syntax}
    9 
    10 \CFA extends the C enumeration declaration \see{\VRef{s:CEnumeration}} by parameterizing with a type (like a generic type), and adding Plan-9 inheritance \see{\VRef{s:EnumerationInheritance}} using an @inline@ to another enumeration type.
     8\section{Syntax}
     9
     10\CFA extends the C enumeration declaration \see{\VRef{s:CEnumeration}} by parameterizing with a type (like a generic type), and adding Plan-9 inheritance \see{\VRef{s:CFAInheritance}} using an @inline@ to another enumeration type.
    1111\begin{cfa}[identifierstyle=\linespread{0.9}\it]
    1212$\it enum$-specifier:
     
    2424
    2525
    26 \section{Enumeration Operations}
     26\section{Operations}
    2727
    2828\CFA enumerations have access to the three enumerations properties \see{\VRef{s:Terminology}}: label, order (position), and value via three overloaded functions @label@, @posn@, and @value@ \see{\VRef{c:trait} for details}.
     
    4343A A @0@ 3
    4444\end{cfa}
    45 Finally, there is an additional enumeration routine @countof@ (like @sizeof@, @typeof@) that returns the number of enumerators in an enumeration.
    46 \begin{cfa}
    47 enum(int) E { A, B, C, D };
    48 countof( E );  // 4
    49 \end{cfa}
    50 This auto-generated function replaces the C idiom for automatically computing the number of enumerators \see{\VRef{s:Usage}}.
     45Finally, there is an additional enumeration pseudo-function @countof@ (like @sizeof@, @typeof@) that returns the number of enumerators in an enumeration.
     46\begin{cfa}
     47enum(int) E { A, B, C, D } e;
     48countof( E );  // 4, type argument
     49countof( e );  // 4, variable argument
     50\end{cfa}
     51This buildin function replaces the C idiom for automatically computing the number of enumerators \see{\VRef{s:Usage}}.
    5152\begin{cfa}
    5253enum E { A, B, C, D, @N@ };  // N == 4
     
    197198
    198199
    199 \section{Enumeration Inheritance}
    200 \label{s:EnumerationInheritance}
     200\section{Subset}
     201
     202An enumeration's type can be another enumeration.
     203\begin{cfa}
     204enum( char ) Letter { A = 'A', ... };
     205enum( @Letter@ ) Greek { Alph = A, Beta = B, ... }; // alphabet intersection
     206\end{cfa}
     207Enumeration @Greek@ may have more or less enums than @Letter@, but the enum values \emph{must} be from @Letter@.
     208Therefore, @Greek@ enums are a subset of type @Letter@ and are type compatible with enumeration @Letter@, but @Letter@ enums are not type compatible with enumeration @Greek@.
     209
     210
     211\section{Inheritance}
     212\label{s:CFAInheritance}
    201213
    202214\CFA Plan-9 inheritance may be used with \CFA enumerations, where Plan-9 inheritance is containment inheritance with implicit unscoping (like a nested unnamed @struct@/@union@ in C).
    203215Containment is nominative: an enumeration inherits all enumerators from another enumeration by declaring an @inline statement@ in its enumerator lists.
    204216\begin{cfa}
    205 enum( char * ) Names { /* $\see{\VRef[Figure]{s:EnumerationInheritance}}$ */ };
     217enum( char * ) Names { /* $\see{\VRef[Figure]{f:EumeratorTyping}}$ */ };
    206218enum( char * ) Names2 { @inline Names@, Jack = "JACK", Jill = "JILL" };
    207219enum( char * ) Names3 { @inline Names2@, Sue = "SUE", Tom = "TOM" };
     
    302314
    303315
    304 \section{Enumerator Control Structures}
     316\section{Control Structures}
    305317
    306318Enumerators can be used in multiple contexts.
     
    392404
    393405
    394 \section{Enumeration Dimension}
     406\section{Dimension}
    395407
    396408\VRef{s:EnumeratorTyping} introduces the harmonizing problem between an enumeration and secondary information.
     
    420432
    421433
    422 \section{Enumeration I/O}
     434\section{I/O}
    423435
    424436As seen in multiple examples, enumerations can be printed and the default property printed is the enumerator's label, which is similar in other programming languages.
     
    473485\label{f:EnumerationI/O}
    474486\end{figure}
    475 
    476487
    477488
  • doc/theses/jiada_liang_MMath/background.tex

    rc03af31 r0c51c8b4  
    232232While C provides a true enumeration, it is restricted, has unsafe semantics, and does not provide useful/advanced enumeration features found in other programming languages.
    233233
    234 \section{\CFA Polymorphism}
    235 
    236 \subsection{Function Overloading}
    237 Function overloading is programming languages feature wherein functions may share the same name, but with different function signatures. In both C++ and \CFA, function names can be overloaded
    238 with different entities as long as they are different in terms of the number and type of parameters.
    239234
    240235\section{\CFA}
     
    253248Experience from \CC and \CFA developers is that the type system implicitly and correctly disambiguates the majority of overloaded names, \ie it is rare to get an incorrect selection or ambiguity, even among hundreds of overloaded (variables and) functions.
    254249In many cases, a programmer has no idea there are name clashes, as they are silently resolved, simplifying the development process.
    255 Depending on the language, ambiguous cases are resolved using some form of qualification or casting.
     250Depending on the language, ambiguous cases are resolved using some form of qualification and/or casting.
    256251
    257252
     
    269264\end{cfa}
    270265The type system examines each call size and selects the best matching overloaded function based on the number and types of the arguments.
    271 If there are intermixed operands, @2 + 3.5@, the type system attempts (safe) conversions changing the arguments to one or more of the parameter type(s).
     266If there are mixed-mode operands, @2 + 3.5@, the type system, like in C/\CC, attempts (safe) conversions, converting the argument type(s) to the parameter type(s).
    272267
    273268
     
    282277\end{cfa}
    283278In this case, the name @f@ is overloaded depending on the number and parameter types.
    284 The type system examines each call size and selects the best matching based on the number and types of the arguments.
     279The type system examines each call size and selects the best match based on the number and types of the arguments.
    285280Here, there is a perfect match for the call, @f( 'A' )@ with the number and parameter type of function (2).
    286281
     
    321316
    322317The prototype for the constructor/destructor are @void ?{}( T &, ... )@ and @void ^?{}( T &, ... )@, respectively.
    323 The first parameter is logically, the \lstinline[language=C++]{this} or \lstinline[language=Python]{self} in other object-oriented languages, and implicitly passed.
     318The first parameter is logically the \lstinline[language=C++]{this} or \lstinline[language=Python]{self} in other object-oriented languages, and implicitly passed.
    324319\VRef[Figure]{f:CFAConstructorDestructor} shows an example of creating and using a constructor and destructor.
    325320Both constructor and destructor can be explicitly called to reuse a variable.
     
    391386\end{cfa}
    392387The assertion on @T@ restricts the range of types that can be manipulated by @bar@ to only those that have an implementation of @foo@ with the matching signature, allowing @bar@'s call to @foo@ in its body.
     388Unlike templates in \CC, which are macro expansions at the call site, \CFA polymorphic functions are compiled, passing the call-site assertion functions as hidden parameters.
     389
    393390
    394391\subsection{Trait}
    395 A @forall@ clause can asserts on multiple types and with multiple asserting functions. A common practice in \CFA is to group
    396 the asserting functions in to a named \newterm{trait}.
    397 
    398 \subsection{Trait}
    399392
    400393A @forall@ clause can assert many restrictions on multiple types.
    401 A common practice is to refactor the assertions into a named \newterm{trait}.
     394A common practice is to refactor the assertions into a named \newterm{trait}, similar to other lnaguages, like Go and Rust.
    402395\begin{cfa}
    403396forall(T) trait @Bird@ {
     
    432425
    433426Most programming languages perform some implicit conversions among basic types to facilitate mixed-mode arithmetic;
    434 otherwise, the program becomes littered with many explicit casts, which is not match programmer expectation.
     427otherwise, the program becomes littered with many explicit casts, which does not match with programmer expectation.
    435428C is an aggressive language as it provides conversions among almost all of the basic types, even when the conversion is potentially unsafe or not meaningful, \ie @float@ to @bool@.
    436429C defines the resolution pattern as ``usual arithmetic conversion''~\cite[\S~6.3.1.8]{C11}, in which C looks for a \newterm{common type} between operands, and converts one or both operands to the common type.
  • doc/theses/jiada_liang_MMath/intro.tex

    rc03af31 r0c51c8b4  
    299299\begin{enumerate}
    300300\item
    301 overloading: provides a pattern to overload functions, literal, and variable for polymorphic enumerations.
    302 \item
    303 scoping: adds name space for enumerations.
    304 \item
    305 safety: defines a safe enumeration conversion scheme.
    306 \item
    307 harmonization: allows enumeration to be mapped with data.
    308 \item
    309 inheritance: implements containment inheritance for enumerations.
     301safety: Define a safe enumeration conversion scheme, both for C and \CFA, and replace ad-hoc C idioms with safer software-engineering approaches.
     302\item
     303overloading: Provide a pattern to overload functions, literals, and variables for polymorphic enumerations using the \CFA type system.
     304\item
     305scoping: Add a name space for enumerations and qualified access into the namespace to deal with the naming problem.
     306\item
     307generalization: Support all language types for enumerators with associated values providing enumeration constants for any type.
     308\item
     309inheritance: Implement subtyping and containment inheritance for enumerations.
     310\item
     311control flow: Extend control-flow structures making it safer and easier to enumerate over an enumeration.
     312\item
     313I/O: Provide input and output of enumerations based on enumerator names.
    310314\end{enumerate}
    311315
Note: See TracChangeset for help on using the changeset viewer.