Questions like this should be asked on the Elixir Forum.

The problem with the expression `[x: 1, y: 2 | [z: 3]]` is that it is
parsed as `[x: 1, y: (2 | [z: 3])]`. As you may guess, the subexpression `2
| [z: 3]` does not make sense.

There's actually a working way to build the keyword list you want: [x: 1,
y: 2] ++ [z: 3].

On Wed, Sep 13, 2017 at 3:56 PM, Allen Madsen <[email protected]> wrote:

> Yesterday I wrote code like the following:
>
> [x: 1, y: 2 | [z: 3]]
>
> I was really surprised when it didn't compile:
>
> ** (CompileError) iex:1: undefined function |/2
>     (stdlib) lists.erl:1354: :lists.mapfoldl/3
>     (stdlib) lists.erl:1355: :lists.mapfoldl/3
>
> The non-shorthand version works fine.
>
> [{:x, 1}, {:y, 2} | [z: 3]]
> #=> [x: 1, y: 2, z: 3]
>
> --
> 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 [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/elixir-lang-core/6e89a635-6642-4f42-ace8-
> 4a36119fa4e5%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/6e89a635-6642-4f42-ace8-4a36119fa4e5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAAPY6ePPtOKu%3D1%2BrxN0yXQF1Qm%3D%2BL0Q1ZtHmmmfjoLMWtn5Waw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to