[plt-scheme] Help with syntax certification

From: Sam TH (samth at ccs.neu.edu)
Date: Wed Feb 27 21:25:20 EST 2008

Sounds great!  I should say that while programming with 'micros' is
not as easy as with more conventional macros for this use case, it
isn't so bad.  Mostly, I just needed to wrap the result of every
transformer with the `splice-requires' function (which we might want
to put in `scheme/require-transform').  So the new programming model
is less needed than the certificate-managing.

And finally, as long as you're thinking about these issues, it took me
quite a while to figure out to use `datum->syntax' in the
implementation of `planet/multiple'.  If that construction could be
made easier, it would be a big help.

But mostly, require-transformers are a very nice addition.

Thanks,

sam th

On Wed, Feb 27, 2008 at 9:17 PM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> The short answer is that `scheme/require-transform' needs to implement
>  and provide more certificate-related functionality. I think you would
>  also like to have support for `require'-form "macro", as opposed to the
>  current "micro" transformers, which can automatically manage
>  certificates in the same way as macros in expression and definition
>  contexts. I'll work on it as soon as possible.
>
>  Matthew
>
>
>
>  At Wed, 27 Feb 2008 17:18:30 -0500, "Sam TH" wrote:
>  > I'm trying to use the new require expanders, and I'm having trouble
>  > with syntax certificates.  Given the following modules:
>  >
>  > --------------------------------------------
>  >
>  > (module m scheme/base
>  >
>  > (require (for-syntax scheme/base scheme/require-transform))
>  >
>  > (define-for-syntax (splice-requires specs)
>  >   (define subs (map (compose cons expand-import) specs))
>  >   (values (apply append (map car subs)) (apply append (map cdr subs))))
>  >
>  > (define-syntax define-module
>  >   (lambda (stx)
>  >     (syntax-case stx ()
>  >       [(_ nm spec ...)
>  >        (syntax/loc stx
>  >          (define-syntax nm
>  >            (make-require-transformer
>  >             (lambda (stx)
>  >               (splice-requires (list (syntax-local-introduce
>  > (quote-syntax spec)) ...))))))])))
>  >
>  > (define-syntax planet/multiple
>  >   (make-require-transformer
>  >    (lambda (stx)
>  >      (syntax-case stx ()
>  >        [(_ plt files ...)
>  >         (let ([mk (lambda (spc)
>  >                     (syntax-case spc (prefix-in)
>  >                       [e
>  >                        (string? (syntax-e #'e))
>  >                        (datum->syntax spc `(planet ,#'e ,#'plt) spc)]
>  >                       [(prefix-in p e)
>  >                        (datum->syntax spc `(prefix-in ,#'p (planet
>  > ,#'e ,#'plt)) spc)]))])
>  >           (splice-requires (map mk (syntax->list #'(files ...)))))]))))
>  >
>  >
>  > (provide galore)
>  > ;; why is this neccessary?
>  > ;(provide planet/multiple)
>  >
>  > (define-module galore
>  >   (planet/multiple ("soegaard" "galore.plt" 3 6)
>  >    (prefix-in table: "table.ss")
>  >    (prefix-in set: "set.ss"))))
>  >
>  > (module n scheme/base
>  >   (require 'm)
>  >   (require (galore)))
>  >
>  > ---------------------------------------------------------
>  >
>  > I get the error:
>  >
>  > compile: access from an uncertified context to unexported syntax from
>  > module: 'm in: planet/multiple
>  >
>  > If I provide `planet/multiple', the error goes away.  But what's the
>  > right solution here?  On Ryan's advice, I tried changing the
>  > definition of `define-module' to the following:
>  >
>  > (define-syntax define-module
>  >   (lambda (stx)
>  >     (syntax-case stx ()
>  >       [(_ nm spec ...)
>  >          (syntax/loc stx
>  >            (define-syntax nm
>  >              (make-require-transformer
>  >               (with-syntax ([(spec ...) (map (syntax-local-certifier)
>  > (syntax->list #'(spec ...)))])
>  >                 (lambda (stx)
>  >                   (splice-requires (list (syntax-local-introduce
>  > (quote-syntax spec)) ...)))))))])))
>  >
>  > Then I get the even stranger error:
>  >
>  >  _: variable used twice in pattern in: prefix-in
>  >
>  > pointing to the second occurrence of `prefix-in' in the definition of
>  > `galore'.  At that point, we were puzzled.
>  >
>  > Thanks,
>  > --
>  > sam th
>  > samth at ccs.neu.edu
>  > _________________________________________________
>  >   For list-related administrative tasks:
>  >   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



-- 
sam th
samth at ccs.neu.edu


Posted on the users mailing list.