Nice TWiki > Doc > MethcallBeginnerExample (r1.1 vs. r1.6) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
 <<O>>  Difference Topic MethcallBeginnerExample (r1.6 - 10 Jan 2004 - IsaacGouy)
Changed:
<
<

for(var i=1; i<n; i++) val = ntoggle.activate().value(); println( ntoggle.activate().value() );

>
>

for(var i=1; i<n; i++) val = ntoggle.activate.value; println( ntoggle.activate.value );

Added:
>
>

println( toggle.activate().value() ); println( ntoggle.activate.value ); When there are no parameters we don't need to use () in method calls (we do need to use them in constructors).

Added:
>
>


 <<O>>  Difference Topic MethcallBeginnerExample (r1.5 - 10 Jan 2004 - IsaacGouy)

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

public NToggle activate(){

>
>

activate(){


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

class Toggle { // define class Toggle

>
>

class Toggle {

Changed:
<
<

boolean value(); // declare method value Toggle activate(); // declare method activate }

>
>

public boolean value() = state;

Changed:
<
<

value(t@Toggle){ // implement method value return t.state;

>
>

public Toggle activate(){ state = !state; return this;

Deleted:
<
<

activate(t@Toggle){ // implement method activate t.state = !t.state; return t;

Changed:
<
<

class NToggle extends Toggle { // define subclass NToggle

>
>

class NToggle extends Toggle {

Deleted:
<
<

}

Changed:
<
<

activate(t@NToggle){ // override Toggle activate t.count++; if (t.count >= t.toggleTrigger){ t.state = !t.state; t.count = 0;

>
>

public NToggle activate(){ count++; if (count >= toggleTrigger){ state = !state; count = 0; } return this;

Deleted:
<
<

return t;


 <<O>>  Difference Topic MethcallBeginnerExample (r1.2 - 27 Aug 2003 - IsaacGouy)
Changed:
<
<

/* Please try the BeginnerExamples? before the NoviceExamples?

>
>

/* Please try the NoviceExamples? before the BeginnerExamples?

Added:
>
>

%META:TOPICMOVED{by="IsaacGouy" date="1062001833" from="Doc.MethcallNoviceExample" to="Doc.MethcallBeginnerExample"}%


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

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

/* Please try the BeginnerExamples before the NoviceExamples
To compile:
   nicec --sourcepath=.. -a methcall.jar methcall
To run:
   java -jar methcall.jar 1000000
*/


void main(String[] args){
   let n =  toSingleInt(args);
   boolean val;

   let toggle = new Toggle();
   for(var i=1; i<n; i++) val = toggle.activate().value();
   println( toggle.activate().value() );

   let ntoggle = new NToggle(toggleTrigger: 3);
   for(var i=1; i<n; i++) val = ntoggle.activate().value();
   println( ntoggle.activate().value() );
}



class Toggle {                  // define class Toggle       
   boolean state = true;        

   boolean value();             // declare method value
   Toggle activate();           // declare method activate
}

value(t@Toggle){                // implement method value 
   return t.state; 
}

activate(t@Toggle){             // implement method activate
   t.state = !t.state; 
   return t; 
}


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

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


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


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

*/
-- IsaacGouy - 27 Aug 2003

Topic MethcallBeginnerExample . { View | Diffs | r1.6 | > | r1.5 | > | r1.4 | More }
Revision r1.1 - 27 Aug 2003 - 00:16 GMT - IsaacGouy
Revision r1.6 - 10 Jan 2004 - 19:04 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.