Changeset 08065aa4 for doc/user/user.tex
- Timestamp:
- Jun 25, 2019, 8:55:45 AM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 62dbb00, b0ab7853
- Parents:
- 28564382
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r28564382 r08065aa4 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Sat Jun 15 16:29:45201914 %% Update Count : 38 4713 %% Last Modified On : Tue Jun 25 08:51:33 2019 14 %% Update Count : 3871 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 3346 3346 3347 3347 3348 \section{ I/O StreamLibrary}3349 \label{s: IOStreamLibrary}3348 \section{Stream I/O Library} 3349 \label{s:StreamIOLibrary} 3350 3350 \index{input/output stream library} 3351 3351 \index{stream library} 3352 3352 3353 The 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.3355 I /O can be unformatted or formatted.3356 Unformatted means \CFA selects the output or input format for values that match with the type of a variable.3357 Formatted 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. 3353 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. 3354 Stream I/O can be implicitly or explicitly formatted. 3355 Implicit formatting means \CFA selects the output or input format for values that match with the type of a variable. 3356 Explicit formatting means additional information is specified to augment how an output or input of value is interpreted. 3357 \CFA formatting is a cross between C ©printf© and \CC ©cout© manipulators, and Python implicit spacing and newline. 3358 Specifically: 3359 3359 \begin{itemize} 3360 3360 \item 3361 ©printf© format codes are dense, making them difficult to read and remember.3361 ©printf©/Python format codes are dense, making them difficult to read and remember. 3362 3362 \CFA/\CC format manipulators are named, making them easier to read and remember. 3363 3363 \item 3364 ©printf© separates format codes from associated variables, making it difficult to match codes with variables.3364 ©printf©/Python separates format codes from associated variables, making it difficult to match codes with variables. 3365 3365 \CFA/\CC co-locate codes with associated variables, where \CFA has the tighter binding. 3366 3366 \item 3367 Format manipulators in \C C have global rather than local effect, except ©setw©.3367 Format manipulators in \CFA have local effect, whereas \CC have global effect, except ©setw©. 3368 3368 Hence, it is common programming practice to toggle manipulators on and then back to the default to prevent downstream side-effects. 3369 3369 Without this programming style, errors occur when moving prints, as manipulator effects incorrectly flow into the new location. 3370 3370 (To guarantee no side-effects, manipulator values must be saved and restored across function calls.) 3371 \item 3372 \CFA has more sophisticated implicit spacing between values than Python, plus implicit newline at the end of a print. 3371 3373 \end{itemize} 3372 3374 The \CFA header file for the I/O library is \Indexc{fstream.hfa}. 3373 3375 3374 For unformatted output, the common case is printing a sequenceof variables separated by whitespace.3376 For implicit formatted output, the common case is printing a series of variables separated by whitespace. 3375 3377 \begin{cquote} 3376 \begin{tabular}{@{}l@{\hspace{ 3em}}l@{}}3377 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\3378 \begin{tabular}{@{}l@{\hspace{2em}}l@{\hspace{2em}}l@{}} 3379 \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}} & \multicolumn{1}{c}{\textbf{Python}} \\ 3378 3380 \begin{cfa} 3379 3381 int x = 1, y = 2, z = 3; … … 3385 3387 cout << x ®<< " "® << y ®<< " "® << z << endl; 3386 3388 \end{cfa} 3389 & 3390 \begin{cfa} 3391 x = 1; y = 2; z = 3 3392 print( x, y, z ) 3393 \end{cfa} 3387 3394 \\ 3395 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3396 1® ®2® ®3 3397 \end{cfa} 3398 & 3388 3399 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3389 3400 1® ®2® ®3 … … 3429 3440 There 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. 3430 3441 3431 For unformatterinput, 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.3442 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. 3432 3443 \begin{cquote} 3433 3444 \begin{lrbox}{\LstBox} … … 3436 3447 \end{cfa} 3437 3448 \end{lrbox} 3438 \begin{tabular}{@{}l@{\hspace{3em}}l@{ }}3449 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}} 3439 3450 \multicolumn{1}{@{}l@{}}{\usebox\LstBox} \\ 3440 \multicolumn{1}{c@{\hspace{ 3em}}}{\textbf{\CFA}} & \multicolumn{1}{c}{\textbf{\CC}} \\3451 \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}} & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CC}} & \multicolumn{1}{c}{\textbf{Python}} \\ 3441 3452 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 3442 3453 sin | x | y | z; … … 3446 3457 cin >> x >> y >> z; 3447 3458 \end{cfa} 3459 & 3460 \begin{cfa}[aboveskip=0pt,belowskip=0pt] 3461 x = int(input()); y = float(input()); z = input(); 3462 \end{cfa} 3448 3463 \\ 3449 3464 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3450 3465 ®1® ®2.5® ®A® 3466 3467 3451 3468 \end{cfa} 3452 3469 & 3453 3470 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3454 3471 ®1® ®2.5® ®A® 3472 3473 3474 \end{cfa} 3475 & 3476 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 3477 ®1® 3478 ®2.5® 3479 ®A® 3455 3480 \end{cfa} 3456 3481 \end{tabular} … … 3705 3730 0b0 0b11011 0b11011 0b11011 0b11011 3706 3731 sout | bin( -27HH ) | bin( -27H ) | bin( -27 ) | bin( -27L ); 3707 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b (58 1s)1001013732 0b11100101 0b1111111111100101 0b11111111111111111111111111100101 0b®(58 1s)®100101 3708 3733 \end{cfa} 3709 3734 … … 3782 3807 ® ®4.000000 ® ®4.000000 4.000000 3783 3808 ® ®ab ® ®ab ab 3784 ab ab ab3785 3809 \end{cfa} 3786 3810 If the value is larger, it is printed without truncation, ignoring the ©minimum©.
Note: See TracChangeset
for help on using the changeset viewer.