Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rd92ff4a r200fcb3  
    11%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -*- Mode: Latex -*- %%%%%%%%%%%%%%%%%%%%%%%%%%%%
    2 %% 
     2%%
    33%% Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    44%%
    55%% The contents of this file are covered under the licence agreement in the
    66%% file "LICENCE" distributed with Cforall.
    7 %% 
    8 %% user.tex -- 
    9 %% 
     7%%
     8%% user.tex --
     9%%
    1010%% Author           : Peter A. Buhr
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Jul 26 17:29:05 2018
    14 %% Update Count     : 3366
     13%% Last Modified On : Tue Dec 11 23:19:26 2018
     14%% Update Count     : 3400
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    7272
    7373% Names used in the document.
    74 \newcommand{\Version}{\input{../../version}}
     74\newcommand{\Version}{\input{build/version}}
    7575\newcommand{\Textbf}[2][red]{{\color{#1}{\textbf{#2}}}}
    7676\newcommand{\Emph}[2][red]{{\color{#1}\textbf{\emph{#2}}}}
     
    178178int main( void ) {
    179179        int x = 0, y = 1, z = 2;
    180         ®sout | x | y | z | endl;®§\indexc{sout}§
     180        ®sout | x | y | z;®§\indexc{sout}§
    181181}
    182182\end{cfa}
     
    210210Even with all its problems, C continues to be popular because it allows writing software at virtually any level in a computer system without restriction.
    211211For system programming, where direct access to hardware, storage management, and real-time issues are a requirement, C is usually the only language of choice.
    212 The TIOBE index~\cite{TIOBE} for July 2018 ranks the top 5 most \emph{popular} programming languages as: \Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail.
     212The TIOBE index~\cite{TIOBE} for July 2018 ranks the top five most \emph{popular} programming languages as \Index*{Java} 16\%, C 14\%, \Index*[C++]{\CC{}} 7.5\%, Python 6\%, Visual Basic 4\% = 47.5\%, where the next 50 languages are less than 4\% each, with a long tail.
    213213The top 3 rankings over the past 30 years are:
    214214\begin{center}
     
    351351The 2011 C standard plus GNU extensions.
    352352\item
    353 \Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]@-fgnu89-inline@}}
     353\Indexc[deletekeywords=inline]{-fgnu89-inline}\index{compilation option!-fgnu89-inline@{\lstinline[deletekeywords=inline]$-fgnu89-inline$}}
    354354Use the traditional GNU semantics for inline routines in C11 mode, which allows inline routines in header files.
    355355\end{description}
     
    430430#endif
    431431\end{cfa}
    432 which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}. 
     432which conditionally includes the correct header file, if the program is compiled using \Indexc{gcc} or \Indexc{cfa}.
    433433
    434434
     
    455455#endif
    456456
    457 ®#include_next <bfdlink.h>                                      §\C{// must have internal check for multiple expansion}§
     457®#include_next <bfdlink.h>                      §\C{// must have internal check for multiple expansion}§
    458458®
    459459#if defined( with ) && defined( __CFA_BFD_H__ ) §\C{// reset only if set}§
     
    504504
    505505C, \CC, and Java (and many other programming languages) have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow}, to perform the exponentiation operation.
    506 \CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@\lstinline@?\?@} and ©?\=?©\index{?\\=?@\lstinline@?\=?@}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
     506\CFA extends the basic operators with the exponentiation operator ©?\?©\index{?\\?@©?\?©} and ©?\=?©\index{?\\=?@©\=?©}, as in, ©x \ y© and ©x \= y©, which means $x^y$ and $x \leftarrow x^y$.
    507507The priority of the exponentiation operator is between the cast and multiplicative operators, so that ©w * (int)x \ (int)y * z© is parenthesized as ©((w * (((int)x) \ ((int)y))) * z)©.
    508508
     
    513513Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the base cannot be negative.
    514514\begin{cfa}
    515 sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
     515sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi);
    516516256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    517517\end{cfa}
    518 Parenthesis are necessary for the complex constants or the expression is parsed as ©1.0f+(2.0fi \ 3.0f)+2.0fi©.
     518Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
    519519The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation versions are available.
    520520For returning an integral value, the user type ©T© must define multiplication, ©*©, and one, ©1©;
     
    527527
    528528
    529 %\subsection{\texorpdfstring{\protect\lstinline@if@ Statement}{if Statement}}
    530 \subsection{\texorpdfstring{\LstKeywordStyle{if} Statement}{if Statement}}
    531 
    532 The ©if© expression allows declarations, similar to ©for© declaration expression:
    533 \begin{cfa}
    534 if ( int x = f() ) ...                                          §\C{// x != 0}§
    535 if ( int x = f(), y = g() ) ...                         §\C{// x != 0 \&\& y != 0}§
    536 if ( int x = f(), y = g(); ®x < y® ) ...        §\C{// relational expression}§
    537 \end{cfa}
    538 Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.}
     529%\subsection{\texorpdfstring{\protect\lstinline@if@/\protect\lstinline@while@ Statement}{if Statement}}
     530\subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
     531
     532The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
     533(Does not make sense for ©do©-©while©.)
     534\begin{cfa}
     535if ( ®int x = f()® ) ...                                        §\C{// x != 0}§
     536if ( ®int x = f(), y = g()® ) ...                       §\C{// x != 0 \&\& y != 0}§
     537if ( ®int x = f(), y = g(); x < y® ) ...        §\C{// relational expression}§
     538if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
     539
     540while ( ®int x = f()® ) ...                                     §\C{// x != 0}§
     541while ( ®int x = f(), y = g()® ) ...            §\C{// x != 0 \&\& y != 0}§
     542while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     543while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
     544\end{cfa}
     545Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical ©&&© operator.\footnote{\CC only provides a single declaration always compared not equal to 0.}
    539546The scope of the declaration(s) is local to the @if@ statement but exist within both the ``then'' and ``else'' clauses.
     547
     548
     549\subsection{Loop Control}
     550
     551The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges.
     552An empty conditional implies ©1©.
     553The up-to range ©~©\index{~@©~©} means exclusive range [M,N);
     554the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
     555The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M);
     556the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
     557©0© is the implicit start value;
     558©1© is the implicit increment value.
     559The up-to range uses ©+=© for increment;
     560the down-to range uses ©-=© for decrement.
     561The loop index is polymorphic in the type of the start value or comparison value when start is implicitly ©0©.
     562\begin{cquote}
     563\begin{tabular}{@{}ll|l@{}}
     564\multicolumn{2}{c|}{loop control} & \multicolumn{1}{c}{output} \\
     565\hline
     566\begin{cfa}
     567while ®()® { sout | "empty"; break; }
     568do { sout | "empty"; break; } while ®()®;
     569for ®()® { sout | "empty"; break; }
     570for ( ®0® ) { sout | "A"; }
     571for ( ®1® ) { sout | "A"; }
     572for ( ®10® ) { sout | "A"; }
     573for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
     574for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
     575for ( ®0.5 ~ 5.5® ) { sout | "D"; }
     576for ( ®5.5 -~ 0.5® ) { sout | "E"; }
     577for ( ®i; 10® ) { sout | i; }
     578for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
     579for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
     580for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
     581for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
     582for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
     583for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
     584enum { N = 10 };
     585for ( ®N® ) { sout | "N"; }
     586for ( ®i; N® ) { sout | i; }
     587for ( ®i; N -~ 0® ) { sout | i; }
     588const int start = 3, comp = 10, inc = 2;
     589for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
     590\end{cfa}
     591&
     592\begin{cfa}
     593sout | nl;
     594sout | nl;
     595sout | nl;
     596sout | "zero" | nl;
     597sout | nl;
     598sout | nl;
     599sout | nl;
     600sout | nl;
     601sout | nl;
     602sout | nl;
     603sout | nl;
     604sout | nl;
     605sout | nl;
     606sout | nl;
     607sout | nl;
     608sout | nl;
     609sout | nl | nl;
     610
     611sout | nl;
     612sout | nl;
     613sout | nl | nl;
     614
     615sout | nl;
     616\end{cfa}
     617&
     618\begin{cfa}
     619empty
     620empty
     621empty
     622zero
     623A
     624A A A A A A A A A A
     625B B B B B
     626C C C C C
     627D D D D D
     628E E E E E
     6290 1 2 3 4 5 6 7 8 9
     6301 3 5 7 9
     63110 8 6 4 2
     6320.5 1.5 2.5 3.5 4.5
     6335.5 4.5 3.5 2.5 1.5
     6342 4 6 8 10
     63510 8 6 4 2
     636
     637N N N N N N N N N N
     6380 1 2 3 4 5 6 7 8 9
     63910 9 8 7 6 5 4 3 2 1
     640
     6413 6 9
     642\end{cfa}
     643\end{tabular}
     644\end{cquote}
    540645
    541646
     
    800905
    801906
     907% for ()  => for ( ;; )
     908% for ( 10 - t ) => for ( typeof(10 - t) ? = 0 ; ? < 10 - t; ? += 1 ) // using 0 and 1
     909% for ( i ; 10 - t ) => for ( typeof(10 - t) i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
     910% for ( T i ; 10 - t ) => for ( T i = 0 ; i < 10 - t; i += 1 ) // using 0 and 1
     911% for ( 3~9 ) => for ( int ? = 3 ; ? < 9; ? += 1 ) // using 1
     912% for ( i ; 3~9 ) => for ( int i = 3 ; i < 9; i += 1 ) // using 1
     913% for ( T i ; 3~9 ) => for ( T i = 3 ; i < 9; i += 1 ) // using 1
     914
     915
    802916%\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}}
    803917\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
     
    805919While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    806920Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    807 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}, as in Java.
     921To prevent having to switch to the ©goto©, \CFA extends the \Indexc{continue}\index{continue@©continue©!labelled}\index{labelled!continue@©continue©} and \Indexc{break}\index{break@©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}, as in Java.
    808922For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    809923for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
     
    8901004\end{figure}
    8911005
    892 Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways:
     1006Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
    8931007\begin{itemize}
    8941008\item
     
    14471561\end{cfa}
    14481562Algol68 infers the following dereferencing ©*p2 = *p1 + x©, because adding the arbitrary integer value in ©x© to the address of ©p1© and storing the resulting address into ©p2© is an unlikely operation.
    1449 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 
     1563Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
    14501564
    14511565Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
     
    22822396        struct T t;
    22832397} s;
    2284        
     2398
    22852399
    22862400
     
    23452459        int bar( int p ) {
    23462460                ®i® += 1;                               §\C{// dependent on local variable}§
    2347                 sout | ®i® | endl;
     2461                sout | ®i®;
    23482462        }
    23492463        return bar;                                     §\C{// undefined because of local dependence}§
     
    23512465int main() {
    23522466        * [int]( int ) fp = foo();      §\C{// int (* fp)( int )}§
    2353         sout | fp( 3 ) | endl;
    2354 }
    2355 \end{cfa}
    2356 because 
     2467        sout | fp( 3 );
     2468}
     2469\end{cfa}
     2470because
    23572471
    23582472Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     
    31173231\begin{cfa}
    31183232int x = 1, y = 2, z = 3;
    3119 sout | x ®|® y ®|® z | endl;
     3233sout | x ®|® y ®|® z;
    31203234\end{cfa}
    31213235&
     
    31383252\begin{cfa}
    31393253[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3140 sout | t1 | t2 | endl;                                  §\C{// print tuples}§
     3254sout | t1 | t2;                                         §\C{// print tuples}§
    31413255\end{cfa}
    31423256\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    31503264&
    31513265\begin{cfa}
    3152 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
     3266sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2);
    31533267\end{cfa}
    31543268\\
     
    31763290A separator does not appear at the start or end of a line.
    31773291\begin{cfa}[belowskip=0pt]
    3178 sout | 1 | 2 | 3 | endl;
     3292sout | 1 | 2 | 3;
    31793293\end{cfa}
    31803294\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    31853299A separator does not appear before or after a character literal or variable.
    31863300\begin{cfa}
    3187 sout | '1' | '2' | '3' | endl;
     3301sout | '1' | '2' | '3';
    31883302123
    31893303\end{cfa}
     
    31923306A separator does not appear before or after a null (empty) C string.
    31933307\begin{cfa}
    3194 sout | 1 | "" | 2 | "" | 3 | endl;
     3308sout | 1 | "" | 2 | "" | 3;
    31953309123
    31963310\end{cfa}
     
    32023316\begin{cfa}[mathescape=off]
    32033317sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3204                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     3318                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    32053319\end{cfa}
    32063320%$
     
    32163330\begin{cfa}[belowskip=0pt]
    32173331sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3218                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
     3332                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
    32193333\end{cfa}
    32203334\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32263340A seperator does not appear before or after a C string begining/ending with the \Index*{ASCII} quote or whitespace characters: \lstinline[basicstyle=\tt,showspaces=true]@`'": \t\v\f\r\n@
    32273341\begin{cfa}[belowskip=0pt]
    3228 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
     3342sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
    32293343\end{cfa}
    32303344\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    32353349If a space is desired before or after one of the special string start/end characters, simply insert a space.
    32363350\begin{cfa}[belowskip=0pt]
    3237 sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4 | endl;
     3351sout | "x (§\color{red}\texttt{\textvisiblespace}§" | 1 | "§\color{red}\texttt{\textvisiblespace}§) x" | 2 | "§\color{red}\texttt{\textvisiblespace}§, x" | 3 | "§\color{red}\texttt{\textvisiblespace}§:x:§\color{red}\texttt{\textvisiblespace}§" | 4;
    32383352\end{cfa}
    32393353\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    32523366\begin{cfa}[mathescape=off,belowskip=0pt]
    32533367sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    3254 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
     3368sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
    32553369\end{cfa}
    32563370%$
     
    32613375\begin{cfa}[belowskip=0pt]
    32623376sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    3263 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
     3377sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
    32643378\end{cfa}
    32653379\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32713385strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
    32723386sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
    3273 sout | 1 | 2 | 3 | endl;
     3387sout | 1 | 2 | 3;
    32743388\end{cfa}
    32753389\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32783392\begin{cfa}[belowskip=0pt]
    32793393sepSet( sout, store );                                          §\C{// change separator back to original}§
    3280 sout | 1 | 2 | 3 | endl;
     3394sout | 1 | 2 | 3;
    32813395\end{cfa}
    32823396\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32893403\begin{cfa}[belowskip=0pt]
    32903404sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    3291 sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
     3405sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
    32923406\end{cfa}
    32933407\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32963410\begin{cfa}[belowskip=0pt]
    32973411sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    3298 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
     3412sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
    32993413\end{cfa}
    33003414\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    33063420Manipulators \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.
    33073421\begin{cfa}[belowskip=0pt]
    3308 sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
     3422sout | sepDisable | 1 | 2 | 3                §\C{// globally turn off implicit separator}§
    33093423\end{cfa}
    33103424\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33123426\end{cfa}
    33133427\begin{cfa}[belowskip=0pt]
    3314 sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
     3428sout | sepEnable | 1 | 2 | 3;           §\C{// globally turn on implicit separator}§
    33153429\end{cfa}
    33163430\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33213435Manipulators \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.
    33223436\begin{cfa}[belowskip=0pt]
    3323 sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
     3437sout | 1 | sepOff | 2 | 3;                      §\C{// locally turn off implicit separator}§
    33243438\end{cfa}
    33253439\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33273441\end{cfa}
    33283442\begin{cfa}[belowskip=0pt]
    3329 sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§
     3443sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// locally turn on implicit separator}§
    33303444\end{cfa}
    33313445\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33343448The tuple separator also responses to being turned on and off.
    33353449\begin{cfa}[belowskip=0pt]
    3336 sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator}§
     3450sout | t1 | sepOff | t2;                                §\C{// locally turn on/off implicit separator}§
    33373451\end{cfa}
    33383452\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33423456use ©sep© to accomplish this functionality.
    33433457\begin{cfa}[belowskip=0pt]
    3344 sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
     3458sout | sepOn | 1 | 2 | 3 | sepOn;       §\C{// sepOn does nothing at start/end of line}§
    33453459\end{cfa}
    33463460\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33483462\end{cfa}
    33493463\begin{cfa}[belowskip=0pt]
    3350 sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
     3464sout | sep | 1 | 2 | 3 | sep ;          §\C{// use sep to print separator at start/end of line}§
    33513465\end{cfa}
    33523466\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33613475int main( void ) {
    33623476        int x = 1, y = 2, z = 3;
    3363         sout | x | y | z | endl;
     3477        sout | x | y | z;
    33643478        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3365         sout | t1 | t2 | endl;                                          // print tuples
    3366         sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    3367         sout | 1 | 2 | 3 | endl;
    3368         sout | '1' | '2' | '3' | endl;
    3369         sout | 1 | "" | 2 | "" | 3 | endl;
     3479        sout | t1 | t2;                                         // print tuples
     3480        sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2);
     3481        sout | 1 | 2 | 3;
     3482        sout | '1' | '2' | '3';
     3483        sout | 1 | "" | 2 | "" | 3;
    33703484        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3371                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
     3485                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
    33723486        sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3373                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    3374         sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    3375         sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4 | endl;
     3487                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3488        sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
     3489        sout | "x ( " | 1 | " ) x" | 2 | " , x" | 3 | " :x: " | 4;
    33763490
    33773491        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    3378         sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
     3492        sout | 1 | 2 | 3 | " \"" | sep | "\"";
    33793493        sepSet( sout, " " );                                            // reset separator to " "
    3380         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
     3494        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"";
    33813495
    33823496        char store[sepSize];
    33833497        strcpy( store, sepGet( sout ) );
    33843498        sepSet( sout, "_" );
    3385         sout | 1 | 2 | 3 | endl;
     3499        sout | 1 | 2 | 3;
    33863500        sepSet( sout, store );
    3387         sout | 1 | 2 | 3 | endl;
     3501        sout | 1 | 2 | 3;
    33883502
    33893503        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    3390         sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
     3504        sout | t1 | t2 | " \"" | sepTuple | "\"";
    33913505        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    3392         sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"" | endl;
    3393 
    3394         sout | sepDisable | 1 | 2 | 3 | endl;           // globally turn off implicit separator
    3395         sout | sepEnable | 1 | 2 | 3 | endl;            // globally turn on implicit separator
    3396        
    3397         sout | 1 | sepOff | 2 | 3 | endl;                       // locally turn on implicit separator
    3398         sout | sepDisable | 1 | sepOn | 2 | 3 | endl; // globally turn off implicit separator
     3506        sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\"";
     3507
     3508        sout | sepDisable | 1 | 2 | 3;          // globally turn off implicit separator
     3509        sout | sepEnable | 1 | 2 | 3;           // globally turn on implicit separator
     3510
     3511        sout | 1 | sepOff | 2 | 3;                      // locally turn on implicit separator
     3512        sout | sepDisable | 1 | sepOn | 2 | 3; // globally turn off implicit separator
    33993513        sout | sepEnable;
    3400         sout | t1 | sepOff | t2 | endl;                         // locally turn on/off implicit separator
    3401 
    3402         sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       // sepOn does nothing at start/end of line
    3403         sout | sep | 1 | 2 | 3 | sep | endl ;           // use sep to print separator at start/end of line
     3514        sout | t1 | sepOff | t2;                                // locally turn on/off implicit separator
     3515
     3516        sout | sepOn | 1 | 2 | 3 | sepOn ;      // sepOn does nothing at start/end of line
     3517        sout | sep | 1 | 2 | 3 | sep ;          // use sep to print separator at start/end of line
    34043518}
    34053519
     
    40664180        Fibonacci f1, f2;
    40674181        for ( int i = 1; i <= 10; i += 1 ) {
    4068                 sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
     4182                sout | next( &f1 ) | ' ' | next( &f2 );
    40694183        } // for
    40704184}
     
    41324246                MyThread f[4];
    41334247        }
    4134         sout | global.value | endl;
     4248        sout | global.value;
    41354249}
    41364250\end{cfa}
     
    42104324void main( First * this ) {
    42114325        for ( int i = 0; i < 10; i += 1 ) {
    4212                 sout | "First : Suspend No." | i + 1 | endl;
     4326                sout | "First : Suspend No." | i + 1;
    42134327                yield();
    42144328        }
     
    42194333        wait( this->lock );
    42204334        for ( int i = 0; i < 10; i += 1 ) {
    4221                 sout | "Second : Suspend No." | i + 1 | endl;
     4335                sout | "Second : Suspend No." | i + 1;
    42224336                yield();
    42234337        }
     
    42264340int main( void ) {
    42274341        signal_once lock;
    4228         sout | "User main begin" | endl;
     4342        sout | "User main begin";
    42294343        {
    42304344                processor p;
     
    42344348                }
    42354349        }
    4236         sout | "User main end" | endl;
     4350        sout | "User main end";
    42374351}
    42384352\end{cfa}
     
    49315045void ?{}( Line * l ) {
    49325046        l->lnth = 0.0;
    4933         sout | "default" | endl;
     5047        sout | "default";
    49345048}
    49355049
     
    49385052void ?{}( Line * l, float lnth ) {
    49395053        l->lnth = lnth;
    4940         sout | "lnth" | l->lnth | endl;
     5054        sout | "lnth" | l->lnth;
    49415055
    49425056}
     
    49445058// destructor
    49455059void ^?() {
    4946         sout | "destroyed" | endl;
     5060        sout | "destroyed";
    49475061        l.lnth = 0.0;
    49485062}
     
    56905804In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    56915805\begin{cfa}
    5692 sout | 'x' | " " | (int)'x' | endl;
     5806sout | 'x' | " " | (int)'x';
    56935807x 120
    56945808\end{cfa}
     
    69207034#include <gmp>§\indexc{gmp}§
    69217035int main( void ) {
    6922         sout | "Factorial Numbers" | endl;
     7036        sout | "Factorial Numbers";
    69237037        Int fact = 1;
    69247038
    6925         sout | 0 | fact | endl;
     7039        sout | 0 | fact;
    69267040        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    69277041                fact *= i;
    6928                 sout | i | fact | endl;
     7042                sout | i | fact;
    69297043        }
    69307044}
Note: See TracChangeset for help on using the changeset viewer.