(let (c accumulator (counts (make-hash-table :test #'equal)))
(handler-case
(loop
(setq c (read-char))
(if (find c "ABCDEFGHIJKLMNOPQRSTUVWXYZ" :test #'char-equal)
(push (char-downcase c) accumulator)
(when accumulator
(incf (gethash (coerce (reverse accumulator) 'string) counts 0))
(setq accumulator nil))))
(end-of-file ()
(when accumulator
(incf (gethash (coerce (reverse accumulator) 'string) counts 0))
(setq accumulator nil))
(maphash #'(lambda (word count)
(push (list count word) accumulator))
counts)
(format t "~{~&~{~a ~a~}~%~}" (reverse (last (sort accumulator #'< :key #'car)
(let ((n (second sb-ext:*posix-argv*)))
(if n (parse-integer n) 100))))))))
It’s not exactly pretty or idiomatic, but its 19 lines appear to get the job done.
Firefox does this when I type in a URL and the server is down. I absolutely hate this behaviour, because I run a bunch of services inside my network.
If I tell my browser ‘fetch http://site.example,’ I mean for it to connect to site.example on HTTP on port 80 nothing more. If there is a web server run ning which wants to redirect me to https://site.example, awesome, but my browser should never assume I mean anything I did not say.)