[erlang-questions] is there something like #line

Oscar Hellström <>
Tue May 29 11:04:00 CEST 2007


Hi all,

Matej Kosik wrote:
> Hello,
> 
> Some languages provide mechanisms for "redefining" the current filename and line number. This is done via #line directive. It is not very useful if one writes the code in Erlang, but it is useful when the Erlang code is generated from some other file. For example from a noweb file. I can tangle the actual code so that before each code chunk will be placed correct
> 
> 	# line <line> <filename>
> 
> command. This way it is possible to influence the compiler error messages and warnings so that they refer to the original file (and line number) rather than to the line number in the generated file.
> 
> Is there a similar directive in Erlang? I have tried to google it out, but with little luck. In `Erlang Reference Manual', section 7.2 there I see two interesting macros:
> 
> 	?FILE.
> 	    The file name of the current module. 
> 	?LINE.
> 	    The current line number.
 >
> 
> Unfortunatelly, when I tried to redefine it, the compiler rejected such redefinitions. Any hint is appreciated.
> 
> PS: I am still not 100% sure that using noweb with Erlang is a good idea. But I have used noweb elsewhere (with C and with Pict) so in my current interesting Erlang-task I decided to try it too.
> 
> Regards
> 
> 

Interesting, I would have thought that putting the following before any 
definition of FILE/LINE macros would work.
-undef(LINE).
-undef(FILE).

Using the following code, test/0 returns the actual line number, not 0.
-module(test).
-compile(export_all).

-undef(LINE).
-define(LINE, 0).


start() -> ?LINE.

Best Regards
-- 
Oscar Hellström, 
Erlang Training and Consulting
http://www.erlang-consulting.com/



More information about the erlang-questions mailing list