【问题标题】:List where integer is expected coming out of function (Racket)列出预期从函数中出来的整数(球拍)
【发布时间】:2014-02-27 09:55:12
【问题描述】:

我正在尝试使用以下方法为多维数组中的点设置一个值:

(vector-set! (vector-ref array (car xy)) (cadr xy) step_count)

但是我收到了这个错误:

vector-ref: contract violation
  expected: exact-nonnegative-integer?
  given: '(- (car xy) 1)
  argument position: 2nd
  other arguments...:
   '#(#(1 0 0 0 0) #(0 0 0 0 0) #(0 0 0 0 0) #(0 0 0 0 0) #(0 0 0 0 0))
   ;the value 1 at position (0,0) was set before by a similar line of code

xy 值由单独的函数生成

我认为我的 (car xy) 正在以列表的形式退出该功能。我该如何阻止这种情况发生?

感谢大家阅读!

【问题讨论】:

    标签: arrays list function multidimensional-array racket


    【解决方案1】:

    您的list 调用错误。例如,您应该使用如下内容:

    (cons (list (+ (car xy) 2) (- (cadr xy) 1)) successors)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 2015-04-17
      • 1970-01-01
      相关资源
      最近更新 更多