How can Scheme's Map function be used to pass two lists to a single function?

3.8k views Asked by At

I have a question about Scheme. I am fairly new to the language, and my question is fairly general:

Is it possible, without defining a recursive function, to use Map (or something like it) to feed two lists of parameters into a function, producing a single new list from the outputs?

For instance, suppose I had:

(define lst1 (list 1 2 3 4 5))
(define lst2 (list 2 4 6 8 10))

And I wanted to then somehow map the + function, supplying each list as a parameter such that the output would be a new list, lst3:

>lst3
(3 6 9 12 15)

To state the question somewhat more succinctly: how might one most efficiently map a binary function when both parameters are lists?

Thanks for any and all help!

1

There are 1 answers

1
leppie On BEST ANSWER
(map + lst1 lst2)

MAP can take any number of lists.

Example:

(map + lst1 lst2 lst1) => (4 8 12 16 20)