[plt-scheme] Custom expansion and certificates

From: Neil Toronto (ntoronto at cs.byu.edu)
Date: Sun Mar 14 04:31:19 EDT 2010

Update: Somehow I stumbled onto something that worked, and then 
something clicked. I pared it down to what I think are essentials (for 
me), and made an abstraction over all this marking, certifying, etc.:

   recertifiable-transform :
     (syntax? -> syntax?) syntax? -> syntax? (syntax? -> syntax?)

which takes a transformer and a syntax object, and returns a syntax 
object and a recertifier. You can apply the recertifier to any syntax 
object that contains an introduced, unexported identifier from the 
original return object, and it'll keep the compiler from complaining 
about identifiers in uncertified contexts.

There's also recertifiable-local-expand, which sends a partially applied 
local-expand to recertifiable-transform as the transformer.

New question: Is this complete enough for most tasks that involve 
transforming the results of local expansions?

Updates to my questions follow.

Neil Toronto wrote:
>  - Why syntax-local-introduce first?

Still no idea. I'm not using it, and all the test cases for the larger 
project I'm working on pass without it.

> - Can syntax have only one mark at a time?

Nope. I peeked through the C code for this and saw... a lot of evilness, 
but also a lot of marks. :)

>  - Why undo the new marks before applying the local certifier?

This leaves all syntax *introduced by the transformer* marked - 
unexported identifiers in particular - so it can be certified locally. 
Then syntax containing it can be recertified later as needed.

>  - How deep is the local certifier's recursion?

Deep, I think. I think the recertifier can be shallow, since only one 
outer expression needs to have the right certificate to keep the 
introduced, unexported identifiers happy.

>  - When am I losing the certificates? In syntax->list or datum->syntax?

Calling syntax->list loses the outermost certificate, which is the 
"safest" place to have one. IOW, syntax->list causes the error when one 
of its immediate subexpressions is an introduced, unexported identifier.

>  - Why doesn't the match's pattern expander use syntax-recertify, when 
> the sequence transformer expander does?

I still don't know. I had to use it.

>  - 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.

Does any macro wizard care to complete/correct?

Neil T

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: expandify.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100314/a9558181/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: get-xs.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100314/a9558181/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: expandify-test.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100314/a9558181/attachment-0002.ksh>

Posted on the users mailing list.