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"]))))))

>From a module (e.g. a definitions pane in DrRacket), I can use it like this:

;; use.rkt
#lang racket
(require "def.rkt")
(define-foo)
foo
(foo)

As expected this prints:

#<procedure:foo>
"a=1"

But if you open a REPL and type those exact lines one by one, it fails
at the last line:

$ racket
Welcome to Racket v5.3.
-> (require "def.rkt")
-> (define-foo)
-> foo
#<procedure:foo>
-> (foo)
; alist->form-urlencoded.11: undefined;
;  cannot reference undefined identifier
; [,bt for context]
-> ,bt
; alist->form-urlencoded.11: undefined;
;  cannot reference undefined identifier
;   context...:
;    /Applications/Racket_v5.3/collects/xrepl/xrepl.rkt:1341:0
;    /Applications/Racket_v5.3/collects/racket/private/misc.rkt:87:7
->

The `foo' procedure is defined; good. But when called, the procedure
body thinks `alist->form-urlencoded' is undefined, it wasn't imported
by the (require net/uri-codec).

(Same thing in a fresh Expressions pane in DrRacket; so not e.g.
related to XREPL or whatever).

Huh ... ?


Back in use.rkt, I can use the macro stepper to expand, and it's what I expect:

(module use racket
  (#%module-begin
   (require "def.rkt")
   (begin (require net/uri-codec) (define (foo)
(alist->form-urlencoded '((a . "1")))))
   foo
   (foo)))

I can also cut and paste that into the REPL, then require that module,
which works:

-> (module use racket
     (#%module-begin
      (require "def.rkt")
      (begin (require net/uri-codec) (define (foo)
(alist->form-urlencoded '((a . "1")))))
      foo
      (foo)))
-> (require 'use)
#<procedure:foo>
"a=1"

So seems it must be the case that a (require "def.rkt") expands
differently in the REPL. But I can't use the macro stepper in the
REPL. (Or can I, somehow?)


Does anyone have any suggestions what's happening and how I could fix
this?  Or should I close the issue unfixed, "as-designed"? o_O
____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to