Racket: Duplicate provide should result in an error

Created on 17 Mar 2019  路  2Comments  路  Source: racket/racket

For instance:

#lang racket
(provide a a)
(define a 1)

should result in an error.

This would help catching silly copy and paste mistakes like this:

#lang racket
(provide a-long-name a-long-name) ; forgot to change a-long-name to a-long-name*
(define a-long-name 1)
(define a-long-name* 2)

Most helpful comment

Concerns:

  • Such a change could break existing programs.

  • It is useful for require and provide to be "idempotent" when produced by macros.

(Speaking of macros, one way to avoid such mistakes is to define and use a define/provide macro? I feel like that's part of this theme.)

All 2 comments

Concerns:

  • Such a change could break existing programs.

  • It is useful for require and provide to be "idempotent" when produced by macros.

(Speaking of macros, one way to avoid such mistakes is to define and use a define/provide macro? I feel like that's part of this theme.)

If you'd like to use provide instead of something like define/provide, I recommend keeping each provided identifier on its own line. This makes the duplication more immediately apparent:

#lang racket
(provide a-long-name
         a-long-name) ; forgot to change a-long-name to a-long-name*
(define a-long-name 1)
(define a-long-name* 2)
Was this page helpful?
0 / 5 - 0 ratings