Changes in / [77acd07d:3f8ab8f]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/Paper.tex

    r77acd07d r3f8ab8f  
    10521052\label{s:WithClauseStatement}
    10531053
    1054 Grouping heterogenous data into \newterm{aggregate}s is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers:
     1054Grouping heterogenous data into \newterm{aggregate}s (structure/union) is a common programming practice, and an aggregate can be further organized into more complex structures, such as arrays and containers:
    10551055\begin{cfa}
    1056 struct S {                                                              $\C{// aggregate}$
    1057         char c;                                                         $\C{// fields}$
     1056struct S {                                                                      $\C{// aggregate}$
     1057        char c;                                                                 $\C{// fields}$
    10581058        int i;
    10591059        double d;
     
    10611061S s, as[10];
    10621062\end{cfa}
    1063 However, routines manipulating aggregates have repeition of the aggregate name to access its containing fields:
     1063However, routines manipulating aggregates must repeat the aggregate name to access its containing fields:
    10641064\begin{cfa}
    10651065void f( S s ) {
    1066         `s.`c; `s.`i; `s.`d;                            $\C{// access containing fields}$
     1066        `s.`c; `s.`i; `s.`d;                                    $\C{// access containing fields}$
    10671067}
    10681068\end{cfa}
     
    10701070\begin{C++}
    10711071class C {
    1072         char c;                                                         $\C{// fields}$
     1072        char c;                                                                 $\C{// fields}$
    10731073        int i;
    10741074        double d;
    1075         int mem() {                                                     $\C{// implicit "this" parameter}$
    1076                 `this->`c; `this->`i; `this->`d;$\C{// access containing fields}$
     1075        int mem() {                                                             $\C{// implicit "this" parameter}$
     1076                `this->`c; `this->`i; `this->`d;        $\C{// access containing fields}$
    10771077        }
    10781078}
    10791079\end{C++}
    1080 Nesting of member routines in a \lstinline[language=C++]@class@ allows eliding \lstinline[language=C++]@this->@ because of nested lexical-scoping.
     1080Nesting of member routines in a \lstinline[language=C++]@class@ allows eliding \lstinline[language=C++]@this->@ because of lexical scoping.
    10811081
    10821082% In object-oriented programming, there is an implicit first parameter, often names @self@ or @this@, which is elided.
     
    10881088% \TODO{Fill out section. Be sure to mention arbitrary expressions in with-blocks, recent change driven by Thierry to prioritize field name over parameters.}
    10891089
    1090 \CFA provides a @with@ clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing field identifiers.
    1091 Hence, the qualified fields become variables, and making it easier to optimize field references in a block.
     1090\CFA provides a @with@ clause/statement (see Pascal~\cite[\S~4.F]{Pascal}) to elide aggregate qualification to fields by opening a scope containing the field identifiers.
     1091Hence, the qualified fields become variables with the side-effect that it is easier to optimizing field references in a block.
    10921092\begin{cfa}
    1093 void f( S s ) `with( s )` {                             $\C{// with clause}$
    1094         c; i; d;                                                        $\C{\color{red}// s.c, s.i, s.d}$
     1093void f( S s ) `with( s )` {                                     $\C{// with clause}$
     1094        c; i; d;                                                                $\C{\color{red}// s.c, s.i, s.d}$
    10951095}
    10961096\end{cfa}
     
    10981098\begin{cfa}
    10991099int mem( S & this ) `with( this )` {            $\C{// with clause}$
    1100         c; i; d;                                                        $\C{\color{red}// this.c, this.i, this.d}$
     1100        c; i; d;                                                                $\C{\color{red}// this.c, this.i, this.d}$
    11011101}
    11021102\end{cfa}
    1103 The key generality over the object-oriented approach is that one aggregate parameter \lstinline[language=C++]@this@ is not treated specially over other aggregate parameters:
     1103The generality over the object-oriented approach is that multiple aggregate parameters can be opened, not just \lstinline[language=C++]@this@:
    11041104\begin{cfa}
    11051105struct T { double m, n; };
    11061106int mem( S & s, T & t ) `with( s, t )` {        $\C{// multiple aggregate parameters}$
    1107         c; i; d;                                                        $\C{\color{red}// s.c, s.i, s.d}$
    1108         m; n;                                                           $\C{\color{red}// t.m, t.n}$
     1107        c; i; d;                                                                $\C{\color{red}// s.c, s.i, s.d}$
     1108        m; n;                                                                   $\C{\color{red}// t.m, t.n}$
    11091109}
    11101110\end{cfa}
    1111 The equivalent object-oriented style is:
     1111The equivalent object-oriented approach is:
    11121112\begin{cfa}
    1113 int S::mem( T & t ) {                                   $\C{// multiple aggregate parameters}$
    1114         c; i; d;                                                        $\C{\color{red}// this-\textgreater.c, this-\textgreater.i, this-\textgreater.d}$
    1115         `t.`m; `t.`n;
     1113int S::mem( T & t ) {                                           $\C{// multiple aggregate parameters}$
     1114        c; i; d;                                                                $\C{\color{red}// this-\textgreater.c, this-\textgreater.i, this-\textgreater.d}$
     1115        `t.`m; `t.`n;                                                   $\C{// must qualify}$
     1116}
     1117\end{cfa}
     1118
     1119\begin{cfa}
     1120struct S { int i, j; } sv;
     1121with( sv ) {
     1122        S & sr = sv;
     1123        with( sr ) {
     1124                S * sp = &sv;
     1125                with( *sp ) {
     1126                        i = 3; j = 4;                                   $\C{\color{red}// sp-{\textgreater}i, sp-{\textgreater}j}$
     1127                }
     1128                i = 3; j = 4;                                           $\C{\color{red}// sr.i, sr.j}$
     1129        }
     1130        i = 3; j = 4;                                                   $\C{\color{red}// sv.i, sv.j}$
    11161131}
    11171132\end{cfa}
     
    11221137        struct S1 { ... } s1;
    11231138        struct S2 { ... } s2;
    1124         `with( s1 )` {                                          $\C{// with statement}$
     1139        `with( s1 )` {                                                  $\C{// with statement}$
    11251140                // access fields of s1 without qualification
    1126                 `with( s2 )` {                                  $\C{// nesting}$
     1141                `with( s2 )` {                                          $\C{// nesting}$
    11271142                        // access fields of s1 and s2 without qualification
    11281143                }
     
    11401155struct T { int i; int k; int m } b, c;
    11411156`with( a, b )` {
    1142         j + k;                                                  $\C{// unambiguous, unique names define unique types}$
    1143         i;                                                              $\C{// ambiguous, same name and type}$
    1144         a.i + b.i;                                              $\C{// unambiguous, qualification defines unique names}$
    1145         m;                                                              $\C{// ambiguous, same name and no context to define unique type}$
    1146         m = 5.0;                                                $\C{// unambiguous, same name and context defines unique type}$
    1147         m = 1;                                                  $\C{// unambiguous, same name and context defines unique type}$
    1148 }
    1149 `with( c )` { ... }                                     $\C{// ambiguous, same name and no context}$
    1150 `with( (S)c )` { ... }                                  $\C{// unambiguous, same name and cast defines unique type}$
     1157        j + k;                                                                  $\C{// unambiguous, unique names define unique types}$
     1158        i;                                                                              $\C{// ambiguous, same name and type}$
     1159        a.i + b.i;                                                              $\C{// unambiguous, qualification defines unique names}$
     1160        m;                                                                              $\C{// ambiguous, same name and no context to define unique type}$
     1161        m = 5.0;                                                                $\C{// unambiguous, same name and context defines unique type}$
     1162        m = 1;                                                                  $\C{// unambiguous, same name and context defines unique type}$
     1163}
     1164`with( c )` { ... }                                                     $\C{// ambiguous, same name and no context}$
     1165`with( (S)c )` { ... }                                          $\C{// unambiguous, same name and cast defines unique type}$
    11511166\end{cfa}
    11521167
    11531168The components in the "with" clause
    11541169
    1155   with ( a, b, c ) { ... }
     1170  with( a, b, c ) { ... }
    11561171
    11571172serve 2 purposes: each component provides a type and object. The type must be a
Note: See TracChangeset for help on using the changeset viewer.