Yes that is my understanding. On 01/17/2012 01:43 AM, Veer Singh wrote: > Thanks , I think I understand it now , so roughly following steps > happens(apology for incorrect terminology) : > > 1. bind the identifier 'phases' to some val(a syntax transformer) in phase 1 > > i) during the above step id 'phase2' is bound to some val i.e syntax > transformer in phase 2 > > ii) (phase2) is expanded i.e it is looked up in phase 2 and it's syntax > transformer applied , which returns the syntax object which is basically #'0 > since cnt was 0 at the time of application of transformer. > > iii) step 1 done. > > > > 2. encounters macro call (set-compile) and expansion takes place and set > cnt=1(phase 1) , cnt=2(phase 2). > > 3. encounters macro call (phases) looks up in phase 1 and its transformer is > applied and we get (list 1 0) , since > (p1 cnt=1) and (p2 0). > > > > On Tue, Jan 17, 2012 at 12:51 PM, Jon Rafkind <rafk...@cs.utah.edu > <mailto:rafk...@cs.utah.edu>> wrote: > > I'm guessing a little bit but I think its because the `phases' macro is > expanded at phase 2 before `set-compile' is called. If you put (set-compile) > before the definition of `phases' then you get '(1 2). > > > On 01/17/2012 12:06 AM, Veer Singh wrote: >> >> Why macro call (phases) produces '(1 0) and not '(1 2) ? >> >> >> (module mod1 racket >> (require (for-syntax syntax/parse)) >> ;"mod-compile.rkt")) >> (require (for-syntax >> (for-syntax syntax/parse racket ))) >> ;"mod-compile.rkt"))) >> (provide set-compile phases) >> >> ;For phase 1 >> (begin-for-syntax >> (define cnt 0) >> >> (define (store! v) >> (set! cnt v))) >> >> ;For phase 2 >> (begin-for-syntax (begin-for-syntax >> (define cnt 0) >> >> (define (store! v) >> (set! cnt v)))) >> >> ;;set the value of "cnt" in phase1 and phase2 >> (define-syntax (set-compile stx) >> (syntax-parse stx >> [(_) #'(begin >> >> (begin-for-syntax >> ; in "cnt" in phase 1 cnt=1 >> (store! 1) >> (begin-for-syntax >> ; in "cnt" in phase 2 cnt=2 >> (store! 2))) >> 'done)])) >> >> >> ;;return the value of cnt in phase1 and phase2 >> (define-syntax (phases stx) >> >> ;phase2 ??? >> (define-syntax (phase2 stx) >> (syntax-parse stx >> [(_) (with-syntax ([p cnt]) >> #'p)])) >> >> >> ;phase1 >> (syntax-parse stx >> [(_) (with-syntax ([p1 cnt] >> [p2 (phase2)]) >> #'(list p1 p2))])) >> >> (set-compile) >> (phases) >> ;produces (list 1 0), but why not (list 1 2) >> >> ) >> >> >> Thanks >> >> >> >> ____________________ >> Racket Users list: >> http://lists.racket-lang.org/users > > > ____________________ > Racket Users list: > http://lists.racket-lang.org/users > >
____________________ Racket Users list: http://lists.racket-lang.org/users