[racket] filtering syntax
At Wed, 18 Jan 2012 16:53:14 +0100, Marijn wrote:
> So after rewriting for syntax-case, this becomes the below, where I
> have also inserted a call to internal-definition-context-seal which
> was mentioned by the documentation as being required, but causes no
> obvious problems when absent. Should it be used here?
Yes, it should be used.
I think that an error is triggered only if a syntax object with the
relevant context ends up syntax-quoted the output of a macro. That is,
if you remove the call to `internal-definition-context-seal' and change
the ending #'' to #'#' (so that the result of expansion is a `syntax'
form instead of a `quote' form), then the compiler complains.
Even if the compiler has no reason to complain, though, using
`internal-definition-context-seal' can speed macro expansion, since the
expander cannot memoize certain binding calculations if the lexical
context is unsealed.
> #lang racket
>
> (provide dependency-graph)
>
> (require (for-syntax syntax/free-vars))
>
> (define-syntax (dependency-graph stx)
> (syntax-case stx ()
> ((_ ((id rule) ...))
> (let ((ctx (syntax-local-make-definition-context)))
> (syntax-local-bind-syntaxes (syntax->list #'(id ...)) #f ctx)
> (internal-definition-context-seal ctx)
> (with-syntax
> (((dep ...)
> (map (lambda (expr)
> (free-vars
> (local-expand expr 'expression '() ctx)))
> (syntax->list #'(rule ...)))))
> #''((id . dep) ...))) )))