[plt-scheme] Resources in the transformer environment

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Oct 27 18:16:12 EDT 2006

I had forgotten that again... Not being able to `local-expand' a
`letrec-syntaxes+values' form seems like a significant limitation or
`local-expand'.

For example, if you put a `define-struct' definition inside a
`with-database' form, then the internal definitions in the body of
`with-database' turn into a `letrec-syntaxes+values' instead of a plain
old `letrec-values'. With `letrec-syntaxes+values' in the stop list, a
`dbo-class*' expression in the body won't be expanded, which was the
goal.

I imagine that putting `letrec-syntaxes+values' in the stop list going
to work well enough for your immediate purposes, but I need to look at
this more (or, at the very least, properly document the current
limitation).

Thanks,
Matthew

At Fri, 27 Oct 2006 18:04:42 -0400, "Jon Zeppieri" wrote:
> Eh, I figured out the problem from this:
> 
> http://list.cs.brown.edu/pipermail/plt-scheme/2003-July/003177.html
> 
> It appears to be working now that I added letrec-syntaxes+values to
> the stop list for local-expand.
> 
> -Jon
> 
> 
> On 10/27/06, Jon Zeppieri <zeppieri at gmail.com> wrote:
> > Hi,
> >
> > So, I've attempted to implement the macro suggested below:
> >
> > On Fri, 27 Oct 2006 08:13:22 0800, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> > > Would it make sense to have a form like
> > >
> > >  (with-database
> > >   "host.domain.foo" 3306 "my_username" "my_password" "my_schema"
> > >   <body>)
> > >
> > > that opened the database both a compile time and at run time? The macro
> > > might be implemented as mostly
> > >
> > >   (dynamic-wind
> > >    (lambda () <...open the database...>)
> > >    (lambda () ... (local-expand <body> ...) ...)
> > >    (lambda () <...close the database...>))
> > >
> > > but the expansion of <body> would also be wrapped with a similar
> > > `dynamic-wind' to perform the same DB open and close.
> >
> > Here is the code:
> >
> >   (define-syntax (with-database stx)
> >     (syntax-case stx ()
> >       ((_ (host port username password schema) body-expr ...)
> >        (dynamic-wind (lambda ()
> >                        (display "opening transformer DB connection\n")
> >                        (current-connection (connect
> > (syntax-object->datum #'host)
> >
> > (syntax-object->datum #'port)
> >
> > (syntax-object->datum #'username)
> >
> > (syntax-object->datum #'password)
> >
> > (syntax-object->datum #'schema))))
> >                      (lambda ()
> >                        (local-expand #'(dynamic-wind (lambda ()
> >                                                        (display
> > "opening runtime DB connection\n")
> >
> > (current-connection (connect host port username password schema)))
> >                                                      (lambda ()
> >                                                        body-expr ...)
> >                                                      (lambda ()
> >                                                        (display
> > "closing runtime DB connection\n")
> >                                                        (close
> > (current-connection))))
> >                                      (syntax-local-context)
> >                                      '()))
> >                      (lambda ()
> >                        (display "closing transformer DB connection\n")
> >                        (close (current-connection)))))))
> >
> >
> > When I attempt to use it, however, there is a problem:
> >
> > (module foo mzscheme
> >
> >   (require (lib "dbo.ss" "dbo"))
> >
> >   (with-database (<host> <port> <username> <password> <schema>)
> >     (define project%
> >       (dbo-class* "project" object% ()
> >                   (super-new)))
> >
> >     (define o (make-object project%))
> >     (define ps (send o find #:all))
> >     (display ps))
> > )
> >
> > ...results in...
> >
> > opening transformer DB connection
> > closing transformer DB connection
> > compile: identifier used out of context in: local-accessor
> >
> >
> > Perhaps I'm expanding the body in the wrong context?
> >
> > -Jon
> >
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.