C# 是否有一个.net库具有持久不变的向量类(如Clojure/Scala中所示)?
我花了一个小时在谷歌上搜索,可以找到各种.NET不可变列表、集合和地图。不过,我还没有找到一个持久不变的向量 我所追求的是Scala的不可变向量(我相信在Clojure中也是如此)。它必须可以从C#库调用 Microsoft land中是否存在这种情况?您可以查看。 它是CLR/DLR执行引擎之上Clojure语言的实现。 我想您不能简单地将代码复制粘贴到项目中,但只需很少的工作就可以提取特定的持久数据结构。 查看Clojure\Clojure\Lib中的PersistentVector.cs等实现C# 是否有一个.net库具有持久不变的向量类(如Clojure/Scala中所示)?,c#,.net,collections,clojure,functional-programming,C#,.net,Collections,Clojure,Functional Programming,我花了一个小时在谷歌上搜索,可以找到各种.NET不可变列表、集合和地图。不过,我还没有找到一个持久不变的向量 我所追求的是Scala的不可变向量(我相信在Clojure中也是如此)。它必须可以从C#库调用 Microsoft land中是否存在这种情况?您可以查看。 它是CLR/DLR执行引擎之上Clojure语言的实现。 我想您不能简单地将代码复制粘贴到项目中,但只需很少的工作就可以提取特定的持久数据结构。 查看Clojure\Clojure\Lib中的PersistentVector.cs等
Ido.包中也有一个.NET实现(来自C#库)的持久性向量,在NuGet上 以下是该项目首页的使用示例:
// Create an empty PersistentVector and add some elements
PersistentVector<string> vector =
PersistentVector<string>.Empty()
.Conj("hello")
.Conj("world")
.Conj("!");
PersistentVector<string> vector2 = vector.Conj("!!!").Update(0,"hi");
Console.WriteLine(vector2[0]); // hi
Console.WriteLine(vector[0]); // hello
Console.WriteLine(vector2[3]); // !!!
Console.WriteLine(vector.Length); // 3
Console.WriteLine(vector2.Length); // 4
// remove the last element from a PersistentVector
PersistentVector<string> vector3 = vector2.Initial;
Console.WriteLine(vector3.Length); // 3
//创建一个空的PersistentVector并添加一些元素
持久向量=
PersistentVector.Empty()
.Conj(“你好”)
.Conj(“世界”)
.Conj(“!”);
PersistentVector向量2=vector.Conj(!!!).Update(0,“hi”);
Console.WriteLine(vector2[0]);//你好
Console.WriteLine(向量[0]);//你好
Console.WriteLine(vector2[3]);/!!!
Console.WriteLine(vector.Length);//3.
Console.WriteLine(矢量2.Length);//4.
//从PersistentVector中删除最后一个元素
PersistentVector vector3=vector2.初始值;
Console.WriteLine(矢量3.Length);//3.