[racket] new to Scheme and functional programming- weird error I can't wrap my mind around

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Thu Nov 17 02:59:05 EST 2011

> Using the draw-circle function defined in draw.ss, I wanted to draw a green
> circle centered at (posn 150 150), with radius 20.
>> (draw-circle (make-posn 150 150) 20 'green)
> . . draw-circle: expects a posn as first argument, given #<posn>
> I don't understand the above error. Draw-circle expects a posn structure,
> and DrRacket recognized that I gave it one. So where did the error stem
> from?

Hello!

Note: the 'draw.ss' library is obsolete.  It still works, but you you
may want to use the 2htdp/image library instead, because it's easier
to use.   For example, if you're using 2htdp/image, then getting a
circle to show up is just a matter of:

    (circle 20 "solid" "green")

If you look at the next edition of How To Design Programs, you'll see
that it uses 2htdp/image quite a bit.  You can read the section here:

    http://www.ccs.neu.edu/home/matthias/HtDP2e/prologue.html

which shows how to play with images.


Anyway, the teachpacks in DrRacket assume that you're using one of the
specialized teaching languages.  If you're using one of the Student
languages (Beginner, Intermediate, or Advanced), I believe those
language levels should already have the posn structure defined for
you, and in which case you don't (and shouldn't) need to define it
yourself.

Are you using one of the Student languages?


(What's really going on with that error message is this: Racket allows
different modules to define structures with any name, and you've
created a posn structure that coincidentally has the name "posn".  But
the draw library still knows that it's not the posn that it's looking
for.  draw-circle and the other functions in the draw.ss teachpack
expects one that originate from the lang/posn library.)

Good luck!


Posted on the users mailing list.