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; }

Last Post!

hauleth

hauleth

It came out from C, I do not know if there is any previous example of -- operator.

Where Next?

Popular in Questions Top

RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
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
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

Other popular topics Top

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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement