Dictionary Example

The Dictionary Problem describes the story that led to its creation. In this example, we translate the solution to TL. First we translate the simple word file to an XML file. Next, the template (Example 1-5) is translated to TL and extended with a test stub.

dictionary.template
public class Dictionary {

	String[] words = {
	#for  "//word"#
		"#"."#",
	#end#
	};

	boolean isWord(String w) {
		for (int j=0; j<words.length; ++j) {
			if (w.equals(words[j])) {
				return true;
			}
		}
		return false;
	}

	public static void main(String[] args) {
		Dictionary d = new Dictionary();
		for (int j=0; j<args.length; ++j) {
			System.out.println(args[j]
				+" is "+(d.isWord(args[j])?"":"not ")
				+"in the dictionary.");
		}
	}
}