[racket] Arrows in DrRacket

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon May 26 13:15:27 EDT 2014

This does something. Not sure if it what you have in mind. The pink
arrows are showing the tail positions. I broke that with the values
expression, but you also wouldn't see it if 'bind' and 'ref' were in
separate modules.

Robby


#lang racket

(begin-for-syntax
  (define vars (make-hash))
  )

(define-syntax (bind stx)
  (syntax-case stx ()
    [(bind id)
     (let ([sym (syntax-e #'id)])
       (hash-set! vars sym (syntax-local-introduce #'id))
       #'(void))]))

(define-syntax (ref stx)
  (syntax-case stx ()
    [(ref id)
     (let* ([sym (syntax-e #'id)]
            [def-id-stx (hash-ref vars sym)])
       (with-syntax ([def-id (syntax-local-introduce def-id-stx)])
         #'(let ([def-id (void)])
             (values id))))]))

(bind x)
(ref x)

On Mon, May 26, 2014 at 10:33 AM, Alexander D. Knauth
<alexander at knauth.org> wrote:
> Is this what you meant?
>
> It doesn’t work, and it also draws a pink arrow (that I don’t want) from the
> x in (ref x) to the beginning of the let expression in the definition of
> ref,
> and also, if I put a let around the (ref x), it also draws another pink
> arrow (that I don’t want) from the beginning of the let expression in the
> definition of ref to the beginning of the let expression around (ref x).
>
> #lang racket
>
> (begin-for-syntax
>   (define vars (make-hash))
>   )
>
> (define-syntax (bind stx)
>   (syntax-case stx ()
>     [(bind id)
>      (let ([sym (syntax-e #'id)])
>        (hash-set! vars sym #'id)
>        #'(void))]))
>
> (define-syntax (ref stx)
>   (syntax-case stx ()
>     [(ref id)
>      (let* ([sym (syntax-e #'id)]
>             [def-id-stx (hash-ref vars sym)])
>        (with-syntax ([def-id (datum->syntax def-id-stx sym def-id-stx)]
>                      [ref-id (datum->syntax def-id-stx sym #'id)])
>          #'(let ([def-id (void)])
>              ref-id)))]))
>
> (bind x)
> (ref x)
>
> Any suggestions?
>
> Anything I’m doing wrong?
>
> On May 26, 2014, at 12:05 AM, Robby Findler <robby at eecs.northwestern.edu>
> wrote:
>
> Oh, check syntax just collects the identifiers it finds in the
> properties and, if the identifiers are free-identifier=? to each
> other, draws an arrow. I'm not sure what behavior you want here, but
> maybe the best thing is if you just expand into some dead code that
> has lets in the way that you want the arrows to be.
>
> Robby
>
> On Sun, May 25, 2014 at 9:49 PM, Alexander D. Knauth
> <alexander at knauth.org> wrote:
>
> It’s working, but I have no Idea how to show lexical scoping
>
> If I have this:
> (bind x)
> (ref x)
> It works like I want it to work.
>
> Also for some reason this works:
> (let ()
>  (bind x)
>  (void))
> (ref x)
> Which is good I guess in some ways, but still weird.
> It’s good because it gives me a chance to define my own lexical scoping
> rules, but how do I do that?
>
> I think it has something to do with the 2 xs having the same syntax-marks,
> but I’m not sure.
>
> The problem is that I can’t make them have different syntax-marks.  To do
> this I think I would have to use (make-syntax-introducer) instead of
> syntax-local-introduce, but for some reason that’s not working.
>
> If I change the definition of stx-introducer from syntax-local-introduce to
> (make-syntax-introducer), then it doesn’t work.  I don’t really know what
> I’m doing here, but I think that If I want to have different references in
> different scopes point to only their own respective definitions (lexical
> scoping), then I think I would have to use (make-syntax-introducer) instead
> of syntax-local-introduce.  But that’s not working, so then how do I do
> that?
>
> #lang racket
>
> (begin-for-syntax
>  (define stx-introducer syntax-local-introduce)
>  ;; (define stx-introducer (make-syntax-introducer))
>  )
>
> (define-syntax (bind stx)
>  (syntax-case stx ()
>    [(bind-1 id)
>     (let ([new-id (stx-introducer #'id)] [id.length (string-length
> (symbol->string (syntax-e #'id)))])
>       (syntax-property #`(void)
>                        'sub-range-binders
>                        (list (vector new-id 0 id.length new-id 0
> id.length))))]))
>
> (define-syntax (ref stx)
>  (syntax-case stx ()
>    [(ref-1 id)
>     (syntax-property #'(void)
>                      'disappeared-use
>                      (list (stx-introducer #'id)))]))
>
> (let ()
>  (bind x)
>  (void))
> (ref x)
>
> On May 25, 2014, at 6:00 PM, Robby Findler <robby at eecs.northwestern.edu>
> wrote:
>
> Yes. One approach is to expand into a program that never runs but that
> has the identifiers in the binding relationships you want check syntax
> to show. Another approach is to add properties to your program that
> tells check syntax what to draw. You can read about the second
> approach here:
>
> http://docs.racket-lang.org/tools/Check_Syntax.html?q=check%20syntax#%28part._.Syntax_.Properties_that_.Check_.Syntax_.Looks_.For%29
>
> Let us know if you get stuck when you try it!
>
> Robby
>
> On Sun, May 25, 2014 at 2:41 PM, Alexander D. Knauth
> <alexander at knauth.org> wrote:
>
> Is there any way to use syntax properties or anything like that to tell
> DrRacket where to draw the arrows to?
>
> I’m trying to make my own language and I wanted to be able to have DrRacket
> draw the arrows.
>
> Also is there a way to have it draw multiple arrows, so that for example it
> would draw arrows not only to the original definition but also to all of the
> expressions that set! it?
>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
>
>
>


Posted on the users mailing list.