Skip to content

Instantly share code, notes, and snippets.

@cky
Last active January 4, 2016 04:59
Show Gist options
  • Save cky/8572253 to your computer and use it in GitHub Desktop.
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!
(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