[erlang-questions] The Erlang Rationale

Ulf Wiger <>
Fri Oct 3 08:30:26 CEST 2008


2008/10/3 Richard O'Keefe <>:
>
> I then mentioned ?HERE as a possible idea that would leave the
> source code with a visible mention of "at this point I pass my
> source location" -- hence would be more tokens to type than
> using a macro -- but in a much shorter and potentially richer
> form than ?MODULE, ?LINE.
>
> Given my history of writing EEPS, readers were expected to see this
> as a pre-pre-EEP for ?HERE.  Today I've mailed out patches to add a
> prototype version of ?HERE that gives you {?MODULE,?LINE,undefined}
> with undefined as a place-holder for a future {function,arity}.


I've been using ?HERE quite often in my code. It may seem unintuitive,
but it works, since macros are simply a syntactic expansion:

-module(here).
-compile(export_all).

-define(HERE, {?MODULE, ?LINE, undefined}).

f() ->
    {?HERE,
     ?HERE}.

$ erl
Eshell V5.6.4  (abort with ^G)
1> here:f().
{{here,9,undefined},{here,10,undefined}}
2>

So no need to patch epp before one can start using it.

It's possible to add to the macro a way to find out the current
module and arity as well.

In a previous thread:
http://groups.google.com/group/erlang-questions/browse_thread/thread/ee2929a3c67375b8

-define(FUNCTION,element(2,process_info(self(),current_function))).

Then we could make our HERE definition:

-define(HERE, {?MODULE, ?LINE, ?FUNCTION}).


BR,
Ulf W



More information about the erlang-questions mailing list