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/macro.rkt

28 lines
698 B
Racket

11 years ago
#lang racket/base
(require (for-syntax racket/base))
11 years ago
(require racket/syntax)
11 years ago
11 years ago
(provide define->macro)
11 years ago
11 years ago
11 years ago
(define-syntax define->macro
(syntax-rules ()
[(_ (proc-name arg ... . rest-arg) proc-expr ...) (define->macro proc-name (λ(arg ... . rest-arg) proc-expr ...))]
[(_ proc-name proc) (define-syntax proc-name
(syntax-id-rules ()
[(proc-name expr (... ...)) (proc expr (... ...))]
[proc-name proc]))]))
11 years ago
11 years ago
11 years ago
;(define foo (λ(x) (add1 x)))
(define->macro foo (λ(x) (add1 x)))
11 years ago
11 years ago
(foo 4)
(map foo '(2 4 6))
11 years ago
11 years ago
;(define (bar x) (add1 x))
(define->macro (bar x y) (+ x y))
11 years ago
11 years ago
(bar 4 1)
(map bar '(2 4 6) '(2 4 6))