Question

I am learning Racket for an Artificial Intelligence class. For the first project, the teacher gave us a file with contracts and unit tests, we are to code the functions required to make it run. I just created stubs of the functions I will need and met all the contracts except one:

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

The function I declared looks like this at the moment:

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

And the state struct was given by the teacher:

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

With contract:

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

This crashes with error:

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: 

I believe my start-state procedure creates and returns a state struct, but apparently it returns itself and violates the contract. How do I return the struct and not the procedure?

Was it helpful?

Solution

It looks like start-state isn't supposed to be a procedure, but a value. That is, you need to do

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

instead of

(define (start-state) ...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top