方案“错误:(4 6 5 87 7)不是函数" [英] Scheme "Error: (4 6 5 87 7) is not a function"
本文介绍了方案“错误:(4 6 5 87 7)不是函数"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚问了一个类似的问题并得到了我需要的答案,但他的时间我找不到任何会导致此错误的额外括号:错误:(4 6 5 87 7)不是函数".是不是因为别的原因?我的代码需要一个数字,如果它已经在列表中,它不会添加它.如果列表中尚未包含该数字,则添加它.
I just asked a similar question and got the answer I needed, but his time I cannot find any extra parenthesis that would be causing this error: "Error: (4 6 5 87 7) is not a function". Is it due to something else? My code takes a number and if it is already in the list, it does not add it. If the list does not already contain the number, then it adds it.
(define (insert x ls)
(insertHelper x ls '() 0)
)
(define (insertHelper x ls lsReturn counter)
(cond
(
(and (null? ls) (= counter 0))
(reverse (cons x lsReturn))
)
(
(and (null? ls) (>= counter 1))
(reverse lsReturn)
)
(
(eqv? x (car ls))
(insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 1))
)
(
else ((insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 0)))
)
)
)
(define theSet (list 4 6 5 87))
(display theSet)
(display "\n")
(display (insert 7 theSet))
推荐答案
您遇到了括号过多、缩进不好的情况.这应该可以治愈您的疾病:
You suffer from a case of excessive parentheses, sprinkled with bad indentation. This should cure your ailments:
(define (insert x ls)
(insertHelper x ls '() 0))
(define (insertHelper x ls lsReturn counter)
(cond ((and (null? ls) (= counter 0))
(reverse (cons x lsReturn)))
((and (null? ls) (>= counter 1))
(reverse lsReturn))
((eqv? x (car ls))
(insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 1)))
(else
(insertHelper x (cdr ls) (cons (car ls) lsReturn) (+ counter 0)))))
这篇关于方案“错误:(4 6 5 87 7)不是函数"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文