Nice TWiki > Doc > CodeExamples > MethcallIntermediateExample (r1.2) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before the BeginnerExamples

   We've already created jar file toggle.jar containg the 
   the java implementation of the Toggle class.
   Let's see how to compile Nice using classes in a Java jar
   and then how to reference that jar from the executable 
   jar containing the Nice program.

To compile:
   \methcall>nicec --sourcepath .. --classpath toggle.jar -a methcall.jar methcall
   nice.lang: parsing
   methcall: parsing
   methcall: typechecking
   methcall: generating code
   methcall: linking
   methcall: writing in archive
   nice.lang: writing in archive

Create toggle_classpath.txt file with contents
   Class-Path: ./ toggle.jar

Update manifest to include toggle.jar on classpath
   \methcall> jar umf toggle_classpath.txt methcall.jar

To run:
   \methcall> java -jar methcall.jar 10
*/


import methcall_intermediate.*; // Java Toggle class

class NToggle extends Toggle {
    int toggleTrigger = 0;
    int count = 0;
}


activate(t@NToggle){ 
    t.count++;
    if (t.count >= t.toggleTrigger){
        t.state = !t.state;
        t.count = 0;
    }
    return t; }


void main(String[] args){
    int n =  nTimes(args);

    var val = true;
    let toggle = new Toggle(true);
    for(int i=0; i<n; i++) {
       val = toggle.activate().value();
    }
    println(val);

    val = true;
    let ntoggle = new NToggle(true, toggleTrigger: 3);
    for(int i=0; i<n; i++) {
       val = ntoggle.activate().value();
    }
    println(val);
}


int nTimes(String[] s){
    try { return Integer.parseInt(s[0]); }
    catch (Exception e){ return 1; } }


/* Notes - language
Compare with Java at the "Win32 Language Shootout"

*/
-- IsaacGouy - 30 Aug 2003

Topic MethcallIntermediateExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.2 - 17 Sep 2003 - 18:16 GMT - IsaacGouy
Parents: WebHome > CodeExamples
Copyright © 1999-2003 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback.