Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Right, this came up a year ago with a version that ranks among the top here: https://news.ycombinator.com/item?id=26465857

  (defmethod performance-count ((path-file string))
    (let ((map (make-hash-table :test 'equal)))
      (with-open-file (stream path-file :direction :input :if-does-not-exist nil)
        (when stream
          (loop for line = (read-line stream nil 'end)
         until (eq line 'end)
         do
         (let ((split (split-string #\space (string-downcase line))))
           (dolist (word split)
      (let ((index (gethash word map)))
        (if index
            (setf (gethash word map) (incf index))
          (setf (gethash word map) 1))))))
          (let ((keys (sort (alexandria:hash-table-keys map) 
  (lambda(x y)(> (gethash x map)(gethash y map))))))
     (dolist (key keys)
       (format t "~A ~A~%" key (gethash key map))))))))


You don't need those extra newlines if you'd prefix every code line with two spaces, by the way. It makes it much more readable if you do that.


Nice! I didn't know that trick.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: