[plt-scheme] Units implementation: to access imports by indexes

From: Ryan Culpepper (ryanc at ccs.neu.edu)
Date: Thu May 14 12:08:21 EDT 2009

Keiko Nakata wrote:
> Hello,
> Would it have been possible to compile units into e.g. vectors
> and to access imports by indexes? In particular, having local aliases
> for imports is indispensable? 
> Eventually I would like to tweak the current unit implementation so
> that members of a compound unit, which belong to different constituent
> units, are initialized in a more independent order a la lazy
> evaluation. At this moment I am not sure if it is feasible at all, but
> it seems access by indexes is more handy for my goal. 

To a first degree of approximation, an import is represented as a vector 
of boxes. The vector is unpacked in the unit body and hidden temporary 
names are given to the boxes. The imported names are bound as macros 
that expand into box accesses ('unbox') of the hidden names.

If the box indirection were eliminated, then it would be impossible to 
garbage collect unit-exported values independently: a closure that 
referred to one imported name would keep all of them alive, because that 
reference would really be a reference to the vector plus an index.

(With Stevie's introduction of unit contracts, the representation has 
changed somewhat, but the basic idea is the same, with extra steps for 
contract wrapping.)

Perhaps you should try changing the boxes to promises. Currently, only 
definitions of exports are rewritten to use boxes, but you might need to 
rewrite local (unexported) definitions to use promises too.


Posted on the users mailing list.