Changeset fa4915c for doc/user


Ignore:
Timestamp:
May 31, 2021, 2:08:13 PM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
arm-eh, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr
Children:
01916bc, 829405b
Parents:
cc022a9
Message:

update macros to reflect changed to common macros, remove otype

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rcc022a9 rfa4915c  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat May  8 08:51:33 2021
    14 %% Update Count     : 5062
     13%% Last Modified On : Mon May 31 09:03:34 2021
     14%% Update Count     : 5071
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    2929\usepackage{epic,eepic}
    3030\usepackage{upquote}                                                                    % switch curled `'" to straight
    31 \usepackage{calc}
    32 \usepackage{varioref}                                                                   % extended references
    3331\usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig}
    3432\renewcommand{\thesubfigure}{\alph{subfigure})}
     
    3735\usepackage{mathptmx}                                   % better math font with "times"
    3836\usepackage[usenames]{color}
    39 \usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
    40 \usepackage{breakurl}
    41 
    42 \renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
    43 
    44 \usepackage[pagewise]{lineno}
    45 \renewcommand{\linenumberfont}{\scriptsize\sffamily}
    46 \usepackage[firstpage]{draftwatermark}
    47 \SetWatermarkLightness{0.9}
    48 
    49 % Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
    50 % removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
    51 % AFTER HYPERREF.
    52 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
    53 
    54 \setlength{\topmargin}{-0.45in}                                                 % move running title into header
    55 \setlength{\headsep}{0.25in}
    56 
    57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    58 
    5937\newcommand{\CFALatin}{}
    6038% inline code ©...© (copyright symbol) emacs: C-q M-)
     
    6745\usepackage{common}                                                                             % common CFA document macros
    6846%\input{common}                                                                                 % common CFA document macros
     47\usepackage[dvips,plainpages=false,pdfpagelabels,pdfpagemode=UseNone,colorlinks=true,pagebackref=true,linkcolor=blue,citecolor=blue,urlcolor=blue,pagebackref=true,breaklinks=true]{hyperref}
     48\usepackage{breakurl}
     49
     50\renewcommand\footnoterule{\kern -3pt\rule{0.3\linewidth}{0.15pt}\kern 2pt}
     51
     52\usepackage[pagewise]{lineno}
     53\renewcommand{\linenumberfont}{\scriptsize\sffamily}
     54\usepackage[firstpage]{draftwatermark}
     55\SetWatermarkLightness{0.9}
     56
     57% Default underscore is too low and wide. Cannot use lstlisting "literate" as replacing underscore
     58% removes it as a variable-name character so keywords in variables are highlighted. MUST APPEAR
     59% AFTER HYPERREF.
     60\renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}
     61
     62\setlength{\topmargin}{-0.45in}                                                 % move running title into header
     63\setlength{\headsep}{0.25in}
     64
     65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     66
    6967\setlength{\gcolumnposn}{3in}
    7068\CFAStyle                                                                                               % use default CFA format-style
    71 \lstset{language=CFA}                                                                   % CFA default lnaguage
     69%\lstset{language=CFA}                                                                  % CFA default lnaguage
    7270\lstnewenvironment{C++}[1][]                            % use C++ style
    7371{\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}}
     
    168166In contrast, \CFA has 30 years of hindsight and a clean starting point.
    169167
    170 Like \Index*[C++]{\CC{}}, there may be both an old and new ways to achieve the same effect.
     168Like \Index*[C++]{\CC{}}, there may be both old and new ways to achieve the same effect.
    171169For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result.
    172170\begin{center}
     
    260258The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
    261259\begin{cfa}
    262 ®forall( otype T )® T identity( T val ) { return val; }
     260®forall( T )® T identity( T val ) { return val; }
    263261int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$
    264262\end{cfa}
     
    293291which can be augmented simply with a polymorphic, type-safe, \CFA-overloaded wrappers:
    294292\begin{cfa}
    295 forall( otype T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) {
     293forall( T | { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) {
    296294        int comp( const void * t1, const void * t2 ) { /* as above with double changed to T */ }
    297295        return (T *)bsearch( &key, arr, size, sizeof(T), comp ); }
    298296
    299 forall( otype T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
     297forall( T | { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {
    300298        T * result = bsearch( key, arr, size ); $\C{// call first version}$
    301299        return result ? result - arr : size; } $\C{// pointer subtraction includes sizeof(T)}$
     
    532530Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
    533531\begin{cfa}
    534 int ®``®otype = 3; $\C{// make keyword an identifier}$
     532int ®``®coroutine = 3; $\C{// make keyword an identifier}$
    535533double ®``®forall = 3.5;
    536534\end{cfa}
     
    613611The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
    614612\begin{cfa}
    615 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     613forall( T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    616614T ?®\®?( T ep, unsigned int y );
    617 forall( otype T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
     615forall( T | { void ?{}( T & this, one_t ); T ?*?( T, T ); } )
    618616T ?®\®?( T ep, unsigned long int y );
    619617\end{cfa}
     
    865863  case 1:  case 2:  case 3:
    866864        ...
    867         ®// implicit end of switch (break)
    868   ®case 5:
     865        $\R{\LstCommentStyle{// implicit end of switch (break)}}$
     866  case 5:
    869867        ...
    870868        ®fallthru®; $\C{// explicit fall through}$
     
    27782776For example, the C quick-sort is wrapped into the following polymorphic \CFA routine:
    27792777\begin{cfa}
    2780 forall( otype T | { int ?<?( T, T ); } )
     2778forall( T | { int ?<?( T, T ); } )
    27812779void qsort( const T * arr, size_t dimension );
    27822780\end{cfa}
     
    32393237The integration of polymorphism, type assertions, and monomorphic specialization of tuple-assertions are a primary contribution of this thesis to the design of tuples.
    32403238\begin{cfa}
    3241 forall(otype T, dtype U)
     3239forall(T, dtype U)
    32423240void f(T x, U * y);
    32433241
     
    32473245The argument matching algorithm binds ©T© to ©int© and ©U© to ©const char©, and calls the function as normal.
    32483246
    3249 Tuples can contain otype and dtype components.
     3247Tuples can contain polymorphic types.
    32503248For example, a plus operator can be written to add two triples of a type together.
    32513249\begin{cfa}
    3252 forall(otype T | { T ?+?(T, T); })
     3250forall(T | { T ?+?(T, T); })
    32533251[T, T, T] ?+?([T, T, T] x, [T, T, T] y) {
    32543252        return [x.0+y.0, x.1+y.1, x.2+y.2];
     
    32683266Furthermore, these calls can be made ambiguous by introducing seemingly different functions.
    32693267\begin{cfa}
    3270 forall(otype T | { T ?+?(T, T); })
     3268forall(T | { T ?+?(T, T); })
    32713269[T, T, T] ?+?([T, T] x, [T, T, T, T]);
    3272 forall(otype T | { T ?+?(T, T); })
     3270forall(T | { T ?+?(T, T); })
    32733271[T, T, T] ?+?(T x, [T, T, T, T, T]);
    32743272\end{cfa}
     
    32943292\begin{cfa}
    32953293int f([int, double], double);
    3296 forall(otype T, otype U | { T f(T, U, U); })
     3294forall(T, U | { T f(T, U, U); })
    32973295void g(T, U);
    32983296g(5, 10.21);
     
    73817379\leavevmode
    73827380\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7383 forall( otype T | { int ?<?( T, T ); } ) $\C{// location}$
     7381forall( T | { int ?<?( T, T ); } ) $\C{// location}$
    73847382T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$
    73857383
    7386 forall( otype T | { int ?<?( T, T ); } ) $\C{// position}$
     7384forall( T | { int ?<?( T, T ); } ) $\C{// position}$
    73877385unsigned int bsearch( T key, const T * arr, size_t dim );
    73887386
    7389 forall( otype T | { int ?<?( T, T ); } )
     7387forall( T | { int ?<?( T, T ); } )
    73907388void qsort( const T * arr, size_t dim );$\indexc{qsort}$
    73917389
    7392 forall( otype E | { int ?<?( E, E ); } ) {
     7390forall( E | { int ?<?( E, E ); } ) {
    73937391        E * bsearch( E key, const E * vals, size_t dim );$\indexc{bsearch}$ $\C{// location}$
    73947392        size_t bsearch( E key, const E * vals, size_t dim );$\C{// position}$
     
    73997397}
    74007398
    7401 forall( otype K, otype E | { int ?<?( K, K ); K getKey( const E & ); } ) {
     7399forall( K, E | { int ?<?( K, K ); K getKey( const E & ); } ) {
    74027400        E * bsearch( K key, const E * vals, size_t dim );
    74037401        size_t bsearch( K key, const E * vals, size_t dim );
     
    74087406}
    74097407
    7410 forall( otype E | { int ?<?( E, E ); } ) {
     7408forall( E | { int ?<?( E, E ); } ) {
    74117409        void qsort( E * vals, size_t dim );$\indexc{qsort}$
    74127410}
     
    74287426double abs( double _Complex );
    74297427long double abs( long double _Complex );
    7430 forall( otype T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
     7428forall( T | { void ?{}( T *, zero_t ); int ?<?( T, T ); T -?( T ); } )
    74317429T abs( T );
    74327430\end{cfa}
     
    74657463\leavevmode
    74667464\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    7467 forall( otype T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
    7468 forall( otype T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
    7469 forall( otype T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
    7470 forall( otype T ) void swap( T * t1, T * t2 );$\indexc{swap}$
     7465forall( T | { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$
     7466forall( T | { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$
     7467forall( T | { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$
     7468forall( T ) void swap( T * t1, T * t2 );$\indexc{swap}$
    74717469\end{cfa}
    74727470
Note: See TracChangeset for help on using the changeset viewer.