2

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

[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: 

我相信我的起始状态程序创建并返回了一个状态结构,但显然它返回了自己并违反了合同。如何返回结构而不是过程?

4

1 回答 1

3

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

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

代替

(define (start-state) ...)
于 2013-10-09T02:46:32.307 回答