[racket] Delimiting scope

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Wed Jan 22 13:49:11 EST 2014

One idea for this macro is to turn the body into a function that you
lift to the top-level but call in that stop. This would make it only
able to refer to globals. If you wanted to go further, you could have
it lift a submodule definition to the top, generate a local-require,
and then generate a call to the function. This would make it totally
separate.

On Tue, Jan 21, 2014 at 11:57 AM, antoine <antoine.brand at sfr.fr> wrote:
> 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?
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users



-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.