# [plt-scheme] Newbie map question

 From: Francisco Jesús Martínez Serrano (franjesus at gmail.com) Date: Thu Dec 30 07:22:41 EST 2004 Previous message: [plt-scheme] California Schemin' on such a winter's day Next message: [plt-scheme] Newbie map question Messages sorted by: [date] [thread] [subject] [author]

```Hi, i'm learning scheme "the hard way", making a school project.

I need to manipulate vectors and do some basic vector algebra.

When faced with something as 'trivial' as the sum, I know I can sum
vectors (lists) just as this:

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

The problem of this approach is that map + is not a procedure I can
pass as an argument to a function (inner or outer product, for
example), i need a self-contained map+. I can do this just by
defining:

(define map+
(lambda (v1 v2)
(map + v1 v2)))

The problem of this approach is that it only works with 2 arguments. I
know I can iterate through the list of vectors and accomplish it, but
that seems too inefficient when a simple map + will do. Something like
this:

(define map+
(lambda vecs
(map + vecs)))

or better:

(define elementwise
(lambda (f)
(lambda vecs
(map f vecs))))

(define map+ (elementwise +))

Which doesn't work because vecs is a list of vectors, and map expects
each vector as an argument

I know it's very simple, but can somebody give me a clue?

Thanks.

```

 Posted on the users mailing list. Previous message: [plt-scheme] California Schemin' on such a winter's day Next message: [plt-scheme] Newbie map question Messages sorted by: [date] [thread] [subject] [author]