William James
8/29/2015 7:03:00 AM
Frank Buss wrote:
> (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))))
Gauche Scheme:
(define (file-byte-iterate file procedure)
(with-input-from-file file
(cut generator-for-each procedure read-byte)))
>
> (defun print-vector (vector)
> (loop for count across vector
> for i = 0 then (1+ i) do
> (format t "~a: ~a~%" i count)))
(define (print-vector vec)
(vector-for-each-with-index
(cut format #t "~a: ~a\n" <> <>)
vec))
>
> 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)))
(let1 counts (make-vector 256 0)
(file-byte-iterate "temp.bak" ($ inc! $ vector-ref counts $))
(print-vector counts))
--
The struggle of our time is to concentrate, not to dissipate: to renew our
association with traditional wisdom: to re-establish a vital connection between
the individual and the race. It is, in a word, a struggle against Liberalism.
--- T. S. Elliot