[英]accumulate not working in Scheme Lang R5RS
I solved a problem which involved using map
and accumulate
but it gave me this error: "accumulate: undefined;" cannot reference undefined identifier.
我解决了一个涉及使用
map
和accumulate
的问题,但它给了我这个错误: "accumulate: undefined;" cannot reference undefined identifier.
"accumulate: undefined;" cannot reference undefined identifier.
This is my code: 这是我的代码:
;Procedure to test it with
(define (double x)
(* 2 x))
(define (my-map proc sequence)
(accumulate (lambda (x y) (cons (proc x) y)) '() sequence))
Please can anyone tell me how to fix this problem? 请任何人告诉我如何解决此问题?
The procedure accumulate
is not defined in R5RS. R5RS中未定义过程
accumulate
。 But it's simple enough to define your own: 但是定义您自己的足够简单:
(define (accumulate proc init lst)
(if (null? lst)
init
(proc (car lst)
(accumulate proc init (cdr lst)))))
For future reference, accumulate
is also known as foldr
, fold-right
, inject
or reduce
in other programming languages, consult your interpreter's documentation for more details. 对于未来的参考,
accumulate
也被称为foldr
, fold-right
, inject
或reduce
在其他编程语言,请咨询您翻译的文档,了解更多详情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.