Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax-local-lift-require is permitted in a 'module-begin context in Racket 7, but does not actually work #2052

Closed
lexi-lambda opened this issue Apr 20, 2018 · 4 comments

Comments

@lexi-lambda
Copy link
Member

The following program fails with an error:

#lang racket/base

(require (for-syntax racket/base
                     syntax/strip-context)
         syntax/parse/define)

(provide #%module-begin)

(define-syntax-parser #%module-begin
  [(_ . body)
   (syntax-local-lift-require
    'racket
    (datum->syntax #f (cons '#%module-begin (strip-context #'body))))])

(module* test (submod "..")
  (match-define _ #f))
expand: namespace mismatch; cannot locate module instance
  module: #<module-path-index:racket/match/match>
  use phase: 0
  definition phase: 0
  for identifier: #<syntax:bad.rkt:16:3 match-define>

It fails on Racket 6.12 as well, but much earlier and with a different (less confusing) error:

syntax-local-lift-requires: could not find target context
  context...:
   standard-module-name-resolver

I would actually very much appreciate it if syntax-local-lift-require was made to work properly in a 'module-begin context, but if that doesn’t make any sense, it should signal an error like it does in Racket 6.12.

@mflatt
Copy link
Member

mflatt commented Apr 24, 2018

I've pushed a repair to restore v6.12 behavior.

So far, trying to make syntax-local-lift-require work in a 'module-begin context doesn't sound like a good idea. For the purposes I can imagine, a trampoline to a macro within #%plain-module-begin seems better. However, you may have an example that I haven't imagined, so I'm open to the possibility that syntax-local-lift-require should work in a 'module-begin context.

@lexi-lambda
Copy link
Member Author

I think you’re right that I can make a trampoline work in my case with a little extra work, so I’ll give it a try, and if it works, I’ll close this issue as resolved.

For context, what I’m doing is a bit unorthodox. I’m interested in essentially expanding the body of one module in a module with a different module language, and I want to be able to introduce all the bindings of the original module language before expanding its #%module-begin. However, what I can probably do is expand to my own #%plain-module-begin to get a 'module expansion context, expand the other module’s contents in a 'module-begin context, and manually extract the subforms from the resulting #%plain-module-begin form to splice them into the form I’ve already expanded to.

@mflatt
Copy link
Member

mflatt commented Apr 24, 2018

In case you haven't looked at it already, I think the "hyper-literate" package does something like that, but with local-expand on a synthesized submodule (if I remember correctly).

@lexi-lambda
Copy link
Member Author

Yes, it looks like I got a trampoline that works for my needs. I think I can also apply this technique to fix something in Hackett, but that’s for another day. Thanks for your help. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants