Current line number in PLT Scheme

Here is how to get the current line number programmatically in PLT Scheme (via Jay):

#lang scheme
(define-syntax (current-line-number stx)
  (quasisyntax/loc stx
    '#,(syntax-line stx)))
(printf "~a: ~a~n" (current-line-number) 6)
(printf "~a: ~a~n" (current-line-number) 8)

(via plt)

2 thoughts on “Current line number in PLT Scheme”

  1. Hi there. I tried similar stuff in Gauche once, but got stuck when I wanted to wrap (current-line-number) in another macro. E.g. when you define a macro (report x) that expands into (printf “~a: ~a~n” (current-line-number) x), does it print the line number where (report x) appears, or the line number where (current-line-number) appears in the definition of report?

  2. It reports the line number where current-line-number appears (in the macro). Here is what I tried:
    (define-syntax-rule (debug-body body)
    (begin body (printf “At line: ~a~n” (current-line-number))))
    (debug-body (printf “Hello, world.~n”))

Leave a Reply

Your email address will not be published. Required fields are marked *