Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why is Lisp not as popular as Python?

25 views
Skip to first unread message

Robert L.

unread,
Sep 16, 2017, 2:07:36 PM9/16/17
to
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
0 new messages