Let's see how much of this I can understand.

1) FILE & LINE are macros.
2) in (lambda (src <-- this variable here
    the src is linked to the reader/parser object, which is why we can query it for the current line / file number?
3) Why the ##'s

Thanks!

On Sat, May 2, 2009 at 8:23 PM, Marc Feeley <feeley@iro.umontreal.ca> wrote:

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