[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: module questions



Quoting Michael Vanier:
> By using "load" or the module system, right?  If the latter, then how does
> one use units to avoid the mutual-recursion-between-modules problem
> described previously if the units are in different modules?  I may be
> missing something obvious here, so be gentle :-)

Units that are linked together don't refer to each other. Instead, they
both refer to a set of signatures, and then some third bit of code
refers to both units to link them together. Example below.

If unit `A' wants to dynamically invoke unit `B', and unit `B' wants to
dynamically invoke unit `A', then you're back to square one. You'd have
to abstract over one of the invocations --- the one in `B', say --- and
let some other bit of code choose a specific invovation --- of `A',
say. That seems like an unusual situation, though.

Matthew

----------------------------------------

(module a mzscheme
  (require (lib "unitsig.ss")
           sigs)
  
  (provide a@)
  
  (define a@
    (unit/sig a^
      (import b^)
      (define (odd n)
        (if (zero? n)
            #f
            (even (sub1 n)))))))

(module b mzscheme
  (require (lib "unitsig.ss")
           sigs)

  (provide b@)
  
  (define b@
    (unit/sig b^
      (import a^)
      (define (even n)
        (if (zero? n)
            #t
            (odd (sub1 n)))))))

(module oe mzscheme
  (require (lib "unitsig.ss")
           sigs
           a
           b)
  (provide odd even)
  
  (define-values/invoke-unit/sig
   ((open a^) (open b^))
   (compound-unit/sig
     (import)
     (link [A : a^ (a@ B)]
           [B : b^ (b@ A)])
     (export (open A) (open B)))))