Changeset fa4915c
 Timestamp:
 May 31, 2021, 2:08:13 PM (3 years ago)
 Branches:
 ADT, armeh, astexperimental, enum, forallpointerdecay, jacob/cs343translation, master, newastuniqueexpr, pthreademulation, qualifiedEnum
 Children:
 01916bc, 829405b
 Parents:
 cc022a9
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

doc/user/user.tex
rcc022a9 rfa4915c 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sat May 8 08:51:33202114 %% Update Count : 50 6213 %% Last Modified On : Mon May 31 09:03:34 2021 14 %% Update Count : 5071 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 29 29 \usepackage{epic,eepic} 30 30 \usepackage{upquote} % switch curled `'" to straight 31 \usepackage{calc}32 \usepackage{varioref} % extended references33 31 \usepackage[labelformat=simple,aboveskip=0pt,farskip=0pt]{subfig} 34 32 \renewcommand{\thesubfigure}{\alph{subfigure})} … … 37 35 \usepackage{mathptmx} % better math font with "times" 38 36 \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 underscore50 % removes it as a variablename character so keywords in variables are highlighted. MUST APPEAR51 % AFTER HYPERREF.52 \renewcommand{\textunderscore}{\leavevmode\makebox[1.2ex][c]{\rule{1ex}{0.075ex}}}53 54 \setlength{\topmargin}{0.45in} % move running title into header55 \setlength{\headsep}{0.25in}56 57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%58 59 37 \newcommand{\CFALatin}{} 60 38 % inline code ©...© (copyright symbol) emacs: Cq M) … … 67 45 \usepackage{common} % common CFA document macros 68 46 %\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 variablename 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 69 67 \setlength{\gcolumnposn}{3in} 70 68 \CFAStyle % use default CFA formatstyle 71 \lstset{language=CFA} % CFA default lnaguage69 %\lstset{language=CFA} % CFA default lnaguage 72 70 \lstnewenvironment{C++}[1][] % use C++ style 73 71 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®},#1}} … … 168 166 In contrast, \CFA has 30 years of hindsight and a clean starting point. 169 167 170 Like \Index*[C++]{\CC{}}, there may be both anold and new ways to achieve the same effect.168 Like \Index*[C++]{\CC{}}, there may be both old and new ways to achieve the same effect. 171 169 For example, the following programs compare the C, \CFA, and \CC I/O mechanisms, where the programs output the same result. 172 170 \begin{center} … … 260 258 The signature feature of \CFA is \emph{\Index{overload}able} \Index{parametricpolymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name): 261 259 \begin{cfa} 262 ®forall( otypeT )® T identity( T val ) { return val; }260 ®forall( T )® T identity( T val ) { return val; } 263 261 int forty_two = identity( 42 ); $\C{// T is bound to int, forty\_two == 42}$ 264 262 \end{cfa} … … 293 291 which can be augmented simply with a polymorphic, typesafe, \CFAoverloaded wrappers: 294 292 \begin{cfa} 295 forall( otypeT  { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) {293 forall( T  { int ?<?( T, T ); } ) T * bsearch( T key, const T * arr, size_t size ) { 296 294 int comp( const void * t1, const void * t2 ) { /* as above with double changed to T */ } 297 295 return (T *)bsearch( &key, arr, size, sizeof(T), comp ); } 298 296 299 forall( otypeT  { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) {297 forall( T  { int ?<?( T, T ); } ) unsigned int bsearch( T key, const T * arr, size_t size ) { 300 298 T * result = bsearch( key, arr, size ); $\C{// call first version}$ 301 299 return result ? result  arr : size; } $\C{// pointer subtraction includes sizeof(T)}$ … … 532 530 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escapemechanism: 533 531 \begin{cfa} 534 int ®``® otype = 3; $\C{// make keyword an identifier}$532 int ®``®coroutine = 3; $\C{// make keyword an identifier}$ 535 533 double ®``®forall = 3.5; 536 534 \end{cfa} … … 613 611 The exponentiation operator is available for all the basic types, but for userdefined types, only the integralcomputation version is available. 614 612 \begin{cfa} 615 forall( otypeT  { void ?{}( T & this, one_t ); T ?*?( T, T ); } )613 forall( T  { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 616 614 T ?®\®?( T ep, unsigned int y ); 617 forall( otypeT  { void ?{}( T & this, one_t ); T ?*?( T, T ); } )615 forall( T  { void ?{}( T & this, one_t ); T ?*?( T, T ); } ) 618 616 T ?®\®?( T ep, unsigned long int y ); 619 617 \end{cfa} … … 865 863 case 1: case 2: case 3: 866 864 ... 867 ®// implicit end of switch (break)868 ®case 5:865 $\R{\LstCommentStyle{// implicit end of switch (break)}}$ 866 case 5: 869 867 ... 870 868 ®fallthru®; $\C{// explicit fall through}$ … … 2778 2776 For example, the C quicksort is wrapped into the following polymorphic \CFA routine: 2779 2777 \begin{cfa} 2780 forall( otypeT  { int ?<?( T, T ); } )2778 forall( T  { int ?<?( T, T ); } ) 2781 2779 void qsort( const T * arr, size_t dimension ); 2782 2780 \end{cfa} … … 3239 3237 The integration of polymorphism, type assertions, and monomorphic specialization of tupleassertions are a primary contribution of this thesis to the design of tuples. 3240 3238 \begin{cfa} 3241 forall( otypeT, dtype U)3239 forall(T, dtype U) 3242 3240 void f(T x, U * y); 3243 3241 … … 3247 3245 The argument matching algorithm binds ©T© to ©int© and ©U© to ©const char©, and calls the function as normal. 3248 3246 3249 Tuples can contain otype and dtype components.3247 Tuples can contain polymorphic types. 3250 3248 For example, a plus operator can be written to add two triples of a type together. 3251 3249 \begin{cfa} 3252 forall( otypeT  { T ?+?(T, T); })3250 forall(T  { T ?+?(T, T); }) 3253 3251 [T, T, T] ?+?([T, T, T] x, [T, T, T] y) { 3254 3252 return [x.0+y.0, x.1+y.1, x.2+y.2]; … … 3268 3266 Furthermore, these calls can be made ambiguous by introducing seemingly different functions. 3269 3267 \begin{cfa} 3270 forall( otypeT  { T ?+?(T, T); })3268 forall(T  { T ?+?(T, T); }) 3271 3269 [T, T, T] ?+?([T, T] x, [T, T, T, T]); 3272 forall( otypeT  { T ?+?(T, T); })3270 forall(T  { T ?+?(T, T); }) 3273 3271 [T, T, T] ?+?(T x, [T, T, T, T, T]); 3274 3272 \end{cfa} … … 3294 3292 \begin{cfa} 3295 3293 int f([int, double], double); 3296 forall( otype T, otypeU  { T f(T, U, U); })3294 forall(T, U  { T f(T, U, U); }) 3297 3295 void g(T, U); 3298 3296 g(5, 10.21); … … 7381 7379 \leavevmode 7382 7380 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 7383 forall( otypeT  { int ?<?( T, T ); } ) $\C{// location}$7381 forall( T  { int ?<?( T, T ); } ) $\C{// location}$ 7384 7382 T * bsearch( T key, const T * arr, size_t dim );$\indexc{bsearch}$ 7385 7383 7386 forall( otypeT  { int ?<?( T, T ); } ) $\C{// position}$7384 forall( T  { int ?<?( T, T ); } ) $\C{// position}$ 7387 7385 unsigned int bsearch( T key, const T * arr, size_t dim ); 7388 7386 7389 forall( otypeT  { int ?<?( T, T ); } )7387 forall( T  { int ?<?( T, T ); } ) 7390 7388 void qsort( const T * arr, size_t dim );$\indexc{qsort}$ 7391 7389 7392 forall( otypeE  { int ?<?( E, E ); } ) {7390 forall( E  { int ?<?( E, E ); } ) { 7393 7391 E * bsearch( E key, const E * vals, size_t dim );$\indexc{bsearch}$ $\C{// location}$ 7394 7392 size_t bsearch( E key, const E * vals, size_t dim );$\C{// position}$ … … 7399 7397 } 7400 7398 7401 forall( otype K, otypeE  { int ?<?( K, K ); K getKey( const E & ); } ) {7399 forall( K, E  { int ?<?( K, K ); K getKey( const E & ); } ) { 7402 7400 E * bsearch( K key, const E * vals, size_t dim ); 7403 7401 size_t bsearch( K key, const E * vals, size_t dim ); … … 7408 7406 } 7409 7407 7410 forall( otypeE  { int ?<?( E, E ); } ) {7408 forall( E  { int ?<?( E, E ); } ) { 7411 7409 void qsort( E * vals, size_t dim );$\indexc{qsort}$ 7412 7410 } … … 7428 7426 double abs( double _Complex ); 7429 7427 long double abs( long double _Complex ); 7430 forall( otypeT  { void ?{}( T *, zero_t ); int ?<?( T, T ); T ?( T ); } )7428 forall( T  { void ?{}( T *, zero_t ); int ?<?( T, T ); T ?( T ); } ) 7431 7429 T abs( T ); 7432 7430 \end{cfa} … … 7465 7463 \leavevmode 7466 7464 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 7467 forall( otypeT  { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$7468 forall( otypeT  { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$7469 forall( otypeT  { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$7470 forall( otypeT ) void swap( T * t1, T * t2 );$\indexc{swap}$7465 forall( T  { int ?<?( T, T ); } ) T min( T t1, T t2 );$\indexc{min}$ 7466 forall( T  { int ?>?( T, T ); } ) T max( T t1, T t2 );$\indexc{max}$ 7467 forall( T  { T min( T, T ); T max( T, T ); } ) T clamp( T value, T min_val, T max_val );$\indexc{clamp}$ 7468 forall( T ) void swap( T * t1, T * t2 );$\indexc{swap}$ 7471 7469 \end{cfa} 7472 7470
Note: See TracChangeset
for help on using the changeset viewer.