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

f.foreach(String word => { dictionary.put(word, 1); }); f.close();

>
>

f.foreach(String word => { dictionary[word] = 1; }); f.close;

Changed:
<
<

while ((s = r.readLine()) != null) expr(s);

>
>

while ((s = r.readLine) != null) expr(s);

Changed:
<
<

f.foreach(String word => { dictionary.put(word, 1);} );

>
>

f.foreach(String word => { dictionary[word] = 1; });


 <<O>>  Difference Topic SpellcheckBeginnerExample (r1.3 - 10 Jan 2004 - IsaacGouy)

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

java -jar spellcheck.jar < input.txt > out.txt

>
>

java -jar spellcheck.jar < input.txt


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

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

/* Please try the NoviceExamples before the BeginnerExamples
To compile:
   nicec --sourcepath=.. -a spellcheck.jar spellcheck
To run:
   java -jar spellcheck.jar < input.txt > out.txt
*/

import java.io.*;

void main(String[] args){
   HashMap<String,int> dictionary = new HashMap();

   try {
      let f = new BufferedReader(new FileReader("Usr.Dict.Words"));
      f.foreach(String word => { dictionary.put(word, 1); });
      f.close();
   } 
   catch (IOException e) { 
      System.err.println(e); 
      return; 
   }

   try {
      let r = new BufferedReader(new InputStreamReader(System.in));
      r.foreach(String word => { 
         if (!dictionary.containsKey(word)) println(word); });
   } 
   catch (IOException e) { 
      System.err.println(e); 
   }
}


void foreach(BufferedReader r, String -> void expr) { 
   ?String s;
   while ((s = r.readLine()) != null) expr(s);
}


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

   f.foreach(String word => { dictionary.put(word, 1);} );
Method foreach takes a function as a parameter, and in this call
the function is defined inline - it's an anonymous function.

*/
-- IsaacGouy - 27 Aug 2003 %META:TOPICMOVED{by="IsaacGouy" date="1062001469" from="Doc.SpellcheckNoviceExample" to="Doc.SpellcheckBeginnerExample"}%

Topic SpellcheckBeginnerExample . { View | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.1 - 27 Aug 2003 - 16:23 GMT - IsaacGouy
Revision r1.4 - 10 Jan 2004 - 19:06 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.