[erlang-questions] Why no ?FUNCTION macro
G Bulmer
gbulmer@REDACTED
Thu Sep 20 16:35:55 CEST 2007
Adam
I'm just curious, but is the requirement to get an atom (or string)
as a macro expansion, e.g. available at compile time, or would it be
okay if it were available from a function at run-time (where you
could also use the full power of Erlang to manipulate the value)?
As Richard Carlsson explained, knowing the function name at pre-
processor time may be quite difficult. Further, it may have no
obvious meaning for anonymous fun's (lambda expressions).
Specifically, I'm curious to know if you need to use the function
name value in debug-style messages (and hence as late as run-time may
be okay), or whether you really need to do something during pre-
processor or compile time (e.g. like C tokenising to build lexically
new names).
As I said, this is only curiosity, but if the need is a run-time
name, maybe an ingenious function to dig through the stack trace
returned by erlang:get_stacktrace() would be workable.
I was looking at Joe's Book at try_test.erl in section 4.9 which
gives a way to get this information. I realise this is a bit ugly,
but I haven't found how to get a stack trace *without* generating an
exception.
On the basis that the information appears to be available at run-time
to erlang:get_stacktrace(), then maybe there is a way to get it
without generating an exception, and I'd like to know. If not
available now, it does look like a candidate for a future release,
and I'd be happy with a run time function, but I realise that may be
inadequate for your need.
Garry
> Date: Thu, 20 Sep 2007 13:30:03 +0200
> From: "Adam Lindberg" <adam@REDACTED>
> Subject: [erlang-questions] Why no ?FUNCTION macro
> ...
> Why is there no ?FUNCTION macro? If it is possible to do ?MODULE
> and ?LINE
> it should be possible to do ?FUNCTION too?
>
> Cheers!
> Adam
More information about the erlang-questions
mailing list