Exemple #1
0
 std::ostream& sing(int day, int count) {
   return day ? count <= day ? sing(day, count + 1) << (count == 1 && day > 1 ? "and " : "")
                                                    << gift[count - 1] << '\n'
                             : sing(day - 1, 1) << "\nOn the "
                                                << day
                                                << " day of Christmas, "
                                                   "my true love gave to me:\n"
              : out;
 }
int main() {
  int bottles = 10;

  while(bottles) {
    sing(bottles);
    sing(bottles);
    printf("And if one green bottle should accidently fall,\nThere'd be ");
    sing(--bottles);
    printf("\n");
  }

  return 0;
}
Exemple #3
0
int main()
{ AddStreamRetain as(std::cerr); // ***
  LOG("start");

  std::string logFileName="tmp/messages.log";
  std::ofstream logFile(logFileName.c_str());
  bool logFileOk = !!logFile;

  { AddStreamRetain as_if(logFile,logFileOk); // ***
    LOG("open log file '" << logFileName << "': " << (logFileOk ? "ok" : "failed"));
      

    std::string songFileName="tmp/song.out";
    std::ofstream songFile(songFileName.c_str());
    bool songFileOk = !!songFile;
    LOG("open song file '" << songFileName << "': " << (songFileOk ? "ok" : "failed"));

    std::stringstream sout;

    { NullStreamRetain as; // stop precursion to ancestor retains
      { AddStreamRetain as_if(songFile,songFileOk); // ***
        { AddStreamRetain as(sout); // ***
           sing();
        }
      }
    }
    LOG("sung: " << sout.str());
  }

  LOG("finish");
  return 0;
}
Exemple #4
0
void update_lyrics()
{
  static int currentsong = 0, online = 0;
  if (currentsong > MAXSONGS)
    return;

  if (online < jukebox[currentsong].lines)
  {
    sing(jukebox[currentsong].lyrics[online]);
    online++;
  }
  else /* The song is done */
  {     
   if (!jukefront)
   {
      if (MAXSONGS >=0)
        currentsong = number(0, MAXSONGS);
   }
   else 
   {
     struct jukeboxrequest *temp = jukefront; 
     currentsong = jukefront->songnum;
     jukefront = jukefront->next;  /* Dequeue! */
     free(temp);
    /* memset((char *) temp, 0, sizeof(struct jukeboxrequest));*/

   }       
  }
}
int
main()
{
    cuex_init();
//    cuex_t e1 = cuex_var_new_e();
//    cuex_t e2 = cuex_var_new_e();

    _0 = cuex_hole(0);
    _1 = cuex_hole(1);
    _2 = cuex_hole(2);
    _3 = cuex_hole(3);
    _10 = cuex_hole(10);

    test(cuex_o1_mu(cuex_o2_apply(cuex_o1_lambda(_10),
				  cuex_o1_mu(cuex_o2_apply(_0, cuex_o2_apply(_1, _2))))));
    test(L(M(apply(_0, _1))));
    test(L(M(L(apply(_0, apply(_1, _2))))));
    //test(M(sing(M(gprod(M(_2), L(M(_3)))))));
    test(M(L(M(_2))));
    test(L(gprod(M(L(gprod(_1, _0))), _0)));
    test(L(gprod(_0, M(L(gprod(_0, _1))))));
    test(L(M(gprod(M(sing(L(M(sing(_2))))), M(sing(_2))))));
//    test(gprod(M(gprod(_0, L(M(sing (gprod(_1, _0)))))),
//	       L(M(sing(gprod(_1, _0))))));
    test(gprod(M(gprod(_0, L(M(gprod(_1, _0))))),
	       L(M(gprod(_1, _0)))));
    test(L(L(gprod(M(gprod(_0, _2)), _0))));

// CU_SEED48=1181758125
//    test(L(M(gprod(gprod(L(gprod(e1, M(gprod(_0, _2)))),
//			       M(gprod(_0, _2))),
//			 L(e2)))));
    test(L(M(gprod(L(M(gprod(_0, _2))), M(gprod(_0, _2))))));
    // need to encode the level difference between μ-bind in μ-contexts
    // cuex_o2_meta_mupath:leveldiff(HEAD_SEQ, LAST_COMP)
    
    test(L(gprod(_0, M(sing(L(L(M(gprod(gprod(_1, _3), _0)))))))));
    return 0;
}