All pastes #2047254 Raw Edit

group-by-car

public text v1 · immutable
#2047254 ·published 2011-04-16 20:19 UTC
rendered paste body
(require 'cl)
(defun* group-by-car (pairs &key (test #'equal))
  "Group the values of pairs by their CARs."
  (loop with keys
        with data
        for (key value) in pairs
        for values = (cons value (assoc* key data :test test))
        do (pushnew key keys :test test)
        do (push (cons key values) data)
        finally return
        (loop for key in (nreverse keys)
              collect (assoc key data))))