Mapreduce in Lisp


(defun mapreduce (mapfn reducefn lst)
  (let (db keylist)
    (dolist (item lst)
      (dolist (resitem (funcall mapfn item))
        (or (setq keylist
                  (assoc (first resitem) db
                         :test 'equal))
            (push (setq keylist
                        (list (first resitem)))
                  db))
        (push (second resitem) (rest keylist)) ) )
    (mapcar #'(lambda (keylist)
                (list (first keylist)
                      (reduce reducefn
                              (rest keylist))))
            db) ))

>(mapreduce 'identity '+ '(((a 3) (b 2) (c 1))
                           ((b 7) (d 3) (c 5))))

((D 3) (C 6) (B 9) (A 3))

Contents    Page-10    Prev    Next    Page+10    Index