Gleam: Nested list prepend

Created on 17 Apr 2019  路  3Comments  路  Source: gleam-lang/gleam

What are your thoughts on supporting nested list prepends?

Example:

[1 | 2 | [3,4]]

Current equivalence:

[1 | [2 | [3,4]]]
help wanted

Most helpful comment

Seems my memory is correct and its [1, 2 | [3]] in both Erlang and Elixir. Let's use the same syntax as them for this.

I would suggest we alter the AST for cons to have a vector of elements for the head to support this:

https://github.com/lpil/gleam/blob/ace1a6db1c73005a29c2913ae9a0e6f4bc1f35bf/gleam/src/ast.rs#L234

https://github.com/lpil/gleam/blob/ace1a6db1c73005a29c2913ae9a0e6f4bc1f35bf/gleam/src/ast.rs#L398

All 3 comments

I would be in favour of this addition.

What's the Erlang syntax for this? In my head it's [1, 2 | List]

I'm not very familiar with Erlang. In Haskell it is:

Prelude> 1:2:[3,4]
[1,2,3,4]

Seems my memory is correct and its [1, 2 | [3]] in both Erlang and Elixir. Let's use the same syntax as them for this.

I would suggest we alter the AST for cons to have a vector of elements for the head to support this:

https://github.com/lpil/gleam/blob/ace1a6db1c73005a29c2913ae9a0e6f4bc1f35bf/gleam/src/ast.rs#L234

https://github.com/lpil/gleam/blob/ace1a6db1c73005a29c2913ae9a0e6f4bc1f35bf/gleam/src/ast.rs#L398

Was this page helpful?
0 / 5 - 0 ratings