# [racket] how must I interpreted this exercise

 From: Roelof Wobben (r.wobben at home.nl) Date: Sun Jun 24 15:43:01 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]

```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.

Op 23-6-2012 23:17, Matthias Felleisen schreef:
>
> Assuming you don't literally mean 'print', here is a function that
> does what you want:
>
> ;; Sentence is one of:
> ;; -- empty
> ;; -- (cons String Sentence)
>
> (define s1 '("This" "is" "a" "sentence."))
> (define s2 '("And" "this" "is" "one," "too."))
>
> ;; Sentence N -> Sentence
> ;; add 's' to the 2nd word in s if it is longer than i letters
>
> (check-expect (change s1 2) s1)
> (check-expect (change s2 3) (cons "And" (cons "thiss" (rest (rest s2)))))
>
> (define (change s i)
>   (if (> (string-length (second s)) i)
>       (cons (first s) (cons (string-append (second s) "s") (rest (rest
> s))))
>       s))
>
> If it doesn't what you want, follow the design recipe and let us know
> at which step you're stuck.
>
>
>
> On Jun 23, 2012, at 2:45 PM, Roelof Wobben wrote:
>
>> I have another "problem" I try to solve in my head.
>>
>> Suppose I want to change one word in a sentence depening if a
>> comparision is true or false.
>>
>> I could do this in pseudo code.
>>
>> if comparision is true then print "it's true" else  print "it's not true"
>>
>> It works but I type two time's "it's true".
>>
>> Can this be done so I have to type only one time the sentence and
>> depeding on true or false the word not is used.
>>
>> Roelof
>>
>>
>>
>> Op 23-6-2012 16:18, Matthias Felleisen schreef:
>>>
>>> Origin means (0,0) or plain 0 in English.
>>>
>>>
>>> On Jun 22, 2012, at 2:42 PM, Roelof Wobben wrote:
>>>
>>>> Hello,
>>>>
>>>> I try to make this exercise :
>>>>
>>>> Exercise 76: A programmer has chosen to represent locations as
>>>> Cartesian points or just points:
>>>>
>>>>     ;Location is one of:
>>>>     ;–Posn
>>>>     ;–Number
>>>>     ;interp. Posn are positions on the Cartesian grid,
>>>>     ;Numbers are positions on the number line
>>>>
>>>> Design the function in-reach, which determines whether or not a
>>>> given location’s distance to the origin is strictly less than some
>>>> constantR.
>>>>
>>>> So I must design a function called in-reach.
>>>>
>>>> Am I right I need to use two structs (Posn) . One for the given
>>>> location and one for the origon ?
>>>>
>>>> Regards,
>>>>
>>>> Roelof
>>>>
>>>>
>>>>
>>>> ____________________
>>>>  Racket Users list:
>>>> http://lists.racket-lang.org/users
>>>
>>
>>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120624/d8d52679/attachment-0001.html>
```

 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]