Changeset caa3e2c for doc/theses/mike_brooks_MMath/programs
- Timestamp:
- Jul 29, 2024, 9:49:07 AM (8 months ago)
- Branches:
- master
- Children:
- b67d7a5b
- Parents:
- b8e047a
- Location:
- doc/theses/mike_brooks_MMath/programs
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified doc/theses/mike_brooks_MMath/programs/hello-accordion.cfa ¶
rb8e047a rcaa3e2c 9 9 10 10 forall( T, @[NprovTerty]@, @[Nmunicipalities]@ ) 11 struct Can adaPop {11 struct CanPop { 12 12 array( T, @NprovTerty@ ) provTerty; $\C{// nested VLA}$ 13 13 array( T, @Nmunicipalities@ ) municipalities; $\C{// nested VLA}$ … … 19 19 20 20 forall( T, [NprovTerty], [Nmunicipalities] ) 21 void ?{}( T &, Can adaPop( T, NprovTerty, Nmunicipalities ) & this ) {}21 void ?{}( T &, CanPop( T, NprovTerty, Nmunicipalities ) & this ) {} 22 22 23 23 forall( T &, [NprovTerty], [Nmunicipalities] ) 24 void ^?{}( Can adaPop( T, NprovTerty, Nmunicipalities ) & this ) {}24 void ^?{}( CanPop( T, NprovTerty, Nmunicipalities ) & this ) {} 25 25 26 26 … … 39 39 40 40 forall( T, [NprovTerty], [Nmunicipalities] ) 41 void check( Can adaPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) {41 void check( CanPop( T, NprovTerty, Nmunicipalities ) & pop ) with( pop ) { 42 42 total_pt = total_mun = 0; 43 43 for ( i; NprovTerty ) total_pt += provTerty[i]; … … 60 60 int main( int argc, char * argv[] ) { 61 61 const int npt = ato( argv[1] ), nmun = ato( argv[2] ); 62 @Can adaPop( int, npt, nmun ) pop;@62 @CanPop( int, npt, nmun ) pop;@ 63 63 // read in population numbers 64 64 @check( pop );@ … … 71 71 Total province/territory: 36,991,981 72 72 Total municipalities: 36,991,981 73 $\$$ ./a.out 13 3654 74 Total province/territory: 36,991,981 75 Total municipalities: 36,991,981 73 76 */ 74 77 -
TabularUnified doc/theses/mike_brooks_MMath/programs/hello-array.cfa ¶
rb8e047a rcaa3e2c 9 9 10 10 forall( [@N@] ) $\C{// array dimension}$ 11 array( bool, @N@ ) & f( array( float, @N@ ) & x, array( float, @N@ ) & y ) {11 array( bool, @N@ ) & f( array( float, @N@ ) & x, array( float, @N@ ) & y ) { 12 12 array( bool, @N@ ) & ret = *@alloc@(); $\C{// sizeof ret used by alloc}$ 13 13 for ( i; @N@ ) { … … 29 29 30 30 int main( int argc, char * argv[] ) { 31 const int @ n@ = ato( argv[1] );$\C{// deduce conversion type}$32 array( float, @ n@ ) x, y; $\C{// VLAs}$33 for ( i; n ) {$\C{// initialize arrays}$31 const int @dim@ = ato( argv[1] ); $\C{// deduce conversion type}$ 32 array( float, @dim@ ) x, y; $\C{// VLAs}$ 33 for ( i; dim ) { $\C{// initialize arrays}$ 34 34 x[i] = 3.14 / (i + 1); 35 35 y[i] = x[i] + 0.005 ; 36 36 } 37 array( bool, @ n@ ) & result = @f( x, y )@; $\C{// call}$37 array( bool, @dim@ ) & result = @f( x, y )@; $\C{// call}$ 38 38 sout | "result: " | nonl; $\C{// print result}$ 39 for ( i; n)39 for ( i; dim ) 40 40 sout | result[i] | nonl; 41 41 sout | nl; -
TabularUnified doc/theses/mike_brooks_MMath/programs/hello-md.cfa ¶
rb8e047a rcaa3e2c 138 138 139 139 140 print1d_cstyle( m[ 2 ]); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$140 print1d_cstyle( @m[ 2 ]@ ); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ 141 141 142 142
Note: See TracChangeset
for help on using the changeset viewer.