[plt-scheme] How to apply a multi-argument function to each element of a list

From: Barry Brown (barry at cs.sierracollege.edu)
Date: Tue Mar 2 18:54:54 EST 2010

Sorry this is probably a basic question. Other than being familiar  
with the HtDP material, I am kind of a Scheme newbie.

I'm working on an assignment for my students to implement RSA  
encryption. One of the problems is, naturally, to write a function  
called encrypt that consumes the encryption key pair e and n, along  
with a message m to encrypt. They are using the Pretty Big language.

encrypt : number number number -> number

I would then like to use the encrypt function to encrypt a list of  
numbers. Now, if Scheme had implicit currying like Haskell, I could do  
something like this:

(map (encrypt 17 40) (list 100 115 76))

How can I do this in Scheme? The students have not seen lambda, nor  
will they be introduced to it. This for a course in discrete  
structures; I'm using Scheme to help illustrate some of the concepts  
they are learning.

I think the syntax ought to be similar to the "apply" function, but  
instead of constructing an argument list, it applies the function to  
each element of the list, using the two given arguments:

(apply-func encrypt 17 40 (list 100 115 76))

would be equivalent to:

(list (encrypt 17 40 100) (encrypt 17 40 115) (encrypt 17 40 76))

Thanks in advance!


Posted on the users mailing list.