;;; Take the draw library, and augment it with just one function: ;;; ;; make-color: num, num, num --> color ;; Takes in the red, green, and blue components of a color ;; (each in [0,256) ) and returns a color object suitable ;; for use with draw-solid-rect. ;; ;(define (make-color r g b) ...) ;;;;; ;; 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 color^ (make-color)) (define color-unit (unit/sig color^ (import plt:userspace^ draw^) ; Now, the implementation: (define (make-color r g b) (make-object color% r g b)) )) ;; At this point, color-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)] [ color-bound-unit : color^ (color-unit p draw) ]) (export (open draw) (open color-bound-unit))) #| ;; v200 will simplify teachpacks (as any other module). ;; So don't worry about this magic: ;; 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.". 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. |#