[racket] Delimiting scope
Bonjour,
I have tested this code:
;;;;
#lang racket
(require
(for-syntax racket))
(define-syntax (delimit-scope stx)
(syntax-case stx ()
[(_ form)
((make-syntax-introducer)
(datum->syntax #'here (syntax->datum #'form)))]))
(define z 13)
(let ([z 14])
(delimit-scope
z))
;;;;
And it capture the module level binding.
So i have write another version, this one check all identifier from stx and
raise an exception if it is bind at module level:
;;;;
#lang racket
(require
(for-syntax racket))
(define-syntax (delimit-scope-bis stx)
(syntax-case stx ()
[(_ form)
(let ([marked (syntax-local-introduce (datum->syntax #'here (syntax->datum #'form)))])
(if (and (identifier? marked)
(list? (identifier-binding marked)))
(raise (format "~a cannot be lexical scoped" (syntax->datum marked)))
(let loop ([lst (syntax->list marked)])
(when (not (empty? lst))
(let ([f (first lst)])
(cond [(and (identifier? f)
(list? (identifier-binding f)))
(raise (format "~a cannot be lexical scoped" (syntax->datum f)))]
[(syntax->list f)
(loop f)])))))
s)]))
(define a 13)
(let ([a 12])
(delimit-scope-bis
a))
uncaught exception: "a cannot be lexical scoped"
;;;;
Is there a way to delimit module level bind using syntax mark mechanisme?
Can i view the syntax marks of a syntax object?