# [racket] how must I interpreted this exercise

 From: Roelof Wobben (r.wobben at home.nl) Date: Mon Jun 25 02:41:30 EDT 2012 Previous message: [racket] how must I interpreted this exercise Next message: [racket] how must I interpreted this exercise Messages sorted by: [date] [thread] [subject] [author]

You mean something like this :

(check-expect (calculate 0 3) 3)
(define (calculate getal1 getal2)
(cond
[ (equal? getal1 0) getal2]
[ (equal? getal2 0) getal1]
[else (sqrt (+ (* getal1 getal1) (* getal2 getal2)))]
))

; String -> String
; This function produces a string depending on the input "niet " or ""
(check-expect (afdrukken "") "Het ingegeven punt is dichtbij het 0 punt")
(check-expect (afdrukken "niet ") "Het ingegeven punt is niet dichtbij
het 0 punt")
(define (afdrukken s)
(string-append first_tekst s middle_tekst)
)

; Struct -> String
; Function who outputs "niet" or a empty string depending on the
calculated distance compared with R.
(check-expect (is-near (make-posn 1 0) 5) "Het ingegeven punt is
dichtbij het 0 punt")
(check-expect (is-near (make-posn 3 4)  5) "Het ingegeven punt is niet
dichtbij het 0 punt")
(define (is-near s r)
( if (< (calculate (posn-x s) (posn-y s)) r) (afdrukken "")
(afdrukken "niet ")
))

Roelof

Op 25-6-2012 6:18, Richard Cleis schreef:
> Check-expect is used to test your function.
> Make that work first.
>
> Then you can use the design recipe to make a new function.
>
> The new function will accept the output of your first function and return the message that you want… without any repeated words in the function.
>
> rac
>
> On Jun 24, 2012, at 1:43 PM, Roelof Wobben wrote:
>
>> Hello,
>>
>> This soluation is not what I was looking for.
>> And it uses list which I don't have learned so far.
>>
>> So far I have this :
>>
>> ; constanten
>>
>> (define R 5)
>> (define first_tekst "Het ingegeven punt")
>> (define is_tekst "is")
>> (define middle_tekst "dichtbij het 0 nulpunt")
>> (define niet "niet")
>>
>>
>> ;Number Number -> Number
>> ;This function calculates the distance of a given point compared to the origin
>> (check-expect (calculate 1 0) 1)
>> (check-expect (calculate 3 4) 5)
>> (check-expect (calculate 0 3) 3)
>> (define (calculate getal1 getal2)
>>    (cond
>>      [ (equal? getal1 0) getal2]
>>      [ (equal? getal2 0) getal1]
>>      [else (sqrt (+ (* getal1 getal1) (* getal2 getal2)))]
>>      ))
>>
>> ; Struct -> String
>> ; Function who outputs a string dependinh on the outcome of the calculation of the distance to the origin
>> (check-expect (is-near (make-s 1 0) "Het ingegeven punt is dichtbij het nulpunt"))
>> (check-expect (is-near (make-s 3 4) "Het ingeven punt is niet dichtbij het nulpunt"))
>> (define (is-near s r)
>>    ( if (< (calculate (posn-x s) (posn-y s)) r)
>>
>>
>> Now I can do  (string append  first_tekst is middle-tekst) and (string-append first-tekst  is niet middle-tekst)  but then I do almost two times the same with one difference the niet part.
>> And Im looking for a better solution.
>>

 Posted on the users mailing list. Previous message: [racket] how must I interpreted this exercise Next message: [racket] how must I interpreted this exercise Messages sorted by: [date] [thread] [subject] [author]