IEx and pipes ergonomics (with Ecto)

46 views
Skip to first unread message

thibaut...@gmail.com

unread,
Nov 24, 2021, 11:34:05 AM11/24/21
to elixir-lang-core
Hello,

A coworker (new to Elixir) was quite surprised today when pasting this code into IEx:

import Ecto.Query a = DB.Resource |> where([r], not is_nil(r.datagouv_id)) |> group_by([r], r.datagouv_id) |> having([r], count(r.datagouv_id) > 1) |> select([r], r.datagouv_id) |> DB.Repo.all()

Evaluating "a" afterwards here gives an answer that surprised him: DB.Resource (yet the IEx evaluation shows the list of selected binaries, which is even more surprising).

I realise work has been done to make pasting multilines statements in IEx better (https://hexdocs.pm/iex/1.12.2/IEx.html#module-pasting-multiline-expressions-into-iex), yet I feel this breaks the POLS quite a bit, and wanted to report it back.

There are fixes to that (e.g. finishing lines by |>) but I feel it is very unnatural and far away from Elixir snippets you'll find online.

Do you think it is worth opening an issue for IEx here?

Cheers,

-- Thibaut

José Valim

unread,
Nov 24, 2021, 11:36:53 AM11/24/21
to elixir-l...@googlegroups.com
There is nothing we can do unfortunately, without perhaps changing upstream (i.e. how the Erlang shell system works). The shell reads line by line, and therefore "a = DB.Resource" is a complete line on its own, which will therefore evaluate successfully.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/f216f8cf-e786-4279-9619-559ca0a00977n%40googlegroups.com.

José Valim

unread,
Nov 24, 2021, 11:37:27 AM11/24/21
to elixir-l...@googlegroups.com
Even then, it is debatable if we should do this change. One benefit of how things work today is that you can see intermediate results, and I can see people not happy if this behaviour is removed. :)

Adam Lancaster

unread,
Nov 24, 2021, 11:39:35 AM11/24/21
to elixir-l...@googlegroups.com
As a work around would having this be the first line make a difference?

`a = DB.Resource |> where([r], not is_nil(r.datagouv_id))`

Best

Adam

On 24 Nov 2021, at 16:37, José Valim <jose....@dashbit.co> wrote:

Even then, it is debatable if we should do this change. One benefit of how things work today is that you can see intermediate results, and I can see people not happy if this behaviour is removed. :)

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
Nov 24, 2021, 11:52:44 AM11/24/21
to elixir-l...@googlegroups.com
No, it is still a complete expression. Only if you wrap it parens, for example!

thibaut...@gmail.com

unread,
Nov 24, 2021, 12:37:22 PM11/24/21
to elixir-lang-core
Hi,

> There is nothing we can do unfortunately, without perhaps changing upstream (i.e. how the Erlang shell system works)

I understand ; thanks for the explanation ! We will use work-arounds for now.

-- Thibaut

thibaut...@gmail.com

unread,
Nov 25, 2021, 3:13:57 AM11/25/21
to elixir-lang-core
Forgot to reply on this:

> One benefit of how things work today is that you can see intermediate results, and I can see people not happy if this behaviour is removed. :)

To clarify, I was definitely not hinting to remove that : this part is really lovely indeed !

I think this is probably what took us by surprise by the way, because somehow we are lead to think the assignment (a =) will be also be taken care of, with that level of polish.

It would be incredible to have something able to detect that we have an assignment in the previous statement, and re-assign if the next line is a |> (but there are probably tons of edge cases if we start dealing with this...).

Anyway - thanks for the clarification!

-- Thibaut

José Valim

unread,
Nov 25, 2021, 4:29:07 AM11/25/21
to elixir-l...@googlegroups.com
Oh, I see now. This is tricky because we could take care of the assign but cases like pattern matching likely would fail (because we would execute the pattern multiple times).

Please open up an issue anyway, it probably merits investigation.

thibaut...@gmail.com

unread,
Nov 25, 2021, 10:45:28 AM11/25/21
to elixir-lang-core
Done here with full case detailed. Thanks for the discussion!


-- Thibaut

Reply all
Reply to author
Forward
0 new messages