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

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40082 209
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement