3
votes

I have to write my own map function using foldr.

The easiest solution that comes to mind is:

(define (my-map f lst)    
 (foldr (lambda (x y) (cons (f x) y)) empty lst))

However, I'm supposed to do this without using lambda (or any kind of helper function), recursion, or any non-foldr abstract list function.

I also have the following questions available to me (which I cannot modify):

(define (compose f g)
  (lambda (x) (f (g x))))

(define (curry f)
  (lambda (x) (lambda (y) (f x y))))

(define (uncurry f)
  (lambda (x y) ((f x) y)))

My guess is that I have to make some kind of equivalent to (lambda (x y) (cons (f x) y)) using the above functions. How exactly would I go about doing this?

1

1 Answers

5
votes

Try

(define (my-map f lst)    
  (foldr (uncurry (compose (curry cons) f))
         empty lst))