OvermindDL1

OvermindDL1

Elixir pipe into operator bug

So I have a ~>/3 operator in scope and am trying to pipe in to it like:

a
|> (b ~> c)

And this works just fine if I build the AST manually (like via {:~>, [], [a, b, c]}) or call it directly (like via Blah.~>(1, 2, 3)), but I keep getting errors like this:

** (ArgumentError) cannot pipe a into 1 ~> 2, the :~> operator can only take two arguments

Which is of course a bit of hogwash since that function/operator can take 3 arguments just fine. Not even using any macro work or anything of the sort in relation to it, just standard function naming since function names can be anything, and the normal built-in pipe operator.

This seems to be an issue with lots of operator-like function names.

This is trivially replicatable via a minimal case like:

iex(1)> defmodule Blah do
...(1)>   def unquote(:~>)(a, b, c), do: a+b+c 
...(1)> end
{:module, Blah,
 <<70, 79, 82, 49, 0, 0, 4, 120, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 123,
   0, 0, 0, 14, 11, 69, 108, 105, 120, 105, 114, 46, 66, 108, 97, 104, 8, 95,
   95, 105, 110, 102, 111, 95, 95, 7, 99, ...>>, {:~>, 3}}
iex(2)> 
nil
iex(3)> defmodule BlahTest do
...(3)>   import Blah
...(3)>   def test() do
...(3)>     1
...(3)>     |> (2 ~> 3) # Purely example data
...(3)>   end
...(3)> end
** (ArgumentError) cannot pipe 1 into 2 ~> 3, the :~> operator can only take two arguments
    (elixir) lib/macro.ex:155: Macro.pipe/3 
    (stdlib) lists.erl:1263: :lists.foldl/3
    (elixir) expanding macro: Kernel.|>/2
    iex:7: BlahTest.test/0

It works fine as well if I prefix the module name on it:

defmodule BlahTest do
  import Blah
  def test() do
    1
    |> Blah.~>(2, 3)
  end
end

It just fails if I try to use it directly, like via importing it, which is super weird since operators are just 2-arity functions of special names, but using those names with other arities works just fine otherwise in every-single-case that I can find except for with pipes.

As far as I can see in the code this is an explicit test and failure on the specific ‘operator’ names, but no test on if the operator actually exist with the given higher arity first (it’s just assuming that it doesn’t exist…), but I have no clue why it’s there (no comments as to the reasoning in the source…), this language inconsistency is breaking a DSEL I was trying to build for some math stuff… :frowning:

First Post!

blatyo

blatyo

Conduit Core Team

I suspect this is on purpose based on the warning for using the + operator in a pipeline.

Can you call it normally with 3 args? a ~> b, c

Also, I’d expect the syntax to be:

a
|> ~>(b, c)

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
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
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
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
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
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
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
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
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
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement