簡體   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