Nice TWiki > Doc > CodeExamples > SpellcheckBeginnerExample (r1.3) TWiki webs:
Dev | Doc | Main | TWiki | Sandbox
Doc . { Changes | Index | Search | Go }
/* Please try the NoviceExamples before the BeginnerExamples
To compile:
   nicec --sourcepath=.. -a spellcheck.jar spellcheck
To run:
   java -jar spellcheck.jar < input.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

Topic SpellcheckBeginnerExample . { Edit | Attach | Ref-By | Printable | Diffs | r1.4 | > | r1.3 | > | r1.2 | More }
Revision r1.3 - 10 Jan 2004 - 15:46 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.

Doc.SpellcheckBeginnerExample moved from Doc.SpellcheckNoviceExample on 27 Aug 2003 - 16:24 by IsaacGouy - put it back