[plt-scheme] help with higher order functions

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Mar 18 10:42:51 EDT 2009

What is the proper Scheme idiom to write this function?

;; add-lists: (listof number) (listof number) -> (listof number)
;; consumes: two lists of numbers
;; produces: the item-wise sum (ala vector addition)
(define (add-lists l1 l2)
  (cond
    [(empty? l1) empty]
    [(cons? l1) (cons (+ (first l1) (first l2))
                             (add-list (rest l1) (rest l2)))]))

I guess what I want is something like a zip function. There must be a
standard way to process lists in parallel, but I don't know what it
is.

Todd

P.S. Still working on the nifty assignment. I got distracted by
figuring out how to do bitmaps.


Posted on the users mailing list.