> On Nov 21, 2015, at 6:21 AM, thomas.lynch > <[email protected]> wrote: > > The example in the manual for quote-srcloc shows it wrapped as a syntax > object, and it gives the correct call point location answer. however, when > the result from quoteloc is instead put in a variable, then variable has the > wrong location (not the call location of stx). > > An explanation of this behavior would shed a lot of light on this subject. > > The objective here is to get a source/loc structure with call point from the > stx passed into the syntax transformer. Is this what quote-srcloc is for? > > #lang racket > > (require syntax/location) > (require (for-syntax syntax/location)) > > (define-syntax (here stx) #`(quote-srcloc #,stx)) > > (define-syntax (here2 stx) > (let( > [a-location (quote-srcloc stx)] > ) > (datum->syntax stx a-location) > ))
The quote-srcloc form is meant to be used in a runtime position (something required normally), not within a transformer (something required for-syntax). The thing you're probably looking for is either build-source-location list from syntax/srcloc (http://docs.racket-lang.org/syntax/Source_Locations.html#%28def._%28%28lib._syntax%2Fsrcloc..rkt%29._build-source-location-list%29%29). For example: #lang racket (require (for-syntax syntax/srcloc)) (define-syntax (here2 stx) (let ([a-location (build-source-location-list stx)]) #`(quote #,(datum->syntax stx a-location)))) build-source-location-list is basically a syntax-srcloc->list function, that also happens to work with multiple arguments and multiple types of arguments. > > (here) > (here2) > > > #| > [email protected]> (enter! "test-here.rkt") > [re-loading /home/deep/liquid-extensions/liquid/test-here.rkt] > (srcloc "<pkgs>/liquid-extensions/liquid/test-here.rkt" 21 0 342 6) <-- yes > line 21 > (srcloc "<pkgs>/liquid-extensions/liquid/test-here.rkt" 15 36 276 3) <-- > heck no should be line 22 > [email protected]> > > |# -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

