[racket] Macros that use local-require (hygiene issues?)

From: Alexander D. Knauth (alexander at knauth.org)
Date: Thu Nov 6 16:31:57 EST 2014

I think I had a similar sort of problem about a year ago (I was at either RacketCon or a Hackathon that same weekend and Mathew Flatt figured it out), and the solution was changing (only-in path a) to (only-in path [a a]).

#lang racket/load
;;provider
(module T racket
  (provide a)
  (define a 1))
;; requirer
(module R racket
  (require (for-syntax syntax/parse))
  (define-syntax (test-binding stx)
    (syntax-parse stx
      [(_ path)
       #'(let () (local-require (only-in path [a a])) a)]))
  (test-binding 'T))
;; go
(require ‘R)


On Nov 6, 2014, at 4:09 PM, Spencer Florence <spencer at florence.io> wrote:

> Hi All,
> 
> I've been struggling to have a macro be given a path then require something from that path. The following code produces and "Unbound Identifier" error, although I would expect it to evaluate to 1. Could someone provide insight into what is going on?
> 
> #lang racket/load
> ;;provider
> (module T racket
>   (provide a)
>   (define a 1))
> ;; requirer
> (module R racket
>   (require (for-syntax syntax/parse))
>   (define-syntax (test-binding stx)
>     (syntax-parse stx
>       [(_ path)
>        #'(let () (local-require (only-in path a)) a)]))
>   (test-binding 'T))
> ;; go
> (require 'R)
> 
> 
> P.S. I attempted to do this with `dynamic-require,` but that failed because in my actual program `path` is sometimes `(submod "..")`, which caused an error about not having a base path.
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.