[plt-scheme] Current line number

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Jan 18 16:01:43 EST 2010

On Jan 18, Paulo J. Matos wrote:
> Hi,
> 
> I don't think there is such a thing but does plt provide a
> (current-line-number) that returns the line number where this is located
> (current-source-file) that returns the filename path
> ?
> 
> If not, is it possible to implement it in Scheme?

Try this:

  (define-syntax (show-here stx)
    (with-syntax ([src  (format "~a" (syntax-source stx))]
                  [line (syntax-line stx)]
                  [col  (syntax-column stx)]
                  [pos1 (syntax-position stx)]
                  [pos2 (+ (syntax-position stx) (syntax-span stx))])
      #'(printf ">>> ~a:~a:~a ~a-~a\n" src line col pos1 pos2)))

(There's also `this-expression-source-directory',
`this-expression-file-name', and a bunch of other utilities around.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!


Posted on the users mailing list.