How to make an infinate nested list

in python, there is

>>> a=[]
>>> a.append(a)
>>> a
[[...]]

how to implement this in elixir?

In Elixir this bug is fixed :slight_smile:

8 Likes

feature? bug? :upside_down_face:

Can you show what you’re actually trying to do? If you want a collection that emits an infinite number of values there is Stream.repeatedly. Beyond that, this feels like an X / Y problem.

2 Likes
def infinite(list \\ []) do
  [infinite(list)]
end

infinite()

Just for fun. Didn’t test it. It will take infinite time before it returns. And I expect the output to be 42.

1 Like

Closest thing I can think of would be a function that is infinitely callable, like this:

f = fn g -> fn -> g.(g) end end

h = f.(f)

h.().().().().().().().().()
1 Like

It’s a self-referencing structure I think,
in the python example above, a[0] == a

We know what it is, but we don’t know your use case. With an actual use case we might come up with a good solution instead of mimicking something from another language.

2 Likes

It is not possible to do something like that in Elixir due to strict evaluation and immutability. If you have both of these properties in your language, then it is impossible to achieve what you want there.

1 Like