[racket] Simplified scut-like macro
#lang racket
(define-syntax (fun stx)
(syntax-case stx ()
((fun body rest ...)
(with-syntax ((x (datum->syntax #'body 'x))
(y (datum->syntax #'body 'y))
(z (datum->syntax #'body 'z)))
(let ([y? (identifier-binding #'y)]
[z? (identifier-binding #'z)])
#`(case-lambda [(x) (letrec (#,@(if y? '() (list #'(y y)))
#,@(if z? '() (list #'(z z))))
body rest ...)]
[(x y) (letrec (#,@(if z? '() (list #'(z z))))
body rest ...)]
[(x y z) body rest ...]))))))
(map (fun x) '(1 2 3))
(map (fun (+ x x)) '(1 2 3))
(map (fun (+ x y)) '(1 2 3) '(1 2 3))
(define y 10)
(map (fun (+ x y)) '(1 2 3))
(map (fun (+ x z)) '(1 2 3))