Find the source location of the syntax error in DrRacket

35 views
Skip to first unread message

Shu-Hung You

unread,
Aug 13, 2021, 10:45:26 PM8/13/21
to Racket Users
Here are two syntax errors that behave differently in DrRacket:

#lang racket

(define-syntax (m-late stx)
#'(let () (define x 0)))
(define-syntax (m-early stx)
#'(let-syntax () (define x 0)))

; (m-late)
; (m-early)

DrRacket *correctly* highlights the source location of the errors in
both cases. Additionally, for (m-early) I can click on the X button to
jump to the error location.

However, for (m-late) the X button brings me to internal Racket code.
What's going on here?

In case it helps, here are the error messages when I run the code in terminal:

;; m-late
errstx.rkt:4:4: begin (possibly implicit): no expression after a
sequence of internal definitions
in: (begin (define x 0))
location...:
/Volumes/ramdisk/errstx.rkt:4:4
/Volumes/ramdisk/errstx.rkt:4:12

;; m-early
<collects>/racket/private/letstx-scheme.rkt:38:17: begin (possibly
implicit): no expression after a sequence of internal definitions
in: (begin (define x 0))
location...:
<collects>/racket/private/letstx-scheme.rkt:38:17
/Volumes/ramdisk/errstx.rkt:6:19

Sorawee Porncharoenwase

unread,
Aug 14, 2021, 1:49:07 AM8/14/21
to Shu-Hung You, Racket Users

Isn’t that a matter of putting more syntax/loc? I tried:

(-define-syntax let-syntaxes
    (lambda (stx)
      (syntax-case stx ()
    [(_ ([(id ...) expr] ...) body1 body ...)
     (with-syntax ([((tmp ...) ...) 
            (map
             generate-temporaries 
             (syntax->list (syntax ((id ...) ...))))])
       (with-syntax ([inner-body
                      (syntax/loc stx
                        (letrec-syntaxes+values
                            ([(id ...)
                              (values
                               (make-rename-transformer (quote-syntax tmp))
                               ...)] ...)
                            ()
                          body1 body ...))])
         (syntax/loc stx
           (letrec-syntaxes+values ([(tmp ...) expr] ...) ()
             inner-body))))])))

and the button now functions as you expect.


--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAMTzy%2BZtpWGdtkZkvzF4%3D25kpqUqGKsBcCDf4T%3DY3S2hV0v_GA%40mail.gmail.com.

Shu-Hung You

unread,
Aug 14, 2021, 11:00:29 AM8/14/21
to Sorawee Porncharoenwase, Robby Findler, Racket Users
Cool! I thought the existing syntax/loc have already put the correct
source location on the output of the macro, but the inner let is
taking over the stack frame.

Robby Findler

unread,
Aug 14, 2021, 12:01:23 PM8/14/21
to Shu-Hung You, Sorawee Porncharoenwase, Racket Users
I'm not 100% sure but I think that's right: the marks clobber each other so that you see the inner frame and a `let`'s body is in tail position wrt to the let itself. So in this program:

#lang racket/base

(define (f x) (car x))

(let ()
  (let ()
    (+ (let ()
         (let ()
           (f #f))))))


You see the stack frames for the + and for the call to `car`, but not for the `let`s or the call to `f`.

Robby



Reply all
Reply to author
Forward
0 new messages