方案 - 与列表相等的函数
我写了这个程序:
(define find-combination
{lambda (a b)
(if (eq? ((quotient (car a) (car b)) (quotient (car (cdr a)) (car (cdr b)))))
(display "1*v1" + ((quotient (car a) (car b))*"v2"))
(display "0*v1" + "0*v2"))})
(find-combination (list 2 2) (list 2 1))
a和b是两个列表。它给了我下一个问题:程序应用:预期程序,给定:1;论点是: 2.
我不明白问题是什么。有人可以帮助我吗?感谢你。
I wrote this program:
(define find-combination
{lambda (a b)
(if (eq? ((quotient (car a) (car b)) (quotient (car (cdr a)) (car (cdr b)))))
(display "1*v1" + ((quotient (car a) (car b))*"v2"))
(display "0*v1" + "0*v2"))})
(find-combination (list 2 2) (list 2 1))
a and b are two lists. Its give me the next problem: procedure application: expected procedure, given: 1; arguments were: 2.
I didn't get what is the problem. Someone can help me? Thank u.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您在
eq?
之后有太多括号 - 您编写的内容意味着评估(quotient (car a) (car b))
并将其视为带参数的函数(商(car (cdr a)) (car (cdr b)))
。该错误意味着第一个结果被评估为1
并且您的解释器期望它是一个过程,而不是一个整数。此行应该是:甚至:
除此之外,带有
display
调用的行是错误的 - Scheme 没有中缀表示法,因此+
和*< /code> 不合适。
First of all you have too much brackets after
eq?
- what you wrote means evaluating(quotient (car a) (car b))
and treating it as a function with argument(quotient (car (cdr a)) (car (cdr b)))
. The error means that first thing was evaluated to1
and your interpreter expected it to be a procedure, not an integer. This line should be:or even:
Apart from that, lines with
display
calls are wrong - Scheme doesn't have an infix notation, so+
and*
are out of place.首先,您的代码中有一组大括号(lambda 之前的大括号)
此外,您在传递给 eq 的参数周围还有另一组括号?
它应该是这样的:
First of all you have a set of curly braces in your code(the one before lambda)
Also you have another set of paranthesis around the parameters you passed to eq?
It should be something like this:
在Scheme和Racket中,括号改变了事物的含义。
是一个数字,但是
是对 1 作为函数的调用...但是 1 是一个数字,而不是函数,所以这会导致您描述的错误。
你对花括号的使用也让我有点不安。
In Scheme and Racket, parentheses change the meaning of things.
is a number, but
is a call to 1 as a function... but 1 is a number, not a function, so this will cause the error you describe.
Your use of curly braces is also a little unsettling to me.