3

example:

-module(func).

%% ====================================================================
%% API functions
%% ====================================================================
-export([do/2]).


do(Param, {?MODULE,[a]}) ->
    Param.

Why I can call the function by

{func,[a]}:do(1)

The call succ by returning "1".

I cannot see any explanation in Erlang doc. But There are many usage in mochiweb such as: https://github.com/mochi/mochiweb/blob/master/src/mochiweb_request.erl

Mark_H
  • 770
  • 1
  • 6
  • 19
  • 5
    http://stackoverflow.com/questions/16960745/what-is-a-tuple-module-in-erlang They're there for backwards compatibility and generally not recommended which is probably why there's not much easily accessible official documentation. – Dogbert May 08 '17 at 09:03
  • 4
    [This question](http://stackoverflow.com/q/5339012/113848) shows how those modules used to look before the "parameterised modules" feature was removed in Erlang/OTP release R16B. – legoscia May 08 '17 at 09:07
  • Thanks. That answer is clear. – Mark_H May 08 '17 at 09:10
  • You are asking two quite separate questions. To answer the one in the title, there is nothing special about `do(Param, {?MODULE,[a]})`: `?MODULE` is a standard macro which is replaced by the module name, so you have a perfectly normal pattern-matching definition: `do(Param, {func,[a]}) -> ...` which you would usually call as `func:do(1, {func,[a]})`. The other comments explain why you can _also_ call it as `{func,[a]}:do(1)`. – Alexey Romanov May 08 '17 at 19:34

0 Answers0