Skip to content

Instantly share code, notes, and snippets.

@nerdyworm
Created November 5, 2011 21:37
Show Gist options
  • Save nerdyworm/1342055 to your computer and use it in GitHub Desktop.
Save nerdyworm/1342055 to your computer and use it in GitHub Desktop.
things all of them.
(defun letter-freq (str)
(let ((ht (make-hash-table)))
(loop :for char :across str :do
(incf (gethash char ht 0)))
(maphash (lambda (k v)
(format t "~@C: ~D~%" k v))
ht)))
(defun letter-freq-in-file (file)
(with-open-file (stream file)
(let ((str (make-string (file-length stream))))
(read-sequence str stream)
(letter-freq str))))
(letter-freq-in-file "test.txt")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment