Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 27, 2022 07:42 pm GMT

Why I think the dot is not a problem in Elixir

The Elixir community knows that, in Elixir, when you define an anonymous function and assign it to a variable, you have to use a dot (.) to call it:

iex(1)> double = fn x -> x*2 end#Function<44.65746770/1 in :erl_eval.expr/5>iex(2)> double.(3)6iex(3)>

This doesn't happen in Erlang:

1> Double = fun(X) -> X*2 end.#Fun<erl_eval.44.65746770>2> Double(3).63>

You don't have to put a dot between Double and (3) in Erlang.

But you have to put a dot at the end of each line.

The late Joe Armstrong, one of the creators of Erlang, wrote in 2013, when he spent "A Week with Elixir," more specifically in the section "Funs have an extra dot in the name":

In school I learned to call functions by writing f(10) not f.(10) this is really a function with a name like Shell.f(10) (its a function defined in the shell) The shell part is implicit so it should just be called f(10).
If you leave it like this expect to spend the next twenty years of your life explaining why. Expect thousands of mails in hundreds of forums.

I believe this didn't happen. One or other person complains here and there, but not "thousands".

Why? My opinion is that Elixir developers usually don't assign an anonymous function to a variable. That's why this is not a big problem. Am I right?


Original Link: https://dev.to/adolfont/why-i-think-the-dot-is-not-a-problem-in-elixir-1nia

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To