# How can i use 'map' with a procedure on a list of lists

**URL:** <https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251>\
**Category:** General\
**Created:** [August 26, 2023, 10:16am UTC](https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251 "2023-08-26T10:16:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [August 26, 2023, 10:16am UTC](https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251/1 "2023-08-26T10:16:23Z")

</div>

example :

(map + (list 1 2) (list 3 4) (list 5 6))

(9 12)

suppose now i have a list : (list (list 1 2) (list 3 4) (list 5 6))

and i want to do the same with the elements of the list, how can i do?

note here i have 3 elements in ((list 1 2) (list 3 4) (list 5 6)) but the solution must works for any number of elements.

i can not find a solution to this problem in Scheme ,and it is not the first time i have this problem.

this is really a problem in scheme, for this reason some,srfi give methods working both on elements and on container containing the elements (vector or list)  
example:

`(array-ref array k ...)`  
`(array-ref array index)`  
Returns the contents of the element of array at index k .... The sequence k ... must be a valid index to array. In the second form, index must be either a vector or a 0-based 1-dimensional array containing k

in [SRFI 25: Multi-dimensional Array Primitives](https://srfi.schemers.org/srfi-25/srfi-25.html)

what i want to do is a sum of lists taking advantage of the n-arity of + operator......

presented differently, i have a list of elements (e1 e2 ... eN) in scheme and i want to do  
(map + e1 e2 ... eN)

eN being a list of numbers ,each eN of the same length

if i remember ,for example Kawa scheme allow unsplicing @lst outside of a back-quote  
but this non standart

---

<div class="post-metadata">

**Author:** ![jimpjorps](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jimpjorps/32/140_2.png) [@jimpjorps](https://racket.discourse.group/u/jimpjorps)\
**Post date:** [August 26, 2023, 10:54am UTC](https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251/2 "2023-08-26T10:54:16Z")

</div>

Unless I'm misunderstanding what you're asking, it looks like `apply` is what you want:

```scheme
> (define xss (list (list 1 2)
                    (list 3 4)
                    (list 5 6)))
> (apply map + xss)
'(9 12)

```

---

<div class="post-metadata">

**Author:** ![damien\_mattei](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/damien_mattei/32/2706_2.png) [@damien\_mattei](https://racket.discourse.group/u/damien_mattei)\
**Post date:** [August 26, 2023, 11:53am UTC](https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251/3 "2023-08-26T11:53:12Z")

</div>

yes ,thank you

i should have find that myself 😢

but why apply accepts map + ?  
anyway i should have found this solution:

```scheme
(define xss2 (cons + xss))
(apply map xss2)
(9 12)

```

---

<div class="post-metadata">

**Author:** ![jimpjorps](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jimpjorps/32/140_2.png) [@jimpjorps](https://racket.discourse.group/u/jimpjorps)\
**Post date:** [August 26, 2023, 12:01pm UTC](https://racket.discourse.group/t/how-can-i-use-map-with-a-procedure-on-a-list-of-lists/2251/4 "2023-08-26T12:01:56Z")

</div>

[The Racket Guide's section on functions](https://docs.racket-lang.org/guide/application.html#%28part._apply%29) has a good write-up of what `apply` does.

In short, `(apply f (list a b c))` is equivalent to `(f a b c)`. It takes the list elements and gives them to the function as its arguments.

You can give `apply` additional arguments between the function and the list: `(apply f x (list a b c))` is equivalent to `(f x a b c)`. In the previous example, `+` becomes the first argument of `map`, and then the lists in `xss` become the remaining arguments.
