[plt-scheme] picture language predicates?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Mon Sep 7 06:26:29 EDT 2009

On Mon, Sep 7, 2009 at 9:58 AM, Wolfgang De Meuter<wdmeuter at vub.ac.be> wrote:
> Hello
>
> I'm trying to use the picture language to create some courseware. Are there
> any predicates allowing me to test whether a picture is a circle,
> rectangle,... If not... any other hacks that allow me to know what the
> 'type' of a picture is? I was thinking about writing procedures for
> calculating circumferences for various pictures.
>
> Regards
> Wolf

Images are not shapes, they are a way of rendering shapes.  Similarly,
strings are not numbers, but they are a way of rendering numbers [e.g.
(number->string 5) = "5", etc.].  If you want to compute the perimeter
of a shape, you should construct a datatype for shapes [using
define-struct and so forth], just as if you want to compute square
roots, you would use a number and not a string representing that
number.

It is somewhat unfortunate that the image constructors mislead the
user by saying (circle ...) and (rectangle ...) and so forth, instead
of (render-circle ...) and (render-rectangle ...) which might be
clearer.  Nevertheless, once you have an image, all you really have is
a 2-dimensional vector of pixels.  The program can't tell if they were
constructed by a circle constructor, a rectangle constructor, or by
copy and paste from a web page.

--Carl


Posted on the users mailing list.