如何获取Clojure数据结构的旧版本 [英] How to get older versions for clojure data structures

查看:61
本文介绍了如何获取Clojure数据结构的旧版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Clojure使用持久性数据结构,由于它在内部保存矢量或地图,因此有没有办法访问它?

Clojure is using persistent data structures , is there a way to access older versions of vector or maps since it is keeping it internally ?

让我们说一个Vector,我的意思是因为clojure不会复制完整的结构并将其内部保留在树中(请参阅

Lets say for a Vector ,what i meant is since clojure is not copying full structure and keeping it in a tree internally (see https://hypirion.com/musings/understanding-persistent-vector-pt-1) and keeps older structure values too, is there a way to use this to do some senarios like undo/redo or replay, It is using the same principle for Datomic to retrieve older version for data, so im asking if it is possible to get this in clojure.

推荐答案

根据Kris的评论,使用add-watch似乎是正确的答案,David Nolen在这里描述了这种方法 https://swannodette.github.io/2013/12/31/time-旅行

As per Kris's comment, using add-watch is the right answer it seems , David Nolen has described this approach here https://swannodette.github.io/2013/12/31/time-travel

这篇关于如何获取Clojure数据结构的旧版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆