[racket] why is the comparimng always false

From: Stephen Bloch (bloch at adelphi.edu)
Date: Fri Jun 29 17:52:31 EDT 2012

Another thing I recommend: every time you write a define-struct, write down (in comments) the contracts for all the functions it gives you for free.

For example,
; a person has a forename and a family-name (both strings), and a birth-year (a number).
(define-struct person forename family-name birth-year)
; make-person : string string number -> person
; person-forename : person -> string
; person-family-name : person -> string
; person-birth-year : person -> number
; person? : anything -> boolean

Go through several of the examples in the book, writing down these contracts and then using those functions to see whether you got the contracts right.  Then go back to your cat/chameleon example and do the same for Vcat and Vcham.  You can see why the following can't be right:

> (define-struct Vcat (Xcat Hcat Richting))
> ; Vcat = (make-editor Number Number)
> ; interp. (make-editor x h) where x is the x-coordinate of the cat and h is the happiness of the cat.
> ; make-editor Number Number -> Vcat
> ; Vcat-Xcat Editor -> Number
> ; Vcat-Hcat Editor -> Number
> ; Vcat-Richting -> String
> ; Vcat? Editor Any -> Boolean

Stephen Bloch
sbloch at adelphi.edu

Posted on the users mailing list.