Changeset 96aca388 for doc/user


Ignore:
Timestamp:
Sep 17, 2025, 9:18:00 AM (3 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
295ed2d1
Parents:
d2e6f84
Message:

wording and formatting changes to multiple sections

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rd2e6f84 r96aca388  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon Sep 15 21:14:57 2025
    14 %% Update Count     : 7220
     13%% Last Modified On : Wed Sep 17 09:15:48 2025
     14%% Update Count     : 7251
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    607607
    608608C, \CC, Java and other programming languages have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, using a routine like \Indexc{pow( x, y )} instead.
    609 Ada, Haskell, Python and other programming languages often use operators ©^© or ©**© for exponentiation.
     609Ada, Haskell, Python and other programming languages have an exponentiation operator often using operators ©^© or ©**©.
    610610However, neither of these operators work in C as ©^© means exclusive-or and ©**© means double dereference.
    611611Furthermore, using a routine for exponentiation does not match with mathematical expectation, \ie ©-x**-y© becomes ©pow( -x, -y )©.
     
    882882\end{enumerate}
    883883
    884 Before discussing potential language changes to deal with these problems, it is worth observing that in a typical C program:
     884Before discussing language changes to deal with these problems, it is worth observing that in a typical C program:
    885885\begin{itemize}
    886886\item
     
    902902\end{cfa}
    903903still works.
    904 Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing shell arguments.
    905 Therefore, to preserve backwards compatibility, it is necessary to introduce a new kind of ©switch© statement, called \Indexc{choose}, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword \Indexc{fallthrough}, \eg:
     904Nevertheless, reversing the default action would have a non-trivial effect on case actions that compound, such as the above example of processing command-line arguments.
     905To preserve backwards compatibility, a new kind of ©switch© statement, called \Indexc{choose} is introduced, with no implicit fall-through semantics and an explicit fall-through if the last statement of a case-clause ends with the new keyword \Indexc{fallthrough}, \eg:
    906906\begin{cfa}
    907907®choose® ( i ) {
     
    931931\item
    932932Dealing with unreachable code in a ©switch©/©choose© body is solved by restricting declarations and initialization to the start of statement body, which is executed \emph{before} the transfer to the appropriate ©case© clause\footnote{
    933 Essentially, these declarations are hoisted before the ©switch©/©choose© statement and both declarations and statement are surrounded by a compound statement.} and precluding statements before the first ©case© clause.
     933These declarations are hoisted before the ©switch©/©choose© statement and both declarations and statement are surrounded by a compound statement.} and precluding statements before the first ©case© clause.
    934934Further declarations at the same nesting level as the statement body are disallowed to ensure every transfer into the body is sound.
    935935\begin{cfa}
     
    10331033The range character, ©'~'©, is decorated on the left and right to control how the set values are presented in the loop body.
    10341034The range character can be prefixed with ©'+'© or ©'-'© indicating the \emph{direction} the range is scanned, \ie from left to right (ascending) or right to left (descending).
    1035 Ascending stepping uses operator \Indexc{+=};
    1036 descending stepping uses operator \Indexc{-=}.
     1035Ascending uses operator \Indexc{+=};
     1036descending uses operator \Indexc{-=}.
    10371037If there is no prefix character, it defaults to ©'+'©.
    10381038\begin{cfa}
     
    10431043For descending iteration, the ©L© and ©H© values are \emph{implicitly} switched, and the increment/decrement for ©S© is toggled.
    10441044Hence, the order of values in a set may not be the order the values are presented during looping.
    1045 When changing the iteration direction, this form is faster and safer, \ie the direction prefix can be added/removed without changing existing (correct) program text.
     1045Changing the iteration direction is faster and safer because the direction prefix can be added/removed without changing existing (correct) range information.
    10461046\R{Warning}: reversing the range endpoints for descending order results in an empty set.
    10471047\begin{cfa}
     
    12861286
    12871287
     1288
    12881289\end{cfa}
    12891290&
    12901291\begin{cfa}
    12911292int main() {
     1293        sout | nlOff;
    12921294        for ( S i = 0; i < (S){10,10}; i += 1 ) { sout | i; } sout | "A" | nl; // C
    12931295        for ( S i; 0 ~ (S){10,10} ) { sout | i; } sout | "B" | nl; // CFA
     
    14241426The following example is a linear search for the key 3 in an array, where finding the key is handled with a ©break© and not finding with the ©else© clause on the loop construct.
    14251427\begin{cquote}
    1426 \begin{cfa}
    1427 int a[10];
    1428 \end{cfa}
    1429 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{3em}}l@{}}
     1428\begin{tabular}{@{}lll@{}}
     1429\multicolumn{2}{@{}l@{}}{\lstinline{int a[10]}} \\
    14301430\begin{cfa}
    14311431
     
    27042704\begin{tabular}{@{}l|ll|l@{}}
    27052705\multicolumn{2}{@{}c}{\textbf{length}} & \multicolumn{2}{c@{}}{\textbf{pattern}} \\
    2706 \multicolumn{4}{@{}l}{\lstinline{string name = "PETER"}} \\
     2706\multicolumn{4}{@{}l}{\lstinline{string name = "PETER"};} \\
    27072707\begin{cfa}
    27082708s = name( 0, 4 );
     
    27622762\begin{cquote}
    27632763\begin{tabular}{@{}l|l@{}}
    2764 \multicolumn{2}{@{}l}{\lstinline{string digit = "0123456789"}} \\
     2764\multicolumn{2}{@{}l}{\lstinline{string digit = "0123456789"};} \\
    27652765\begin{cfa}[escapechar={}]
    27662766digit( 3, 3 ) = "";
     
    28192819\begin{cquote}
    28202820\begin{tabular}{@{}l|l@{}}
    2821 \multicolumn{2}{@{}l}{\lstinline{string digit = "0123456789"}} \\
     2821\multicolumn{2}{@{}l}{\lstinline{string digit = "0123456789";}} \\
    28222822\begin{cfa}
    28232823i = find( digit, '3' );
     
    28372837\begin{cquote}
    28382838\begin{tabular}{@{}l|l@{}}
    2839 \begin{cfa}
    2840 charclass vowels{ "aeiouy" };
     2839\multicolumn{2}{@{}l}{\lstinline{charclass vowels\{ "aeiouy" \};}} \\
     2840\begin{cfa}
    28412841i = include( "aaeiuyoo", vowels );
    28422842i = include( "aabiuyoo", vowels );
     
    28442844&
    28452845\begin{cfa}
    2846 
    284728468  // compliant
    284828472  // b non-compliant
     
    29952994\subsection{C Compatibility}
    29962995
    2997 To ease conversion from C to \CFA, \CFA provides companion C @string@ functions.
    2998 Hence, it is possible to convert a block of C string operations to \CFA strings just by changing the type @char *@ to @string@.
     2996To ease conversion from C to \CFA, \CFA provides companion C ©string© functions.
     2997Hence, it is possible to convert a block of C string operations to \CFA strings just by changing the type ©char *© to ©string©.
    29992998\begin{cquote}
    30002999\begin{tabular}{@{}ll@{}}
     
    30163015\end{tabular}
    30173016\end{cquote}
    3018 However, the conversion fails with I/O because @printf@ cannot print a @string@ using format code @%s@ because \CFA strings are not null terminated.
     3017However, the conversion fails with I/O because ©printf© cannot print a ©string© using format code ©%s© as \CFA strings are not null terminated.
    30193018Nevertheless, this capability does provide a useful starting point for conversion to safer \CFA strings.
    30203019
     
    30313030\begin{cquote}
    30323031\begin{tabular}{@{}l|l@{}}
     3032\multicolumn{2}{@{}l}{\lstinline{string s = "abc";}} \\
    30333033\begin{C++}
    3034 string s = "abc";
    30353034cout << setw(10) << left << setfill( 'x' ) << s << endl;
    30363035\end{C++}
    30373036&
    30383037\begin{C++}
    3039 
    30403038"abcxxxxxxx"
    30413039\end{C++}
     
    30483046\begin{cquote}
    30493047\begin{tabular}{@{}l|l@{}}
    3050 \begin{cfa}
    3051 string s = "abc";
     3048\multicolumn{2}{@{}l}{\lstinline{string s = "abc";}} \\
     3049\begin{cfa}
    30523050sout | bin( s ) | nl
    30533051           | oct( s ) | nl
     
    30593057&
    30603058\begin{cfa}
    3061 
    30623059"0b1100001 0b1100010 0b1100011"
    30633060"0141 0142 0143"
     
    30763073\begin{cquote}
    30773074\begin{tabular}{@{}l|l@{}}
     3075\multicolumn{2}{@{}l}{\lstinline{char ch, c[10];}} \\
     3076\multicolumn{2}{@{}l}{\lstinline{string s;}} \\
    30783077\begin{C++}
    3079 char ch, c[10];
    3080 string s;
    30813078cin >> ch >> setw( 5 ) >> c  >> s;
    30823079®abcde   fg®
     
    30843081&
    30853082\begin{C++}
    3086 
    3087 
    30883083'a' "bcde" "fg"
    30893084
     
    31023097\setlength{\tabcolsep}{10pt}
    31033098\begin{tabular}{@{}l|l@{}}
     3099\multicolumn{2}{@{}l}{\lstinline{char ch, c[10];}} \\
     3100\multicolumn{2}{@{}l}{\lstinline{string s;}} \\
    31043101\begin{C++}
    3105 char ch, c[10];
    3106 string s;
    31073102sin | ch | wdi( 5, c ) | s;
    31083103®abcde fg®
Note: See TracChangeset for help on using the changeset viewer.