Answer by Zain for Why are there two kinds of functions in Elixir?
In elixir we use def for simply define a function like we do in other languages.fn creates an anonymous function refer to this for more clarification
View ArticleAnswer by Gram for Why are there two kinds of functions in Elixir?
Elixir has optional braces for functions, including functions with 0 arity. Let's see an example of why it makes a separate calling syntax important:defmodule Insanity do def dive(), do: fn() -> 1...
View ArticleAnswer by Ian for Why are there two kinds of functions in Elixir?
fn -> syntax is for using anonymous functions. Doing var.() is just telling elixir that I want you to take that var with a func in it and run it instead of referring to the var as something just...
View ArticleAnswer by ryanwinchester for Why are there two kinds of functions in Elixir?
Only the second kind of function seems to be a first-class object and can be passed as a parameter to other functions. A function defined in a module needs to be wrapped in a fn. There's some syntactic...
View ArticleAnswer by Jayson for Why are there two kinds of functions in Elixir?
I've never understood why explanations of this are so complicated.It's really just an exceptionally small distinction combined with the realities of Ruby-style "function execution without...
View ArticleAnswer by Mig R for Why are there two kinds of functions in Elixir?
I may be wrong since nobody mentioned it, but I was also under the impression that the reason for this is also the ruby heritage of being able to call functions without brackets.Arity is obviously...
View ArticleAnswer by sobolevn for Why are there two kinds of functions in Elixir?
There's an excellent blog post about this behavior: linkTwo types of functionsIf a module contains this:fac(0) when N > 0 -> 1;fac(N) -> N* fac(N-1).You can’t just cut and paste this into the...
View ArticleAnswer by Fred the Magic Wonder Dog for Why are there two kinds of functions...
I don't know how useful this will be to anyone else, but the way I finally wrapped my head around the concept was to realize that elixir functions aren't Functions. Everything in elixir is an...
View ArticleAnswer by José Valim for Why are there two kinds of functions in Elixir?
Just to clarify the naming, they are both functions. One is a named function and the other is an anonymous one. But you are right, they work somewhat differently and I am going to illustrate why they...
View ArticleWhy are there two kinds of functions in Elixir?
I'm learning Elixir and wonder why it has two types of function definitions:functions defined in a module with def, called using myfunction(param1, param2)anonymous functions defined with fn, called...
View Article
More Pages to Explore .....