我正在为人工智能课程学习球拍。对于第一个项目,老师给了我们一个包含合约和单元测试的文件,我们将编写使其运行所需的功能。我刚刚创建了我需要的功能的存根,并满足了所有合同,除了一个:
[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:
我相信我的起始状态程序创建并返回了一个状态结构,但显然它返回了自己并违反了合同。如何返回结构而不是过程?