[plt-scheme] Custom expansion and certificates

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Mar 14 08:51:20 EDT 2010

At Sat, 13 Mar 2010 20:57:01 -0700, Neil Toronto wrote:
> All *I* want to do is rebuild syntax 
> lists, perhaps with a couple of macro calls inserted.

That's a job for just `syntax-recertify'. It turns out that the useful
part of your `recertifiable-transform' is just

 (define-for-syntax (recertifiable-transform transform stx)
   (let ([new-stx (transform stx)]
         [inspector (current-code-inspector)])
     (define (recertify s) (syntax-recertify s new-stx inspector #f))
     (values new-stx recertify)))

Note that `syntax-recertify' is a privileged operation, since it
enables rewriting code in an arbitrary way. But the privilege is
granted in our tools' code-inspector configurations, currently.


I can see why you're trying to use `make-syntax-introducer' and
`certifier', but those don't really work with `local-expand'. They're
intended for cases where you're writing your own kind of macro expander
that looks up its own kind of transformer bindings and installs it own
marks and certificates while applying those transformers. (Both `match'
and `for' have their own kinds of transformers, and they're not using
`local-expand' to apply those transformers.) In that case, you attach
and manipulate certificates with a key that gives it control over the
certificates. But `local-expand' doesn't give you the keys that it uses
for its own certificates, except indirectly though `syntax-recertify'.


> >  - Why use an inactive vs. an active certifier?
> 
> The real question is, what's the difference between an active and an 
> inactive certificate? I can't find a good summary of *what they are* in 
> the docs - just the fact that there *is* a distinction and (in scattered 
> places) that it matters in certain ways.

Section 16.2.5.1 of the Guide is the only explanation so far. (I am
working toward a better explanation, but so far I'm still in the
trying-to-try phase.)

Active certificates show up on expansion results, while inactive
certificates are attached to `syntax'-quoted terms that will be used in
later expansion results. In other words, syntax objects with inactive
certificates form a kind of closure that can be instantiated later as a
certified expressions.



Posted on the users mailing list.