Spell Checker Back to the Win32 Shootout
Back to dada's perl lab

[The Original Shootout]   [NEWS]   [FAQ]   [Methodology]   [Platform Details]   [Acknowledgements]   [Scorecard]  
All Source For Spell Checker
spellcheck.awka
# $Id: spellcheck.gawk,v 1.3 2001/05/20 06:13:00 doug Exp $
# http://www.bagley.org/~doug/shootout/

BEGIN {
    delete ARGV;
    while (getline < "Usr.Dict.Words") {
    dict[$0] = 1;
    }
}
{
    if (!dict[$1]) {
    print $1
    }
}
spellcheck.bcc
/* -*- mode: c -*-
 * $Id: spellcheck.gcc,v 1.7 2001/07/26 14:52:16 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Brad Knotwell
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define inline
#include "simple_hash.h"

#define MAXLINELEN 128

struct ht_ht *dict = NULL;

int handleInput(FILE *input,void (*hashManipFn)(char *))
{
    int wordbufsize = 80,i = 0;
    char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
    char line[MAXLINELEN];
    
    if((wordbuf = malloc(wordbufsize+1)) == NULL) 
        return(fprintf(stderr,"malloc\n"),0);

    while (fgets(line, MAXLINELEN, input))
    for (cp=line; *cp > 0; cp++) {
        if (isspace(*cp)) {
        if (i) {
            wordbuf[i] = '\0';
                    hashManipFn(wordbuf);
            i = 0;
        }
        } else {
        wordbuf[i++] = *cp;
        if (i == wordbufsize) {
            wordbufsize *= 2;
            if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
                        return(fprintf(stderr, "realloc\n"), 0);
        }
        }
        }

    free(wordbuf);
    return(1);
}

void spellCheck(char *key) { 
    if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
}

void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
 
int main(int argc, char *argv[]) {
    FILE *fh;
    int rc;

    /*  
        ht_create doesn't handle malloc and calloc failures 
        so this is superfluous 
    */
    if((dict = ht_create(40000)) == NULL)
        return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
    
    if ((fh = fopen("Usr.Dict.Words", "r")) == NULL) 
        return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);

    rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);

    ht_destroy(dict);
    return(rc);
}
spellcheck.cygperl
#!/usr/local/bin/perl
# $Id: spellcheck.perl,v 1.4 2001/01/23 01:30:42 doug Exp $
# http://www.bagley.org/~doug/shootout/

use strict;

# read dictionary
my %dict = ();
open(DICT, "<Usr.Dict.Words") or
    die "Error, unable to open Usr.Dict.Words\n";
while (<DICT>) {
    chomp;
    $dict{$_} = 1;
}
close(DICT);

while (<STDIN>) {
    chomp;
    print "$_\n" if (!$dict{$_});
}
spellcheck.erlang
%%% -*- mode: erlang -*-
%%% $Id: spellcheck.erlang,v 1.1 2001/05/26 05:05:04 doug Exp $
%%% http://www.bagley.org/~doug/shootout/

-module(spellcheck).
-export([main/0, main/1]).


main() -> main(['1']).
main(Args) ->
    % load dictionary into hash table (erlang ets table)
    Dict = load_dict(),
    % read words from stin and print those not in dictionary
    spell(Dict),
    halt(0).


load_dict() ->
    Dict = ets:new(i_am_a_carrot, [set]),
    {ok, In} = file:open("Usr.Dict.Words", [raw]),
    % I'm just guessing that the file opened above has fd=3
    % this is a total hack, but I could find nothing in the Erlang
    % documention on how to do this.
    Port = open_port({fd, 3, 1}, [eof, {line, 64}]),
    read_dict(Port, Dict),
    file:close(In),
    Dict.


load_dict_1() ->
    Dict = ets:new(i_am_a_carrot, [set]),
    %{ok, In} = file:open("Usr.Dict.Words", [read]),
    %Port = open_port({fd, ????, 1}, [eof, {line, 64}]),
    Port = open_port({spawn, "cat Usr.Dict.Words"}, [eof, {line, 64}]),
    read_dict(Port, Dict),
    %file:close(In),
    Dict.


read_dict(Port, Dict) ->
    receive
    {Port, {_, {_, Word}}} ->
        Atom = list_to_atom(Word),
        ets:insert(Dict, { Atom, 1 }),
        read_dict(Port, Dict);
    {Port, eof} -> ok
    end.


spell(Dict) ->
    Port = open_port({fd, 0, 1}, [eof, {line, 64}]),
    spell(Port, Dict).

spell(Port, Dict) ->
    receive
    {Port, {_, {_, Word}}} ->
        Atom = list_to_atom(Word),
        case ets:lookup(Dict, Atom) of
        [] -> io:format("~w~n",[Atom]);
        _  -> ok
        end,
        spell(Port, Dict);
    {Port, eof} -> ok
    end.
spellcheck.gawk
# $Id: spellcheck.gawk,v 1.3 2001/05/20 06:13:00 doug Exp $
# http://www.bagley.org/~doug/shootout/

BEGIN {
    delete ARGV;
    while (getline < "Usr.Dict.Words") {
    dict[$0] = 1;
    }
}
{
    if (!dict[$1]) {
    print $1
    }
}
spellcheck.gcc
/* -*- mode: c -*-
 * $Id: spellcheck.gcc,v 1.7 2001/07/26 14:52:16 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Brad Knotwell
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "simple_hash.h"

#define MAXLINELEN 128

struct ht_ht *dict = NULL;

int handleInput(FILE *input,void (*hashManipFn)(char *))
{
    int wordbufsize = 80,i = 0;
    char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
    char line[MAXLINELEN];
    
    if((wordbuf = malloc(wordbufsize+1)) == NULL) 
        return(fprintf(stderr,"malloc\n"),0);

    while (fgets(line, MAXLINELEN, input))
    for (cp=line; *cp > 0; cp++) {
        if (isspace(*cp)) {
        if (i) {
            wordbuf[i] = '\0';
                    hashManipFn(wordbuf);
            i = 0;
        }
        } else {
        wordbuf[i++] = *cp;
        if (i == wordbufsize) {
            wordbufsize *= 2;
            if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
                        return(fprintf(stderr, "realloc\n"), 0);
        }
        }
        }

    free(wordbuf);
    return(1);
}

void spellCheck(char *key) { 
    if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
}

void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
 
int main(int argc, char *argv[]) {
    FILE *fh;
    int rc;

    /*  
        ht_create doesn't handle malloc and calloc failures 
        so this is superfluous 
    */
    if((dict = ht_create(40000)) == NULL)
        return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
    
    if ((fh = fopen("Usr.Dict.Words", "r")) == NULL) 
        return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);

    rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);

    ht_destroy(dict);
    return(rc);
}
spellcheck.gforth
\ -*- mode: forth -*-
\ $Id: spellcheck.gforth,v 1.1 2001/05/26 15:47:18 doug Exp $
\ http://www.bagley.org/~doug/shootout/
\ from Anton Ertl

wordlist constant dict

32 constant max-word

create line max-word 2 + allot

: read-dict 
    get-current dict set-current
    s" Usr.Dict.Words" r/o open-file throw
    begin
    line max-word 2 pick read-line throw
    while
    line swap nextname create
    repeat
    2drop set-current ;

: spellcheck 
    begin
    line max-word 2 pick read-line throw
    while
    line swap 2dup dict search-wordlist if
        drop 2drop
    else
        type cr
    endif
    repeat
    2drop ;

read-dict stdin spellcheck bye
spellcheck.ghc
-- $Id: spellcheck.ghc,v 1.1 2001/03/02 15:46:08 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- from Julian Assange

-- compile with: ghc -O -package data

module Main(main) where
import FiniteMap(addToFM_C,emptyFM,elemFM)

addFM fm [] = fm
addFM fm (x:xs) = addFM (addToFM_C (\_ _ -> ()) fm x ()) xs

main = do
         d <- readFile "Usr.Dict.Words"
         interact $ unlines . filter (\x -> not $ elemFM x (addFM emptyFM (lines d))) . lines
spellcheck.guile
#!/usr/local/bin/guile \
-e main -s
!#

;;; $Id: spellcheck.guile,v 1.2 2001/06/29 23:12:37 doug Exp $
;;; http://www.bagley.org/~doug/shootout/

(use-modules (ice-9 format))

(define (main args)
  (let ((n (or (and (= (length args) 2) (string->;number (cadr args))) 1))
    (dict (make-hash-table 10000)))
    (with-input-from-file "Usr.Dict.Words"
      (lambda ()
    (let loop ((line (read-line)))
      (cond ((eof-object? line) #f)
        (else
         (hash-set! dict line #t)
         (loop (read-line)))))))
    (let loop ((word (read-line)))
      (cond ((eof-object? word) #f)
        (else
         (if (not (hash-ref dict word))
         (display (format "~A\n" word)))
         (loop (read-line)))))))
    
spellcheck.ici
// $Id: spellcheck.ici,v 1.0 2003/01/03 12:21:00 dada Exp $
// http://dada.perl.it/shootout
//
// contributed by Tim Long

dict := set();
forall (w in gettokens(fopen("Usr.Dict.Words"), "\n", ""))
    dict[w] = 1;

while (w = getline())
{
    if (!dict[w])
        printf("%s\n", w);
}
spellcheck.icon
# -*- mode: icon -*-
# $Id: spellcheck.icon,v 1.1 2001/01/28 03:20:33 doug Exp $
# http://www.bagley.org/~doug/shootout/

procedure main(argv)
    local dict
    n := argv[1] | 1
    dict := table(0)
    f := open("Usr.Dict.Words") | {
    write(&errout, "Can't open \"Usr.Dict.Words\"")
    fail
    }
    while line := read(f) do line ? {
    dict[line] := 1
    }
    close(f)
    while line := read() do line ? {
    if (not member(dict,line)) then {
        write(line)
    }
    }
end    


spellcheck.java
// $Id: spellcheck.java,v 1.2 2000/12/20 14:29:31 doug Exp $
// http://www.bagley.org/~doug/shootout/

import java.io.*;
import java.util.*;

public class spellcheck {
    public static void main(String args[]) throws IOException {
    int n = Integer.parseInt(args[0]);
    HashMap dict = new HashMap();
    String word;

    try {
        BufferedReader in = new BufferedReader(new FileReader("Usr.Dict.Words"));
        while ((word = in.readLine()) != null) {
        dict.put(word, new Integer(1));
        }
        in.close();
        } catch (IOException e) {
            System.err.println(e);
            return;
        }
    
    try {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while ((word = in.readLine()) != null) {
        if (!dict.containsKey(word)) {
            System.out.println(word);
        }
        }
        } catch (IOException e) {
            System.err.println(e);
            return;
        }
    }
}
spellcheck.lcc
/* -*- mode: c -*-
 * $Id: spellcheck.gcc,v 1.7 2001/07/26 14:52:16 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Brad Knotwell
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define inline
#include "simple_hash.h"

#define MAXLINELEN 128

struct ht_ht *dict = NULL;

int handleInput(FILE *input,void (*hashManipFn)(char *))
{
    int wordbufsize = 80,i = 0;
    char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
    char line[MAXLINELEN];
    
    if((wordbuf = malloc(wordbufsize+1)) == NULL) 
        return(fprintf(stderr,"malloc\n"),0);

    while (fgets(line, MAXLINELEN, input))
    for (cp=line; *cp > 0; cp++) {
        if (isspace(*cp)) {
        if (i) {
            wordbuf[i] = '\0';
                    hashManipFn(wordbuf);
            i = 0;
        }
        } else {
        wordbuf[i++] = *cp;
        if (i == wordbufsize) {
            wordbufsize *= 2;
            if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
                        return(fprintf(stderr, "realloc\n"), 0);
        }
        }
        }

    free(wordbuf);
    return(1);
}

void spellCheck(char *key) { 
    if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
}

void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
 
int main(int argc, char *argv[]) {
    FILE *fh;
    int rc;

    /*  
        ht_create doesn't handle malloc and calloc failures 
        so this is superfluous 
    */
    if((dict = ht_create(40000)) == NULL)
        return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
    
    if ((fh = fopen("Usr.Dict.Words", "r")) == NULL) 
        return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);

    rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);

    ht_destroy(dict);
    return(rc);
}
spellcheck.lua
-- $Id: spellcheck.lua,v 1.2 2001/01/23 01:30:42 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- based on code from Roberto Ierusalimschy

assert(readfrom("Usr.Dict.Words"))
local dict = {}
while 1 do
  local line = read()
  if line == nil then break end
  dict[line] = 1
end
readfrom()    -- closes dictionary

while 1 do
  local word = read()
  if word == nil then break end
  if not dict[word] then print(word) end
end
spellcheck.lua5
-- $Id: spellcheck.lua,v 1.2 2001/01/23 01:30:42 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- based on code from Roberto Ierusalimschy
-- contributed by Roberto Ierusalimschy

local dict = {}
for line in io.lines("Usr.Dict.Words") do
  dict[line] = true
end

for word in io.lines() do
  if not dict[word] then print(word) end
end

spellcheck.mawk
# $Id: spellcheck.mawk,v 1.2 2001/05/20 06:13:00 doug Exp $
# http://www.bagley.org/~doug/shootout/

BEGIN {
    delete ARGV;
    while (getline < "Usr.Dict.Words") {
    dict[$0] = 1;
    }
}
{
    if (!dict[$1]) {
    print $1
    }
}
spellcheck.mercury
% ---------------------------------------------------------------------------- %
% spellcheck.m
% Ralph Becket <rbeck@microsoft.com>
% Tue Jan  9 16:43:59 GMT 2001
% vim: ts=4 sw=4 et tw=0 wm=0 ff=unix
%
% ---------------------------------------------------------------------------- %

:- module mytest.

:- interface.

:- import_module io.



:- pred main(io__state, io__state).
:- mode main(di, uo) is det.



:- implementation.

:- import_module map, int, list, string, require, std_util, char.



:- type dict == map(string, unit).



main -->
    io__see("Usr.Dict.Words", Res),
    (   { Res = ok },           read_dictionary(map__init, Dict)
    ;   { Res = error(ErrNo) }, { error(io__error_message(ErrNo)) }
    ),
    io__seen,
    find_errors(Dict).



:- pred read_dictionary(dict, dict, io__state, io__state).
:- mode read_dictionary(in, out, di, uo) is det.

read_dictionary(D0, D) -->
    io__read_line_as_string(Result),
    (
        { Result = ok(Line) },
        { Words  = string__words(char__is_whitespace, Line) },
        { D1     = list__foldl(func(W, M) = M ^ elem(W) := unit, Words, D0) },
        read_dictionary(D1, D)
    ;
        { Result = eof },
        { D      = D0 }
    ;
        { Result = error(ErrNo) },
        { error(io__error_message(ErrNo)) }
    ).



:- pred find_errors(dict, io__state, io__state).
:- mode find_errors(in, di, uo) is det.

find_errors(D) -->
    io__read_line_as_string(Result),
    (
        { Result = ok(Line) },
        { Words  = string__words(char__is_whitespace, Line) },
        list__foldl(
            ( pred(S::in, di, uo) is det -->
                ( if { map__contains(D, S) }
                  then []
                  else io__write_string(S), io__nl
                )
            ),
            Words
        ),
        find_errors(D)
    ;
        { Result = eof }
    ;
        { Result = error(ErrNo) },
        { error(io__error_message(ErrNo)) }
    ).
spellcheck.mingw32
/* -*- mode: c -*-
 * $Id: spellcheck.gcc,v 1.7 2001/07/26 14:52:16 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Brad Knotwell
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "simple_hash.h"

#define MAXLINELEN 128

struct ht_ht *dict = NULL;

int handleInput(FILE *input,void (*hashManipFn)(char *))
{
    int wordbufsize = 80,i = 0;
    char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
    char line[MAXLINELEN];
    
    if((wordbuf = malloc(wordbufsize+1)) == NULL) 
        return(fprintf(stderr,"malloc\n"),0);

    while (fgets(line, MAXLINELEN, input))
    for (cp=line; *cp > 0; cp++) {
        if (isspace(*cp)) {
        if (i) {
            wordbuf[i] = '\0';
                    hashManipFn(wordbuf);
            i = 0;
        }
        } else {
        wordbuf[i++] = *cp;
        if (i == wordbufsize) {
            wordbufsize *= 2;
            if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
                        return(fprintf(stderr, "realloc\n"), 0);
        }
        }
        }

    free(wordbuf);
    return(1);
}

void spellCheck(char *key) { 
    if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
}

void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
 
int main(int argc, char *argv[]) {
    FILE *fh;
    int rc;

    /*  
        ht_create doesn't handle malloc and calloc failures 
        so this is superfluous 
    */
    if((dict = ht_create(40000)) == NULL)
        return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
    
    if ((fh = fopen("Usr.Dict.Words", "r")) == NULL) 
        return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);

    rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);

    ht_destroy(dict);
    return(rc);
}
spellcheck.nice
/* The Great Win32 Language Shootout http://dada.perl.it/shootout/ 
   contributed by Isaac Gouy (Nice novice)

To compile:	
   nicec --sourcepath=.. -d=. -a spellcheck.jar spellcheck

To run:
   java -jar spellcheck.jar < input.txt > out.txt
*/


import java.io.*;


void main(String[] args){
   HashMap dictionary = new HashMap();

   try {
      BufferedReader 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 {
      BufferedReader 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);
}
spellcheck.ocaml
(*
 * $Id: spellcheck.ocaml,v 1.7 2001/07/28 21:52:59 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Markus Mottl
 *)

let dict = Hashtbl.create 40000 and ic = open_in "Usr.Dict.Words" in
try while true do Hashtbl.add dict (input_line ic) true done
with End_of_file -> close_in ic;
let rec loop () =
  let word = input_line stdin in
  if not (Hashtbl.mem dict word) then print_endline word;
  loop () in
try loop () with End_of_file -> ()
spellcheck.ocamlb
(*
 * $Id: spellcheck.ocaml,v 1.7 2001/07/28 21:52:59 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Markus Mottl
 *)

let dict = Hashtbl.create 40000 and ic = open_in "Usr.Dict.Words" in
try while true do Hashtbl.add dict (input_line ic) true done
with End_of_file -> close_in ic;
let rec loop () =
  let word = input_line stdin in
  if not (Hashtbl.mem dict word) then print_endline word;
  loop () in
try loop () with End_of_file -> ()
spellcheck.perl
#!/usr/local/bin/perl
# $Id: spellcheck.perl,v 1.4 2001/01/23 01:30:42 doug Exp $
# http://www.bagley.org/~doug/shootout/

use strict;

# read dictionary
my %dict = ();
open(DICT, "<Usr.Dict.Words") or
    die "Error, unable to open Usr.Dict.Words\n";
while (<DICT>) {
    chomp;
    $dict{$_} = 1;
}
close(DICT);

while (<STDIN>) {
    chomp;
    print "$_\n" if (!$dict{$_});
}
spellcheck.php
#!/usr/local/bin/php -f<?php
/*
 $Id: spellcheck.php,v 1.1 2001/05/16 01:43:37 doug Exp $
 http://www.bagley.org/~doug/shootout/
*/
$dict = array();
$fd = fopen("Usr.Dict.Words", "r");
while (!feof ($fd)) { $dict[chop(fgets($fd, 1024))] = 1; }
fclose($fd);

$fd = fopen("php://stdin", "r");
while (!feof ($fd)) {
    $word = chop(fgets($fd, 1024));
    if (! $dict[$word]) {
    print "$word\n";
    }
}
fclose($fd);
?>
spellcheck.pike
#!/usr/local/bin/pike// -*- mode: pike -*-
// $Id: spellcheck.pike,v 1.5 2000/12/05 16:04:06 doug Exp $
// http://www.bagley.org/~doug/shootout/

void main() {
    array(string) a = Stdio.read_file("Usr.Dict.Words")/"\n";
    mapping dictionary = mkmapping(a, allocate(sizeof(a), 1));
    while (string word = Stdio.stdin.gets()) {
    if (!dictionary[word]) write("%s\n", word);
    }
}
spellcheck.poplisp
;;; -*- mode: lisp -*-
;;; $Id: spellcheck.cmucl,v 1.2 2001/06/22 15:25:17 doug Exp $
;;; http://www.bagley.org/~doug/shootout/

  (declare (optimize (speed 3) (debug 0) (safety 0)))
  (let* ((dict (make-hash-table :test 'equal :size 10000)))

    (with-open-file (dictfile "Usr.Dict.Words" :direction :input)
            (do ((line (read-line dictfile)
                   (read-line dictfile nil 'eof)))
            ((eq line 'eof))
              (setf (gethash line dict) t)))

    (do ((word (read-line *standard-input*)
           (read-line *standard-input* nil 'eof)))
    ((eq word 'eof))
      (if (not (gethash word dict))
      (write-line word))))
spellcheck.python
#!/usr/local/bin/python
# $Id: spellcheck.python,v 1.6 2001/05/15 22:22:37 doug Exp $
# http://www.bagley.org/~doug/shootout/
# From Fred Bremmer

import sys

def main():
    dict = {}
    dict_has_key = dict.has_key
    for line in open("Usr.Dict.Words").xreadlines():
        word = line[:-1]
        if word: dict[word] = 1

    for line in sys.stdin.xreadlines():
        word = line[:-1]
        if word:
            if not dict_has_key(word): print word

main()
spellcheck.ruby
#!/usr/local/bin/ruby
# -*- mode: ruby -*-
# $Id: spellcheck.ruby,v 1.6 2001/01/23 01:30:42 doug Exp $
# http://www.bagley.org/~doug/shootout/

dict = Hash.new
file = open("Usr.Dict.Words")
while file.gets()
    dict[$_.chomp!] = 1
end
file.close()

count = word = 0
while STDIN.gets()
    unless dict.has_key? $_.chomp!
    puts $_
    end
end
spellcheck.se
-- -*- mode: eiffel -*-
-- $Id: spellcheck.se,v 1.3 2001/05/23 18:24:46 doug Exp $
-- http://www.bagley.org/~doug/shootout/
-- from Steve Thompson

-- <LOC-OFF>
indexing
   description: "This class performs the spell check test" 
   author : Steve Thompson
   email  : "Steve_Thompson@prodigy.net"
   date   : February 18, 2001
   compile: "compile -clean -boost -no_split -O3 main.e -o main"
   run    : "main < Input"
-- <LOC-ON>

class SPELLCHECK

creation make
   
feature -- Creation
   
   make is
      do
     read_dictionary
     from
        std_input.read_line 
     until std_input.end_of_input loop
        if dictionary.has(std_input.last_string) = False then
           print(std_input.last_string + "%N")
        end
        std_input.read_line
     end 
      end -- make
   
feature -- Queries
   
   dictionary: DICTIONARY[INTEGER, STRING]
   
feature -- Commands
   
   read_dictionary is
      local
     file: STD_FILE_READ
     value: INTEGER 
      do
     value := 1
     from
        !!dictionary.with_capacity(60000)
        !!file.connect_to("Usr.Dict.Words")
     until
        file.end_of_input
     loop
        file.read_line
        dictionary.add(value, file.last_string)
     end
     file.disconnect
      end -- read_dictionary

end
spellcheck.slang
% $Id: spellcheck.slang,v 1.0 2003/01/03 14:46:00 dada Exp $
% http://dada.perl.it/shootout/
%
% contributed by John E. Davis

define main()
{
   variable dict = Assoc_Type[Int_Type, 0];
   
   foreach (fopen("Usr.Dict.Words", "r")) using ("line")
     {
    variable word = strtrim();
    dict[word] = 1;
     }

   foreach (stdin)
     {
    word = strtrim ();
    !if (dict[word])
      () = fprintf (stdout, "%s\n", word);
     }
}

main();
spellcheck.smlnj
(* -*- mode: sml -*-
 * $Id: spellcheck.smlnj,v 1.2 2001/07/09 00:25:28 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 *)

structure Test : sig
    val main : (string * string list) -> OS.Process.status
end = struct

open TextIO;

fun chop str = String.substring (str, 0, (String.size str) - 1);

fun spellcheck () =
    let
    val dict = HashTable.mkTable (HashString.hashString, op =) (40000, (Fail "not found"))
    in
    let val din = openIn "Usr.Dict.Words"
        fun init_dict din dict =
        ( HashTable.insert dict (chop (inputLine din), 1);
          init_dict din dict )
    in
        init_dict din dict
    end handle EndOfFile => ();

    let fun check_words dict =
        let val word = chop (inputLine stdIn) in
            case HashTable.find dict word of
            SOME _ => ()
              | NONE => (print word ; print "\n");
            check_words dict
        end
    in
        check_words dict
    end handle EndOfFile => ()
    end

fun atoi s = case Int.fromString s of SOME num => num | NONE => 0;

fun main(name, args) = 
    let
    val arg = hd(args @ ["1"])
    val num = atoi arg
    in
    spellcheck ();
    OS.Process.success
    end
end

val _ = SMLofNJ.exportFn("spellcheck", Test.main);
spellcheck.tcl
#!/usr/local/bin/tclsh
# $Id: spellcheck.tcl,v 1.9 2001/07/12 12:13:56 doug Exp $
# http://www.bagley.org/~doug/shootout/
# from: Miguel Sofer
# some modifications suggested by Kristoffer Lawson

proc main {} {
    set 1 [open "Usr.Dict.Words" r]
    foreach  2 [read $1 [file size "Usr.Dict.Words"]] {
    set $2 1
    }
    close $1

    fconfigure stdout -buffering full
    while {[gets stdin 1] >= 0} {
        if {[catch {set $1}]} {
            puts $1
        }
    }
}

main
spellcheck.vc
/* -*- mode: c -*-
 * $Id: spellcheck.gcc,v 1.7 2001/07/26 14:52:16 doug Exp $
 * http://www.bagley.org/~doug/shootout/
 * with help from Brad Knotwell
 */

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#define inline
#include "simple_hash.h"

#define MAXLINELEN 128

struct ht_ht *dict = NULL;

int handleInput(FILE *input,void (*hashManipFn)(char *))
{
    int wordbufsize = 80,i = 0;
    char *cp, *wordbuf = (char *)malloc(wordbufsize + 1);
    char line[MAXLINELEN];
    
    if((wordbuf = malloc(wordbufsize+1)) == NULL) 
        return(fprintf(stderr,"malloc\n"),0);

    while (fgets(line, MAXLINELEN, input))
    for (cp=line; *cp > 0; cp++) {
        if (isspace(*cp)) {
        if (i) {
            wordbuf[i] = '\0';
                    hashManipFn(wordbuf);
            i = 0;
        }
        } else {
        wordbuf[i++] = *cp;
        if (i == wordbufsize) {
            wordbufsize *= 2;
            if((wordbuf = realloc(wordbuf, wordbufsize + 1)) == NULL)
                        return(fprintf(stderr, "realloc\n"), 0);
        }
        }
        }

    free(wordbuf);
    return(1);
}

void spellCheck(char *key) { 
    if (ht_find_new(dict,key)->val != 1) printf("%s\n",key);
}

void hashLoad(char *key) { ht_find_new(dict,key)->val = 1; }
 
int main(int argc, char *argv[]) {
    FILE *fh;
    int rc;

    /*  
        ht_create doesn't handle malloc and calloc failures 
        so this is superfluous 
    */
    if((dict = ht_create(40000)) == NULL)
        return(fprintf(stderr,"hash creation failed\n"),EXIT_FAILURE);
    
    if ((fh = fopen("Usr.Dict.Words", "r")) == NULL) 
        return(fprintf(stderr,"couldn't open dictionary\n"),EXIT_FAILURE);

    rc = ((handleInput(fh,hashLoad) && handleInput(stdin,spellCheck)) ? EXIT_SUCCESS : EXIT_FAILURE);

    ht_destroy(dict);
    return(rc);
}