chrix75
Hi,
I’ve started learning Elixir by reading the book Programming Elixir and I’ve got one question (at this moment
). What is the motivation for using the . character to call a function ?
It’s strange to write myFunc.() instead of myFunc(). I suppose I find that weird because of my other languages knowledge ![]()
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Hello,
I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter).
The diffic...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I think I’ve found a small improvement I could contribute to <%= web_namespace %>.CoreComponents (installer/templates/phx_web/compo...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Aludel - LLM Evaluation Workbench
Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
You do use the dot for functions bound to variables. Not for
defined functions,This is mainly to distinguish in case of nameclashes.
chrix75
I don’t get the point
Sorry.
When could we have any problem calling
foo(1)in place offoo.(1)?From your code, is it for the case we have a function bound to
foovariable inside the module M ?Thanks
satom99
Just to clarify, these are refered to as anonymous functions. Which, as mentioned, are nameless and should be called using a dot and may also be defined using the & shorthand. Refer to this lesson for a better overview.
NobbZ
This is very contrived but shows my point:
AstonJ
The dot is only used when calling anonymous functions that have been bound to a variable (and not functions defined inside a module). The dot also reminds us that it is an anonymous function.
This is an anonymous function:
And called like this:
This is a function defined inside a module:
And called like this:
If you continue reading the book Dave goes on to explain this
AstonJ
This is also a great point - the name of the variable isn’t the name of the function:
Here,
foois just the name of the variable that the anonymous function has been bound to - the function itself is nameless/anonymous.Named functions always go inside a module:
Here, the name of the function is
foo.Specifically, we call this
foo/1where1is the arity (the number of arguments the function takes)cmkarlsson
Joe Armstrong called it
I quote:
“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.”
AstonJ
Haha, I have to admit that it was one of the things that I wondered myself - but I think that is also true of other things that are different to what we’re used to (or for some reason or another, feel peculiar to us). Once we learn about them it just makes sense and we move on.
With that said, I have been thinking about whether we could do with a Frequently Asked Questions section, as well as perhaps a Glossary section - for common stuff like this. We can then easily direct people to the associated thread whenever the topic comes up (with the added benefit them many people will browse such sections as well)
jeremyjh
It has already been explained in this thread but for additional context this early thread may help as well. I do not think anyone mentions it directly but it is also important to know two things:
Elixir solves the ambiguity between variable and atom names by prefixing atoms with a colon but including a colon in local function invocation seems like a worse trade-off than a dot for anonymous functions.
I think it is a shame though and easily the biggest remaining wart in the language, and the cost of it is probably a diminished usage of anonymous functions in everyday code.
NobbZ
I do use them as I need them and I like the erlang and elixir way.
In go code I write for work when I have a long function body in legacy code I often see
foo()and then searching begins… My first reaction is scanning the list of functions on the right, but it’s not there. Then I scroll up to the current functions head to see if it is passed in as an argument, I don’t even find it there so I scroll even more up and see a dot imported package… I hate this ambiguity…In elixir and erlang I can see at least if it is a variable or a “real” function.