[erlang-questions] How to get the line number of current executable code?

Edwin Fine <>
Fri Aug 15 22:29:50 CEST 2008


Something I've wished for in numerous languages over the years is a macro
that expands to the current function, something like ?MODULE. I don't
suppose there is one lurking somewhere in Erlang...?

2008/8/15 Matt Williamson <>

> You should trust the macro. It must use a similar method to Python's
> because they are both compiled to bytecode and thus there wouldn't *really*
> be line numbers in either one.
>
> 2008/8/15 devdoer bird <>
>
>> Thanks.
>>
>> How can I do this without macro? I know python supply some tools to
>> determine the line number in run time,like inspect module.
>>
>>
>> 2008/8/16, Anders Nygren <>:
>>>
>>> 2008/8/15 devdoer bird <>:
>>> > HI:
>>> >
>>> > I want to implement a function like "get_current_lineno()/0" to get the
>>> > current line number of the calling point?
>>> > Eg.
>>> > .....
>>> > ....
>>> > io:format("current line is ~w\n",[get_current_lineno()])
>>> > .....
>>> >
>>> > the above code will print the line number of the calling point in the
>>> source
>>> > file.
>>> >
>>> > How can I do this  in erlang?
>>>
>>> There is a predefined macro ?LINE that does that
>>> so
>>> io:format("current line is ~w\n",[?LINE])
>>>
>>> /Anders
>>>
>>> > _______________________________________________
>>> > erlang-questions mailing list
>>> > 
>>> > http://www.erlang.org/mailman/listinfo/erlang-questions
>>> >
>>>
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
For every expert there is an equal and opposite expert - Arthur C. Clarke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080815/573d37e0/attachment.html>


More information about the erlang-questions mailing list