Frank Buss wrote:
> but you can tweak Lisp to be optimized for such tasks. For example if you
> add:
>
> (defmacro file-byte-iterate (file byte &body body)
> (let ((s (gensym)))
> `(with-open-file (,s ,file :element-type 'unsigned-byte)
> (loop for ,byte = (read-byte ,s nil)
> until (eql ,byte nil)
> do ,@body))))
>
> (defun print-vector (vector)
> (loop for count across vector
> for i = 0 then (1+ i) do
> (format t "~a: ~a~%" i count)))
>
> then the code is three lines:
>
> (let ((counts (make-array 256 :initial-element 0)))
> (file-byte-iterate "my-file" byte (incf (aref counts byte)))
> (print-vector counts)))
(require srfi/42) ; do-ec
(let ((v (make-vector 256 0)))
(call-with-input-file "data-file"
(lambda (port)
(do-ec (:port byte port read-byte)
(dict-update! v byte add1))))
(do-ec (: byte (index i) v) (printf "~a: ~a~%" i byte)))
--
Africans gang-rape and clitorectomize Finnish girl; government arrests Finn whom
they accuse of complaining:
http://www.wvwnews.net/story.php?id=6746