Subject: Re: Why is Lisp not as popular as Python?
From: rpw3@rpw3.org (Rob Warnock)
Date: Thu, 28 Apr 2005 05:26:17 -0500
Newsgroups: comp.lang.lisp
Message-ID: <eMSdnV4uKY3UJ-3fRVn-3w@speakeasy.net>
Andr� Thieme  <address.good.until.2005.may.16@justmail.de> wrote:
+---------------
| I once wrote a program (in Python) that reads a file and counts how 
| often each byte between 0 and 255 occurs. It then printed the results 
| like that:
| 0: 417
| 1: 120
...
| With this tool I wanted to get an evidence how compressed a file is. 
| This "program" was a 3-liner. How can I do it in max. 3 lines in Lisp?
+---------------

It's quite easy in 4 lines of CL; is that good enough?

    (with-open-file (s "file.name" :element-type '(unsigned-byte 8))
      (let ((counts (make-array 256 :initial-element 0)))
	(loop for b = (read-byte s nil) while b do (incf (aref counts b)))
	(loop for b below 256 do (format t "~d: ~d~%" b (aref counts b)))))


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607