[erlang-questions] Why no ?FUNCTION macro

Richard Carlsson <>
Thu Sep 20 14:34:29 CEST 2007


Adam Lindberg wrote:
> Hi all!
> 
> Why is there no ?FUNCTION macro? If it is possible to do ?MODULE and 
> ?LINE it should be possible to do ?FUNCTION too?

Maybe it is possible, but it's not quite as simple, in any case. Note
that these are preprocessor macros. ?LINE is trivial to keep track of
during preprocessing, and the ?MODULE macro is only defined *after* the
complete '-module(...).' declaration has been seen (also not hard to
recognize during preprocessing), but for a function definition you
would probably want it to be defined immediately after the leading
"<name> (" tokens, so you could write e.g. "foo(?FUNCTION, ...) ...".
But at that point, it is perhaps not certain that what you are seeing
is actually a function. To make sure, the preprocessor would have to be
able to do rather a lot of real parsing (patterns and guards can be
pretty complex) interleaved with preprocessor expansion. Or you could
just say "what the heck", and define it as soon as you se "<name> (" at
the start of a declaration; I'm just not totally convinced that this
would be a good idea; it smells like a hack to me.
     /Richard




More information about the erlang-questions mailing list