[plt-scheme] compound mutually recursive units

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Thu Jan 22 18:11:57 EST 2009

On Jan 22, 2009, at 10:31 AM, Keiko Nakata wrote:

> Hello.
> I want to compound a unit from several units to form recursive
> bindings, where the imports of a constituent unit are
> supplied by several other constituents; I cannot figure out how to do
> this concisely.
> Here is a snippet from my code, which implements a toy language:
> ;; heap
> (define-signature Heap_import^ (eval_cexpr eval_mexpr))
> (define-signature Heap_export^ (heap_locate new_location  
> eval_location))
> (define-unit Heap@  (import Heap_import^)  (export Heap_export^) ... )
> ;; the core language
> (define-signature Cexpr_import^ (eval_location))
> (define-signature Cexpr_export^ (subst_cexpr eval_cexpr))
> (define-unit Cexpr@ (import Cexpr_import^) (export Cexpr_export^) ...)
> ;; the mixin language
> (define-signature Mexpr_import^ (heap_locate new_location  
> eval_location subst_cexpr))
> (define-signature Mexpr_export^ (eval_mexpr))
> (define-unit Mexpr@ (import Mexpr_import^) (export  
> Mexpr_export^) ... )

Typically, you define signatures for the exports of your units, like so:

(define-signature Heap^ (heap_locate new_location eval_location))
(define-signature Cexpr^ (subst_cexpr eval_cexpr))
(define-signature Mexpr^ (eval_mexpr))

Instead of creating a new signature for each unit to describe its  
imports, you pick the subset of the signatures above that covers the  
bindings each unit needs. So the unit definitions would look like this:

(define-unit Heap@
   (import Cexpr^ Mexpr^)
   (export Heap^)

(define-unit Cexpr@
   (import Heap^)
   (export Cexpr^)

(define-unit Mexpr@
   (import Heap^ Cexpr^)
   (export Mexpr^)

This means that units often import things that they don't actually  
need, just because they belong to the same signature as something else  
they do need. This is not a problem.

Finally, you can compound the units together using 'define-compound- 
unit/infer'. For example, if you want that unit to re-export  
everything defined by the others, list all of the subunits' export  
signatures in the compound unit's export clause:

(define-compound-unit/infer Program@
   (export Heap^ Cexpr^ Mexpr^)
   (link Heap@ Cexpr@ Mexpr@))

Hope that helps,

> I want to compound all the three units Heap@, Cexpr@ and Mexpr at .
> An easiest way seems to split up signatures in pieces, which does not
> sound very elegant.
> I appreciate any advice.
> Kind regards,
> Keiko
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.