I have a struct that represents a move
(struct move (tile x y rotations) #:prefab)
Pass is also allowed, so I have a bool that test for an action:
(define (action? v)
(if (or (pass? v)
(move? v))
#t
;; else
#f
)
)
I can declare a move like
(define test (move (tile 'blue (list (posn 0 0 ) (posn 1 0) (posn 2 0) (posn 3 0) (posn 3 1))) 2 4 0))
And when I test for action? it passes:
(action? test) #t
However, when I use this file on a different module, the move structure is not accepted as a valid move:
state-transition: contract violation expected: (and/c action? ???) given: '#s(move #s(tile blue (#s(posn 0 0) #s(posn 1 0) #s(posn 2 0) #s(posn 3 0) #s(posn 3 1))) 2 4 0) which isn't: ???
Here is the state-transition contract provided by the teacher:
[state-transition (->i ([s state?]
[a (s) (and/c action?
(cut state-action-legal? <> s))])
[result state?])]
So I have basically the same object in two places. In one of them it passes the test, and in the other one it fails and a contract is broken. Why is this happening?
Edit
Here is the definition of state-action-legal?
(define (state-action-legal? state action)
(not (state-action-violation state action))
)
And state-action-violation returns string indicating the reason the action is not legal or #F if the action is legal. I know they are both working properly because we tested them manually and the teacher provided unit tests to ensure proper implementation and these functions pass all of them.
End edit
Thank you for your help.