in python, there is
>>> a=[]
>>> a.append(a)
>>> a
[[...]]
how to implement this in elixir?
in python, there is
>>> a=[]
>>> a.append(a)
>>> a
[[...]]
how to implement this in elixir?
In Elixir this bug is fixed
feature? bug?
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.
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.
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.().().().().().().().().()
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.
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.