First, I apologize for the beginner question. I am an experienced developer, but new to Scheme. I have created a contract requiring a positive integer, but when I provide a real number, the contract is not violated:
(define/contract (listofOne n)
(-> (and integer? positive?) (listof integer?))
(cond
((= n 0) '())
(else (cons 1 (listofOne (- n 1))))))
(listofOne 12.5)
I expected the contract to be violated, but instead I got an infinite loop and a buffer overflow. Why did the contract remain unviolated? The first query in my predicate was integer?
, so I don't see how the contract could have returned true with an input of 12.5
.
EDIT: Just to clarify, I am not looking for a way to make the contract violate. I already know that I can use and/c, and (thanks to @soegaard) that I can reverse positive?
and integer?
to get it to violate. What I'm looking for at this point is to understand what is going on here.
Thanks in advance for the help!