[racket] Exercise 19 How to design programs, second edition

From: Zack H (zdhickman at gmail.com)
Date: Mon Aug 19 10:07:43 EDT 2013

Yep, that's just a limitation within BSL.

If you're still wanting to use the student packs and not the full language,
considering graduating to Intermediate Student and using locals:


(define (image-classify userImage)
  (local [(define imageHeight (image-height userImage))
          (define imageWidth (image-width userImage))]
    (cond [(> imageHeight imageWidth) "tall"]
          [(= imageHeight imageWidth) "square"]
          [else "wide"])))


On Mon, Aug 19, 2013 at 9:52 AM, Nedim M <nedimm at outlook.com> wrote:

> Hello,
>
> I am having a trouble solving Exercise 19 (How to design programs, second edition):
>
> Define the function image-classify, which consumes an image and produces
> "tall" if the image is taller than it is wide, "wide" if it is wider
> than it is tall, or "square" if its width and height are the same. See
> exercise 10 for ideas.
>
> Here is my code:
>
> (require 2htdp/image)
>
> (define (image-classify userImage)
>
>     (define imageHeight (image-height userImage))
>     (define imageWidth (image-width userImage))
>
>     (if (> imageHeight imageWidth)
>         "tall"
>         (if (= imageHeight imageWidth)
>             "square"
>         "wide"
>         )
>     )
> )
>
> Here is my code for exercise 10:
>
> (require 2htdp/image)
> (define cat <imageOfCat>)
>
> (define catHeight (image-height cat))
> (define catWidth (image-width cat))
>
> (if (> catHeight catWidth)
>     "tall"
>
>     (if (= catHeight catWidth)
>         "square"
>     "wide"
>     )
>
> )
>
> Language is beginning student.
> It looks like that declaring calculated constant inside function doesn't work. Example:
>
>
> (define (image-classify userImage)
> (define imageHeight (image-height userImage))
>
>
>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>
>


-- 
Thank you,
Zack Hickman
Freelance Web Programming/Wordpress Specialization
http://www.zhickman.com
zack at zhickman.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130819/297d8949/attachment.html>

Posted on the users mailing list.