[plt-scheme] htdp and modules

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Nov 22 12:21:45 EST 2007

On Nov 22, 2007, at 11:57 AM, Jan Christiansen wrote:

> We would like to use the provide command. Is it possible to get  
> this as well?
> We also thought about using contracts. Is there a way to use  
> contracts with the HtDP languages in a similar way?

Yes, see below.

>> May I ask why you are not using HtDP this term?
>
> We really would like to use HtDP (and we at least use it for the  
> first quarter of the course) but we would also like to use the  
> module system for the next exercises. We want to demonstrate the  
> ideas of abstract data types.

That's a legitimate concern. I have considered this myself for HtDP/ 
2e (though I wouldn't call this abstract data type. This term is too  
loaded.)

Here are two modules that work in the way you want. The first imports  
contract.ss, though note the unusual spec (when compared with the  
mzscheme language). It also exports a value and a function via  
provide/contract. The second one imports these values.

Assumptions: the modules are in Intermediate Student (+) and the  
requires are restricted to a two-element lib syntax for libraries and  
a one-element string syntax for local files.

If I had time to teach modular organizations, I would use this style.  
-- Matthias


(module foo (lib "htdp-intermediate.ss" "lang")
   (require (lib "testing.ss" "htdp"))
   (require (lib "world.ss" "htdp"))

   (require (lib "contract.ss" "mzlib"))

   (define-struct world (x))
   ;; World = (make-world Nat)

   ;; data example:
   (define world0 (make-world 10))

   ;; World -> Scene
   (define (world-image w)
     (place-image (circle 3 'solid 'red) (world-x w) 50 BACK))

   ;; Scene
   (define BACK (empty-scene 100 100))

   (check-expect (world-image world0)
                 (place-image (circle 3 'solid 'red) 10 50 BACK))
   (generate-report)

   (provide/contract
    [world0 world?]
    [world-image (-> world? image?)]))




(module bar (lib "htdp-intermediate.ss" "lang")
   (require "foo.scm")

   (define img (world-image world0)))



Posted on the users mailing list.