bluegene

bluegene

Why are blankspaces allowed between Module and function?

Recently after spending an hour debugging/staring at a code, I found out that one or more blankspaces are allowed when invoking a function. For example,

iex(7)> IO. puts "hello"
hello
:ok  
iex(8)> IO.   puts("hello")
hello
:ok

I personally think this will introduce bugs. Here’s one instance where I ran into a problem when I mistakenly typed a period instead of a comma:

def handle_call(request, _caller, state) do
    {:reply, request. state}
end

When invoking a GenServer call, I got,

14:19:30.744 [error] GenServer :my_registry terminating
** (UndefinedFunctionError) function :some_request.state/0 is undefined (module :some_request is not available)
    :some_request.state()
    echo_gen_server.ex:13: EchoGenServer.handle_call/3
    (stdlib) gen_server.erl:661: :gen_server.try_handle_call/4
    (stdlib) gen_server.erl:690: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

What is the reasoning behind allowing blankspaces between Module and function invocation? Shouldn’t the compiler flag this and reported as error?

Most Liked

lpil

lpil

Creator of Gleam

This is quite normal behaviour for a parser. With most parser technologies it is considerably more difficult to add this kind of whitespace sensitivity (and it would disallow splitting map access chains over multiple lines).

Try adding whitespace in random places in various languages, I think you’ll be surprised where it’s allowed. :slight_smile:

hauleth

hauleth

It just makes parser simpler, as it tokenise it to {{:., [], [IO, :puts]}, [], ["hello"]} (simplified). As you can see . is independent operator, lust like + or |>. Disallowing spaces around only one operator just for sake of I-have-no-idea-what would be pointless.

Nicd

Nicd

This reminds me of the PHP “downto” operator --> :slight_smile::

$a = 100;
while ($a --> 0) { echo $a, PHP_EOL; }

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement