Better HN
topnewbestaskshowjobs
Log inSign up

vatine

1 karma · joined Mar 9, 2020 (6y ago) · 1 submissions

Submissions

comment 6y ago · link · parent

OTOH, a more idiomatic version would be (and I would consider using the loop facility to be idiomatic):

  (defun count (pair-list)
    (let ((hash (make-hash-table)))
      (loop for (val key) in pair-list
        do (incf (gethash key hash 0) val))
      (loop for key being the hash-key of hash
        collect (list (gethash key hash) key))))
This drops us from 10 to 7 lines, which is clearly shorter. But, it's also relatively simple to change it from summing a list of (<count> <key>) to a list of (<key> <count>), something that I genuinely can't comment on for the K version. I suspect it would be as simple as first doing a permutation on the input, and (if needed) un-permute the result.