Created
January 11, 2013 21:25
-
-
Save dyoo/4514083 to your computer and use it in GitHub Desktop.
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
#lang racket/base | |
(require (for-syntax racket/base)) | |
(provide swap) | |
;; taken from: | |
;;http://docs.racket-lang.org/guide/syntax-case.html | |
(define-syntax swap | |
(lambda (stx) | |
(syntax-case stx () | |
[(swap x y) | |
(if (and (identifier? #'x) | |
(identifier? #'y)) | |
#'(let ([tmp x]) | |
(set! x y) | |
(set! y tmp)) | |
(raise-syntax-error #f | |
"not an identifier" | |
stx | |
(if (identifier? #'x) | |
#'y | |
#'x)))]))) | |
(module* test racket/base | |
(require (submod "..") | |
rackunit) | |
(define x 'x) | |
;; A little setup for running the compiler for the run-time tests | |
(define-namespace-anchor anchor) | |
(define ns (namespace-anchor->namespace anchor)) | |
(define-syntax-rule (try-compile expr) | |
(parameterize ([current-namespace ns]) | |
(compile 'expr))) | |
(check-exn exn:fail:syntax? | |
(lambda () (try-compile (swap x 2))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment