<div dir="ltr">How cool is that?! Thanks!<br><br><div class="gmail_quote">On Fri, Aug 15, 2008 at 5:06 PM, Ulf Wiger <span dir="ltr"><<a href="mailto:ulf@wiger.net">ulf@wiger.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Why sure, you just do this:<br>
<br>
-module(m).<br>
-export([f/0]).<br>
<br>
-define(FUNCTION, hd(element(2,element(2,catch erlang:error([]))))).<br>
<br>
f() -><br>
{current_function, ?FUNCTION}.<br>
<br>
<br>
<br>
Eshell V5.5.4 (abort with ^G)<br>
1> c(m).<br>
{ok,m}<br>
2> m:f().<br>
{current_function,{m,f,0}}<br>
3><br>
<br>
BR,<br>
Ulf W ;-)<br>
<br>
2008/8/15 Edwin Fine <<a href="mailto:erlang-questions_efine@usa.net">erlang-questions_efine@usa.net</a>>:<br>
<div><div></div><div class="Wj3C7c">> Something I've wished for in numerous languages over the years is a macro<br>
> that expands to the current function, something like ?MODULE. I don't<br>
> suppose there is one lurking somewhere in Erlang...?<br>
><br>
> 2008/8/15 Matt Williamson <<a href="mailto:dawsdesign@gmail.com">dawsdesign@gmail.com</a>><br>
>><br>
>> You should trust the macro. It must use a similar method to Python's<br>
>> because they are both compiled to bytecode and thus there wouldn't *really*<br>
>> be line numbers in either one.<br>
>><br>
>> 2008/8/15 devdoer bird <<a href="mailto:devdoer2@gmail.com">devdoer2@gmail.com</a>><br>
>>><br>
>>> Thanks.<br>
>>><br>
>>> How can I do this without macro? I know python supply some tools to<br>
>>> determine the line number in run time,like inspect module.<br>
>>><br>
>>><br>
>>> 2008/8/16, Anders Nygren <<a href="mailto:anders.nygren@gmail.com">anders.nygren@gmail.com</a>>:<br>
>>>><br>
>>>> 2008/8/15 devdoer bird <<a href="mailto:devdoer2@gmail.com">devdoer2@gmail.com</a>>:<br>
>>>> > HI:<br>
>>>> ><br>
>>>> > I want to implement a function like "get_current_lineno()/0" to get<br>
>>>> > the<br>
>>>> > current line number of the calling point?<br>
>>>> > Eg.<br>
>>>> > .....<br>
>>>> > ....<br>
>>>> > io:format("current line is ~w\n",[get_current_lineno()])<br>
>>>> > .....<br>
>>>> ><br>
>>>> > the above code will print the line number of the calling point in the<br>
>>>> > source<br>
>>>> > file.<br>
>>>> ><br>
>>>> > How can I do this in erlang?<br>
>>>><br>
>>>> There is a predefined macro ?LINE that does that<br>
>>>> so<br>
>>>> io:format("current line is ~w\n",[?LINE])<br>
>>>><br>
>>>> /Anders<br>
>>>><br>
>>>> > _______________________________________________<br>
>>>> > erlang-questions mailing list<br>
>>>> > <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>>>> > <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
>>>> ><br>
>>><br>
>>><br>
>>> _______________________________________________<br>
>>> erlang-questions mailing list<br>
>>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>>> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
>><br>
>><br>
>> _______________________________________________<br>
>> erlang-questions mailing list<br>
>> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
>> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
><br>
><br>
> --<br>
> For every expert there is an equal and opposite expert - Arthur C. Clarke<br>
><br>
> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>For every expert there is an equal and opposite expert - Arthur C. Clarke<br>
</div>