开发者

Trying to make a procedure called map-odd-mapper in scheme

I'm trying to make a procedure called map-odd-mapper where I 开发者_运维问答take a proc that can then be applied to a list

ex:

((make-odd-mapper add-one) (list 14 38 29 10 57))
(15 30 58)

I was thinking of putting it as a let function as in (define (make-odd-mapper f) (let (..........something using ret-odds to allow for the indices so that you can get the odd numbers....

ret-odds is defined as (define (ret-odds lst) (if (null? lst) null (cons (car lst) (if (null? (cdr lst)) null (ret-odds (cdr (cdr lst))))))) the point of this is just to make a proc which will allow me to apply a procedure such as add-one to a list of odd indices....


This problem can be broken down into two smaller ones. At the risk of being pedantic: can you describe what these two smaller problems would be, and provide test cases for them?


(define (make-odd-mapper f) (lambda (lst) (ret-odds (map f lst))))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜