Kernel.--/2 weird behaviour
++
and --
are right-associative operations. Your initial code:
[:foo, :bar] -- [:foo] -- [:foo, :bar]
Is actually evaluated as
[:foo, :bar] -- ([:foo] -- [:foo, :bar])
When you take what's in the brackets: you remove a list of elements from [:foo]
, and the list you remove contains the original list ([:foo]
) thus evaluates to an empty list []
.
Then you remove this empty list from the leftmost list:
[:foo, :bar] -- []
Which leaves you with the result [:foo, :bar]
.