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

32 lines
755 B
Racket

#lang racket/base
(require (for-syntax racket/base))
(require racket/syntax)
(provide define->macro)
(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]))]))
;(define foo (λ(x) (add1 x)))
(define->macro foo (λ(x) (add1 x)))
(foo 4)
(map foo '(2 4 6))
;(define (bar x) (add1 x))
(define->macro (bar x y) (+ x y))
(bar 4 1)
(map bar '(2 4 6) '(2 4 6))
(define-syntax zam (add1 x))
(zam 4)
(map zam '(2 4 6))