Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    re9a3c69d r86f384b  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Jul 13 11:44:57 2017
    14 %% Update Count     : 2690
     13%% Last Modified On : Sun Jul  2 09:49:56 2017
     14%% Update Count     : 2503
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    5757\CFAStyle                                                                                               % use default CFA format-style
    5858
    59 \lstnewenvironment{C++}[1][]
    60 {\lstset{language=C++,moredelim=**[is][\protect\color{red}]{®}{®}#1}}
    61 {}
    62 
    6359% inline code ©...© (copyright symbol) emacs: C-q M-)
    6460% red highlighting ®...® (registered trademark symbol) emacs: C-q M-.
     
    141137
    142138\CFA{}\index{cforall@\CFA}\footnote{Pronounced ``\Index*{C-for-all}'', and written \CFA, CFA, or \CFL.} is a modern general-purpose programming-language, designed as an evolutionary step forward for the C programming language.
    143 The syntax of \CFA builds from C and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
     139The syntax of the \CFA language builds from C, and should look immediately familiar to C/\Index*[C++]{\CC{}} programmers.
    144140% Any language feature that is not described here can be assumed to be using the standard \Celeven syntax.
    145 \CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving similar performance.
    146 Like C, \CFA is a statically typed, procedural (non-\Index{object-oriented}) language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.
     141\CFA adds many modern programming-language features that directly lead to increased \emph{\Index{safety}} and \emph{\Index{productivity}}, while maintaining interoperability with existing C programs and achieving C performance.
     142Like C, \CFA is a statically typed, procedural language with a low-overhead runtime, meaning there is no global \Index{garbage-collection}, but \Index{regional garbage-collection}\index{garbage-collection!regional} is possible.
    147143The primary new features include parametric-polymorphic routines and types, exceptions, concurrency, and modules.
    148144
    149 One of the main design philosophies of \CFA is to ``\Index{describe not prescribe}'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''.
    150 Programmers can cautiously add \CFA extensions to their C programs in any order and at any time to incrementally move towards safer, higher-level programming.
    151 A programmer is always free to reach back to C from \CFA, for any reason, and in many cases, new \CFA features can be locally switched back to there C counterpart.
    152 There is no notion or requirement for \emph{rewriting} a legacy C program in \CFA;
    153 instead, a programmer evolves a legacy program into \CFA by incrementally incorporating \CFA features.
    154 As well, new programs can be written in \CFA using a combination of C and \CFA features.
    155 
    156 \Index*[C++]{\CC{}} had a similar goal 30 years ago, allowing object-oriented programming to be incrementally added to C.
    157 However, \CC currently has the disadvantages of a strong object-oriented bias, multiple legacy design-choices that cannot be updated, and active divergence of the language model from C, all of which requires significant effort and training to incrementally add \CC to a C-based project.
     145One of the main design philosophies of \CFA is to ``describe not prescribe'', which means \CFA tries to provide a pathway from low-level C programming to high-level \CFA programming, but it does not force programmers to ``do the right thing''.
     146Programmers can cautiously add \CFA extensions to their C programs in any order and at any time to incrementally move towards safer, higher-level programming features.
     147A programmer is always free to reach back to C from \CFA for any reason, and in many cases, new \CFA features have a fallback to a C mechanism.
     148There is no notion or requirement for rewriting a legacy C program in \CFA;
     149instead, a programmer evolves an existing C program into \CFA by incrementally incorporating \CFA features.
     150New programs can be written in \CFA using a combination of C and \CFA features.
     151\Index*[C++]{\CC{}} had a similar goal 30 years ago, but currently has the disadvantages of multiple legacy design-choices that cannot be updated and active divergence of the language model from C, requiring significant effort and training to incrementally add \CC to a C-based project.
    158152In contrast, \CFA has 30 years of hindsight and a clean starting point.
    159153
     
    162156\begin{quote2}
    163157\begin{tabular}{@{}l@{\hspace{1.5em}}l@{\hspace{1.5em}}l@{}}
    164 \multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{C}} & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{\CC}}      \\
    165 \begin{cfa}
     158\multicolumn{1}{c@{\hspace{1.5em}}}{\textbf{\CFA}}      & \multicolumn{1}{c}{\textbf{C}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
     159\begin{cfa}
     160#include <fstream>§\indexc{fstream}§
     161
     162int main( void ) {
     163        int x = 0, y = 1, z = 2;
     164        ®sout | x | y | z | endl;®
     165}
     166\end{cfa}
     167&
     168\begin{lstlisting}
    166169#include <stdio.h>§\indexc{stdio.h}§
    167170
     
    170173        ®printf( "%d %d %d\n", x, y, z );®
    171174}
    172 \end{cfa}
     175\end{lstlisting}
    173176&
    174 \begin{cfa}
    175 #include <fstream>§\indexc{fstream}§
    176 
    177 int main( void ) {
    178         int x = 0, y = 1, z = 2;
    179         ®sout | x | y | z | endl;®§\indexc{sout}§
    180 }
    181 \end{cfa}
    182 &
    183 \begin{cfa}
     177\begin{lstlisting}
    184178#include <iostream>§\indexc{iostream}§
    185179using namespace std;
     
    188182        ®cout<<x<<" "<<y<<" "<<z<<endl;®
    189183}
    190 \end{cfa}
     184\end{lstlisting}
    191185\end{tabular}
    192186\end{quote2}
    193187While the \CFA I/O looks similar to the \Index*[C++]{\CC{}} output style, there are important differences, such as automatic spacing between variables as in \Index*{Python} (see~\VRef{s:IOLibrary}).
    194188
    195 \subsection{Background}
    196 
    197189This document is a programmer reference-manual for the \CFA programming language.
    198190The manual covers the core features of the language and runtime-system, with simple examples illustrating syntax and semantics of each feature.
    199191The manual does not teach programming, i.e., how to combine the new constructs to build complex programs.
    200 A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented, as well as some experience programming in C/\CC.
    201 Implementers should refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
     192A reader should already have an intermediate knowledge of control flow, data structures, and concurrency issues to understand the ideas presented as well as some experience programming in C/\CC.
     193Implementers may refer to the \CFA Programming Language Specification for details about the language syntax and semantics.
    202194Changes to the syntax and additional features are expected to be included in later revisions.
    203195
     
    208200This installation base and the programmers producing it represent a massive software-engineering investment spanning decades and likely to continue for decades more.
    209201Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    210 For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
     202For system programming, where direct access to hardware and dealing with real-time issues is a requirement, C is usually the language of choice.
    211203The TIOBE index~\cite{TIOBE} for March 2016 showed the following programming-language popularity: \Index*{Java} 20.5\%, C 14.5\%, \Index*[C++]{\CC{}} 6.7\%, \Csharp 4.3\%, \Index*{Python} 4.3\%, where the next 50 languages are less than 3\% each with a long tail.
    212204As well, for 30 years, C has been the number 1 and 2 most popular programming language:
     
    224216\end{center}
    225217Hence, C is still an extremely important programming language, with double the usage of \Index*[C++]{\CC{}}; in many cases, \CC is often used solely as a better C.
    226 Love it or hate it, C has been an important and influential part of computer science for 40 years and its appeal is not diminishing.
    227 Unfortunately, C has many problems and omissions that make it an unacceptable programming language for modern needs.
    228 
    229 As stated, the goal of the \CFA project is to engineer modern language-features into C in an evolutionary rather than revolutionary way.
     218Love it or hate it, C has been an important and influential part of computer science for 40 years and sit appeal is not diminishing.
     219Unfortunately, C has too many problems and omissions to make it an acceptable programming language for modern needs.
     220
     221As stated, the goal of the \CFA project is to engineer modern language features into C in an evolutionary rather than revolutionary way.
    230222\CC~\cite{C++14,C++} is an example of a similar project;
    231 however, it largely extended the C language, and did not address most of C's existing problems.\footnote{%
     223however, it largely extended the language, and did not address many existing problems.\footnote{%
    232224Two important existing problems addressed were changing the type of character literals from ©int© to ©char© and enumerator from ©int© to the type of its enumerators.}
    233 \Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language-features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
     225\Index*{Fortran}~\cite{Fortran08}, \Index*{Ada}~\cite{Ada12}, and \Index*{Cobol}~\cite{Cobol14} are examples of programming languages that took an evolutionary approach, where modern language features (\eg objects, concurrency) are added and problems fixed within the framework of the existing language.
    234226\Index*{Java}~\cite{Java8}, \Index*{Go}~\cite{Go}, \Index*{Rust}~\cite{Rust} and \Index*{D}~\cite{D} are examples of the revolutionary approach for modernizing C/\CC, resulting in a new language rather than an extension of the descendent.
    235 These languages have different syntax and semantics from C, do not interoperate directly with C, and are not systems languages because of restrictive memory-management or garbage collection.
     227These languages have different syntax and semantics from C, and do not interoperate directly with C, largely because of garbage collection.
    236228As a result, there is a significant learning curve to move to these languages, and C legacy-code must be rewritten.
    237 These costs can be prohibitive for many companies with a large software-base in C/\CC, and a significant number of programmers require retraining to the new programming language.
    238 
    239 The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixes many of the well known C problems while containing modern language-features.
     229These costs can be prohibitive for many companies with a large software base in C/\CC, and a significant number of programmers requiring retraining to a new programming language.
     230
     231The result of this project is a language that is largely backwards compatible with \Index*[C11]{\Celeven{}}~\cite{C11}, but fixing some of the well known C problems and containing many modern language features.
    240232Without significant extension to the C programming language, it is becoming unable to cope with the needs of modern programming problems and programmers;
    241233as a result, it will fade into disuse.
    242234Considering the large body of existing C code and programmers, there is significant impetus to ensure C is transformed into a modern programming language.
    243 While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language-features.
    244 While some may argue that modern language-features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today.
     235While \Index*[C11]{\Celeven{}} made a few simple extensions to the language, nothing was added to address existing problems in the language or to augment the language with modern language features.
     236While some may argue that modern language features may make C complex and inefficient, it is clear a language without modern capabilities is insufficient for the advanced programming problems existing today.
    245237
    246238
    247239\section{History}
    248240
    249 The \CFA project started with \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and advanced assignment capabilities using the notion of tuples.
     241The \CFA project started with \Index*{K-W C}~\cite{Buhr94a,Till89}, which extended C with new declaration syntax, multiple return values from routines, and extended assignment capabilities using the notion of tuples.
    250242(See~\cite{Werther96} for similar work in \Index*[C++]{\CC{}}.)
    251 The first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}.
    252 
    253 The signature feature of \CFA is \Index{overload}able \Index{parametric-polymorphic} functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
     243A first \CFA implementation of these extensions was by Esteves~\cite{Esteves04}.
     244The signature feature of \CFA is parametric-polymorphic functions~\cite{forceone:impl,Cormack90,Duggan96} with functions generalized using a ©forall© clause (giving the language its name):
    254245\begin{lstlisting}
    255246®forall( otype T )® T identity( T val ) { return val; }
     
    259250\CFA{}\hspace{1pt}'s polymorphism was originally formalized by Ditchfiled~\cite{Ditchfield92}, and first implemented by Bilson~\cite{Bilson03}.
    260251However, at that time, there was little interesting in extending C, so work did not continue.
    261 As the saying goes, ``\Index*{What goes around, comes around.}'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
     252As the saying goes, ``What goes around, comes around.'', and there is now renewed interest in the C programming language because of legacy code-bases, so the \CFA project has been restarted.
    262253
    263254
     
    266257
    267258\CFA is designed to integrate directly with existing C programs and libraries.
    268 The most important feature of \Index{interoperability} is using the same \Index{calling convention}s, so there is no complex interface or overhead to call existing C routines.
     259The most important feature of \Index{interoperability} is using the same \Index{calling convention}s, so there is no overhead to call existing C routines.
    269260This feature allows \CFA programmers to take advantage of the existing panoply of C libraries to access thousands of external software features.
    270261Language developers often state that adequate \Index{library support} takes more work than designing and implementing the language itself.
    271262Fortunately, \CFA, like \Index*[C++]{\CC{}}, starts with immediate access to all exiting C libraries, and in many cases, can easily wrap library routines with simpler and safer interfaces, at very low cost.
    272 Hence, \CFA begins by leveraging the large repository of C libraries at little cost.
     263Hence, \CFA begins by leveraging the large repository of C libraries with little cost.
    273264
    274265\begin{comment}
     
    313304\end{comment}
    314305
    315 However, it is necessary to differentiate between C and \CFA code because of name \Index{overload}ing, as for \CC.
     306However, it is necessary to differentiate between C and \CFA code because of name overloading, as for \CC.
    316307For example, the C math-library provides the following routines for computing the absolute value of the basic types: ©abs©, ©labs©, ©llabs©, ©fabs©, ©fabsf©, ©fabsl©, ©cabsf©, ©cabs©, and ©cabsl©.
    317 Whereas, \CFA wraps each of these routines into ones with the overloaded name ©abs©:
     308Whereas, \CFA wraps each of these routines into ones with the common name ©abs©:
    318309\begin{cfa}
    319310char abs( char );
     
    335326Hence, there is the same need as in \CC, to know if a name is a C or \CFA name, so it can be correctly formed.
    336327There is no way around this problem, other than C's approach of creating unique names for each pairing of operation and type.
    337 This example strongly illustrates a core idea in \CFA: \emph{the \Index{power of a name}}.
     328This example strongly illustrates a core idea in \CFA: \emph{the power of a name}.
    338329The name ``©abs©'' evokes the notion of absolute value, and many mathematical types provide the notion of absolute value.
    339 Hence, knowing the name ©abs© is sufficient to apply it to any type where it is applicable.
    340 The time savings and safety of using one name uniformly versus $N$ unique names cannot be underestimated.
    341 
    342 
    343 \section[Compiling a CFA Program]{Compiling a \CFA Program}
     330Hence, knowing the name ©abs© should be sufficient to apply it to any type where it is applicable.
     331The time savings and safety of using one name uniformly versus $N$ unique names should not be underestimated.
     332
     333
     334\section[Compiling CFA Program]{Compiling \CFA Program}
    344335
    345336The command ©cfa© is used to compile \CFA program(s), and is based on the GNU \Indexc{gcc} command, \eg:
    346337\begin{cfa}
    347 cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA{}§-files [ assembler/loader-files ]
     338cfa§\indexc{cfa}\index{compilation!cfa@©cfa©}§ [ gcc-options ] C/§\CFA§-files [ assembler/loader-files ]
    348339\end{cfa}
    349340\CFA programs having the following ©gcc© flags turned on:
     
    368359\Indexc{-debug}\index{compilation option!-debug@©-debug©}
    369360The program is linked with the debugging version of the runtime system.
    370 The debug version performs runtime checks to help during the debugging phase of a \CFA program, but can substantially slow program execution.
     361The debug version performs runtime checks to help during the debugging phase of a \CFA program, but substantially slows the execution of the program.
    371362The runtime checks should only be removed after the program is completely debugged.
    372363\textbf{This option is the default.}
     
    424415\end{description}
    425416These preprocessor variables allow conditional compilation of programs that must work differently in these situations.
    426 For example, to toggle between C and \CFA extensions, use the following:
     417For example, to toggle between C and \CFA extensions, using the following:
    427418\begin{cfa}
    428419#ifndef __CFORALL__
     
    435426
    436427
    437 \section{Constant Underscores}
    438 
    439 Numeric constants are extended to allow \Index{underscore}s\index{constant!underscore}, \eg:
     428\section{Constants Underscores}
     429
     430Numeric constants are extended to allow \Index{underscore}s within constants\index{constant!underscore}, \eg:
    440431\begin{cfa}
    4414322®_®147®_®483®_®648;                                    §\C{// decimal constant}§
     
    450441L®_®§"\texttt{\textbackslash{x}}§®_®§\texttt{ff}§®_®§\texttt{ee}"§;     §\C{// wide character constant}§
    451442\end{cfa}
    452 The rules for placement of underscores are:
    453 \begin{enumerate}[topsep=5pt,itemsep=5pt,parsep=0pt]
     443The rules for placement of underscores is as follows:
     444\begin{enumerate}
    454445\item
    455446A sequence of underscores is disallowed, \eg ©12__34© is invalid.
     
    472463\label{s:BackquoteIdentifiers}
    473464
    474 \CFA introduces in new keywords (see \VRef{s:CFAKeywords}) that can clash with existing C variable-names in legacy code.
    475 Keyword clashes are accommodated by syntactic transformations using the \CFA backquote escape-mechanism:
     465\CFA accommodates keyword clashes with existing C variable-names by syntactic transformations using the \CFA backquote escape-mechanism:
    476466\begin{cfa}
    477467int ®`®otype®`® = 3;                    §\C{// make keyword an identifier}§
     
    501491
    502492
    503 \section{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break}}{Labelled continue / break}}
     493\section{Labelled Continue/Break}
    504494
    505495While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    506496Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    507 To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85}.
     497To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@\lstinline $continue$!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@\lstinline $break$!labelled}\index{labelled!break@©break©} with a target label to support static multi-level exit\index{multi-level exit}\index{static multi-level exit}~\cite{Buhr85,Java}.
    508498For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    509499for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
    510500\VRef[Figure]{f:MultiLevelResumeTermination} shows the labelled ©continue© and ©break©, specifying which control structure is the target for exit, and the corresponding C program using only ©goto©.
    511501The innermost loop has 7 exit points, which cause resumption or termination of one or more of the 7 \Index{nested control-structure}s.
    512 Java supports both labelled ©continue© and ©break© statements.
    513502
    514503\begin{figure}
     
    633622
    634623
    635 \section{\texorpdfstring{\LstKeywordStyle{switch} Statement}{switch Statement}}
     624\section{Switch Statement}
    636625
    637626C allows a number of questionable forms for the ©switch© statement:
     
    674663        ®// open input file
    675664®} else if ( argc == 2 ) {
    676         ®// open input file (duplicate)
     665        ®// open input file
    677666
    678667®} else {
     
    687676\begin{cfa}
    688677switch ( i ) {
    689   ®case 1: case 3: case 5:®     // odd values
    690         // odd action
     678  case 1: case 3: case 5:       // odd values
     679        // same action
    691680        break;
    692   ®case 2: case 4: case 6:®     // even values
    693         // even action
     681  case 2: case 4: case 6:       // even values
     682        // same action
    694683        break;
    695684}
     
    697686However, this situation is handled in other languages without fall-through by allowing a list of case values.
    698687While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive to many programmers and is different from virtually all other programming languages with a ©switch© statement.
    699 Hence, default fall-through semantics results in a large number of programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
     688Hence, default fall-through semantics results in a large number of programming errors as programmers often forget the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
    700689
    701690\item
     
    781770and there is only a medium amount of fall-through from one ©case© clause to the next, and most of these result from a list of case values executing common code, rather than a sequence of case actions that compound.
    782771\end{itemize}
    783 These observations put into perspective the \CFA changes to the ©switch©.
     772These observations help to put the \CFA changes to the ©switch© into perspective.
    784773\begin{enumerate}
    785774\item
     
    802791  case 7:
    803792        ...
    804         ®break®                                         §\C{// redundant explicit end of switch}§
     793        ®break®                                         §\C{// explicit end of switch}§
    805794  default:
    806795        j = 3;
     
    808797\end{cfa}
    809798Like the ©switch© statement, the ©choose© statement retains the fall-through semantics for a list of ©case© clauses;
    810 An implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
    811 An explicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement.
     799the implicit ©break© is applied only at the end of the \emph{statements} following a ©case© clause.
     800The explicit ©fallthru© is retained because it is a C-idiom most C programmers expect, and its absence might discourage programmers from using the ©choose© statement.
    812801As well, allowing an explicit ©break© from the ©choose© is a carry over from the ©switch© statement, and expected by C programmers.
    813802\item
     
    838827
    839828
    840 \section{\texorpdfstring{\LstKeywordStyle{case} Clause}{case Clause}}
     829\section{Case Clause}
    841830
    842831C restricts the ©case© clause of a ©switch© statement to a single value.
     
    911900\begin{cfa}
    912901case ®1~5, 12~21, 35~42®:
    913 \end{cfa}
    914 
    915 
    916 \section{\texorpdfstring{\LstKeywordStyle{with} Clause / Statement}{with Clause / Statement}}
    917 \label{s:WithClauseStatement}
    918 
    919 In \Index{object-oriented} programming, there is an implicit first parameter, often names \textbf{©self©} or \textbf{©this©}, which is elided.
    920 \begin{C++}
    921 class C {
    922         int i, j;
    923         int mem() {              ®// implicit "this" parameter
    924                 i = 1;          ®// this->i
    925 ®               j = 3;          ®// this->j
    926 ®       }
    927 }
    928 \end{C++}
    929 Since CFA is non-object-oriented, the equivalent object-oriented program looks like:
    930 \begin{cfa}
    931 struct C {
    932         int i, j;
    933 };
    934 int mem( C &this ) {    // explicit "this" parameter
    935         ®this.®i = 1;                     // "this" is not elided
    936         ®this.®j = 2;
    937 }
    938 \end{cfa}
    939 but it is cumbersome having to write "©this.©" many times in a member.
    940 \CFA provides a ©with© clause/statement to elided the "©this.©".
    941 \begin{cfa}
    942 int mem( C &this ) ®with this® {
    943         i = 1;                  ®// this.i
    944 ®       j = 2;                  ®// this.j
    945 ®}
    946 \end{cfa}
    947 which extends to multiple routine parameters:
    948 \begin{cfa}
    949 struct D {
    950         double m, n;
    951 };
    952 int mem2( C &this1, D &this2 ) ®with this1, this2® {
    953         i = 1; j = 2;
    954         m = 1.0; n = 2.0;
    955 }
    956 \end{cfa}
    957 The ©with© clause/statement comes from Pascal~\cite[\S~4.F]{Pascal}.
    958 
    959 The statement form is used within a block:
    960 \begin{cfa}
    961 int foo() {
    962         struct S1 { ... } s1;
    963         struct S2 { ... } s2;
    964         ®with s1® {
    965                 // access fields of s1 without qualification
    966                 ®with s2® {  // nesting
    967                         // access fields of s2 without qualification
    968                 }
    969         }
    970         ®with s1, s2® {
    971                 // access unambiguous fields of s1 and s2 without qualification
    972         }
    973 }
    974 \end{cfa}
    975 
    976 Names clashes when opening multiple structures are ambiguous.
    977 \begin{cfa}
    978 struct A { int i; int j; } a, c;
    979 struct B { int i; int k; } b, c;
    980 ®with a, b® {
    981         j + k;                                          §\C{// unambiguous}§
    982         i;                                                      §\C{// ambiguous}§
    983         a.i + b.i;                                      §\C{// unambiguous}§
    984 }
    985 ®with c® {                                              §\C{// ambiguous}§
    986         // ...
    987 }
    988902\end{cfa}
    989903
     
    12221136
    12231137
    1224 \section{Pointer / Reference}
     1138\section{Pointer/Reference}
    12251139
    12261140C provides a \newterm{pointer type};
     
    25362450\end{cfa}
    25372451\\
    2538 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     2452\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    253924531® ®2® ®3
    25402454\end{cfa}
    25412455&
    2542 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     2456\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    254324571 2 3
    25442458\end{cfa}
     
    25472461The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators.
    25482462Similar simplification occurs for \Index{tuple} I/O, which prints all tuple values separated by ``\lstinline[showspaces=true]@, @''.
    2549 \begin{cfa}
    2550 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
     2463\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2464[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
    25512465sout | t1 | t2 | endl;                                  §\C{// print tuples}§
    25522466\end{cfa}
    2553 \begin{cfa}[showspaces=true,aboveskip=0pt]
    2554 1®, ®2®, ®3 4®, ®5®, ®6
     2467\begin{cfa}[mathescape=off,showspaces=true,belowskip=0pt]
     24681®, ®2®, ®3 3®, ®4®, ®5
    25552469\end{cfa}
    25562470Finally, \CFA uses the logical-or operator for I/O as it is the lowest-priority overloadable operator, other than assignment.
     
    25712485\\
    25722486&
    2573 \begin{cfa}[showspaces=true,aboveskip=0pt]
     2487\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    257424883 3 12 0 3 1 2
    25752489\end{cfa}
     
    25892503sout | 1 | 2 | 3 | endl;
    25902504\end{cfa}
    2591 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     2505\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    259225061 2 3
    25932507\end{cfa}
     
    26562570\subsection{Manipulator}
    26572571
    2658 The following \CC-style \Index{manipulator}s and routines control implicit seperation.
     2572The following routines and \CC-style \Index{manipulator}s control implicit seperation.
    26592573\begin{enumerate}
    26602574\item
    2661 Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sep}\index{manipulator!sep@©sep©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
     2575Routines \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string.
    26622576The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    2663 \begin{cfa}[mathescape=off,belowskip=0pt]
     2577\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    26642578sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    2665 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
     2579sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
    26662580\end{cfa}
    26672581%$
     
    26702584\end{cfa}
    26712585%$
    2672 \begin{cfa}[belowskip=0pt]
     2586\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    26732587sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    26742588sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
    26752589\end{cfa}
    2676 \begin{cfa}[showspaces=true,aboveskip=0pt]
     2590\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
    267725911® ®2® ®3 ®" "®
    26782592\end{cfa}
    2679 ©sepGet© can be used to store a separator and then restore it:
    2680 \begin{cfa}[belowskip=0pt]
    2681 char store[®sepSize®];                                          §\C{// sepSize is the maximum separator size}§
    2682 strcpy( store, sepGet( sout ) );
    2683 sepSet( sout, "_" );
    2684 sout | 1 | 2 | 3 | endl;
    2685 \end{cfa}
    2686 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2687 1®_®2®_®3
    2688 \end{cfa}
    2689 \begin{cfa}[belowskip=0pt]
    2690 sepSet( sout, store );
    2691 sout | 1 | 2 | 3 | endl;
    2692 \end{cfa}
    2693 \begin{cfa}[showspaces=true,aboveskip=0pt]
    2694 1® ®2® ®3
    2695 \end{cfa}
    2696 
    2697 \item
    2698 Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTuple}\index{manipulator!sepTuple@©sepTuple©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
     2593
     2594\item
     2595Routine \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string.
    26992596The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters).
    2700 \begin{cfa}[belowskip=0pt]
     2597\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    27012598sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    2702 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
    2703 \end{cfa}
    2704 \begin{cfa}[showspaces=true,aboveskip=0pt]
    2705 1 2 3 4 5 6 ®" "®
    2706 \end{cfa}
    2707 \begin{cfa}[belowskip=0pt]
     2599sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
     2600\end{cfa}
     2601\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     26021 2 3 4 ®" "®
     2603\end{cfa}
     2604\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
    27082605sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    27092606sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
    27102607\end{cfa}
    2711 \begin{cfa}[showspaces=true,aboveskip=0pt]
    2712 1, 2, 3 4, 5, 6 ®", "®
    2713 \end{cfa}
    2714 As for ©sepGet©, ©sepGetTuple© can be use to store a tuple separator and then restore it.
    2715 
    2716 \item
    2717 Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items.
    2718 \begin{cfa}[belowskip=0pt]
    2719 sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
    2720 \end{cfa}
    2721 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     2608\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt]
     26091, 2, 3, 4 ®", "®
     2610\end{cfa}
     2611
     2612\item
     2613Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.
     2614\begin{cfa}[mathescape=off,belowskip=0pt]
     2615sout | sepOn | 1 | 2 | 3 | sepOn | endl;        §\C{// separator at start/end of line}§
     2616\end{cfa}
     2617\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2618® ®1 2 3® ®
     2619\end{cfa}
     2620\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2621sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
     2622\end{cfa}
     2623\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     262412 3
     2625\end{cfa}
     2626The tuple separator also responses to being turned on and off.
     2627\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2628sout | sepOn | t1 | sepOff | t2 | endl;         §\C{// locally turn on/off implicit separation}§
     2629\end{cfa}
     2630\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     2631, 1, 23, 4
     2632\end{cfa}
     2633Notice a tuple seperator starts the line because the next item is a tuple.
     2634
     2635\item
     2636Manipulators \Indexc{sepDisable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} \emph{globally} toggle printing the separator, \ie the seperator is adjusted with respect to all subsequent printed items, unless locally adjusted.
     2637\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2638sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separation}§
     2639\end{cfa}
     2640\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    27222641123
    27232642\end{cfa}
    2724 \begin{cfa}[belowskip=0pt]
    2725 sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
     2643\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2644sout | 1 | ®sepOn® | 2 | 3 | endl;                      §\C{// locally turn on implicit separator}§
     2645\end{cfa}
     2646\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     26471® ®23
     2648\end{cfa}
     2649\begin{cfa}[mathescape=off,aboveskip=0pt,belowskip=0pt]
     2650sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separation}§
    27262651\end{cfa}
    27272652\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
    272826531 2 3
    27292654\end{cfa}
    2730 
    2731 \item
    2732 Manipulators \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} \emph{locally} toggle printing the separator, \ie the seperator is adjusted only with respect to the next printed item.
    2733 \begin{cfa}[belowskip=0pt]
    2734 sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
    2735 \end{cfa}
    2736 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2737 12 3
    2738 \end{cfa}
    2739 \begin{cfa}[belowskip=0pt]
    2740 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§
    2741 \end{cfa}
    2742 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2743 1 23
    2744 \end{cfa}
    2745 The tuple separator also responses to being turned on and off.
    2746 \begin{cfa}[belowskip=0pt]
    2747 sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator}§
    2748 \end{cfa}
    2749 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2750 1, 2, 34, 5, 6
    2751 \end{cfa}
    2752 ©sepOn© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line;
    2753 use ©sep© to accomplish this functionality.
    2754 \begin{cfa}[belowskip=0pt]
    2755 sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
    2756 \end{cfa}
    2757 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2758 1 2 3
    2759 \end{cfa}
    2760 \begin{cfa}[belowskip=0pt]
    2761 sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
    2762 \end{cfa}
    2763 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    2764 ® ®1 2 3® ®
    2765 \end{cfa}
    27662655\end{enumerate}
    27672656
    27682657\begin{comment}
    27692658#include <fstream>
    2770 #include <string.h>                                                                             // strcpy
    27712659
    27722660int main( void ) {
    27732661        int x = 1, y = 2, z = 3;
    27742662        sout | x | y | z | endl;
    2775         [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
     2663        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 3, [ 4, 5 ] ];
    27762664        sout | t1 | t2 | endl;                                          // print tuples
    27772665        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     
    27872675
    27882676        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    2789         sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
     2677        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    27902678        sepSet( sout, " " );                                            // reset separator to " "
    27912679        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    27922680
    2793         char store[sepSize];
    2794         strcpy( store, sepGet( sout ) );
    2795         sepSet( sout, "_" );
    2796         sout | 1 | 2 | 3 | endl;
    2797         sepSet( sout, store );
    2798         sout | 1 | 2 | 3 | endl;
     2681        sout | sepOn | 1 | 2 | 3 | sepOn | endl;        // separator at start of line
     2682        sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn off implicit separator
     2683
     2684        sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separation
     2685        sout | 1 | sepOn | 2 | 3 | endl;                        // locally turn on implicit separator
     2686        sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separation
    27992687
    28002688        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    2801         sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
     2689        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    28022690        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    28032691        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    28042692
    2805         sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separator
    2806         sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separator
    2807        
    2808         sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn on implicit separator
    2809         sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator
    2810         sout | sepEnable;
    2811         sout | t1 | sepOff | t2 | endl;                         // locally turn on/off implicit separator
    2812 
    2813         sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       // sepOn does nothing at start/end of line
    2814         sout | sep | 1 | 2 | 3 | sep | endl ;           // use sep to print separator at start/end of line
     2693        sout | t1 | t2 | endl;                                          // print tuple
     2694        sout | sepOn | t1 | sepOff | t2 | endl;         // locally turn on/off implicit separation
    28152695}
    28162696
     
    53445224
    53455225
    5346 \section{\texorpdfstring{\CFA Keywords}{Cforall Keywords}}
     5226\section{\CFA Keywords}
    53475227\label{s:CFAKeywords}
    53485228
    5349 \CFA introduces the following new keywords.
    5350 
    53515229\begin{quote2}
    5352 \begin{tabular}{lllll}
     5230\begin{tabular}{llll}
    53535231\begin{tabular}{@{}l@{}}
    5354 ©_At©                   \\
     5232©_AT©                   \\
    53555233©catch©                 \\
    53565234©catchResume©   \\
    53575235©choose©                \\
    53585236©coroutine©             \\
     5237©disable©               \\
    53595238\end{tabular}
    53605239&
    53615240\begin{tabular}{@{}l@{}}
    5362 ©disable©               \\
    53635241©dtype©                 \\
    53645242©enable©                \\
    53655243©fallthrough©   \\
    53665244©fallthru©              \\
     5245©finally©               \\
     5246©forall©                \\
    53675247\end{tabular}
    53685248&
    53695249\begin{tabular}{@{}l@{}}
    5370 ©finally©               \\
    5371 ©forall©                \\
    53725250©ftype©                 \\
    53735251©lvalue©                \\
    53745252©monitor©               \\
     5253©mutex©                 \\
     5254©one_t©                 \\
     5255©otype©                 \\
    53755256\end{tabular}
    53765257&
    53775258\begin{tabular}{@{}l@{}}
    5378 ©mutex©                 \\
    5379 ©one_t©                 \\
    5380 ©otype©                 \\
    53815259©throw©                 \\
    53825260©throwResume©   \\
    5383 \end{tabular}
    5384 &
    5385 \begin{tabular}{@{}l@{}}
    53865261©trait©                 \\
    53875262©try©                   \\
    53885263©ttype©                 \\
    53895264©zero_t©                \\
    5390                                 \\
    53915265\end{tabular}
    53925266\end{tabular}
     
    56745548// C unsafe allocation
    56755549extern "C" {
    5676 void * malloc( size_t size );§\indexc{memset}§
     5550void * mallac( size_t size );§\indexc{memset}§
    56775551void * calloc( size_t dim, size_t size );§\indexc{calloc}§
    56785552void * realloc( void * ptr, size_t size );§\indexc{realloc}§
Note: See TracChangeset for help on using the changeset viewer.