Hacker News new | ask | show | jobs
by mahmud 5279 days ago
Fairly idiomatic code. Just minor nitpick.

To traverse directories use fad:walk-directory from CL-FAD. It takes a starting directory and a single-argument function, then traversing that directory recursively calling the function with each child as an argument.

I wrote this earlier to count what languages I've used in 2011, because I didn't trust my cursory examination with ls(1).

  (let ((start-2011 (encode-universal-time 1 0 0 1 1 2011))
        (lang-stat (make-hash-table :test #'equalp)))
    (fad:walk-directory #p"~/hack" 
        (lambda (f)
  	(when (>= (file-write-date f) start-2011)
  	  (when-let (type (string-trim "~" (pathname-type f)))
  	    (incf (gethash type lang-stat 0))))))
    (loop for k in (sort (hash-table-keys lang-stat) #'string-lessp)
       do (format t "~a~10t~a~%" k (gethash k lang-stat 0))))