[plt-scheme] Newbie map question

 From: Robby Findler (robby at cs.uchicago.edu) Date: Thu Dec 30 08:33:29 EST 2004 Previous message: [plt-scheme] Newbie map question Next message: [plt-scheme] v299 build on OS X -- wchar.h? wctype.h? Messages sorted by: [date] [thread] [subject] [author]

```I think you're looking for the function apply.

Robby

At Thu, 30 Dec 2004 13:22:41 +0100, Francisco Jesús Martínez Serrano wrote:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> 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] Newbie map question Next message: [plt-scheme] v299 build on OS X -- wchar.h? wctype.h? Messages sorted by: [date] [thread] [subject] [author]