MapReduce Example


(defun nutrition (food)
  (rest (assoc food
    '((hamburger (calories 80) (fat 8)
                 (protein 20))
      (bun (calories 200) (carbs 40) (protein 8)
           (fiber 4))
      (cheese (calories 100) (fat 15) (sodium 150))
      (lettuce (calories 10) (fiber 2))
      (tomato (calories 20) (fiber 2))
      (mayo (calories 40) (fat 5) (sodium 20)) ) )))

>(nutrition 'bun)

((CALORIES 200) (CARBS 40) (PROTEIN 8) (FIBER 4))

>(mapreduce 'nutrition '+ '(hamburger bun cheese
                            lettuce tomato mayo))

((SODIUM 170) (FIBER 8) (CARBS 40) (PROTEIN 28)
 (FAT 28) (CALORIES 450))

Contents    Page-10    Prev    Next    Page+10    Index