帮助创建Scheme图-多种功能
我应该定义一个函数,该函数将函数列表和另一个列表作为参数,并返回通过按顺序将所有函数应用于列表元素而获得的值列表。
我想出了以下内容,但收到错误:
+: expects type <number> as 1st argument, given: (1 2 3); other arguments were: 1
当我尝试将函数与示例输入一起使用时, (map-many (list (lambda (x) (+ x 1)) (lambda (x) ( * xx))) '(1 2 3))
。任何建议将不胜感激。
(define (map-many fun-list lst)
(if (null? lst) lst
(map ((car fun-list) lst)
(map-many (cdr fun-list) lst))))
I am supposed to define a function that takes as arguments a list of functions and another list and returns a list of values obtained by applying all the functions, in sequence, over the elements of the list.
I came up with the following but I receive the error:
+: expects type <number> as 1st argument, given: (1 2 3); other arguments were: 1
when I try to use the function with the sample input, (map-many (list (lambda (x) (+ x 1)) (lambda (x) (* x x))) '(1 2 3))
. Any suggestions would be appreciated.
(define (map-many fun-list lst)
(if (null? lst) lst
(map ((car fun-list) lst)
(map-many (cdr fun-list) lst))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的错误是:
(null? lst)
而不是(null? fun-list)
上完成了递归。Your errors were:
(null? lst)
instead of(null? fun-list)
.您向
map
传递了错误的函数。不要传递((car fun-list) lst)
,而是尝试仅传递(car fun-list)
。You're passing the wrong function to
map
. Instead of passing((car fun-list) lst)
, try passing just(car fun-list)
.你的措辞对我来说有点不清楚。您应该执行以下操作吗?有两个列表,一个是过程(我们称之为列表 P),另一个是值(我们称之为列表 V)。所以你要找到一个列表,其中:
等等?
Your wording is a bit unclear to me. Are you supposed to do the following? Have two lists, one of procedures (let's call this list P), another with values (let's call this list V). So you're looking to then find a list where:
and so on?