[racket] filtering syntax

From: Veer Singh (veer.chah at gmail.com)
Date: Wed Jan 18 05:36:36 EST 2012

This seems to work (blind hack), I really don't know
what syntax-local-make-definition-context and syntax-local-bind-syntaxes
does
I can only assume that they introduce some kind of bindings in particular
context.


(define-syntax (depgraph stx)
  (syntax-parse stx
    [(_ ((id:id expr:expr ...) ...))

     (define id-lst (syntax->list #'(id ...)))
     (define ctx (syntax-local-make-definition-context))
     (syntax-local-bind-syntaxes id-lst #f ctx)
     (with-syntax ([p #'((lambda () expr ...) ...)])
       (define p-lst (syntax->list #'p))
       (define vars
         (map (lambda (e)
                (free-vars
                 (local-expand e 'expression '() ctx))) p-lst))
       (with-syntax ([((f ...) ...) vars])
         #''((id (f ...)) ...)))]))


(define simple-arith
 (depgraph
  ((a #f)
   (b (* 3 a))
   (c (+ 5 a b))
   (d (let ((a 9)) (- c a))) )))

simple-arith
;((a ()) (b (a)) (c (b a)) (d (c)))



On Wed, Jan 18, 2012 at 1:46 PM, Marijn <hkBst at gentoo.org> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 17-01-12 16:14, Sam Tobin-Hochstadt wrote:
> > On Tue, Jan 17, 2012 at 4:06 AM, Marijn <hkBst at gentoo.org> wrote:
> >> On 16-01-12 15:28, Sam Tobin-Hochstadt wrote:
> >>> On Mon, Jan 16, 2012 at 7:57 AM, Marijn <hkBst at gentoo.org>
> >>> wrote:
> >>>>
> >>>> ((_ ((id rule) ...)) (with-syntax (((dep ...) (free-vars
> >>>> (expand #'(rule ...)))))
> >>>
> >>> You need to use `local-expand', not `expand', here.  Probably
> >>> like this:
> >>>
> >>> (local-expand #'(rule ...) 'expression '())
> >>>
> >>
> >> If I use that instead I still get the same error. Perhaps it
> >> needs to be something like:
> >>
> >> (local-expand #'(rule ...) 'expression '(id ...))
> >>
> >> but '(id ...) is not in the right form...
> >
> > Ah, I see the problem.  You're trying to expand expressions with
> > unbound variables, and they give an expansion error as they
> > should. You might be able to use the stop list to make this work,
> > but the right solution is to bind the variables.
>
> I don't understand how or where I should bind these identifiers that
> I'm trying to detect are free. A working example of how to use
> free-vars would really help.
>
> Marijn
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.18 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk8Wf/gACgkQp/VmCx0OL2xItQCcDVKB+NzajXbsjg9JfIoUZvSP
> PG4An0aV6d4XuZeBQNQqj+rtNnx6yCuz
> =0a9B
> -----END PGP SIGNATURE-----
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120118/b37c3465/attachment.html>

Posted on the users mailing list.