Scheme / DrRacket - display function with foldr

I need to write my own map function using foldr.

The simplest solution that comes to mind:

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

      

However, I have to do it without using a lambda (or any helper function), recursion, or any abstract list function other than foldr.

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

(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)))

      

I am guessing I should be doing some kind of equivalent to (lambda (xy) (cons (fx) y)) using the above functions. How exactly will I do this?

+3


source to share


1 answer


Try



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

      

+5


source







All Articles