Suppose I now want to cycle through the list,i.e. when the last item of the list was retrieved via backtracking, i want to start obtaining the first item again. So, list_item(X), backtracks infinitely, and without generation of excess memory.
A more mundane solution is below. It should probably be called the more elegant one as it is easily understandable and doesn’t depend on the shady area of infinite data structures. The above one is to impress
After trying it out a bit, i really like this structure.
L is essentially a pointer to itself, and hence the cyclicity.
I recall the notion of sets that contain themselves – there is a whole theory about it with alternative foundational axioms. But, for the purpose of creating a cyclic list that seems great.