Changeset 720eec9 for doc/theses/mike_brooks_MMath/programs
- Timestamp:
- Oct 25, 2024, 4:09:56 PM (5 months ago)
- Branches:
- master
- Children:
- 33474e6
- Parents:
- d031f7f
- Location:
- doc/theses/mike_brooks_MMath/programs
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa ¶
rd031f7f r720eec9 39 39 40 40 forall( [C], [S] ) 41 void init( @School( C, S ) & classes@, int class, int student, int pref ) with( classes) {42 classIds[class] = class; $\C{// handle dynamic offsets of fields within structure}$43 s tudentIds[student] = student;44 preferences[class][student] = pref;41 void put( @School( C, S ) & s@, int class, int student, int pref ) { 42 s.classIds[class] = class; $\C{// fields' offsets are dynamic }$ 43 s.studentIds[student] = student; 44 s.preferences[class][student] = pref; 45 45 } 46 46 … … 62 62 sin | classes | students; 63 63 @School( classes, students ) school;@ 64 int class, student, preference;65 // read data into school calling init66 // for each student's class/preferences67 try {68 for ( ) {69 sin | class | student | preference;70 init( school, class, student, preference );71 }72 } catch( end_of_file * ) {}64 // elided: read data into school, calling put 65 { int class, student, preference; 66 // for each student's class/preferences 67 try { 68 for ( ) { 69 sin | class | student | preference; 70 put( school, class, student, preference ); 71 } 72 } catch( end_of_file * ) {} } 73 73 for ( s; students ) { 74 74 sout | "student" | s | nonl; -
TabularUnified doc/theses/mike_brooks_MMath/programs/hello-array.cfa ¶
rd031f7f r720eec9 49 49 */ 50 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 #ifdef SHOWERR1 65 51 66 void fred() { 67 68 69 70 array( float, @10@ ) x; 71 array( float, @20@ ) y; 72 f( x, x ); $\C[0.5in]{// ok}$ 73 f( y, y ); $\C{// ok}$ 74 f( x, y ); $\C{// error}\CRT$ 75 76 77 78 79 } 80 81 82 83 84 85 86 87 88 89 90 forall( [M], [N] ) 91 void bad( array(float, M) &x, 92 array(float, N) &y ) { 93 f( x, x ); $\C[0.5in]{// ok}$ 94 f( y, y ); $\C{// ok}$ 95 96 f( x, y ); $\C{// error}\CRT$ 97 } 98 99 #endif 100 101 102 103 104 105 106 107 108 109 110 forall( [M], [N] ) 111 void bad_fixed( array( float, M ) & x, 112 array( float, N ) & y ) { 113 f( x, x ); $\C[0.5in]{// ok}$ 114 f( y, y ); $\C{// ok}$ 115 if ( M == N ) 116 f( x, @(array( float, M ) &)@y ); $\C{// ok}$ 117 } 118 119 120 121 122 123 124 void fred_ok_only() { 52 125 array( float, @10@ ) x; 53 126 array( float, @20@ ) y; … … 57 130 } 58 131 59 #ifdef SHOWERR160 forall( [M], [N] )61 void bad( array(float, M) &x, array(float, N) &y ) {62 f( x, x ); $\C[1.5in]{// ok}$63 f( y, y ); $\C{// ok}$64 f( x, y ); $\C{// error}\CRT$65 }66 #endif67 68 69 132 70 133 forall( [M], [N] ) 71 void bad_fixed( array( float, M ) & x, array( float, N ) & y ) { 72 if ( M == N ) 73 f( x, @(array( float, M ) &)@y ); $\C{// cast y to matching type}$ 134 void bad_ok_only( array(float, M) &x, 135 array(float, N) &y ) { 136 f( x, x ); 137 f( y, y ); 138 139 // f( x, y ); 74 140 } 141 75 142 76 143 // Local Variables: //
Note: See TracChangeset
for help on using the changeset viewer.