What if you instead rename the lang's imports (e.g. with prefix-in), and 
rely on the fact that your definitions override those supplied by the lang?

That way you could write the exact same provide for all the files: 
"provide-if-not-defined" is simply provide. However, you would need to 
manually use the renamed imports in your implmentation.

Rough sketch:

#lang racket/base

(module v1 racket/base
  (provide +))

(module v2 racket/base
  (provide +)
  (require (prefix-in rkt: racket/base))
  ;; At this point, both + and rkt:+ are aliases.
  ;; But after the the following definition, + is yours:
  (define (+ . vs) ;; like racket/base + but wrapped in a list
    (list (apply rkt:+ vs))))

;; (require 'v1)
;; (+ 1 2) => 3

;; (require 'v2)
;; (+ 1 2) => '(3)


On Wednesday, September 2, 2020 at 10:29:12 AM UTC-4, Shriram Krishnamurthi 
wrote:
>
> Related to my previous post [
> https://groups.google.com/g/racket-users/c/OqyqDFxwhf0], I have several 
> cases where I have this kind of pattern:
>
> V1:
>
> #lang racket
> (provide +)
>
> V2:
>
> #lang racket
> (provide [rename-out (my-+ +)])
> (define my-+ …)
>
> Each variant provides some/all primitives directly from the module's lang, 
> while a sibling variant changes their behavior.
>
> Since there are a lot of names, it gets tiresome to remember which things 
> have and haven't been exported. Duplicates are of course caught statically, 
> but missing names are not "caught" at all at module definition time.
>
> It'd be nice to be able to write, say a block like
>
> #lang racket
> (provide-if-not-defined +)
>
> at the top of BOTH files. In V1, this turns into provide; in V2 I'd still 
> write the rename-out, but would only need to do this for the (usually) 
> small number of operations that I am overriding. Having a common block at 
> the top of each variant would ensure that the variants provide the same 
> language.
>
> Shriram
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/fbdc80bf-fe01-441d-af93-e7d614374b56o%40googlegroups.com.

Reply via email to