@a.nastaev has joined the channel
@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!
Remind me!
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.
Thanks again!
Maybe you think of plragde ?
AAAA, I’m really sorry!
No worries.
Yes you are right!
Sorry!
What’s missing from your solution?
well it is not working for all data types. It works only for numbers…
Okay. What is your output for strings, and what is the expected output?
It is going immediately to the end: last #false
It is not evaluating it somehow
(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))
You are missing the result for a negative number
Hmmm…
Let me think
@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?:
(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!