Changeset 06ffa95 for doc


Ignore:
Timestamp:
Mar 14, 2025, 7:15:01 PM (12 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
8617ee90
Parents:
7611631
Message:

change shareEdit to share and proofreading of string chapter

Location:
doc/theses/mike_brooks_MMath
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified doc/theses/mike_brooks_MMath/programs/sharing-demo.cfa

    r7611631 r06ffa95  
    1111//      sout | "Consider two strings @s1@ and @s1a@ that are in an aliasing relationship, and a third, @s2@, made by a simple copy from @s1@.";
    1212
    13         #define S1 string s1  = "abc"
    14         #define S1A string s1a = s1`shareEdits
    15         #define S2 string s2  = s1
     13        #define S1 string s1 = "abc"
     14        #define S1A string s1a = s1`share
     15        #define S2 string s2 = s1a
    1616        S1;
    1717        S1A;
     
    2323        open( outfile, "build/sharing1.tex" );
    2424        outfile | "\\begin{cquote}";
    25         outfile | "\\begin{tabular}{@{}llll@{}}";
     25        outfile | "\\begin{tabular}{@{}rlll@{}}";
    2626        outfile | "\t\t\t& @s1@\t& @s1a@\t& @s2@\t\\\\";
    27         outfile | xstr(S1) | "\t\\\\";
    28         outfile | xstr(S1A) | "\t\\\\";
    29         outfile | xstr(S2) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2;
    30         outfile | "\\end{tabular}";
    31         outfile | "\\end{cquote}";
    32         close( outfile );
    33 
    34 //      sout | "Aliasing (@`shareEdits@) means that changes flow in both directions; with a simple copy, they do not.";
     27        outfile | xstr(S1) | "\t& @\"" | s1 | "\"@\t\\\\";
     28        outfile | xstr(S1A) | "\t& \t& @\"" | s1a | "\"@\t\\\\";
     29        outfile | xstr(S2) | "\t& \t& \t& @\"" | s2 | "\"@";
     30        outfile | "\\end{tabular}";
     31        outfile | "\\end{cquote}";
     32        close( outfile );
     33
     34//      sout | "Aliasing (@`share@) means that changes flow in both directions; with a simple copy, they do not.";
    3535        open( outfile, "build/sharing2.tex" );
    3636        outfile | "\\begin{cquote}";
    37         outfile | "\\begin{tabular}{@{}llll@{}}";
     37        outfile | "\\begin{tabular}{@{}rlll@{}}";
    3838        outfile | "\t\t& @s1@\t& @s1a@\t& @s2@\t\\\\";
    39         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
    40 
    41         #define S1s1 s1 [1] = '+'
     39        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
     40
     41        #define S1s1 s1[1] = '+'
    4242        S1s1;
    4343        assert( s1 == "a+c" );
    44         outfile | xstr(S1s1) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     44        outfile | xstr(S1s1) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    4545
    4646        #define S1As1 s1a[1] = '-'
    4747        S1As1;
    4848        assert( s1a == "a-c" );
    49         outfile | xstr(S1As1) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
    50 
    51         #define S2s1 s2 [1] = '|'
     49        outfile | xstr(S1As1) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
     50
     51        #define S2s1 s2[1] = '|'
    5252        S2s1;
    5353        assert( s2 == "a|c" );
    54         outfile | xstr(S2s1) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2;
     54        outfile | xstr(S2s1) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@";
    5555        outfile | "\\end{tabular}";
    5656        outfile | "\\end{cquote}";
     
    6161        open( outfile, "build/sharing3.tex" );
    6262        outfile | "\\begin{cquote}";
    63         outfile | "\\begin{tabular}{llll}";
     63        outfile | "\\begin{tabular}{@{}rlll@{}}";
    6464        outfile | "\t\t& @s1@\t& @s1a@\t& @s2@\t\\\\";
    65         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     65        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    6666
    6767        #define S1qrs s1  = "qrs"
    6868        S1qrs;
    6969        assert( s1 == "qrs" );
    70         outfile | xstr(S1qrs) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     70        outfile | xstr(S1qrs) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    7171
    7272        #define S1Atuv s1a = "tuv"
    7373        S1Atuv;
    7474        assert( s1a == "tuv" );
    75         outfile | xstr(S1Atuv) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     75        outfile | xstr(S1Atuv) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    7676
    7777        #define S2wxy s2  = "wxy"
    7878        S2wxy;
    7979        assert( s2 == "wxy" );
    80         outfile | xstr(S2wxy) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2;
     80        outfile | xstr(S2wxy) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@";
    8181        outfile | "\\end{tabular}";
    8282        outfile | "\\end{cquote}";
     
    8787        open( outfile, "build/sharing4.tex" );
    8888        outfile | "\\begin{cquote}";
    89         outfile | "\\begin{tabular}{llll}";
     89        outfile | "\\begin{tabular}{@{}rlll@{}}";
    9090        outfile | "\t\t& @s1@\t& @s1a@\t& @s2@\t\\\\";
    91         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     91        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    9292
    9393        #define S1S2 s1  = s2
     
    9696        assert( s1a == "wxy" );
    9797        assert( s2 == "wxy" );
    98         outfile | xstr(S1S2) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     98        outfile | xstr(S1S2) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    9999
    100100        #define S1aaa s1  = "aaa"
     
    103103        assert( s1a == "aaa" );
    104104        assert( s2 == "wxy" );
    105         outfile | xstr(S1aaa) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     105        outfile | xstr(S1aaa) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    106106
    107107        #define S2S1 s2  = s1
     
    110110        assert( s1a == "aaa" );
    111111        assert( s2 == "aaa" );
    112         outfile | xstr(S2S1) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     112        outfile | xstr(S2S1) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    113113
    114114        #define S2bbb s2  = "bbb"
     
    117117        assert( s1a == "aaa" );
    118118        assert( s2 == "bbb" );
    119         outfile | xstr(S2bbb) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     119        outfile | xstr(S2bbb) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    120120
    121121        #define S2S1a s2  = s1a
     
    124124        assert( s1a == "aaa" );
    125125        assert( s2 == "aaa" );
    126         outfile | xstr(S2S1a) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     126        outfile | xstr(S2S1a) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    127127
    128128        #define S2ccc s2  = "ccc"
     
    131131        assert( s1a == "aaa" );
    132132        assert( s2 == "ccc" );
    133         outfile | xstr(S2ccc) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     133        outfile | xstr(S2ccc) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    134134
    135135        #define S1xxx s1  = "xxx"
     
    138138        assert( s1a == "xxx" );
    139139        assert( s2 == "ccc" );
    140         outfile | xstr(S1xxx) | "\t& " | s1 | "\t& " | s1a | "\t& " | s2 | "\t\\\\";
     140        outfile | xstr(S1xxx) | "\t& @\"" | s1 | "\"@\t& @\"" | s1a | "\"@\t& @\"" | s2 | "\"@";
    141141        outfile | "\\end{tabular}";
    142142        outfile | "\\end{cquote}";
     
    149149        open( outfile, "build/sharing5.tex" );
    150150        outfile | "\\begin{cquote}";
    151         outfile | "\\begin{tabular}{llll}";
     151        outfile | "\\begin{tabular}{@{}rlll@{}}";
    152152        outfile | "\t\t\t\t& @s1@\t& @s1_mid@\t& @s2@\t\\\\";
    153153
    154         #define D2_s1_abcd string s1     = "abcd"
     154        #define D2_s1_abcd string s1 = "abcd"
    155155        D2_s1_abcd;
    156         outfile | xstr(D2_s1_abcd) | "\t\\\\";
    157 
    158         #define D2_s1mid_s1 string s1_mid = s1(1,2)`shareEdits
     156        outfile | xstr(D2_s1_abcd) | "\t& @\"" | s1 | "\"@\t\\\\";
     157
     158        #define D2_s1mid_s1 string s1_mid = s1(1,2)`share
    159159        D2_s1mid_s1;
    160         outfile | xstr(D2_s1mid_s1) | "\t\\\\";
    161 
    162         #define D2_s2_s1 string s2     = s1(1,2)
     160        outfile | xstr(D2_s1mid_s1) | "\t& \t& @\"" | s1_mid | "\"@\t\\\\";
     161
     162        #define D2_s2_s1 string s2 = s1_mid(0,2)
    163163        D2_s2_s1;
    164164        assert( s1 == "abcd" );
    165165        assert( s1_mid == "bc" );
    166166        assert( s2 == "bc" );
    167         outfile | xstr(D2_s2_s1) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
    168         outfile | "\\end{tabular}";
    169         outfile | "\\end{cquote}";
    170         close( outfile );
    171 
    172 //      sout | "Again, @`shareEdits@ passes changes in both directions; copy does not.  Note the difference in index values, with the \\emph{b} position being 1 in the longer string and 0 in the shorter strings.  In the case of s1 aliasing with @s1_mid@, the very same character is being accessed by different postitions.";
     167        outfile | xstr(D2_s2_s1) | "\t& \t& \t& @\"" | s2 | "\"@";
     168        outfile | "\\end{tabular}";
     169        outfile | "\\end{cquote}";
     170        close( outfile );
     171
     172//      sout | "Again, @`share@ passes changes in both directions; copy does not.  Note the difference in index values, with the \\emph{b} position being 1 in the longer string and 0 in the shorter strings.  In the case of s1 aliasing with @s1_mid@, the very same character is being accessed by different postitions.";
    173173        open( outfile, "build/sharing6.tex" );
    174174        outfile | "\\begin{cquote}";
    175         outfile | "\\begin{tabular}{llll}";
     175        outfile | "\\begin{tabular}{@{}rlll@{}}";
    176176        outfile | "\t\t\t\t& @s1@\t& @s1_mid@\t& @s2@\t\\\\";
    177         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     177        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    178178
    179179        #define D2_s1_plus s1    [1] = '+'
     
    182182        assert( s1_mid == "+c" );
    183183        assert( s2 == "bc" );
    184         outfile | xstr(D2_s1_plus) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     184        outfile | xstr(D2_s1_plus) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    185185
    186186        #define D2_s1mid_minus s1_mid[0] = '-'
     
    189189        assert( s1_mid == "-c" );
    190190        assert( s2 == "bc" );
    191         outfile | xstr(D2_s1mid_minus) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     191        outfile | xstr(D2_s1mid_minus) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    192192
    193193        #define D2_s2_pipe s2    [0] = '|'
     
    196196        assert( s1_mid == "-c" );
    197197        assert( s2 == "|c" );
    198         outfile | xstr(D2_s2_pipe) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     198        outfile | xstr(D2_s2_pipe) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t";
    199199        outfile | "\\end{tabular}";
    200200        outfile | "\\end{cquote}";
     
    204204        open( outfile, "build/sharing7.tex" );
    205205        outfile | "\\begin{cquote}";
    206         outfile | "\\begin{tabular}{llll}";
     206        outfile | "\\begin{tabular}{@{}rlll@{}}";
    207207        outfile | "\t\t\t\t& @s1@\t& @s1_mid@\t& @s2@\t\\\\";
    208         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     208        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    209209
    210210        #define D2_s1mid_ff s1_mid = "ff"
     
    213213        assert( s1_mid == "ff" );
    214214        assert( s2 == "|c" );
    215         outfile | xstr(D2_s1mid_ff) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     215        outfile | xstr(D2_s1mid_ff) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t\\\\";
    216216
    217217        #define D2_s2_gg s2     = "gg"
     
    220220        assert( s1_mid == "ff" );
    221221        assert( s2 == "gg" );
    222         outfile | xstr(D2_s2_gg) | "\t& " | s1 | "\t& " | s1_mid | "\t& " | s2 | "\t\\\\";
     222        outfile | xstr(D2_s2_gg) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s2 | "\"@\t";
    223223        outfile | "\\end{tabular}";
    224224        outfile | "\\end{cquote}";
     
    232232        open( outfile, "build/sharing8.tex" );
    233233        outfile | "\\begin{cquote}";
    234         outfile | "\\begin{tabular}{lll}";
     234        outfile | "\\begin{tabular}{@{}rll@{}}";
    235235        outfile | "\t\t\t\t& @s1@\t& @s1_mid@\t\\\\";
    236         outfile | "\\multicolumn{1}{r}{initial} & " | s1 | "\t& " | s1_mid | "\t\\\\";
     236        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t\\\\";
    237237
    238238        assert( s1 == "affd" );
    239239//      assert( s1_mid == "fc" );                                                                                                        // ????????? bug?
    240         outfile | xstr(D2_s2_gg) | "\t& " | s1 | "\t& " | s1_mid | "\t\\\\";
     240//      outfile | xstr(D2_s2_gg) | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t\\\\";
    241241
    242242        #define D2_s1mid_hhhh s1_mid = "hhhh"
     
    244244        assert( s1 == "ahhhhd" );
    245245        assert( s1_mid == "hhhh" );
    246         outfile  | xstr(D2_s1mid_hhhh)  | "\t& " | s1 | "\t& " | s1_mid | "\t\\\\";
     246        outfile  | xstr(D2_s1mid_hhhh)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t\\\\";
    247247
    248248        #define D2_s1mid_i s1_mid = "i"
     
    250250        assert( s1 == "aid" );
    251251        assert( s1_mid == "i" );
    252         outfile  | xstr(D2_s1mid_i)  | "\t& " | s1 | "\t& " | s1_mid | "\t\\\\";
     252        outfile  | xstr(D2_s1mid_i)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t\\\\";
    253253
    254254        #define D2_s1mid_empty s1_mid = ""
     
    256256        assert( s1 == "ad" );
    257257        // assert( s1_mid == "" );    ------ Should be so, but fails
    258         outfile  | xstr(D2_s1mid_empty)  | "\t& " | s1 | "\t& " | s1_mid | "\t\\\\";
     258        outfile  | xstr(D2_s1mid_empty)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t\\\\";
    259259
    260260        #define D2_s1mid_jj s1_mid = "jj"
     
    262262        assert( s1 == "ajjd" );
    263263        assert( s1_mid == "jj" );
    264         outfile  | xstr(D2_s1mid_jj)  | "\t& " | s1 | "\t& " | s1_mid | "\t\\\\";
     264        outfile  | xstr(D2_s1mid_jj)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_mid | "\"@\t";
    265265        outfile | "\\end{tabular}";
    266266        outfile | "\\end{cquote}";
     
    270270        open( outfile, "build/sharing9.tex" );
    271271        outfile | "\\begin{cquote}";
    272         outfile | "\\begin{tabular}{lllll}";
     272        outfile | "\\begin{tabular}{@{}rllll@{}}";
    273273        outfile | "\t\t\t\t& @s1@\t& @s1_bgn@\t& @s1_mid@\t& @s1_end@\t\\\\";
    274 
    275         #define D2_s1bgn_s1     string s1_bgn = s1(0, 1)`shareEdits
     274        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& & @\"" | s1_mid | "\"@\t\\\\";
     275
     276        #define D2_s1bgn_s1     string s1_bgn = s1(0, 1)`share
    276277        D2_s1bgn_s1;
    277         outfile  | xstr(D2_s1bgn_s1)  | "\t\\\\";
    278 
    279         #define D2_s1end_s1 string s1_end = s1(3, 1)`shareEdits
     278        outfile  | xstr(D2_s1bgn_s1)  | "\t& \t& @\"" | s1_bgn | "\"@\t\\\\";
     279
     280        #define D2_s1end_s1 string s1_end = s1(3, 1)`share
    280281        D2_s1end_s1;
     282        outfile  | xstr(D2_s1end_s1)  | "\t& \t& \t& \t& @\"" | s1_end | "\"@\t\\\\";
    281283        assert( s1 == "ajjd" );
    282284        assert( s1_bgn == "a" );
    283285        assert( s1_mid == "jj" );
    284286        assert( s1_end == "d" );
    285         outfile  | xstr(D2_s1end_s1)  | "\t& " | s1 | "\t& " | s1_bgn | "\t& " | s1_mid | "\t& " | s1_end | "\t\\\\";
    286287
    287288        #define D1_s1bgn_zzz s1_bgn = "zzzz"
     
    291292        assert( s1_mid == "jj" );
    292293        assert( s1_end == "d" );
    293         outfile  | xstr(D1_s1bgn_zzz)  | "\t& " | s1 | "\t& " | s1_bgn | "\t& " | s1_mid | "\t& " | s1_end | "\t\\\\";
     294        outfile  | xstr(D1_s1bgn_zzz)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_bgn | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s1_end | "\"@\t";
    294295        outfile | "\\end{tabular}";
    295296        outfile | "\\end{cquote}";
     
    299300        open( outfile, "build/sharing10.tex" );
    300301        outfile | "\\begin{cquote}";
    301         outfile | "\\begin{tabular}{llllll}";
     302        outfile | "\\begin{tabular}{@{}rlllll@{}}";
    302303        outfile | "\t\t\t\t& @s1@\t& @s1_bgn@\t& @s1_crs@\t& @s1_mid@\t& @s1_end@\t\\\\";
    303 
    304         #define D2_s1crs_s1 string s1_crs = s1(3, 2)`shareEdits
     304        outfile | "\\multicolumn{1}{r}{initial} & @\"" | s1 | "\"@\t& @\"" | s1_bgn | "\"@\t& & @\"" | s1_mid | "\"@\t& @\"" | s1_end | "\"@\t\\\\";
     305
     306        #define D2_s1crs_s1 string s1_crs = s1(3, 2)`share
    305307        D2_s1crs_s1;
    306308        assert( s1 == "zzzzjjd" );
     
    309311        assert( s1_mid == "jj" );
    310312        assert( s1_end == "d" );
    311         outfile  | xstr(D2_s1crs_s1)  | "\t& " | s1 | "\t& " | s1_bgn | "\t& " | s1_crs | "\t& " | s1_mid | "\t& " | s1_end | "\t\\\\";
     313        outfile  | xstr(D2_s1crs_s1)  | "\t& \t& \t& @\"" | s1_crs | "\"@\t\\\\";
    312314
    313315        #define D2_s1crs_ppp s1_crs = "+++"
     
    318320        assert( s1_mid == "j" );
    319321        assert( s1_end == "d" );
    320         outfile  | xstr(D2_s1crs_ppp)  | "\t& " | s1 | "\t& " | s1_bgn | "\t& " | s1_crs | "\t& " | s1_mid | "\t& " | s1_end | "\t\\\\";
     322        outfile  | xstr(D2_s1crs_ppp)  | "\t& @\"" | s1 | "\"@\t& @\"" | s1_bgn | "\"@\t& @\"" | s1_crs | "\"@\t& @\"" | s1_mid | "\"@\t& @\"" | s1_end | "\"@\t";
    321323        outfile | "\\end{tabular}";
    322324        outfile | "\\end{cquote}";
     
    326328
    327329        string word = "Phi";
    328         string consonants = word(0,2)`shareEdits;
    329         string miniscules = word(1,2)`shareEdits;
     330        string consonants = word(0,2)`share;
     331        string miniscules = word(1,2)`share;
    330332        assert( word == "Phi" );
    331333        assert( consonants == "Ph" );
     
    340342
    341343        string all = "They said hello again";
    342         string greet     = all(10,5)`shareEdits;
    343         string greet_bgn = all(10,1)`shareEdits;
    344         string greet_end = all(14,1)`shareEdits;
     344        string greet     = all(10,5)`share;
     345        string greet_bgn = all(10,1)`share;
     346        string greet_end = all(14,1)`share;
    345347
    346348        assert( all == "They said hello again" );
  • TabularUnified doc/theses/mike_brooks_MMath/string.tex

    r7611631 r06ffa95  
    99
    1010To prepare for the following discussion, comparisons among C, \CC, Java and \CFA strings are presented, beginning in \VRef[Figure]{f:StrApiCompare}.
    11 It provides a classic ``cheat sheet'' presentation, summarizing the names of the most common closely-equivalent operations.
     11It provides a classic ``cheat sheet'' presentation, summarizing the names of the most-common closely-equivalent operations.
    1212The over-arching commonality is that operations work on groups of characters for assigning, copying, scanning, and updating.
    1313
     
    3939hence, most of its group operations are error prone and expensive.
    4040Most high-level string libraries use a separate length field and specialized storage management to implement group operations.
    41 Interestingly, \CC strings retain null termination just in case it is needed to interface with C library functions.
     41Interestingly, \CC strings retain null termination in case it is needed to interface with C library functions.
    4242\begin{cfa}
    4343int open( @const char * pathname@, int flags );
     
    5252While \VRef[Figure]{f:StrApiCompare} emphasizes cross-language similarities, it elides many specific operational differences.
    5353For example, the @replace@ function selects a substring in the target and substitutes it with the source string, which can be smaller or larger than the substring.
    54 \CC performs the modification on the mutable receiver object.
     54\CC performs the modification on the mutable receiver object
    5555\begin{cfa}
    5656string s1 = "abcde";
     
    6060\end{cfa}
    6161while Java allocates and returns a new string with the result, leaving the receiver unmodified.
     62\label{p:JavaReplace}
    6263\begin{java}
    6364String s = "abcde";
    6465String r = s.replace( "cde", "xy" );  $\C[2.25in]{// replace by text, immutable}$
     66System.out.println( s + ' ' + r );
     67$\texttt{abcde abxy}$
     68\end{java}
     69% Generally, Java's @String@ type is immutable.
     70Java provides a @StringBuffer@ near-analog that is mutable.
     71\begin{java}
    6572StringBuffer sb = new StringBuffer( "abcde" );
    66 sb.replace( 2, 5, "xy" );  $\C{// replace by position, mutable}\CRT$
    67 System.out.println( s + ' ' + r + ' ' + sb );
    68 $\texttt{abcde abxy abxy}$
     73sb.replace( 2, 5, "xy" );  $\C[2.25in]{// replace by position, mutable}\CRT$
     74System.out.println( sb );
     75$\texttt{abxy}$
    6976\end{java}
    70 Generally, Java's @String@ type is immutable.
    71 Java provides a @StringBuffer@ near-analog that is mutable, but the differences are significant; for example, @StringBuffer@'s @substring@ functions still return copies rather than mutable selections.
    72 Finally, the operations between these type are asymmetric, \eg @string@ has @replace@ by text but not replace by position and vice versa for @StringBuffer@.
     77However, there are significant differences;
     78\eg, @StringBuffer@'s @substring@ function returns a @String@ copy that is immutable.
     79Finally, the operations between these type are asymmetric, \eg @String@ has @replace@ by text but not replace by position and vice versa for @StringBuffer@.
    7380
    7481More significant operational differences relate to storage management, often appearing through assignment (@target = source@), and are summarized in \VRef[Figure]{f:StrSemanticCompare}.
     
    140147$\texttt{\small abcde abcde abcde bcde cde}$
    141148\end{cfa}
    142 Note, all of these strings rely on the single null termination character at the end of @s@.
     149Note, all of these aliased strings rely on the single null termination character at the end of @s@.
    143150The issue of symmetry does not apply to C strings because the value and pointer strings are essentially different types, and so this feature is scored as not applicable for C.
    144 With the type not managing the text buffer, there is no ownership question, \ie operations on @s1@ or @s2@ never leads to their memory becoming reusable.
     151With the type not managing the text storage, there is no ownership question, \ie operations on @s1@ or @s2@ never leads to their memory becoming reusable.
    145152While @s3@ is a valid C-string that contains a proper substring of @s1@, the @s3@ technique does not constitute having a fragment referent because null termination implies the substring cannot be chosen arbitrarily; the technique works only for suffixes.
    146153
     
    157164\end{cfa}
    158165The lax symmetry reflects how the validity of @s1@ depends on the content and lifetime of @s@.
    159 It is common practice in \CC to use the @s1@-style pass by reference, with the understanding that the callee only use the referenced string for the duration of the call, \ie no side-effect using the parameter.
    160 So, when the called function is a constructor, it is typical to use an @s2@-style copy initialization to string-object-typed member.
     166It is common practice in \CC to use the @s1@-style pass by reference, with the understanding that the callee only uses the referenced string for the duration of the call, \ie no side-effect using the parameter.
     167So, when the called function is a constructor, it is typical to use an @s2@-style copy-initialization to string-object-typed member.
    161168Exceptions to this pattern are possible, but require the programmer to assure safety where the type system does not.
    162 The @s3@ initialization is constrained to copy the substring because @c_str@ always provides a null-terminated character, which is different from source string.
     169The @s3@ initialization is constrained to copy the substring because @c_str@ always provides a null-terminated character, which may be different from the source string.
    163170@s3@ assignment could be fast by reference counting the text area and using copy-on-write, but would require an implementation upgrade.
    164171
    165172In Java, @String@ also offers a high-level abstraction:
    166 \begin{cfa}
     173\begin{java}
    167174String s = "abcde";
    168175String s1 = s;  $\C[2.25in]{// snapshot state, strict symmetry, variable-constrained referent}$
     
    173180$\texttt{\small abcde abcde bc c}$
    174181$\texttt{\small true false false}$
    175 \end{cfa}
     182\end{java}
    176183Note, @substring@ takes a start and end position, rather than a start position and length.
    177184Here, facts about Java's implicit pointers and pointer equality can over complicate the picture, and so are ignored.
     
    180187With @s2@, the case for fast-copy is more subtle.
    181188Certainly, its value is not pointer-equal to @s@, implying at least a further allocation.
    182 TODO: finish the fast-copy case.
    183 Java's immutable strings mean aliasing is impossible with the @String@ type.
    184 Java's @StringBuffer@ provides aliasing, though without supporting symmetric treatment of a fragment referent; as a result, @StringBuffer@ scores as \CC.
    185 The easy symmetry that the Java string enjoys is aided by Java's garbage collection; Java's @s2@ is doing effectively the operation of \CC's @s2@, though without the consequence to of complicating memory management.
    186 
    187 Finally, In \CFA, @string@ also offers a high-level abstraction:
     189\PAB{TODO: finish the fast-copy case.}
     190Java does not meet the aliasing requirement because immutability make it impossible to modify.
     191Java's @StringBuffer@ provides aliasing (see @replace@ example on \VPageref{p:JavaReplace}), though without supporting symmetric treatment of a fragment referent, \eg @substring@ of a @StringBuffer@ is a @String@;
     192as a result, @StringBuffer@ scores as \CC.
     193The easy symmetry that the Java string enjoys is aided by Java's garbage collection; Java's @s2@ is doing effectively the operation of \CC's @s3@, though without the consequence of complicating memory management.
     194\PAB{What complex storage management is going on here?}
     195
     196Finally, in \CFA, @string@ also offers a high-level abstraction:
    188197\begin{cfa}
    189198string s = "abcde";
    190199string & s1 = s; $\C[2.25in]{// alias state, strict symmetry, variable-constrained referent}$
    191200string s2 = s; $\C{// snapshot state, strict symmetry, variable-constrained referent}$
    192 string s3 = s`shareEdits; $\C{// alias state, strict symmetry, variable-constrained referent}\CRT$
     201string s3 = s`share; $\C{// alias state, strict symmetry, variable-constrained referent}\CRT$
    193202string s4 = s( 1, 2 );
    194203string s5 = s4( 1, 1 );
     
    198207% all helpful criteria of \VRef[Figure]{f:StrSemanticCompare} are satisfied.
    199208The \CFA string manages storage, handles all assignments, including those of fragment referents with fast initialization, provides the choice between snapshot and alias semantics, and does so symmetrically with one type (which assures text validity according to the lifecycles of the string variables).
    200 With aliasing, the intuition is that each string is an editor on an open shared document.
    201 With fragment aliasing, the intuition is that these editor views have been scrolled or zoomed to overlapping, but potentially different, ranges.
     209The intended metaphor for \CFA stings is similar to a GUI text-editor or web browser.
     210Select a consecutive block of text using the mouse generates an aliased substring in the file/dialog-box.
     211Typing into the selected area is like assigning to an aliased substring, where the highlighted text is replaced with more or less text;
     212depending on the text entered, the file/dialog-box content grows or shrinks.
     213\PAB{Need to discuss the example, as for the other languages.}
    202214
    203215The remainder of this chapter explains how the \CFA string achieves this usage style.
    204216
    205217
    206 
    207218\section{Storage Management}
    208219
    209220This section discusses issues related to storage management of strings.
    210 Specifically, it is common for strings to logically overlap completely or partially.
     221Specifically, it is common for strings to logically overlap partially or completely.
    211222\begin{cfa}
    212223string s1 = "abcdef";
     
    218229s3[1] = 'w'; $\C{// what happens to s1 and s2?}$
    219230\end{cfa}
    220 This question is the notion of mutable or immutable strings.
    221 For example, Java has immutable strings that are copied when any overlapping string changes.
    222 Note, the notion of underlying string mutability is not specified by @const@, \eg:
     231which is restricted by a string's mutable or immutable property.
     232For example, Java's immutable strings require copy-on-write when any overlapping string changes.
     233Note, the notion of underlying string mutability is not specified by @const@; \eg in \CC:
    223234\begin{cfa}
    224235const string s1 = "abc";
    225236\end{cfa}
    226 Here, @const@ applies to the @s1@ pointer to @"abc"@, and @"abc"@ is an immutable constant that is \emph{copied} into the string's storage.
    227 Hence, @s1@ is not pointing at an immutable constant, meaning its underlying string is always mutable, unless some other designation is specified, such as Java's global rule.
     237the @const@ applies to the @s1@ pointer to @"abc"@, and @"abc"@ is an immutable constant that is \emph{copied} into the string's storage.
     238Hence, @s1@ is not pointing at an immutable constant, meaning its underlying string can be mutable, unless some other designation is specified, such as Java's global immutable rule.
    228239
    229240
    230241\subsection{Logical overlap}
    231242
    232 \CFA provides a dynamic mechanism to indicate mutable or immutable as an assignment attribute: @`shareEdits@.
    233 
    234 Consider two strings @s1@ and @s1a@ that are in an aliasing relationship, and a third, @s2@, made by a simple copy from @s1@.
    235 Aliasing (@`shareEdits@) means that changes flow in both directions; with a simple copy, they do not.
     243\CFA provides a dynamic mechanism to indicate mutable or immutable using the attribute @`share@.
     244This aliasing relationship is a sticky-property established at initialization.
     245For example, here strings @s1@ and @s1a@ are in an aliasing relationship, while @s2@ is in a copy relationship.
    236246\input{sharing1.tex}
    237 
    238 Aliasing (@`shareEdits@) means that changes flow in both directions; with a simple copy, they do not.
     247Here, the aliasing (@`share@) causes partial changes (subscripting) to flow in both directions.
    239248\input{sharing2.tex}
    240 
    241 Assignment of a value is just a modification.
    242 The aliasing relationship is established at construction and is unaffected by assignment of a value.
     249Similarly for complete changes.
    243250\input{sharing3.tex}
    244251
    245 Assignment from a string is just assignment of a value.
    246 Whether of not the RHS participates in aliasing is irrelevant.  Any aliasing of the LHS is unaffected.
     252Because string assignment copies the value, RHS aliasing is irrelevant.
     253Hence, aliasing of the LHS is unaffected.
    247254\input{sharing4.tex}
    248255
    249 Consider new strings @s1_mid@ being an alias for a run in the middle of @s1@, along with @s2@, made by a simple copy from the middle of @s1@.
     256Now, consider string @s1_mid@ being an alias in the middle of @s1@, along with @s2@, made by a simple copy from the middle of @s1@.
    250257\input{sharing5.tex}
    251 
    252 Again, @`shareEdits@ passes changes in both directions; copy does not.
    253 Note the difference in index values, with the \emph{b} position being 1 in the longer string and 0 in the shorter strings.
    254 In the case of s1 aliasing with @s1_mid@, the very same character is being accessed by different positions.
     258Again, @`share@ passes changes in both directions; copy does not.
     259As a result, the index values for the position of @b@ are 1 in the longer string @"abcd"@ and 0 in the shorter aliased string @"bc"@.
     260This alternate positioning also applies to subscripting.
    255261\input{sharing6.tex}
    256262
    257 Once again, assignment of a value is a modification that flows through the aliasing relationship, without affecting its structure.
     263Finally, assignment flows through the aliasing relationship without affecting its structure.
    258264\input{sharing7.tex}
    259 
    260 In the \emph{ff} step, which is a positive example of flow across an aliasing relationship, the result is straightforward to accept because the flow direction is from contained (small) to containing (large).
    261 The following rules for edits through aliasing substrings will guide how to flow in the opposite direction.
    262 
    263 Growth and shrinkage are natural extensions.
    264 An empty substring is a real thing, at a well-defined location, whose meaning is extrapolated from the examples so far.
    265 The intended metaphor is to operating a GUI text editor.
    266 Having an aliasing substring is like using the mouse to select a few words.
    267 Assigning onto an aliasing substring is like typing from having a few words selected: depending how much you type, the file being edited can get shorter or longer.
     265In the @"ff"@ assignment, the result is straightforward to accept because the flow direction is from contained (small) to containing (large).
     266The following rules explain aliasing substrings that flow in the opposite direction, large to small.
     267
     268Growth and shrinkage are natural extensions, as for the text-editor example mentioned earlier, where an empty substring is as real real as an empty string.
    268269\input{sharing8.tex}
    269270
    270 Multiple portions can be aliased.
    271 When there are several aliasing substrings at once, the text editor analogy becomes an online multi-user editor.
    272 I should be able to edit a paragraph in one place (changing the document's length), without my edits affecting which letters are within a mouse-selection that you had made previously, somewhere else.
     271Multiple portions of a string can be aliased.
     272% When there are several aliasing substrings at once, the text editor analogy becomes an online multi-user editor.
     273%I should be able to edit a paragraph in one place (changing the document's length), without my edits affecting which letters are within a mouse-selection that you had made previously, somewhere else.
    273274\input{sharing9.tex}
    274 
    275 When an edit happens on an aliasing substring that overlaps another, an effect is unavoidable.
    276 Here, the passive party sees its selection shortened, to exclude the characters that were not part of the original selection.
     275When @s1_bgn@'s size increases by 3, @s1_mid@'s starting location moves from 1 to 4 and @s1_end@'s from 3 to 6,
     276
     277When changes happens on an aliasing substring that overlap.
    277278\input{sharing10.tex}
    278 
    279 TODO: finish typesetting the demo
     279Strings @s1_crs@ and @s1_mid@ overlap at character 4, @j@ because the substrings are 3,2 and 4,2.
     280When @s1_crs@'s size increases by 1, @s1_mid@'s starting location moves from 4 to 5, but the overlaping character remains, changing to @'+'@.
     281
     282\PAB{TODO: finish typesetting the demo}
    280283
    281284%\input{sharing-demo.tex}
Note: See TracChangeset for help on using the changeset viewer.