You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sugar/define.rkt

41 lines
1.2 KiB
Racket

11 years ago
#lang racket/base
(require (for-syntax racket/base))
(require racket/contract)
11 years ago
(provide define+provide define+provide/contract define/contract+provide)
11 years ago
11 years ago
;; each define macro recursively converts any form of define
;; into its lambda form (define name body ...) and then operates on that.
11 years ago
(define-syntax (define+provide stx)
11 years ago
(syntax-case stx ()
11 years ago
[(_ (proc arg ... . rest-arg) body ...)
11 years ago
#'(define+provide proc
11 years ago
(λ(arg ... . rest-arg) body ...))]
11 years ago
[(_ name body ...)
#'(begin
(provide name)
(define name body ...))]))
11 years ago
(define-syntax (define+provide/contract stx)
11 years ago
(syntax-case stx ()
11 years ago
[(_ (proc arg ... . rest-arg) contract body ...)
#'(define+provide/contract proc contract
11 years ago
(λ(arg ... . rest-arg) body ...))]
11 years ago
[(_ name contract body ...)
#'(begin
(provide (contract-out [name contract]))
(define name body ...))]))
(define-syntax (define/contract+provide stx)
(syntax-case stx ()
[(_ (proc arg ... . rest-arg) contract body ...)
#'(define/contract+provide proc contract
(λ(arg ... . rest-arg) body ...))]
[(_ name contract body ...)
#'(begin
(provide name)
(define/contract name contract body ...))]))