If the list on the left is constant, ++ operator will compile to exactly the 
same code as cons operator.

[x, y] ++ tail and [x, y | tail] compile to the same thing.

Michał.

On 15 Sep 2017, 00:18 +0200, Allen Madsen <[email protected]>, wrote:
> Sorry, I wasn't asking a question. I was making a proposal as it says in the 
> title. Maybe the body of my message didn't convey that well or are you saying 
> that proposals to change the language shouldn't be made on this mailing list?
>
> You're right that the current parsing of that statement does not make sense. 
> I was suggesting instead of it being parsed like `[x: 1, y: (2 | [z: 3])]` it 
> was parsed like `[{:x, 1}, {:y, 2} | [z: 3]]`.
>
> It is definitely true you can use the list concatenation operator to do what 
> I'm suggesting, but that can have performance implications if the list on the 
> left is large. The cons operator on the other hand is a constant time 
> operation.
>
> This was something I noticed that seemed inconsistent to me. If there's a 
> very good reason not to support it, that's fine.
>
>
> Allen Madsen
> http://www.allenmadsen.com
>
> > On Thu, Sep 14, 2017 at 12:52 PM, Alexei Sholik <[email protected]> 
> > wrote:
> > > 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.
> > > > > 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.
>
> --
> 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/CAK-y3CstkBkwACf6HVMyD0MioTjUo8vtPq_ca1KrTzhQPY4rUw%40mail.gmail.com.
> 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/c8e0762b-5785-4d27-983a-29689848f680%40Spark.
For more options, visit https://groups.google.com/d/optout.

Reply via email to