试图在方案中做一个叫做map-odd-mapper的过程 [英] Trying to make a procedure called map-odd-mapper in scheme
问题描述
我正在尝试一个名为map-odd-mapper的过程,其中我接受一个可以应用于列表的过程。
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)
我正在考虑把它作为一个let函数,如
(define(make- odd-mapper f)
(let(..........某些使用ret-odds来允许索引让你可以得到奇数....
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定义为
(define(ret-odds lst)
(if(null?lst)null
(cons(car lst) if(null?(cdr lst))null(ret-odds(cdr(cdr lst))))))))这个意思只是为了使一个proc能够将一个过程(如add-1)应用到一个奇数索引列表....
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....
推荐答案
(define(make-odd-mapper f)
(lst)(ret-odds(map f lst))))
(define (make-odd-mapper f) (lambda (lst) (ret-odds (map f lst))))
这篇关于试图在方案中做一个叫做map-odd-mapper的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!