I defined a function true?
for use with count in racket/list.
(define (true? expr)
(and (boolean? expr) expr #t))
I noticed I could provide it numeric arguments and my function would happily return #f
.
> (true? 6)
#f
So, I thought I would explore using a racket contract to make non-boolean arguments return an error in contract violation. So I put this code at the tope of my file:
(provide (contract-out
[true? (-> boolean? boolean?)]))
However, after adding the contract I still get the same behavior as above in the racket REPL. I don't understand how that could be. What am I missing?
values
, since Racket treats everything as true except for#f
. E.g.:(count values '(how many #f true #f #f things #f))
– dyoo