#!/usr/bin/newlisp

; create a context/namespace to hold words

; since version 8.8 newLISP has a built in function
; bayes-query, which will do the counting in just
; one statement and much faster

(context 'wc)
(context MAIN)

(define (main)
;;	(HASH:make 'wc)

	(while (read-line)
		(set 'data (parse (lower-case (current-line)) "[^a-z]+" 0))
		(dolist (w data)
			(if (set 'result (eval (symbol (append "_" w) wc) ))
				(set (symbol (append "_" w) wc) (+ result 1))
				(set (symbol (append "_" w) wc) 1))))

	(dolist (w (symbols wc))
		(set 'wrd (name w))
		(if (and (starts-with wrd "_") (!= "_" wrd))
			(push (list (eval w) (slice wrd 1) ) words) ))

	(dolist (w (reverse (sort words)))
		(println (format "%7d %s" (first w) (last w))))
	)

(main)

;; eof


syntax highlighting with newLISP and syntax.cgi