Sunday 15 April 2012

Map + lambda expression in scheme -


I think that I (almost) think about how the map works in the plan, but I have trouble understanding it How this code works:

  (map (langda (xyz) (yxz)) (list 1 2 3 4) (list + - * /) (list 5 6 7 8))  

What really happens inside this process?

We have a map that receives many lists (this Three in the case) and a process that processes them, takes one component of each at a time:

  (map (lambda (exx) (yxz) (list 1 2 3 4) (list + - * /) (list 5 6 7 8))  

The key to understanding is that what is happening in the body of lambda Which passes an element from each list in the second order: We are taking an element from the second list (which is a process). ) And apply it to the elements of first and third lists. For example, for the first three elements we will have:

  (+ 1) 5  

and for other elements:

< Previous> (- 2 6)

and so on. As you know, map will prepare a new list with the result of applying the process for all its input list, element-wise. In this example, the result will be:

  '(6 -4 21 1/2)  

which is similar:

  (list (+ 1) (- 2 6) (* 3 7) (/ 4 8))  

No comments:

Post a Comment