球拍合同和结构问题

时间:2013-10-09 02:39:48

标签: struct racket contract

我正在学习人工智能课程的球拍。对于第一个项目,老师给了我们一个包含合同和单元测试的文件,我们将编写使其运行所需的功能。我刚刚创建了我需要的函数的存根,并且除了一个之外还满足了所有的合同:

[start-state (and/c state? (not/c state-game-over?))]

我声明的功能目前看起来像这样:

(define (start-state)
  (state '() start-tiles 0)
)

状态结构由老师给出:

(struct state (played unplayed passes) #:prefab)

合同:

[struct state ((played (listof (and/c tile? tile-at-origin?)))
             (unplayed (listof (and/c tile? tile-on-board?)))
             (passes pass-count?))]

崩溃时出现错误:

start-state: broke its contract
promised: (and/c state? (not/c state-game-over?))
produced: #<procedure:start-state>
which isn't: state?
in: (and/c state? (not/c state-game-over?))
contract from: 

我相信我的start-state过程会创建并返回一个状态结构,但显然它会自行返回并违反合同。如何返回结构而不是程序?

1 个答案:

答案 0 :(得分:3)

看起来start-state不应该是一个过程,而是一个值。也就是说,你需要做

(define start-state (start ...))

而不是

(define (start-state) ...)
相关问题