Re: [racket-users] Obtain use-site source information

2018-11-21 Thread Matthew Butterick


> On Nov 21, 2018, at 6:44 PM, Shu-Hung You 
>  wrote:

>> (PS ignore "at L ..." — apparently `gensym` in RacketCS is broken.)

Correction: it's not broken. I overlooked the fact that `gensym` is allowed to 
produce symbols that print the same way, though sometimes it does not.

-- 
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.


Re: [racket-users] Obtain use-site source information

2018-11-21 Thread Shu-Hung You
Thanks! However, I am trying to avoid changing USE. The trouble is
that there are too many macros using X that I don't understand, and
these macros themselves are more than one layers deep. It is nearly
impossible to thread the syntax property through the macros.On Wed,
Nov 21, 2018 at 7:30 PM Matthew Butterick  wrote:
>
> (PS ignore "at L ..." — apparently `gensym` in RacketCS is broken.)
>
> > ;; 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.


Re: [racket-users] Obtain use-site source information

2018-11-21 Thread Matthew Butterick
(PS ignore "at L ..." — apparently `gensym` in RacketCS is broken.)

> ;; 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.


Re: [racket-users] Obtain use-site source information

2018-11-21 Thread Matthew Butterick

> On Nov 21, 2018, at 12:44 PM, Shu-Hung You 
>  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"
 '#,label
 (quote-srcloc-string #,(or outer-stx #'stx))
 '#,(current-module-declare-name)
 '#,(current-module-declare-source))]))


(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.


[racket-users] Obtain use-site source information

2018-11-21 Thread Shu-Hung You
I have a macro (let's called it X) that generates unique symbols at
all its uses. I need all its uses to be distinguishable from each
other.

(define-syntax X
  (syntax-parser
[(_ stx)
 (define label (gensym 'L))
 #`(log-error "at ~a (~a) ; ~a ~a"
 '#,label
 (quote-srcloc-string #,#'stx)
 '#,(current-module-declare-name)
 '#,(current-module-declare-source))]))

X is also used in many other macros:

(define-simple-macro (USE)
  (void (vector (X 'USE ;; A

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

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?

Currently, the only information I can get is the client module that
uses USE, obtained by checking (current-module-declare-name) at
expansion time in X.

Shu-Hung

-- 
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.