[racket] A macro's `require' works in module but not in REPL

From: Danny Yoo (dyoo at hashcollision.org)
Date: Fri Oct 19 19:15:26 EDT 2012

On Fri, Oct 19, 2012 at 9:04 AM, Greg Hendershott
<greghendershott at gmail.com> wrote:
> I need to fix a bug, https://github.com/greghendershott/gapi/issues/2 .
> I've distilled to a simple case that exhibits the behavior:
> ;; def.rkt
> #lang racket
> (provide define-foo)
> (define-syntax define-foo
>   (lambda (stx)
>     #`(begin
>         (require net/uri-codec)
>         (define (#,(datum->syntax stx 'foo))
>           (alist->form-urlencoded '([a . "1"]))))))

The macro's outputted code appears to require net/uri-codec.  But
rather that require be part of the macro's output, you probably should
just modify def.rkt so that it requires net/uri-codec directly.

Basically, change def.rkt and lift the require up:

#lang racket
(provide define-foo)

(require net/uri-codec)
(define-syntax define-foo
  (lambda (stx)
    #`(define (#,(datum->syntax stx 'foo))
        (alist->form-urlencoded '([a . "1"])))))

Posted on the users mailing list.