例如字符頻率,如果我輸入字符的序列發現在共同口齒不清
「世界你好」 H = 1個E = 1 L = 3 O - 2 R = 1 W = 1 d = 1
能有人幫我
我發現這個code在線,但我不明白我想要一個簡單的一個
(defun letter-freq (file)
(with-open-file (stream file)
(let ((str (make-string (file-length stream)))
(arr (make-array 256 :element-type 'integer :initial-element 0)))
(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
(format t "~c: ~d~a"
(code-char c) (aref arr c)
(if (zerop (rem i 8)) #\newline #\tab))))))
(letter-freq "test.lisp")
是的,我強烈推薦這本書。事實上,我幾乎沒有做過任何真正的CL編程,因爲我讀了那本書,所以我仍然可以理解引用的代碼。 – drysdam