kpanic
Hi,
I discovered by accident last week this:
Example:
quote do %{hello: "test"}.hello() end == quote do %{hello: "test"}.hello end
true
I get that the AST is the same – with parens or the absence of parens, however why this is an allowed syntax?
Thanks
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #ai
- #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)
dimitarvp
It is simply because the language allows functions without parameters to be called without the parens. In your case
.hello()is canonical Elixir while.hellois just a convenience shorthand syntax.kpanic
Sure, but here we are accessing a map that would return a binary in this case.
For functions it might make sense when arity is 0, however I guess this behaviour might generate confusion since
When we access
hellowe expect the value back and not a pleonastic()function callmichalmuskala
The AST for both things is exactly the same. There’s no way for the compiler to differentiate between the two:
kpanic
Thank you michal, I undestand that the AST is the same. See initial post regarding map access.
Since you are saying that the compiler does not differentiate, I guess we should live with that.
However having in code redundant parentheses (when accessing a map value) seems confusing to me.
is not a function call.
OvermindDL1
Eh, technically it is a function call, it lowers down to become
:maps.get(:hello, %{hello: "test"}). On the beam VM there is no such thing as a map extraction operator like., rather you can extract only by matching out the value via a hardcoded key or by calling the built in internal functions in the:mapsmodule, and Elixir lowers to them.kpanic
Thanks for elaborating @OvermindDL1
However it think that it might be confusing from the syntax perspective. In the end that’s what I mean.
For example:
Not sure if I am too “picky” on this one
LostKobrakai
Here’s the macro that’s being called: Kernel.SpecialForms — Elixir v1.20.2
From the syntax perspective you’re calling
greeting/0ontestquite similar to e.g.which calls
alive?/0onmod. The AST alone just knows aboutmodthe variable, but does not know if the variable will be a map or a alias or whatever.kpanic
@LostKobrakai sure and thanks for the pointers, however don’t you find confusing that accessing to a map/struct and putting a
()is the same as not putting it?As a dev, especially after long hours of work, one may wonder if:
this is a function that a dev defined somewhere or just accessing a map/struct
Maybe is it just me that find this confusing?

gregvaughn
I suspect this is a transitory concern. I suspect you’re coming from an OO world (like most) where it is common to call methods on objects. As a functional language, Elixir has no methods at all. It’s functions. This
.syntax just looks like a method/member access, but it’s really a function. Once you’ve spent more time with Elixir and internalized this information, the confusion should subside.OvermindDL1
Not just you, but sometimes that ambiguity lets you override things too. At one time we had tuple calls too that worked like
{SomeModule, whatever, else, you, want}and if you didblah = {SomeModule, whatever, else, you, want}then didblah.bloop(42)then it ended up callingSomeModule.bloop(42, {SomeModule, whatever, else, you, want}), which was crazy useful for emulating first-class modules on the BEAM, but thanks to recent developments that is now broken…Yep, exactly this.
Conceptually this: