a.nastaev
2019-2-28 16:56:46

@a.nastaev has joined the channel


a.nastaev
2019-2-28 17:15:33

@soegaard2 thanks again for explaining me yesterday all the details about Exercise 9’s problem. Could you or someone point me out how to finish it: (require 2htdp/image) (define in "hello") (if (number? in) (if (>= in 0) (- in 1) (if (string? in) (string-length in) (if (image? in) (* (image-width in) (image-height in)) (if (boolean? in) (if (or in false) 10 20) #false) ))) #false)

each if statement works by itself. In code above everything works for numbers: positive and negative. If I’m defining a string it is not even evaluating it (I went through step evaluator). I guess something is wrong with a syntax, but I couldn’t figure it out I appreciate any help!(require 2htdp/image)

P.S. I love the book and will finish it no matter what. Just frustrated that I’m so dumb!


soegaard2
2019-2-28 17:16:19

Remind me!


a.nastaev
2019-2-28 17:17:26

HTDP2 book Exercise 9. Add the following line to the definitions area of DrRacket: (define in ...) Then create an expression that converts the value of in to a positive number. For a String, it determines how long the String is; for an Image, it uses the area; for a Number, it decrements the number by 1, unless it is already 0 or negative; for #true it uses 10 and for #false 20.


a.nastaev
2019-2-28 17:17:32

Thanks again!


soegaard2
2019-2-28 17:17:59

Maybe you think of plragde ?


a.nastaev
2019-2-28 17:18:35

AAAA, I’m really sorry!


soegaard2
2019-2-28 17:18:42

No worries.


a.nastaev
2019-2-28 17:18:42

Yes you are right!


a.nastaev
2019-2-28 17:18:46

Sorry!


soegaard2
2019-2-28 17:19:18

What’s missing from your solution?


a.nastaev
2019-2-28 17:21:34

well it is not working for all data types. It works only for numbers…


soegaard2
2019-2-28 17:22:27

Okay. What is your output for strings, and what is the expected output?


a.nastaev
2019-2-28 17:23:55

It is going immediately to the end: last #false


a.nastaev
2019-2-28 17:24:08

It is not evaluating it somehow


soegaard2
2019-2-28 17:26:18
(if (number? in)
    ; number
    (if (>= in 0)
        (- in 1)      ; positive number
        missing)   ; negative number
    ; not a number
        (if (string? in)  (string-length in)

            (if (image? in) (* (image-width in) (image-height in))

soegaard2
2019-2-28 17:26:28

You are missing the result for a negative number


a.nastaev
2019-2-28 17:31:52

Hmmm…


a.nastaev
2019-2-28 17:33:24

Let me think


a.nastaev
2019-3-1 04:32:40

@soegaard2 sorry it took sometime to figure out the code. Thanks about your comment that I didn’t cover the result for a negative number or zero. Looks like everything works now. Could you please check it out for me?:


a.nastaev
2019-3-1 04:34:32
(require 2htdp/image)

(define in ...)

(if (string? in)
    ;string
    (string-length in) ;how long the string is
       (if (image? in)
           ;image
           (* (image-width in) (image-height in)) ;image area
           (if (number? in)
               ;number
               (if (> in 0)
                   (- in 1) ;positive number
                   (if (<= in 0)
                       in ;negative number or zero
                       false))
               (if (boolean? in)
                   ;boolean
                   (if (or in false)
                       10 ;true
                       20) ;false
false))))

Also wanted to say huge thank you to @plragde He explained in a clear way what is this exercise about! Thanks a lot! I appreciate all your help guys!