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

坚强是说给别人听的谎言 提交于 2019-12-25 09:08:26

问题


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....


回答1:


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?




回答2:


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



来源:https://stackoverflow.com/questions/5364838/trying-to-make-a-procedure-called-map-odd-mapper-in-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!