List 当球拍中需要数字时使用文字
我试着用这个:List 当球拍中需要数字时使用文字,list,integer,racket,literals,illegalargumentexception,List,Integer,Racket,Literals,Illegalargumentexception,我试着用这个: (vector-set! (vector-ref array (car xy)) (cdr xy) step_count) 其中xy是作为参数传入的类似于“(0)的列表 但我得到了这个错误: vector-set!: contract violation expected: exact-nonnegative-integer? given: '(0) argument position: 2nd other arguments...: '#(0 0 0 0
(vector-set! (vector-ref array (car xy)) (cdr xy) step_count)
其中xy是作为参数传入的类似于“(0)的列表
但我得到了这个错误:
vector-set!: contract violation
expected: exact-nonnegative-integer?
given: '(0)
argument position: 2nd
other arguments...:
'#(0 0 0 0 0)
1
(cdr xy)有一个问题,我想我需要将“(0)转换为0,但我在球拍中找不到一个机制可以做到这一点
我知道这样一句话:
(vector-set! (vector-ref array (sub1 (car xy))) (sub1 (cdr xy)) (read))
使用以下工具形成xy时起作用:
(define xy (cons (read) (read)))
有人能给我指出正确的方向吗
感谢阅读。当您在
列表上使用cdr
时,它表示“列表的其余部分”。列表的其余部分始终是列表
,而不是列表中的单个元素
如果需要列表的第二个元素xy
,则需要使用cadr
(您也可以使用second
)
(define xy (list 1 2 3))
(cdr xy) ; '(2 3)
(cadr xy) ; 2
(second xy) ; 2