繁体   English   中英

积累在Scheme Lang R5RS中不工作

[英]accumulate not working in Scheme Lang R5RS

我解决了一个涉及使用mapaccumulate的问题,但它给了我这个错误: "accumulate: undefined;" cannot reference undefined identifier. "accumulate: undefined;" cannot reference undefined identifier.

这是我的代码:

;Procedure to test it with
(define (double x)
   (* 2 x))

(define (my-map proc sequence) 
   (accumulate (lambda (x y) (cons (proc x) y)) '() sequence))

请任何人告诉我如何解决此问题?

R5RS中未定义过程accumulate 但是定义您自己的足够简单:

(define (accumulate proc init lst)
  (if (null? lst)
      init
      (proc (car lst)
            (accumulate proc init (cdr lst)))))

对于未来的参考, accumulate也被称为foldrfold-rightinjectreduce在其他编程语言,请咨询您翻译的文档,了解更多详情。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM