Ignore:
Timestamp:
Dec 8, 2024, 9:09:02 AM (10 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
fbb5bdd
Parents:
9f7285e
Message:

more proofreading of intro chapter

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/theses/fangren_yu_MMath/intro.tex

    r9f7285e rbc999b7  
    122122In addition, several operations are defined in terms of values @0@ and @1@, \eg:
    123123\begin{cfa}
    124 if (x) x++                                                                      $\C{// if (x != 0) x += 1;}$
     124if ( x ) ++x                    $\C{// if ( x != 0 ) x += 1;}$
    125125\end{cfa}
    126126Every @if@ and iteration statement in C compares the condition with @0@, and every increment and decrement operator is semantically equivalent to adding or subtracting the value @1@ and storing the result.
     
    129129\begin{cfa}
    130130struct S { int i, j; };
    131 void ?{}( S & s, zero_t ) { s.[i,j] = 0; }
     131void ?{}( S & s, zero_t ) { s.[i,j] = 0; } $\C{// constructors}$
    132132void ?{}( S & s, one_t ) { s.[i,j] = 1; }
    133 int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; }
    134 S ?+=?( S & s, one_t ) { s.i++; s.j++; return s; }
    135 S ?-=?( S & s, one_t ) { s.i--; s.j--; return s; }
    136 S ?=?( S & dst, one_t ) { return dst.[i,j] = 1; }
    137 void foo() {
    138         S s = @0@;
    139         s = @1@;
    140         if ( @s@ ) @s++@;
    141 }
     133S ?=?( S & dst, zero_t ) { dst.[i,j] = 0; return dst; } $\C{// assignment}$
     134S ?=?( S & dst, one_t ) { dst.[i,j] = 1; return dst; }
     135S ?+=?( S & s, one_t ) { s.[i,j] += 1; return s; } $\C{// increment/decrement}$
     136S ?-=?( S & s, one_t ) { s.[i,j] -= 1; return s; }
     137int ?!=?( S s, zero_t ) { return s.i != 0 && s.j != 0; } $\C{// comparison}$
     138S s = @0@;
     139s = @0@;
     140s = @1@;
     141if ( @s@ ) @++s@;       $\C{// unary ++/-\,- come from +=/-=}$
    142142\end{cfa}
    143143Hence, type @S@ is first-class with respect to the basic types, working with all existing implicit C mechanisms.
Note: See TracChangeset for help on using the changeset viewer.