Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r200fcb3 rd92ff4a  
    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 : Tue Dec 11 23:19:26 2018
    14 %% Update Count     : 3400
     13%% Last Modified On : Thu Jul 26 17:29:05 2018
     14%% Update Count     : 3366
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    7272
    7373% Names used in the document.
    74 \newcommand{\Version}{\input{build/version}}
     74\newcommand{\Version}{\input{../../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;®§\indexc{sout}§
     180        ®sout | x | y | z | endl;®§\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 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.
     212The 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.
    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{?\\?@©?\?©} and ©?\=?©\index{?\\=?@©\=?©}, 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{?\\?@\lstinline@?\?@} and ©?\=?©\index{?\\=?@\lstinline@?\=?@}, 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);
     515sout | 2 ®\® 8u | 4 ®\® 3u | -4 ®\® 3u | 4 ®\® -3 | -4 ®\® -3 | 4.0 ®\® 2.1 | (1.0f+2.0fi) ®\® (3.0f+2.0fi) | endl;
    516516256 64 -64 0.015625 -0.015625 18.3791736799526 0.264715-1.1922i
    517517\end{cfa}
    518 Parenthesis are necessary for complex constants or the expression is parsed as ©1.0f+®(®2.0fi \ 3.0f®)®+2.0fi©.
     518Parenthesis are necessary for the 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@/\protect\lstinline@while@ Statement}{if Statement}}
    530 \subsection{\texorpdfstring{\LstKeywordStyle{if}/\LstKeywordStyle{while} Statement}{if/while Statement}}
    531 
    532 The ©if©/©while© expression allows declarations, similar to ©for© declaration expression.
    533 (Does not make sense for ©do©-©while©.)
    534 \begin{cfa}
    535 if ( ®int x = f()® ) ...                                        §\C{// x != 0}§
    536 if ( ®int x = f(), y = g()® ) ...                       §\C{// x != 0 \&\& y != 0}§
    537 if ( ®int x = f(), y = g(); x < y® ) ...        §\C{// relational expression}§
    538 if ( ®struct S { int i; } x = { f() }; x.i < 4® ) §\C{// relational expression}§
    539 
    540 while ( ®int x = f()® ) ...                                     §\C{// x != 0}§
    541 while ( ®int x = f(), y = g()® ) ...            §\C{// x != 0 \&\& y != 0}§
    542 while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    543 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
    544 \end{cfa}
    545 Unless 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.}
     529%\subsection{\texorpdfstring{\protect\lstinline@if@ Statement}{if Statement}}
     530\subsection{\texorpdfstring{\LstKeywordStyle{if} Statement}{if Statement}}
     531
     532The ©if© expression allows declarations, similar to ©for© declaration expression:
     533\begin{cfa}
     534if ( int x = f() ) ...                                          §\C{// x != 0}§
     535if ( int x = f(), y = g() ) ...                         §\C{// x != 0 \&\& y != 0}§
     536if ( int x = f(), y = g(); ®x < y® ) ...        §\C{// relational expression}§
     537\end{cfa}
     538Unless 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.}
    546539The 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 
    551 The ©for©/©while©/©do-while© loop-control allows empty or simplified ranges.
    552 An empty conditional implies ©1©.
    553 The up-to range ©~©\index{~@©~©} means exclusive range [M,N);
    554 the up-to range ©~=©\index{~=@©~=©} means inclusive range [M,N].
    555 The down-to range ©-~©\index{-~@©-~©} means exclusive range [N,M);
    556 the down-to range ©-~=©\index{-~=@©-~=©} means inclusive range [N,M].
    557 ©0© is the implicit start value;
    558 ©1© is the implicit increment value.
    559 The up-to range uses ©+=© for increment;
    560 the down-to range uses ©-=© for decrement.
    561 The 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}
    567 while ®()® { sout | "empty"; break; }
    568 do { sout | "empty"; break; } while ®()®;
    569 for ®()® { sout | "empty"; break; }
    570 for ( ®0® ) { sout | "A"; }
    571 for ( ®1® ) { sout | "A"; }
    572 for ( ®10® ) { sout | "A"; }
    573 for ( ®1 ~= 10 ~ 2® ) { sout | "B"; }
    574 for ( ®10 -~= 1 ~ 2® ) { sout | "C"; }
    575 for ( ®0.5 ~ 5.5® ) { sout | "D"; }
    576 for ( ®5.5 -~ 0.5® ) { sout | "E"; }
    577 for ( ®i; 10® ) { sout | i; }
    578 for ( ®i; 1 ~= 10 ~ 2® ) { sout | i; }
    579 for ( ®i; 10 -~= 1 ~ 2® ) { sout | i; }
    580 for ( ®i; 0.5 ~ 5.5® ) { sout | i; }
    581 for ( ®i; 5.5 -~ 0.5® ) { sout | i; }
    582 for ( ®ui; 2u ~= 10u ~ 2u® ) { sout | ui; }
    583 for ( ®ui; 10u -~= 2u ~ 2u® ) { sout | ui; }
    584 enum { N = 10 };
    585 for ( ®N® ) { sout | "N"; }
    586 for ( ®i; N® ) { sout | i; }
    587 for ( ®i; N -~ 0® ) { sout | i; }
    588 const int start = 3, comp = 10, inc = 2;
    589 for ( ®i; start ~ comp ~ inc + 1® ) { sout | i; }
    590 \end{cfa}
    591 &
    592 \begin{cfa}
    593 sout | nl;
    594 sout | nl;
    595 sout | nl;
    596 sout | "zero" | nl;
    597 sout | nl;
    598 sout | nl;
    599 sout | nl;
    600 sout | nl;
    601 sout | nl;
    602 sout | nl;
    603 sout | nl;
    604 sout | nl;
    605 sout | nl;
    606 sout | nl;
    607 sout | nl;
    608 sout | nl;
    609 sout | nl | nl;
    610 
    611 sout | nl;
    612 sout | nl;
    613 sout | nl | nl;
    614 
    615 sout | nl;
    616 \end{cfa}
    617 &
    618 \begin{cfa}
    619 empty
    620 empty
    621 empty
    622 zero
    623 A
    624 A A A A A A A A A A
    625 B B B B B
    626 C C C C C
    627 D D D D D
    628 E E E E E
    629 0 1 2 3 4 5 6 7 8 9
    630 1 3 5 7 9
    631 10 8 6 4 2
    632 0.5 1.5 2.5 3.5 4.5
    633 5.5 4.5 3.5 2.5 1.5
    634 2 4 6 8 10
    635 10 8 6 4 2
    636 
    637 N N N N N N N N N N
    638 0 1 2 3 4 5 6 7 8 9
    639 10 9 8 7 6 5 4 3 2 1
    640 
    641 3 6 9
    642 \end{cfa}
    643 \end{tabular}
    644 \end{cquote}
    645540
    646541
     
    905800
    906801
    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 
    916802%\subsection{\texorpdfstring{Labelled \protect\lstinline@continue@ / \protect\lstinline@break@}{Labelled continue / break}}
    917803\subsection{\texorpdfstring{Labelled \LstKeywordStyle{continue} / \LstKeywordStyle{break} Statement}{Labelled continue / break Statement}}
     
    919805While C provides ©continue© and ©break© statements for altering control flow, both are restricted to one level of nesting for a particular control structure.
    920806Unfortunately, this restriction forces programmers to use \Indexc{goto} to achieve the equivalent control-flow for more than one level of nesting.
    921 To 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.
     807To 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.
    922808For both ©continue© and ©break©, the target label must be directly associated with a ©for©, ©while© or ©do© statement;
    923809for ©break©, the target label can also be associated with a ©switch©, ©if© or compound (©{}©) statement.
     
    1004890\end{figure}
    1005891
    1006 Both labelled ©continue© and ©break© are a ©goto©\index{goto@©goto©!restricted} restricted in the following ways:
     892Both labelled ©continue© and ©break© are a ©goto©\index{goto@\lstinline@goto@!restricted} restricted in the following ways:
    1007893\begin{itemize}
    1008894\item
     
    15611447\end{cfa}
    15621448Algol68 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.
    1563 Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices.
     1449Unfortunately, automatic dereferencing does not work in all cases, and so some mechanism is necessary to fix incorrect choices. 
    15641450
    15651451Rather than inferring dereference, most programming languages pick one implicit dereferencing semantics, and the programmer explicitly indicates the other to resolve address-duality.
     
    23962282        struct T t;
    23972283} s;
    2398 
     2284       
    23992285
    24002286
     
    24592345        int bar( int p ) {
    24602346                ®i® += 1;                               §\C{// dependent on local variable}§
    2461                 sout | ®i®;
     2347                sout | ®i® | endl;
    24622348        }
    24632349        return bar;                                     §\C{// undefined because of local dependence}§
     
    24652351int main() {
    24662352        * [int]( int ) fp = foo();      §\C{// int (* fp)( int )}§
    2467         sout | fp( 3 );
    2468 }
    2469 \end{cfa}
    2470 because
     2353        sout | fp( 3 ) | endl;
     2354}
     2355\end{cfa}
     2356because 
    24712357
    24722358Currently, there are no \Index{lambda} expressions, \ie unnamed routines because routine names are very important to properly select the correct routine.
     
    32313117\begin{cfa}
    32323118int x = 1, y = 2, z = 3;
    3233 sout | x ®|® y ®|® z;
     3119sout | x ®|® y ®|® z | endl;
    32343120\end{cfa}
    32353121&
     
    32523138\begin{cfa}
    32533139[int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    3254 sout | t1 | t2;                                         §\C{// print tuples}§
     3140sout | t1 | t2 | endl;                                  §\C{// print tuples}§
    32553141\end{cfa}
    32563142\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    32643150&
    32653151\begin{cfa}
    3266 sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2);
     3152sout | x * 3 | y + 1 | z << 2 | x == y | (x | y) | (x || y) | (x > z ? 1 : 2) | endl;
    32673153\end{cfa}
    32683154\\
     
    32903176A separator does not appear at the start or end of a line.
    32913177\begin{cfa}[belowskip=0pt]
    3292 sout | 1 | 2 | 3;
     3178sout | 1 | 2 | 3 | endl;
    32933179\end{cfa}
    32943180\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    32993185A separator does not appear before or after a character literal or variable.
    33003186\begin{cfa}
    3301 sout | '1' | '2' | '3';
     3187sout | '1' | '2' | '3' | endl;
    33023188123
    33033189\end{cfa}
     
    33063192A separator does not appear before or after a null (empty) C string.
    33073193\begin{cfa}
    3308 sout | 1 | "" | 2 | "" | 3;
     3194sout | 1 | "" | 2 | "" | 3 | endl;
    33093195123
    33103196\end{cfa}
     
    33163202\begin{cfa}[mathescape=off]
    33173203sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3318                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
     3204                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
    33193205\end{cfa}
    33203206%$
     
    33303216\begin{cfa}[belowskip=0pt]
    33313217sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    3332                 | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x";
     3218                | 7 | "¢ x" | 8 | "» x" | 9 | ") x" | 10 | "] x" | 11 | "} x" | endl;
    33333219\end{cfa}
    33343220\begin{cfa}[basicstyle=\tt,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33403226A 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@
    33413227\begin{cfa}[belowskip=0pt]
    3342 sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx";
     3228sout | "x`" | 1 | "`x'" | 2 | "'x\"" | 3 | "\"x:" | 4 | ":x " | 5 | " x\t" | 6 | "\tx" | endl;
    33433229\end{cfa}
    33443230\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    33493235If a space is desired before or after one of the special string start/end characters, simply insert a space.
    33503236\begin{cfa}[belowskip=0pt]
    3351 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;
     3237sout | "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;
    33523238\end{cfa}
    33533239\begin{cfa}[basicstyle=\tt,showspaces=true,showtabs=true,aboveskip=0pt,belowskip=0pt]
     
    33663252\begin{cfa}[mathescape=off,belowskip=0pt]
    33673253sepSet( sout, ", $" );                                          §\C{// set separator from " " to ", \$"}§
    3368 sout | 1 | 2 | 3 | " \"" | ®sep® | "\"";
     3254sout | 1 | 2 | 3 | " \"" | ®sep® | "\"" | endl;
    33693255\end{cfa}
    33703256%$
     
    33753261\begin{cfa}[belowskip=0pt]
    33763262sepSet( sout, " " );                                            §\C{// reset separator to " "}§
    3377 sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"";
     3263sout | 1 | 2 | 3 | " \"" | ®sepGet( sout )® | "\"" | endl;
    33783264\end{cfa}
    33793265\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    33853271strcpy( store, sepGet( sout ) );                          §\C{// copy current separator}§
    33863272sepSet( sout, "_" );                                            §\C{// change separator to underscore}§
    3387 sout | 1 | 2 | 3;
     3273sout | 1 | 2 | 3 | endl;
    33883274\end{cfa}
    33893275\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    33923278\begin{cfa}[belowskip=0pt]
    33933279sepSet( sout, store );                                          §\C{// change separator back to original}§
    3394 sout | 1 | 2 | 3;
     3280sout | 1 | 2 | 3 | endl;
    33953281\end{cfa}
    33963282\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    34033289\begin{cfa}[belowskip=0pt]
    34043290sepSetTuple( sout, " " );                                       §\C{// set tuple separator from ", " to " "}§
    3405 sout | t1 | t2 | " \"" | ®sepTuple® | "\"";
     3291sout | t1 | t2 | " \"" | ®sepTuple® | "\"" | endl;
    34063292\end{cfa}
    34073293\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    34103296\begin{cfa}[belowskip=0pt]
    34113297sepSetTuple( sout, ", " );                                      §\C{// reset tuple separator to ", "}§
    3412 sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"";
     3298sout | t1 | t2 | " \"" | ®sepGetTuple( sout )® | "\"" | endl;
    34133299\end{cfa}
    34143300\begin{cfa}[showspaces=true,aboveskip=0pt]
     
    34203306Manipulators \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.
    34213307\begin{cfa}[belowskip=0pt]
    3422 sout | sepDisable | 1 | 2 | 3                §\C{// globally turn off implicit separator}§
     3308sout | sepDisable | 1 | 2 | 3 | endl;           §\C{// globally turn off implicit separator}§
    34233309\end{cfa}
    34243310\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34263312\end{cfa}
    34273313\begin{cfa}[belowskip=0pt]
    3428 sout | sepEnable | 1 | 2 | 3;           §\C{// globally turn on implicit separator}§
     3314sout | sepEnable | 1 | 2 | 3 | endl;            §\C{// globally turn on implicit separator}§
    34293315\end{cfa}
    34303316\begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34353321Manipulators \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.
    34363322\begin{cfa}[belowskip=0pt]
    3437 sout | 1 | sepOff | 2 | 3;                      §\C{// locally turn off implicit separator}§
     3323sout | 1 | sepOff | 2 | 3 | endl;                       §\C{// locally turn off implicit separator}§
    34383324\end{cfa}
    34393325\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34413327\end{cfa}
    34423328\begin{cfa}[belowskip=0pt]
    3443 sout | sepDisable | 1 | sepOn | 2 | 3; §\C{// locally turn on implicit separator}§
     3329sout | sepDisable | 1 | sepOn | 2 | 3 | endl; §\C{// locally turn on implicit separator}§
    34443330\end{cfa}
    34453331\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34483334The tuple separator also responses to being turned on and off.
    34493335\begin{cfa}[belowskip=0pt]
    3450 sout | t1 | sepOff | t2;                                §\C{// locally turn on/off implicit separator}§
     3336sout | t1 | sepOff | t2 | endl;                         §\C{// locally turn on/off implicit separator}§
    34513337\end{cfa}
    34523338\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34563342use ©sep© to accomplish this functionality.
    34573343\begin{cfa}[belowskip=0pt]
    3458 sout | sepOn | 1 | 2 | 3 | sepOn;       §\C{// sepOn does nothing at start/end of line}§
     3344sout | sepOn | 1 | 2 | 3 | sepOn | endl ;       §\C{// sepOn does nothing at start/end of line}§
    34593345\end{cfa}
    34603346\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34623348\end{cfa}
    34633349\begin{cfa}[belowskip=0pt]
    3464 sout | sep | 1 | 2 | 3 | sep ;          §\C{// use sep to print separator at start/end of line}§
     3350sout | sep | 1 | 2 | 3 | sep | endl ;           §\C{// use sep to print separator at start/end of line}§
    34653351\end{cfa}
    34663352\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    34753361int main( void ) {
    34763362        int x = 1, y = 2, z = 3;
    3477         sout | x | y | z;
     3363        sout | x | y | z | endl;
    34783364        [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ];
    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;
     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;
    34843370        sout | "x (" | 1 | "x [" | 2 | "x {" | 3 | "x =" | 4 | "x $" | 5 | "x £" | 6 | "x ¥"
    3485                 | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10;
     3371                | 7 | "x ¡" | 8 | "x ¿" | 9 | "x «" | 10 | endl;
    34863372        sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
    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;
     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;
    34903376
    34913377        sepSet( sout, ", $" );                                          // set separator from " " to ", $"
    3492         sout | 1 | 2 | 3 | " \"" | sep | "\"";
     3378        sout | 1 | 2 | 3 | " \"" | sep | "\"" | endl;
    34933379        sepSet( sout, " " );                                            // reset separator to " "
    3494         sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"";
     3380        sout | 1 | 2 | 3 | " \"" | sepGet( sout ) | "\"" | endl;
    34953381
    34963382        char store[sepSize];
    34973383        strcpy( store, sepGet( sout ) );
    34983384        sepSet( sout, "_" );
    3499         sout | 1 | 2 | 3;
     3385        sout | 1 | 2 | 3 | endl;
    35003386        sepSet( sout, store );
    3501         sout | 1 | 2 | 3;
     3387        sout | 1 | 2 | 3 | endl;
    35023388
    35033389        sepSetTuple( sout, " " );                                       // set tuple separator from ", " to " "
    3504         sout | t1 | t2 | " \"" | sepTuple | "\"";
     3390        sout | t1 | t2 | " \"" | sepTuple | "\"" | endl;
    35053391        sepSetTuple( sout, ", " );                                      // reset tuple separator to ", "
    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
     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
    35133399        sout | sepEnable;
    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
     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
    35183404}
    35193405
     
    41804066        Fibonacci f1, f2;
    41814067        for ( int i = 1; i <= 10; i += 1 ) {
    4182                 sout | next( &f1 ) | ' ' | next( &f2 );
     4068                sout | next( &f1 ) | ' ' | next( &f2 ) | endl;
    41834069        } // for
    41844070}
     
    42464132                MyThread f[4];
    42474133        }
    4248         sout | global.value;
     4134        sout | global.value | endl;
    42494135}
    42504136\end{cfa}
     
    43244210void main( First * this ) {
    43254211        for ( int i = 0; i < 10; i += 1 ) {
    4326                 sout | "First : Suspend No." | i + 1;
     4212                sout | "First : Suspend No." | i + 1 | endl;
    43274213                yield();
    43284214        }
     
    43334219        wait( this->lock );
    43344220        for ( int i = 0; i < 10; i += 1 ) {
    4335                 sout | "Second : Suspend No." | i + 1;
     4221                sout | "Second : Suspend No." | i + 1 | endl;
    43364222                yield();
    43374223        }
     
    43404226int main( void ) {
    43414227        signal_once lock;
    4342         sout | "User main begin";
     4228        sout | "User main begin" | endl;
    43434229        {
    43444230                processor p;
     
    43484234                }
    43494235        }
    4350         sout | "User main end";
     4236        sout | "User main end" | endl;
    43514237}
    43524238\end{cfa}
     
    50454931void ?{}( Line * l ) {
    50464932        l->lnth = 0.0;
    5047         sout | "default";
     4933        sout | "default" | endl;
    50484934}
    50494935
     
    50524938void ?{}( Line * l, float lnth ) {
    50534939        l->lnth = lnth;
    5054         sout | "lnth" | l->lnth;
     4940        sout | "lnth" | l->lnth | endl;
    50554941
    50564942}
     
    50584944// destructor
    50594945void ^?() {
    5060         sout | "destroyed";
     4946        sout | "destroyed" | endl;
    50614947        l.lnth = 0.0;
    50624948}
     
    58045690In particular, output of ©char© variable now print a character rather than the decimal ASCII value of the character.
    58055691\begin{cfa}
    5806 sout | 'x' | " " | (int)'x';
     5692sout | 'x' | " " | (int)'x' | endl;
    58075693x 120
    58085694\end{cfa}
     
    70346920#include <gmp>§\indexc{gmp}§
    70356921int main( void ) {
    7036         sout | "Factorial Numbers";
     6922        sout | "Factorial Numbers" | endl;
    70376923        Int fact = 1;
    70386924
    7039         sout | 0 | fact;
     6925        sout | 0 | fact | endl;
    70406926        for ( unsigned int i = 1; i <= 40; i += 1 ) {
    70416927                fact *= i;
    7042                 sout | i | fact;
     6928                sout | i | fact | endl;
    70436929        }
    70446930}
Note: See TracChangeset for help on using the changeset viewer.