[Top][All Lists]
[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: |
Alejandro Forero Cuervo |
Subject: |
Re: [Chicken-users] source file and line number where a macro is called? |
Date: |
Tue, 25 May 2010 04:15:25 +0200 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
> 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.
Thanks, Felix! I will give it a try, see if I can figure out the
contexts in which it won't work and build on it.
Alejo.
http://azul.freaks-unidos.net/