我试图实现一个神经网络,并且每个神经元需要对其他神经元的引用。我一直试图通过原子实现这个参考。Clojure有变量引用吗?
考虑代码
(def neuron1 {:connections [(atom 0)])
(def neuron2 {:connections [(atom neuron1)]})
(update-in neuron1 [:connections 0] #(reset! % neuron2))
这最后会吹堆栈。
因此,它似乎是一个原子包含它的内容,而不是仅仅引用他们。
如果我想传递相当于指针的指令,该怎么办?我必须在
(def neuron1 {:connections [(fn [] neuron2)]})
使用功能,因为并调用它,而不是使用原子和非关联呢?