Is it possible to create circular references in Clojure?

前端 未结 2 865
你的背包
你的背包 2021-02-12 10:06

Ignoring native interop and transients, is it possible to create any data structures in Clojure that contain direct circular references ?

It would seem that immutable da

2条回答
  •  误落风尘
    2021-02-12 11:07

    You can create a circular reference very easily by putting some form of reference inside a data structure, then updating the reference to point back to the overall structure.

    A trivial example:

    (def a [(atom nil)])
    
    (reset! (first a) a)
    

    This will create a list with one element, which is an atom that points back at the list.

提交回复
热议问题