You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
beautiful-racket/beautiful-racket-lib/br/syntax-scopes-test.rkt

62 lines
1.3 KiB
Racket

9 years ago
#lang br
(require (for-syntax br/syntax sugar/debug br/scope) br/syntax br/scope)
9 years ago
(begin-for-syntax
(define-scope blue)
(define-scope yellow)
(define-scope red)
(define-scope green (blue yellow))
(define-scope purple (blue red)))
9 years ago
(define #'(def-blue-x)
(with-blue-binding-form (x)
#'(define x (+ 42 42))))
9 years ago
9 years ago
(define #'(print-blue-x)
(with-purple-identifiers (x)
#'x))
9 years ago
9 years ago
(define #'(define-blue _id _expr)
(with-syntax ([_id (blue-binding-form #'_id)])
#'(define _id _expr)))
9 years ago
9 years ago
(define #'(print-blue-y)
(with-blue-identifiers (y)
#'y))
(scopes (syntax-find (expand-once #'(def-blue-x)) 'x))
(def-blue-x)
(scopes (syntax-find (expand-once #'(print-blue-x)) 'x))
(print-blue-x)
(let ()
(scopes (syntax-find (expand-once #'(print-blue-x)) 'x))
#;(print-blue-x)) ;; error why?
(define-blue y (+ 42 42))
(print-blue-y)
#|
(define #'(def-y)
(with-yellow-binding-form (y)
#'(define y (+ 42))))
#;(scopes (syntax-find (expand-once #'(def-x)) 'x))
#;(def-x)
(def-y)
9 years ago
(scopes (syntax-find (expand-once #'(print-x)) 'x))
(print-x)
9 years ago
(scopes (syntax-find (expand-once #'(print-y)) 'y))
(print-y)
9 years ago
#;(let-syntax ([x (λ(stx) (syntax-case stx () [_ #'42]))])
9 years ago
(* x 4))
|#