[gambit-list] equiv of __FILE__ and __LINE__
Marc Feeley
feeley at iro.umontreal.ca
Sat May 2 23:23:01 EDT 2009
On 1-May-09, at 5:38 PM, lowly coder wrote:
> For C macros, I tend to use __FILE__ and __LINE__ alot. Does gambit
> have an equiv for this?
There's a builtin macro to get the current source file, which is
called "this-source-file". Nothing is builtin to get the line, but
you can get that in the following way:
(##define-syntax FILE
(lambda (src)
(if (not (##source? src))
(error "expected a source object")
(let ((locat (##source-locat src)))
(if (not locat)
(error "location unknown")
(let ((container (##locat-container locat))
(position (##locat-position locat)))
(let ((path (##container->path container)))
path)))))))
(##define-syntax LINE
(lambda (src)
(if (not (##source? src))
(error "expected a source object")
(let ((locat (##source-locat src)))
(if (not locat)
(error "location unknown")
(let ((position (##locat-position locat)))
(let ((filepos (##position->filepos position)))
(let ((line (##fixnum.+ (##filepos-line filepos) 1)))
line))))))))
(pp (list (FILE) (LINE)))
(pp (list (this-source-file) (LINE)))
;; prints:
;;
;; ("/u/feeley/test.scm" 25)
;; ("/u/feeley/test.scm" 26)
Marc
More information about the Gambit-list
mailing list