Skip to content

Instantly share code, notes, and snippets.

@wilbowma
Created February 17, 2023 21:54
Show Gist options
  • Save wilbowma/79dc8d4fbc2080541d3d3446dda2de89 to your computer and use it in GitHub Desktop.
Save wilbowma/79dc8d4fbc2080541d3d3446dda2de89 to your computer and use it in GitHub Desktop.
#lang racket/base
(require
(for-syntax
racket
syntax/parse)
racket/contracts)
(provide (rename-out [new-define/contract define/contract]))
(define-syntax (new-define/contract stx)
(syntax-parse stx
[`(_ (name args ...) contract body ...)
#`(define (name args ...)
(define (unsafe-name)
body ...)
(define/contract (name^)
contract
(unsafe-name))
(if (ENABLE_CONTRACTS?)
(name^)
(unsafe-name)))]))
(define ENABLE_CONTRACTS (make-parameter (and (getenv "ENABLE_CONTRACTS") #true))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment