Skip to content

Instantly share code, notes, and snippets.

@Glorp
Last active January 1, 2016 14:31
Show Gist options
  • Save Glorp/044567d03ba9e29e0935 to your computer and use it in GitHub Desktop.
Save Glorp/044567d03ba9e29e0935 to your computer and use it in GitHub Desktop.
DrRacket-arrows?
#lang racket
(provide (rename-out [my-read read]
[my-read-syntax read-syntax]))
(define (my-read in) (syntax->datum (my-read-syntax #f in)))
(define (my-read-syntax src in)
(define a (read-syntax src in))
(define b (read-syntax src in))
(define res (datum->syntax a
(format "a: ~a~nb: ~a~n"
(syntax-property-symbol-keys a)
(syntax-property-symbol-keys b))))
(datum->syntax a
`(module foo racket
(define ,(datum->syntax a 'foo a a) 0)
,(datum->syntax b 'foo b b)
(display ,res))))
#lang racket
(provide (rename-out [my-read read]
[my-read-syntax read-syntax]))
(define (my-read in) (syntax->datum (my-read-syntax #f in)))
(define (my-read-syntax src in)
(define a (read-syntax src in))
(define b (read-syntax src in))
(define res (datum->syntax a
(format "a: ~a~nb: ~a~n"
(syntax-property-symbol-keys a)
(syntax-property-symbol-keys b))))
(datum->syntax b
`(module foo racket
(define ,(datum->syntax a 'foo a) 0)
,(datum->syntax b 'foo b)
(display ,res))))
#lang reader "lang1.rkt"
a
b
#lang reader "lang2.rkt"
a
b
@Glorp
Copy link
Author

Glorp commented Jan 1, 2016

Using lang1.rkt or lang2.rkt as a reader-lang:

test1.rkt uses lang1.rkt as reader-lang, test2.rkt uses lang2.rkt. Other than that the content of test1.rkt is equal to the content of test2.rkt.

Any program with two s-expresions is a valid program.

Every valid program is transformed into

(define foo 1)
foo

where the first foo uses the source location of the first s-expression in the input program and the second foo uses the source location of the second s-expression. (also does some printing of syntax-properties).

foois turned into syntax-object with (datum->syntax ctxt v [srcloc prop ignored])

In lang1.rkt the "input" syntax objects from the program we are reading are used for ctxt, srcloc and prop. In lang2.rkt they are only used for ctxt and srcloc.

DrRacket arrows?

The programs behave the same in both languages, but DrRacket only draws the "bound occurence" arrow on mouseover for the program that uses lang1.rkt. (draws an arrow from a to b in test1.rkt, since those expressions are used for source locatoins for the different foos, but not in test2.rkt).

So, I'm not super-sure about how DrRacket decides which arrows to draw, but so far I've only been able to get them by using syntax-objects I've got from the regular Racket read-syntax as prop.

also

I've tried moving the arrow around by using different srcloc, which works fine/as expected. E.g. using (list src #f #f 10 10) as srcloc for the first foo makes the arrow go from somewhere in the #lang-line.

Also tried using different syntax objects for prop, and things seem to work fine as long as the syntax object is produced by the regular Racket read-syntax (works fine with e.g. (read-syntax #f (open-input-string "e")))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment