[erlang-questions] Is this code tail recursive?
Dmitrii Dimandt
dmitrii@REDACTED
Fri Sep 17 12:50:01 CEST 2010
I think this is worthy of being placed in the FAQ.
> Most of this has been said before here but to bring it all together and try to clarify it:
>
> - A call to a function without a qualifying module name, i.e. foo(...), is ALWAYS a call to a local function in the same module and the same version of that module. Always. (though see importing below)
>
> - A call to a function which is qualified with a module name, i.e. bar:foo(...), is ALWAYS a call to an exported function in the latest version of that module. Always, even if the module is the same as the one in which the call is made. This is the only way to call a function in another module.
>
> - There is nothing at all special about the predefined macro MODULE, nothing. So in the module 'bar' ?MODULE:foo(...) and bar:foo(...) are exactly the same. The only benefits may be that it is clearer that you are actually calling the same module, and it may save you some work if you change the module name.
>
> - Importing a function from a module provides absolutely no new functionality. It just saves you from having to explicitly qualify the function call with the module name. So if foo/1 is imported from module bar, -import(bar,[foo/1])., then foo(...) and bar:foo(...) are exactly equivalent, the compiler does the conversion internally. It saves you some writing. Many people frown on importing and say you shouldn't do it as it obscures what you are actually doing, I only use for importing functions from some common modules like lists.
>
> I think that's about it.
>
> Robert
>
> ----- Ursprungligt meddelande -----
> Från: "Ryan Zezeski" <rzezeski@REDACTED>
> Till: "Max Lapshin" <max.lapshin@REDACTED>
> Kopia: "Zvi" <zvi.avraham@REDACTED>, erlang-questions@REDACTED
> Skickat: fredag, 17 sep 2010 6:14:48 GMT +01:00 Amsterdam/Berlin/Bern/Rom/Stockholm/Wien
> Ämne: Re: [erlang-questions] Is this code tail recursive?
>
> On Mon, Sep 6, 2010 at 6:31 AM, Max Lapshin <max.lapshin@REDACTED> wrote:
>
>>
>> Yes, of course.
>> Do not forget about difference between f() and ?MODULE:f()
>>
>>
> Max, as a newb to Erlang, are you saying that without the module
> qualification and if you imported a function f/0 from another module it
> would instead call that? Actually, I just went ahead and tried that and the
> compiler gave me an error. So I ask, what are you referring to?
>
> -Ryan
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
More information about the erlang-questions
mailing list