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

fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
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
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

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
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
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
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
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
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
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
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New

We're in Beta

About us Mission Statement