scheme - Why are pattern variables also renamed in macro expansion? -


while reading dybvig's paper syntactic abstraction in scheme, noticed algorithm renames pattern variables. means pattern variables may cause capture. have no idea in case cause capture? can enlighten me?

a macro can expand macro definition using patterns. pattern variables have lexical scope normal variables, need renamed too.

example of macro expanding macro definition.

#lang racket (define-syntax (define-get/put-id stx)   (syntax-case stx ()     [(_ id put!)      #'(define-syntax id          (syntax-id-rules (set!)            [(set! id e) (put! e)]            [(id (... ...)) ((get) (... ...))]            [id (get)]))]))  (define id 0) (set! id 42) (define-get/put-id clock    (λ()  (displayln "reading clock") id)   (λ(x) (displayln "setting clock") (set! id x) id))  clock (set! clock 10) clock  ;;; output reading clock 42 setting clock 10 reading clock 10 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -