> On Nov 21, 2018, at 12:44 PM, Shu-Hung You 
> <shu-hung....@eecs.northwestern.edu> wrote:
> It works, but it would be better if (X 'USE) can log information about
> its uses at B and C in addition to the source location A for debugging
> purpose. If I don't want to change the implementation of USE, is there
> a way for X to obtain the source information of B and C?

Stash it in a syntax property?

#lang racket
(require (for-syntax syntax/parse)
         syntax/location syntax/parse/define)

(define log-error format)
(define void values)
(define vector values)

(define-syntax (X stx0)
  (syntax-parse stx0
    [(_ stx)
     (define label (gensym 'L))
     (define outer-stx (syntax-property stx0 'outer-stx))
     #`(log-error "at ~a (~a) ; ~a ~a"
                 (quote-srcloc-string #,(or outer-stx #'stx))

(define-syntax (USE stx)
  #`(void (vector #,(syntax-property #'(X 'USE) 'outer-stx stx)))) ;; A

(X (or 'here #f))
(X 'there)
(USE) ;; B
(USE) ;; C

;; Result: 
;; "at L (unsaved-editor:24.3) ; #f #f"
;; "at L (unsaved-editor:25.3) ; #f #f"
;; "at L (unsaved-editor:26.0) ; #f #f"
;; "at L (unsaved-editor:27.0) ; #f #f"

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 racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to