RosettaCodeData/Task/Letter-frequency/Common-Lisp/letter-frequency.lisp

13 lines
467 B
Common Lisp
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
(defun letter-freq (file)
(with-open-file (stream file)
(let ((str (make-string (file-length stream)))
2026-04-30 12:34:36 -04:00
(arr (make-array 256 :element-type 'integer :initial-element 0)))
2023-07-01 11:58:00 -04:00
(read-sequence str stream)
(loop for c across str do (incf (aref arr (char-code c))))
(loop for c from 32 to 126 for i from 1 do
2026-04-30 12:34:36 -04:00
(format t "~c: ~d~a"
(code-char c) (aref arr c)
(if (zerop (rem i 8)) #\newline #\tab))))))
2023-07-01 11:58:00 -04:00
(letter-freq "test.lisp")