#include #include #include #include forall( [C], [S] ) $\C{// num courses, num students}$ struct School { @array@( string, C ) course_codes; $\C{// nested VLAs}$ @array@( string, S ) student_ids; @array@( int, C, S ) preferences; $\C{// multidimensional}$ }; forall( [C], [S] ) int getPref( @School( C, S ) & school@, int is, int pref ) { for ( ic; C ) { int curPref = @school.preferences@[ic][is]; $\C{// offset calculation implicit}$ if ( curPref == pref ) return ic; } assert( false ); } int main() { int nc, ns; sin | nc | " courses,"; sin | ns | " students"; @School( nc, ns ) school;@ // ... elided: read data into school { string sv; int iv; // headers' row sin | "\nc\\s"; for ( is ; ns ) { // column label sin | sv; school.student_ids[is] = sv; } // body rows for ( ic ; nc ) { // row label sin | sv; school.course_codes[ic] = sv; for ( is ; ns ) { // matrix item sin | iv; school.preferences[ic][is] = iv; } } } for ( is; ns ) { sout | school.student_ids[is] | ": " | nonl; for ( pref; 1 ~= nc ) { int ic = getPref(school, is, pref); sout | school.course_codes[ ic ] | nonl; } sout | nl; } } // Local Variables: // // compile-command: "sed -f sedcmd hello-accordion.cfa > ../build/tmp.cfa; cfa ../build/tmp.cfa -Wall -Wextra" // // End: //