Changeset 2a301ff for doc/user/user.tex
- Timestamp:
- Aug 31, 2023, 11:31:15 PM (2 years ago)
- Branches:
- master
- Children:
- 950c58e
- Parents:
- 92355883 (diff), 686912c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
doc/user/user.tex (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
doc/user/user.tex
r92355883 r2a301ff 11 11 %% Created On : Wed Apr 6 14:53:29 2016 12 12 %% Last Modified By : Peter A. Buhr 13 %% Last Modified On : Mon Jun 5 21:18:29202314 %% Update Count : 55 2113 %% Last Modified On : Thu Aug 10 21:24:07 2023 14 %% Update Count : 5570 15 15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 16 16 … … 3721 3721 \end{cquote} 3722 3722 The \CFA form has half the characters of the \CC form, and is similar to \Index*{Python} I/O with respect to implicit separators and newline. 3723 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]{, }'' .3723 Similar simplification occurs for \Index{tuple} I/O, which flattens the tuple and prints each value separated by ``\lstinline[showspaces=true]{, }'' (comma space). 3724 3724 \begin{cfa} 3725 3725 [int, [ int, int ] ] t1 = [ 1, [ 2, 3 ] ], t2 = [ 4, [ 5, 6 ] ]; … … 3751 3751 \end{tabular} 3752 3752 \end{cquote} 3753 Input and output use a uniform operator, ©|©, rather than \CC's ©>>© and ©<<© input/output operators.3754 3753 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. 3754 Input and output use a uniform operator, ©|©, rather than \CC's ©<<© and ©>>© input/output operators, which prevents this common error in \CC: 3755 \begin{C++} 3756 cin << i; // why is this generating a lot of error messages? 3757 \end{C++} 3755 3758 3756 3759 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. … … 3855 3858 \Indexc{close} flushes the stream and closes the file. 3856 3859 \item 3857 \Indexc{write} (©ofstream© only) write ©size© bytes to the stream.3858 The bytes are written lazily to file when internal buffers fill.3860 \Indexc{write} (©ofstream© only) writes ©size© bytes to the stream. 3861 The bytes are written lazily when an internal buffer fills. 3859 3862 Eager buffer writes are done with ©flush© 3860 3863 \item 3861 \Indexc{read} (©ifstream© only) read ©size© bytes tothe stream.3864 \Indexc{read} (©ifstream© only) reads ©size© bytes from the stream. 3862 3865 \item 3863 3866 \Indexc{ungetc} (©ifstream© only) pushes the character back to the input stream. … … 3968 3971 3969 3972 \item 3970 If a space is desired before or after one of the special string start/end characters, simply insert a space.3973 If a space is desired before or after one of the special string start/end characters, explicitly insert a space. 3971 3974 \begin{cfa} 3972 3975 sout | "x ($\R{\texttt{\textvisiblespace}}$" | 1 | "$\R{\texttt{\textvisiblespace}}$) x" | 2 | "$\R{\texttt{\textvisiblespace}}$, x" | 3 | "$\R{\texttt{\textvisiblespace}}$:x:$\R{\texttt{\textvisiblespace}}$" | 4; … … 3981 3984 3982 3985 The following \Index{manipulator}s control \Index{implicit output separation}. 3983 The effect of these manipulators is global for an output stream (except ©sep On© and ©sepOff©).3986 The effect of these manipulators is global for an output stream (except ©sep© and ©nosep©). 3984 3987 \begin{enumerate} 3985 3988 \item 3986 \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.3989 \Indexc{sepSet}\index{manipulator!sepSet@©sepSet©} and \Indexc{sepVal}\index{manipulator!sepVal@©sepVal©}/\Indexc{sepGet}\index{manipulator!sepGet@©sepGet©} set and get the separator string. 3987 3990 The separator string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 3988 3991 \begin{cfa}[belowskip=0pt] 3989 3992 sepSet( sout, ", $\LstStringStyle{\textdollar}$" ); $\C{// set separator from " " to ", \$"}$ 3990 sout | 1 | 2 | 3 | " \"" | ®sep ® | "\"";3993 sout | 1 | 2 | 3 | " \"" | ®sepVal® | "\""; 3991 3994 \end{cfa} 3992 3995 \begin{cfa}[showspaces=true,aboveskip=0pt] 3993 1®, $\ LstStringStyle{\textdollar}$®2®, $\LstStringStyle{\textdollar}$®3 ®", $\LstStringStyle{\textdollar}$"®3996 1®, $\color{red}\LstStringStyle{\textdollar}$®2®, $\color{red}\LstStringStyle{\textdollar}$®3 ®", $\color{red}\LstStringStyle{\textdollar}$"® 3994 3997 \end{cfa} 3995 3998 \begin{cfa}[belowskip=0pt] … … 4019 4022 4020 4023 \item 4021 \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.4024 \Indexc{sepSetTuple}\index{manipulator!sepSetTuple@©sepSetTuple©} and \Indexc{sepTupleVal}\index{manipulator!sepTupleVal@©sepTupleVal©}/\Indexc{sepGetTuple}\index{manipulator!sepGetTuple@©sepGetTuple©} get and set the tuple separator-string. 4022 4025 The tuple separator-string can be at most 16 characters including the ©'\0'© string terminator (15 printable characters). 4023 4026 \begin{cfa}[belowskip=0pt] 4024 4027 sepSetTuple( sout, " " ); $\C{// set tuple separator from ", " to " "}$ 4025 sout | t1 | t2 | " \"" | ®sepTuple ® | "\"";4028 sout | t1 | t2 | " \"" | ®sepTupleVal® | "\""; 4026 4029 \end{cfa} 4027 4030 \begin{cfa}[showspaces=true,aboveskip=0pt] … … 4038 4041 4039 4042 \item 4040 \Indexc{sep Disable}\index{manipulator!sepDisable@©sepDisable©} and \Indexc{sepEnable}\index{manipulator!sepEnable@©sepEnable©} globally toggle printing the separator.4043 \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} and \Indexc{sepOn}\index{manipulator!sepOn@©sepOn©} globally toggle printing the separator. 4041 4044 \begin{cfa}[belowskip=0pt] 4042 sout | sepDisable| 1 | 2 | 3; $\C{// turn off implicit separator}$4045 sout | ®sepOff® | 1 | 2 | 3; $\C{// turn off implicit separator}$ 4043 4046 \end{cfa} 4044 4047 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4046 4049 \end{cfa} 4047 4050 \begin{cfa}[belowskip=0pt] 4048 sout | sepEnable| 1 | 2 | 3; $\C{// turn on implicit separator}$4051 sout | ®sepOn® | 1 | 2 | 3; $\C{// turn on implicit separator}$ 4049 4052 \end{cfa} 4050 4053 \begin{cfa}[mathescape=off,showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4053 4056 4054 4057 \item 4055 \Indexc{sep On}\index{manipulator!sepOn@©sepOn©} and \Indexc{sepOff}\index{manipulator!sepOff@©sepOff©} locally toggle printing the separator with respect to the next printed item, and then return to the global separator setting.4058 \Indexc{sep}\index{manipulator!sep@©sep©} and \Indexc{nosep}\index{manipulator!nosep@©nosep©} locally toggle printing the separator with respect to the next printed item, and then return to the global separator setting. 4056 4059 \begin{cfa}[belowskip=0pt] 4057 sout | 1 | sepOff| 2 | 3; $\C{// turn off implicit separator for the next item}$4060 sout | 1 | ®nosep® | 2 | 3; $\C{// turn off implicit separator for the next item}$ 4058 4061 \end{cfa} 4059 4062 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4061 4064 \end{cfa} 4062 4065 \begin{cfa}[belowskip=0pt] 4063 sout | sep Disable | 1 | sepOn| 2 | 3; $\C{// turn on implicit separator for the next item}$4066 sout | sepOff | 1 | ®sep® | 2 | 3; $\C{// turn on implicit separator for the next item}$ 4064 4067 \end{cfa} 4065 4068 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4068 4071 The tuple separator also responses to being turned on and off. 4069 4072 \begin{cfa}[belowskip=0pt] 4070 sout | t1 | sepOff| t2; $\C{// turn off implicit separator for the next item}$4073 sout | t1 | ®nosep® | t2; $\C{// turn off implicit separator for the next item}$ 4071 4074 \end{cfa} 4072 4075 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4073 4076 1, 2, 34, 5, 6 4074 4077 \end{cfa} 4075 ©sep On© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line;4076 use ©sep© to accomplish this functionality.4078 ©sep© \emph{cannot} be used to start/end a line with a separator because separators do not appear at the start/end of a line. 4079 Use ©sep© to accomplish this functionality. 4077 4080 \begin{cfa}[belowskip=0pt] 4078 sout | sepOn | 1 | 2 | 3 | sepOn; $\C{// sepOndoes nothing at start/end of line}$4081 sout | ®sep® | 1 | 2 | 3 | ®sep®; $\C{// sep does nothing at start/end of line}$ 4079 4082 \end{cfa} 4080 4083 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4082 4085 \end{cfa} 4083 4086 \begin{cfa}[belowskip=0pt] 4084 sout | sep | 1 | 2 | 3 | sep ; $\C{// use septo print separator at start/end of line}$4087 sout | ®sepVal® | 1 | 2 | 3 | ®sepVal® ; $\C{// use sepVal to print separator at start/end of line}$ 4085 4088 \end{cfa} 4086 4089 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] … … 4097 4100 \begin{enumerate}[parsep=0pt] 4098 4101 \item 4102 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters. 4103 \item 4104 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} read the newline character, when reading single characters. 4105 \item 4099 4106 \Indexc{nl}\index{manipulator!nl@©nl©} scans characters until the next newline character, \ie ignore the remaining characters in the line. 4100 \item 4101 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} reads the newline character, when reading single characters. 4102 \item 4103 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} read the newline character, when reading single characters. 4107 If ©nlOn© is enabled, the ©nl© is also consumed. 4104 4108 \end{enumerate} 4105 4109 For example, in: … … 4114 4118 \begin{enumerate}[parsep=0pt] 4115 4119 \item 4120 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression. 4121 \item 4122 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} implicitly print a newline at the end of each output expression. 4123 \item 4116 4124 \Indexc{nl}\index{manipulator!nl@©nl©} inserts a newline. 4117 4125 \begin{cfa} 4118 sout | nl; $\C{// only print newline}$4126 sout | ®nl®; $\C{// only print newline}$ 4119 4127 sout | 2; $\C{// implicit newline}$ 4120 sout | 3 | nl | 4 | nl; $\C{// terminating nl merged with implicit newline}$4121 sout | 5 | nl | nl; $\C{// again terminating nl merged with implicit newline}$4128 sout | 3 | ®nl® | 4 | ®nl®; $\C{// terminating nl merged with implicit newline}$ 4129 sout | 5 | ®nl® | ®nl®; $\C{// again terminating nl merged with implicit newline}$ 4122 4130 sout | 6; $\C{// implicit newline}$ 4123 4131 … … 4129 4137 6 4130 4138 \end{cfa} 4131 Note, a terminating ©nl© is merged (overrides) with the implicit newline at the end of the ©sout© expression, otherwise it is impossible to print a single newline 4132 \item 4133 \Indexc{nlOn}\index{manipulator!nlOn@©nlOn©} implicitly prints a newline at the end of each output expression. 4134 \item 4135 \Indexc{nlOff}\index{manipulator!nlOff@©nlOff©} does \emph{not} implicitly print a newline at the end of each output expression. 4139 Note, a terminating ©nl© is merged with (overrides) the implicit newline at the end of the ©sout© expression, otherwise it is impossible to print a single newline 4136 4140 \end{enumerate} 4137 4141 … … 4139 4143 \subsection{Output Value Manipulators} 4140 4144 4141 The following \Index{manipulator}s control formatting of output values (printing), and only affect the format of the argument.4145 The following \Index{manipulator}s control formatting (printing) of the argument output values. 4142 4146 \begin{enumerate} 4143 4147 \item … … 4154 4158 \begin{cfa}[belowskip=0pt] 4155 4159 sout | oct( 0 ) | oct( 27HH ) | oct( 27H ) | oct( 27 ) | oct( 27L ); 4156 0033 033 033 0334160 ®0® 033 033 033 033 4157 4161 sout | oct( -27HH ) | oct( -27H ) | oct( -27 ) | oct( -27L ); 4158 4162 0345 0177745 037777777745 01777777777777777777745 … … 4164 4168 \begin{cfa}[belowskip=0pt] 4165 4169 sout | hex( 0 ) | hex( 27HH ) | hex( 27H ) | hex( 27 ) | hex( 27L ); 4166 0 0x1b 0x1b 0x1b 0x1b4170 0x0 0x1b 0x1b 0x1b 0x1b 4167 4171 sout | hex( -27HH ) | hex( -27H ) | hex( -27 ) | hex( -27L ); 4168 4172 0xe5 0xffe5 0xffffffe5 0xffffffffffffffe5 4169 4173 4170 4174 sout | hex( 0.0 ) | hex( 27.5F ) | hex( 27.5 ) | hex( 27.5L ); 4171 0x0 .p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+14175 0x0p+0 0x1.b8p+4 0x1.b8p+4 0xd.cp+1 4172 4176 sout | hex( -27.5F ) | hex( -27.5 ) | hex( -27.5L ); 4173 4177 -0x1.b8p+4 -0x1.b8p+4 -0xd.cp+1 … … 4286 4290 For the C-string type, precision is the maximum number of printed characters, so the string is truncated if it exceeds the maximum. 4287 4291 \begin{cfa}[belowskip=0pt] 4288 sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" ) ;4292 sout | wd( 6,8, "abcd" ) | wd( 6,8, "abcdefghijk" ) | wd( 6,3, "abcd" ) | ®wd( 10, "" )® | 'X'; 4289 4293 \end{cfa} 4290 4294 \begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt] 4291 abcd abcdefgh abc 4292 \end{cfa} 4295 abcd abcdefgh abc® ®X 4296 \end{cfa} 4297 Note, printing the null string with minimum width L pads with L spaces. 4293 4298 4294 4299 \item … … 4373 4378 sout | t1 | t2 | " \"" | sepGetTuple( sout ) | "\""; 4374 4379 4375 sout | sep Disable| 1 | 2 | 3; // globally turn off implicit separator4376 sout | sep Enable| 1 | 2 | 3; // globally turn on implicit separator4377 4378 sout | 1 | sepOff| 2 | 3; // locally turn on implicit separator4379 sout | sep Disable | 1 | sepOn| 2 | 3; // globally turn off implicit separator4380 sout | sep Enable;4381 sout | t1 | sepOff| t2; // locally turn on/off implicit separator4382 4383 sout | sep On | 1 | 2 | 3 | sepOn ; // sepOndoes nothing at start/end of line4380 sout | sepOff | 1 | 2 | 3; // globally turn off implicit separator 4381 sout | sepOn | 1 | 2 | 3; // globally turn on implicit separator 4382 4383 sout | 1 | nosep | 2 | 3; // locally turn on implicit separator 4384 sout | sepOff | 1 | sep | 2 | 3; // globally turn off implicit separator 4385 sout | sepOn; 4386 sout | t1 | nosep | t2; // locally turn on/off implicit separator 4387 4388 sout | sep | 1 | 2 | 3 | sep ; // sep does nothing at start/end of line 4384 4389 sout | sep | 1 | 2 | 3 | sep ; // use sep to print separator at start/end of line 4385 4390 } … … 4412 4417 Instead, the next sequence of non-whitespace characters are read, and the input sequence is terminated with delimiter ©'\0'©. 4413 4418 The string variable \emph{must} be large enough to contain the input sequence. 4414 4415 The following \Index{manipulator}s control formatting of input values (reading), and only affect the format of the argument. 4416 4419 To force programmers to consider buffer overruns for C-string input, C-strings can only be read with a width field, which should specify a size less than or equal to the C-string size, \eg: 4420 \begin{cfa} 4421 char line[64]; 4422 sin | wdi( ®sizeof(line)®, line ); // must specify size 4423 \end{cfa} 4424 4425 A scanset is a simple regular expression, where the matching set contains any Latin-1 character (8-bits) or character ranges using minus. 4426 For example, the scanset \lstinline{"a-zA-Z -/?§"} matches characters between ©'a'© and ©'z'©, between ©'A'© and ©'Z'©, between space and ©'/'©, and characters ©'?'© and (Latin-1) ©'§'©. 4427 The following string is matched by this scanset: 4428 \begin{cfa} 4429 !&%$ abAA () ZZZ ?? xx§§§§ 4430 \end{cfa} 4431 To match a minus, put it as the first character, ©"-0-9"©. 4432 Note, other complex forms of regular-expression matching is not supported. 4433 4434 The following \Index{manipulator}s control scanning of input values (reading), and only affect the format of the argument. 4417 4435 \begin{enumerate} 4418 4436 \item … … 4457 4475 4458 4476 \item 4459 \Indexc{incl}( scanset, input-string )\index{manipulator!incl@©incl©}4460 For C-string types , the scanset matches any number of characters \emph{in} the set.4477 \Indexc{incl}( scanset, wdi-input-string )\index{manipulator!incl@©incl©} 4478 For C-string types only, the scanset matches any number of characters \emph{in} the set. 4461 4479 Matching characters are read into the C input-string and null terminated. 4462 4480 \begin{cfa}[belowskip=0pt] … … 4469 4487 4470 4488 \item 4471 \Indexc{excl}( scanset, input-string )\index{manipulator!excl@©excl©}4489 \Indexc{excl}( scanset, wdi-input-string )\index{manipulator!excl@©excl©} 4472 4490 For C-string types, the scanset matches any number of characters \emph{not in} the set. 4473 4491 Non-matching characters are read into the C input-string and null terminated. … … 4479 4497 ®xyz®bca 4480 4498 \end{cfa} 4499 4500 \item 4501 \Indexc{getline}( char delimit, wdi-input-string )\index{manipulator!getline@©getline©} 4502 Is an @excl@ with scanset ©"delimit"©, which consumes all characters up to the delimit character. 4503 If the delimit character is omitted, it defaults to ©'\n'© (newline). 4481 4504 \end{enumerate} 4482 4505 … … 4692 4715 sout | i | j | k | x | y | s; 4693 4716 } 4694 4717 \end{cfa} 4718 \begin{cfa}[showspaces=true] 4695 4719 3 0x5 7 1.234568e+07 987.654n abc 4696 4720 3 0x5 7 1.234568e+07 987.654n abc
Note:
See TracChangeset
for help on using the changeset viewer.