Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rc6dc7f2 r9e0a360  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Sat Jul 13 18:36:18 2019
    14 %% Update Count     : 3876
     13%% Last Modified On : Sat Jun 15 16:29:45 2019
     14%% Update Count     : 3847
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    26972697\subsection{Expressions}
    26982698
    2699 % Change order of expression evaluation.
    2700 % http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0145r2.pdf
    2701 
    27022699Multiple-return-value functions provide \CFA with a new syntax for expressing a combination of expressions in the return statement and a combination of types in a function signature.
    27032700These notions are generalized to provide \CFA with \newterm{tuple expression}s and \newterm{tuple type}s.
     
    33493346
    33503347
    3351 \section{Stream I/O Library}
    3352 \label{s:StreamIOLibrary}
     3348\section{I/O Stream Library}
     3349\label{s:IOStreamLibrary}
    33533350\index{input/output stream library}
    33543351\index{stream library}
    33553352
    3356 The goal of \CFA stream input/output (I/O) is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
    3357 Stream I/O can be implicitly or explicitly formatted.
    3358 Implicit formatting means \CFA selects the output or input format for values that match with the type of a variable.
    3359 Explicit formatting means additional information is specified to augment how an output or input of value is interpreted.
    3360 \CFA formatting is a cross between C ©printf© and \CC ©cout© manipulators, and Python implicit spacing and newline.
    3361 Specifically:
     3353The goal of \CFA input/output (I/O) is to simplify the common cases\index{I/O!common case}, while fully supporting polymorphism and user defined types in a consistent way.
     3354\CFA I/O combines ideas from C ©printf©, \CC, and Python.
     3355I/O can be unformatted or formatted.
     3356Unformatted means \CFA selects the output or input format for values that match with the type of a variable.
     3357Formatted means additional information is specified to augment how an output or input of value is interpreted.
     3358\CFA formatting is a cross between C ©printf© and \CC ©cout© manipulators.
    33623359\begin{itemize}
    33633360\item
    3364 ©printf©/Python format codes are dense, making them difficult to read and remember.
     3361©printf© format codes are dense, making them difficult to read and remember.
    33653362\CFA/\CC format manipulators are named, making them easier to read and remember.
    33663363\item
    3367 ©printf©/Python separates format codes from associated variables, making it difficult to match codes with variables.
     3364©printf© separates format codes from associated variables, making it difficult to match codes with variables.
    33683365\CFA/\CC co-locate codes with associated variables, where \CFA has the tighter binding.
    33693366\item
    3370 Format manipulators in \CFA have local effect, whereas \CC have global effect, except ©setw©.
     3367Format manipulators in \CC have global rather than local effect, except ©setw©.
    33713368Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects.
    33723369Without this programming style, errors occur when moving prints, as manipulator effects incorrectly flow into the new location.
    33733370(To guarantee no side-effects, manipulator values must be saved and restored across function calls.)
    3374 \item
    3375 \CFA has more sophisticated implicit spacing between values than Python, plus implicit newline at the end of a print.
    33763371\end{itemize}
    33773372The \CFA header file for the I/O library is \Indexc{fstream.hfa}.
    33783373
    3379 For implicit formatted output, the common case is printing a series of variables separated by whitespace.
     3374For unformatted output, the common case is printing a sequence of variables separated by whitespace.
    33803375\begin{cquote}
    3381 \begin{tabular}{@{}l@{\hspace{2em}}l@{\hspace{2em}}l@{}}
    3382 \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}}       & \multicolumn{1}{c}{\textbf{Python}}   \\
     3376\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
     3377\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
    33833378\begin{cfa}
    33843379int x = 1, y = 2, z = 3;
     
    33903385cout << x ®<< " "® << y ®<< " "® << z << endl;
    33913386\end{cfa}
    3392 &
    3393 \begin{cfa}
    3394 x = 1;  y = 2;  z = 3
    3395 print( x, y, z )
    3396 \end{cfa}
    33973387\\
    3398 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3399 1® ®2® ®3
    3400 \end{cfa}
    3401 &
    34023388\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    340333891® ®2® ®3
     
    34433429There is a weak similarity between the \CFA logical-or operator and the \Index{Shell pipe-operator} for moving data, where data flows in the correct direction for input but the opposite direction for output.
    34443430
    3445 For implicit formatted input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable.
     3431For unformatter input, the common case is reading a sequence of values separated by whitespace, where the type of an input constant must match with the type of the input variable.
    34463432\begin{cquote}
    34473433\begin{lrbox}{\LstBox}
     
    34503436\end{cfa}
    34513437\end{lrbox}
    3452 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}}
     3438\begin{tabular}{@{}l@{\hspace{3em}}l@{}}
    34533439\multicolumn{1}{@{}l@{}}{\usebox\LstBox} \\
    3454 \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}        & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}}       & \multicolumn{1}{c}{\textbf{Python}}   \\
     3440\multicolumn{1}{c@{\hspace{3em}}}{\textbf{\CFA}}        & \multicolumn{1}{c}{\textbf{\CC}}      \\
    34553441\begin{cfa}[aboveskip=0pt,belowskip=0pt]
    34563442sin | x | y | z;
     
    34603446cin >> x >> y >> z;
    34613447\end{cfa}
    3462 &
    3463 \begin{cfa}[aboveskip=0pt,belowskip=0pt]
    3464 x = int(input());  y = float(input());  z = input();
    3465 \end{cfa}
    34663448\\
    34673449\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    34683450®1® ®2.5® ®A®
    3469 
    3470 
    34713451\end{cfa}
    34723452&
    34733453\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    34743454®1® ®2.5® ®A®
    3475 
    3476 
    3477 \end{cfa}
    3478 &
    3479 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
    3480 ®1®
    3481 ®2.5®
    3482 ®A®
    34833455\end{cfa}
    34843456\end{tabular}
     
    35093481
    35103482\item
    3511 A separator does not appear before or after a null (empty) C string, which is a local mechanism to disable insertion of the separator character.
     3483A separator does not appear before or after a null (empty) C string.
    35123484\begin{cfa}
    35133485sout | 1 | "" | 2 | "" | 3;
    35143486123
    35153487\end{cfa}
     3488which is a local mechanism to disable insertion of the separator character.
    35163489
    35173490\item
    35183491{\lstset{language=CFA,deletedelim=**[is][]{¢}{¢}}
    3519 A separator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@, where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     3492A seperator does not appear before a C string starting with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[basicstyle=\tt]@,.;!?)]}%¢»@
    35203493\begin{cfa}[belowskip=0pt]
    35213494sout | 1 | ", x" | 2 | ". x" | 3 | "; x" | 4 | "! x" | 5 | "? x" | 6 | "% x"
     
    352534981®,® x 2®.® x 3®;® x 4®!® x 5®?® x 6®%® x 7§\color{red}\textcent§ x 8®»® x 9®)® x 10®]® x 11®}® x
    35263499\end{cfa}}%
    3527 
    3528 \item
    3529 A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@, where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
     3500where \lstinline[basicstyle=\tt]@»@ is a closing citation mark.
     3501
     3502\item
     3503A separator does not appear after a C string ending with the (extended) \Index*{ASCII}\index{ASCII!extended} characters: \lstinline[mathescape=off,basicstyle=\tt]@([{=$£¥¡¿«@
    35303504%$
    35313505\begin{cfa}[mathescape=off]
     
    35383512\end{cfa}
    35393513%$
     3514where \lstinline[basicstyle=\tt]@¡¿@ are inverted opening exclamation and question marks, and \lstinline[basicstyle=\tt]@«@ is an opening citation mark.
    35403515
    35413516\item
     
    36513626The tuple separator also responses to being turned on and off.
    36523627\begin{cfa}[belowskip=0pt]
    3653 sout | t1 | sepOff | t2; §\C{// turn off implicit separator for the next item
     3628sout | t1 | sepOff | t2; §\C{// locally turn on/off implicit separator
    36543629\end{cfa}
    36553630\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    36753650\subsection{Newline Manipulators}
    36763651
    3677 The following \Index{manipulators} control \Index{newline separation} for input and output.
     3652The following \Index{manipulator} controls \Index{newline separation} for input and output.
    36783653
    36793654For input:
     
    373037050b0 0b11011 0b11011 0b11011 0b11011
    37313706sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L );
    3732 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101
     37070b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b(58 1s)100101
    37333708\end{cfa}
    37343709
     
    37733748
    37743749\item
    3775 \Indexc{nobase}( integer )\index{manipulator!nobase@©nobase©} do not precede ©bin©, ©oct©, ©hex© with ©0b©/©0B©, ©0©, or ©0x©/©0X©.
    3776 Printing the base is the default.
     3750\Indexc{nobase}( integer )\index{manipulator!nobase@©nobase©} do not precede ©bin©, ©oct©, ©hex© with ©0b©/©0B©, ©0©, or ©0x©/©0X©. Printing the base is the default.
    37773751\begin{cfa}[belowskip=0pt]
    37783752sout | nobase( bin( 27 ) ) | nobase( oct( 27 ) ) | nobase( hex( 27 ) );
     
    38083782®  ®4.000000 ® ®4.000000 4.000000
    38093783®  ®ab ® ®ab ab
     3784    ab    ab ab
    38103785\end{cfa}
    38113786If the value is larger, it is printed without truncation, ignoring the ©minimum©.
Note: See TracChangeset for help on using the changeset viewer.