;;; Functions for drawing. ;;; ;;;;; The implementation lies in shapes-body.ss ;;;;; (the rest of this file is the glue that lets this be used as a teachpack). ;; DrScheme v200 will simplify teachpacks (as any other module). ;; So don't worry about this magic: ;; (require-library "draw-sig.ss" "htdp") ;; This gives us the signature drawS. (define-signature draw^ drawS) ;; Rename to draw^. (define-signature shapes^ (;make-posn posn? posn-x posn-y ; Why don't i need to mention these? make-circle circle-location circle-radius circle-color make-rectangle rectangle-location rectangle-height rectangle-color translate-shape draw-shape draw-shapes circle-tool rectangle-tool circ1 rect1)) (define shapes-unit (unit/sig shapes^ (import plt:userspace^ draw^) ; Now, the implementation: (include "shapes-body.ss"))) ;; At this point, shapes-unit is a single unit. ;; If you ever want to use it, you must provide ;; actual implementations of the functions it imports -- ;; namely those in plt:userspace^, xml^. ;; Let's roll together the unit we just made with the imports it needs. ;; (compound-unit/sig (import (p : plt:userspace^)) ; p is a formal argument. (link [ draw : draw^ ((require-library "draw.ss" "htdp") p)] [ shapes-bound-unit : shapes^ (shapes-unit p draw) ]) (export (open shapes-bound-unit))) #| ;; v200 will simplify teachpacks (as any other module). ;; So don't worry about this magic: ;; How compound-unit/sig works. We want to take in two units (namely shapes.ss, and xml.ss), and wrap them into a single compound unit. Note: shapes-body.ss requires the libraries file.ss and function.ss. However, these lbiraries are both subsumed inside plt:userspace^, whew! So it's only xml.ss that remains to be loaded by shapes-body.ss. imports: Thus this compound-unit imports plt:userspace^, and binds it to the name "p". links: the line [draw : draw^ (...)] "draw" is our name for the unit -- it's the formal parameter. The first thing after the colon is the signature for that library, draw^. It's saying, "draw" is what we'll call the unit provided to us; it had better match the signature "draw^". (That's why we loaded draw-sig.ss, to get that signature.) Then, the third part is the actual unit which we provide (to be called "draw"): We need to provide with a unit whose imports are already satisfied. The syntax is: (unit import1 import2 ...) So the require-library returns the draw unit, and looking at draw lib's documentation (or, inside draw.ss), we see that the draw library requires the mzlib:function^ library. So we need to provide that to the unit as an import. Fortunately, plt:userspace^ (which we previously bound to "p") contains this and more; "(p : mzlib:function^)" means "project p down to the mzlib:function^ sig.". Similarly, for shapes-bound-unit that's our new name for a unit; the signature is shapes^ (defined above), and by looking at its imports we see it requries (units whose signature matches) plt:userspace^ and draw^ (in that order), so we prove those units. Finally, we export: open up shapes-bound-unit, and return the unit with those functions. |#