[plt-scheme] Help with syntax certification

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Feb 28 12:20:22 EST 2008

In SVN, the new `scheme/require-syntax' library gives you
`define-require-syntax', and `scheme/base' now provides `combine-in',
so you could write

 (define-syntax-rule (define-module nm spec ...)
   (define-require-syntax nm
     (syntax-rules ()
      [(_) (combine-in spec ...)])))

 (define-require-syntax planet/multiple
   (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)]))])
           #`(combine-in #,@(map mk (syntax->list #'(files ...)))))])))

Meanwhile, Ryan gave you the right advice for your old code, except
that require transformers are a separate expansion system than normal
macros (though both use the same syntax-object machinery, of course),
which means that you needed `syntax-local-require-certifier', which is
now provided by `scheme/require-transform'. (I didn't see the strange
`_' error; using `syntax-local-certifier' ad no effect.)

The `provide' side has been extended analogously.

Matthew

At Wed, 27 Feb 2008 19:17:04 -0700, Matthew Flatt 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



Posted on the users mailing list.