Question

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!

Was it helpful?

Solution

(map + lst1 lst2)

MAP can take any number of lists.

Example:

(map + lst1 lst2 lst1) => (4 8 12 16 20)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top