[racket] how must I interpreted this exercise

From: Roelof Wobben (r.wobben at home.nl)
Date: Mon Jun 25 11:18:46 EDT 2012

One question left : Did I do this exercise the right way ?

Roelof


Op 25-6-2012 16:21, Roelof Wobben schreef:
> Nope, I think I have to read the whole book to get this kind of problems.
> First a lot of things to learn as lists, quote/unquote, lamba.
>
> Roelof
>
>
>
> Op 25-6-2012 16:14, Matthias Felleisen schreef:
>> This is not this kind of problem.
>>
>>
>> On Jun 25, 2012, at 10:06 AM, Richard Cleis wrote:
>>
>>> That is-near a better solution ;o)
>>>
>>> I think HtDP has problems that require assembling sentences from 
>>> different parts of speech. That is a very challenging software field.
>>>
>>> rac
>>>
>>>
>>>
>>> On Jun 25, 2012, at 12:41 AM, Roelof Wobben wrote:
>>>
>>>> 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.
>>>>>>
>>>>
>>>
>>> ____________________
>>>   Racket Users list:
>>>   http://lists.racket-lang.org/users
>>
>
>
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>



Posted on the users mailing list.