Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created January 11, 2013 21:31
Show Gist options
  • Save dyoo/4514112 to your computer and use it in GitHub Desktop.
Save dyoo/4514112 to your computer and use it in GitHub Desktop.
examples for ozzloy of syntax-parse and more tests
#lang racket/base
(require (for-syntax racket/base
syntax/parse))
(provide swap)
(define-syntax (swap stx)
(syntax-parse stx
[(_ x:identifier y:identifier)
#'(let ([tmp x])
(set! x y)
(set! y tmp))]))
(module* test racket/base
(require (submod "..")
rackunit)
;; A little setup for running the compiler and evaluator
;; for the run-time tests
(define-namespace-anchor anchor)
(define ns (namespace-anchor->namespace anchor))
(define-syntax-rule (try expr)
(parameterize ([current-namespace ns])
(eval 'expr)))
;;;;;;;;;;;;;;;;;;;;;;;
(check-exn exn:fail:syntax?
(lambda () (try (begin (define x 'x)
(swap x 2)))))
(check-equal? (try (begin (define x 'foo)
(define y 'bar)
(swap x y)
(list x y)))
'(bar foo)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment