Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created January 24, 2013 20:17
Show Gist options
  • Select an option

  • Save dyoo/4627246 to your computer and use it in GitHub Desktop.

Select an option

Save dyoo/4627246 to your computer and use it in GitHub Desktop.
#lang racket/base
(require (for-syntax racket/base syntax/parse))
(module+ test (require rackunit))
(define-syntax (test+ stx)
(syntax-parse stx
#:literals (=>)
[(_ (fn arg ...) => v)
(with-syntax ([fn-name (symbol->string (syntax->datum #'fn))])
(quasisyntax/loc stx
(module+ test
#,(syntax/loc stx
(test-equal? fn-name
(fn arg ...) v)))))]))
(define (add-the-answer z)
(+ z 42))
(test+ (add-the-answer -41) => 0)
;; Bonus: how could I make the macro accept
#|
(test+ (add-the-answer -41) => 0
(add-the-answer 2 => 44)
|#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment