我應該定義一個函數,它將函數列表和另一個列表作爲參數,並返回通過將所有函數按順序應用於列表元素而獲得的值列表。幫助創建Scheme映射 - 許多函數
我想出了下面,但我收到的錯誤:
+: expects type <number> as 1st argument, given: (1 2 3); other arguments were: 1
,當我嘗試使用功能與樣品輸入,(map-many (list (lambda (x) (+ x 1)) (lambda (x) (* x x))) '(1 2 3))
。任何建議,將不勝感激。
(define (map-many fun-list lst)
(if (null? lst) lst
(map ((car fun-list) lst)
(map-many (cdr fun-list) lst))))
這個函數應該像'(map(apply compose fun-list)lst)'一樣工作。 – 2011-05-20 16:17:25