chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] source file and line number where a macro is called?


From: Felix
Subject: Re: [Chicken-users] source file and line number where a macro is called?
Date: Tue, 25 May 2010 01:33:23 +0200 (CEST)

From: Alejandro Forero Cuervo <address@hidden>
Subject: [Chicken-users] source file and line number where a macro is called?
Date: Mon, 24 May 2010 15:18:18 +0200

> I'm working in a logging extension.  Simplifying, I would like to be
> able to write in my code an expression like:
> 
>     (logging "Starting evaluation of foo")
> 
> To cause an entry like "fooeval.scm:94: Starting evaluation of foo."
> to be written to some file.  The key aspect is to be able to trace
> back the location of the expression that caused an entry to be logged.
> 
> Is there a way I could make this work?  In other words, how can I make
> a macro receive the filename and line number where the expression that
> caused it to be called occurred?
> 

There is `get-line-number':

(define-syntax (ln x r c)
  (list (r 'quote) (get-line-number x)))

(print (ln))

Note that this will not always work and return #f if it can not
retrieve the line-number. Syntax-expansions will usually receive
the line number of the containing syntax form. This facility will
only work in compiled code.


cheers,
felix



reply via email to

[Prev in Thread] Current Thread [Next in Thread]