[racket] why is the comparimng always false

From: Roelof Wobben (r.wobben at home.nl)
Date: Wed Jun 27 10:04:28 EDT 2012

Oke,

If I understand this  the struct Vanimal is not a part of the programm ?

Roelof



Op 27-6-2012 15:56, Matthias Felleisen schreef:
>
> 1. You got trapped in a strange corner of the language:
>
> -- to ask whether some value is a a Vcat you should use Vcat?
> -- BSL should not really allow you to say 'Vcat' all by itself.
> [I need to investigate this problem. Sadly it is not a bug.]
>
>
> 2. Try to understand this:
>
> (define-struct Vcat [x happiness])
> ;; A Vcat is (make-Vcat Number Number)
>
> (define-struct Vcham [x happiness])
> ;; A Vcham is (make-Vcat Number Number)
>
>
> ;; An Animal is one of:
> ;; -- (make-Vcat Number Number)
> ;; -- (make-Vcham Number Number)
>
>
> ;; Animal -> Number
> ;; compute the sum of the x location and the degree of happiness
>
> (check-expect (happiness-quotient (make-Vcham 10 20)) 30)
> (check-expect (happiness-quotient (make-Vcat 10 100)) 110)
>
> (define (happiness-quotient a)
>    (cond
>      [(Vcat? a) (+ (Vcat-x a) (Vcat-happiness a))]
>      [(Vcham? a) (+ (Vcham-x a) (Vcham-happiness a))]))
>
>
>
> On Jun 27, 2012, at 5:08 AM, Roelof Wobben wrote:
>
>> Hello,
>>
>> I try to figure out how I can check if a struct is a Vcat or a Vcham.
>> So i tried this:
>>
>> ; – a VCham
>> (define-struct Vanimal (animal))
>>
>>
>> ; a struct has two parts ( the x-coordinate of a cat and the happiness of the cat)
>> (define-struct Vcat [x happiness])
>> ; make Vcat : number (x) number (h)
>> ; Vcat x -> number
>> ; Vcat h -> number
>> ; Any Vcat? -> Boolean
>>
>> ; a struct has two parts ( the x-coordinate of a kamneleon and the happiness of the kameleon)
>> (define-struct Vcham [x happiness])
>> ; make Vcham : number (x) number (h)
>> ; Vcham x -> number
>> ; Vcham -> number
>>
>> ; Vanimal -> Boolean
>> ; Function which cehcks if a struct is a Vcat
>> (check-expect (check (make-Vanimal(make-Vcat 0 100))) true)
>> (check-expect (check (make-Vanimal(make-Vcham 0 100))) false)
>> (define (check s)
>> ( equal? s Vchat)
>>
>> (check(make-Vanimal (make-Vcat 0 100)))
>>
>>
>> But the answer is false not mather if the struct is a Vchat or a Vcham.
>> Where am I missing something.
>>
>> Roelof
>>
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>



Posted on the users mailing list.