gpt4 book ai didi

error-handling - 方案: Why am I getting this error: assertion-violation: argument of wrong type [car (car #{Unspecific})

转载 作者:行者123 更新时间:2023-12-03 08:38:29 30 4
gpt4 key购买 nike

我相信我已经在程序中发现它是这个函数,但是在到达find_best_candidates函数的第一行之前似乎失败了:


(define (count-the-score candList voterList)
(display "Spot 3")
(cond
((null? voterList) 0)

(else
(cond
((or (= (car candList) 0) (= (car voterList) 0)) (+ 0 (count-the-score (cdr candList)(cdr voterList))))
((equal? (car candList) (car voterList)) (+ 1 (count-the-score (cdr candList)(cdr voterList))))
(else (- (count-the-score (cdr candList) (cdr voterList)) 1))
)
)
)
)

(define (find-max myList)
(define sortedList 0)
(display "Spot 4")
(cond
((null? myList) myList)
((null? (cdr myList)) myList)

(else
(set! sortedList (find-max (cdr myList)))

(cond
((null? sortedList) (cdr myList))
((null? (car sortedList)) (car myList))
((null? (car myList)) sortedList)
((= (car (cdr (car myList))) (car (cdr (car sortedList))))
(append sortedList (list (car myList)))
)
((> (car (cdr (car myList))) (car (cdr (car sortedList))))
(list (car myList))
)

(else
sortedList
)
)
(display "Spot 5")
)
)
)

(define (find_best_candidates Voter Candidates)
(display "Spot 2")
(define best 0)
(define score 0)
(define voterScore 0)
(define tempScore 0)
(define max_till 0)

(cond
((null? Candidates) '())

(else
(set! best (find_best_candidates Voter (cdr Candidates)))

(set! score (count-the-score Voter (cdr (car Candidates))))

(set! voterScore (list (car (car Candidates)) score))

(set! tempScore (append best (list voterScore)))

(set! max_till (find-max best))

)
)
(display "Spot 6")
)


(define (fetch-names myList)
(display "Spot 7")
(define prev_ans 0)
(define ll 0)
(cond
((null? (cdr myList)) (list(car (car myList))))

(else

(set! prev_ans (fetch-names (cdr) myList))

(set! ll (append (list (car (car myList))) prev_ans))
ll
)
)
(display "Spot 8")

)


;Main function;
(define (best_candidates Voter Candidates)
(display "Spot 1")
(fetch-names (find_best_candidates Voter Candidates))
(display "Spot END")
)
导入的数据如下:
(define (test1)
(best_candidates
'( 0 0 0 1 1 1 -1 -1 -1 1)
'((Adams 1 1 1 1 1 1 1 1 1 1)
(Grant -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)
(Polk 1 -1 1 -1 1 -1 1 -1 1 -1)
(Jackson 1 0 1 0 1 0 1 0 1 0)
(Taft 0 -1 0 -1 0 -1 0 -1 0 -1)
(Ford 1 1 1 1 0 0 0 0 0 0)
(Madison 0 0 0 1 -1 0 0 -1 1 1)))
)
; should return (adams ford madison)
我最终收到的错误是:
assertion-violation: argument of wrong type [car]
(car #{Unspecific})

最佳答案

找到了我的问题。在fetch-names函数中,我有(set! prev_ans (fetch-names (cdr) myList)),应将其写为(set! prev_ans (fetch-names (cdr myList)))。我放错了括号。

关于error-handling - 方案: Why am I getting this error: assertion-violation: argument of wrong type [car (car #{Unspecific}),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64359177/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com