Last active
January 4, 2016 04:59
-
-
Save cky/8572253 to your computer and use it in GitHub Desktop.
Gauche-style ^ macros for all combinations of one and two letters. Hi, Mark Weaver!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax pollute-my-namespace | |
(let ((letters "abcdefghijklmnopqrstuvwxyz_") | |
(char->symbol (compose string->symbol string))) | |
(define (make-macros stx) | |
(lambda () | |
(for*/lists (ids syntaxes) | |
((x letters) | |
(y letters)) | |
(if (char=? x y) | |
(values (datum->syntax stx (char->symbol #\^ x)) | |
(with-syntax ((x (char->symbol x))) | |
#'(... (lambda (stx) | |
(syntax-case stx () | |
((_ body ...) | |
(with-syntax ((ax (datum->syntax stx 'x))) | |
#'(lambda (ax) body ...)))))))) | |
(values (datum->syntax stx (char->symbol #\^ x y)) | |
(with-syntax ((x (char->symbol x)) | |
(y (char->symbol y))) | |
#'(... (lambda (stx) | |
(syntax-case stx () | |
((_ body ...) | |
(with-syntax ((ax (datum->syntax stx 'x)) | |
(ay (datum->syntax stx 'y))) | |
#'(lambda (ax ay) body ...)))))))))))) | |
(lambda (stx) | |
(with-syntax ((((name ...) body ...) | |
(call-with-values (make-macros stx) cons))) | |
#'(define-syntaxes (name ...) | |
(values body ...)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment