racket/collects/honu/core/private/debug.rkt
2011-08-09 16:25:28 -06:00

23 lines
596 B
Racket

#lang racket/base
(require (for-syntax racket/base))
(provide debug)
(define-for-syntax (filename path)
(define-values (base name dir?)
(split-path (build-path path)))
name)
(define-for-syntax verbose? (getenv "HONU_DEBUG"))
(define-syntax (debug stx)
(if verbose?
(syntax-case stx ()
[(_ str x ...)
(with-syntax ([file (filename (syntax-source #'str))]
[line (syntax-line #'str)]
[column (syntax-column #'str)])
#'(printf (string-append "~a at ~a:~a " str) file line column x ...))])
#'(void)))