Nice TWiki > Doc > MethcallIntermediateExample (r1.1 vs. r1.4) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic MethcallIntermediateExample (r1.4 - 24 Dec 2003 - IsaacGouy)
Changed:
<
<

activate(t@NToggle){

>
>

activate(NToggle t){


 <<O>>  Difference Topic MethcallIntermediateExample (r1.3 - 17 Sep 2003 - IsaacGouy)
Changed:
<
<

/* Please try the NoviceExamples? before the BeginnerExamples?

>
>

/* Please try the BeginnerExamples? before the IntermediateExamples?

Changed:
<
<

We've already created jar file toggle.jar containg the

>
>

We've already created jar file toggle.jar containing the

Changed:
<
<

import methcall_intermediate.*; // Java Toggle class

>
>

import java_toggle.*; // Java Toggle class


 <<O>>  Difference Topic MethcallIntermediateExample (r1.2 - 17 Sep 2003 - IsaacGouy)
Added:
>
>

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.

Changed:
<
<

nicec --classpath .. --sourcepath .. -a methcall.jar methcall_intermediate

>
>

\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

Changed:
<
<

java -jar methcall.jar 10

>
>

\methcall> java -jar methcall.jar 10

Changed:
<
<

let val = true;

>
>

var val = true;


 <<O>>  Difference Topic MethcallIntermediateExample (r1.1 - 30 Aug 2003 - IsaacGouy)
Added:
>
>

%META:TOPICINFO{author="IsaacGouy" date="1062254580" format="1.0" version="1.1"}% %META:TOPICPARENT{name="CodeExamples"}%

/* Please try the NoviceExamples before the BeginnerExamples
To compile:
   nicec --classpath .. --sourcepath .. -a methcall.jar methcall_intermediate
To run:
   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);

    let 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 . { View | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.1 - 30 Aug 2003 - 14:43 GMT - IsaacGouy
Revision r1.4 - 24 Dec 2003 - 21:36 GMT - IsaacGouy
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.