[racket] module browser

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Wed May 23 16:04:40 EDT 2012

On 05/23/2012 12:31 PM, Neil Van Dyke wrote:
> Thanks, Ryan, that info is helpful, although it's missing most of the
> reasons I've had to partition one library into several modules (macro
> transformers).
> As people have mentioned before, there seems to be a theoretical brick
> wall preventing these tools from seeing references that likely will be
> used in the results of macro transformations. I don't understand that in
> all cases. For one example, the transformers often have templates that
> should know many of the symbols and exactly where they're coming from.
> (Is this information from templates lost too soon? Is the information
> from templates not as precise as I assumed?)

IIRC, 'check-requires' does in fact inspect syntax templates. The 
problem is that it's not possible to predict in what phase(s) the 
identifiers in a syntax template will be interpreted.

For example, consider this module:

(module AMB racket
   (require (for-template (rename-in racket/base [- shifty]))
            (only-in racket/base [+ shifty]))
   (define shifty-stx #'(shifty 1 2))
   (provide shifty-stx))

Does the occurrence of 'shifty' in the syntax template refer to '+' or 
'-'? It might be both.

If it's used in a macro, 'shifty' means '-':

   (require (for-syntax 'AMB))
   (define-syntax m (lambda _ shifty-stx))
   ;; => -1

but if it's evaluated with 'eval', 'shifty' means '+':

   (require 'AMB)
   (eval shifty-stx (make-base-namespace))

(Exercise: add (require (for-meta 2 (rename-in racket/base [+ shifty]))) 
to AMB. See if you can construct a program that interprets 'shifty' as '*'.)


But I'd estimate that 90% of the time, an identifier in a syntax 
template is interpreted at the phase one less than the phase the syntax 
template occurs in. And 90% of the remaining cases it's interpreted in 
the same phase as the syntax template. So that's what 'check-requires' 
assumes (see 'analyze/quote-syntax' in 

If 'check-requires' isn't seeing dependencies from syntax templates, can 
you send me an example?

 > For another example (or
> possibly the same thing), these tools seem to be missing references in
> the code of "syntax-parse" productions that is outside templates and
> that I'd think is unambiguous.

I don't understand what you mean. Can you give an example?


> BTW, a student who is bored over the summer could do worse than to
> enhance the Module Browser in some other ways. First low-hanging fruit
> step might be to put the information from "check-requires" into tooltips
> on the arrows. Then there's a lot one could do with graph drawing. And,
> as a small graphics tweak, you can make it skip redundant repaints
> queued up when dragging. (Summer is good for this. More than a little
> sun exposure will just age your skin prematurely and give you melanoma,
> anyway.)
> Neil V.
> Ryan Culpepper wrote at 05/23/2012 02:28 PM:
>> On 05/23/2012 11:13 AM, Neil Van Dyke wrote:
>>> In the Module Browser, has anyone tried annotating the graph edges with
>>> imported symbols that are actually referenced by the importing module?
>>> Maybe further annotate those symbols with phases?
>> You can get this information (in text form) from the check-requires
>> utility. You may find the code in
>> macro-debugger/analysis/check-requires (and its dependencies) useful
>> if you want to add this information to the module browser. Getting the
>> set of references is actually somewhat tricky, and I think my code
>> does as good a job as possible.
>> Ryan

Posted on the users mailing list.