I've spent a good hour googling, and can find various .NET immutable Lists, Sets and Maps. I have not been able to find a persistent immutable Vector though.
我花了一个小时在google上搜索,发现了各种。net不变的列表、集合和映射。但是我还没有找到一个持久不变的向量。
Something like Scala's immutable Vector is what I'm after (and I believe its similar in Clojure). It must be callable from a C# library.
我追求的是Scala的不可变向量(我相信在Clojure中类似)。它必须可以从c#库调用。
Does such a thing exist in Microsoft-land?
在微软的世界里有这样的东西吗?
2 个解决方案
#1
2
You can check out ClojureCLR implementation. It is an implementation of Clojure language on top of CLR/DLR execution engine. I guess you can't simply copy&paste the code to your project but with little work you can extract specific persistent data structures. Look inside Clojure\Clojure\Lib for implementation such as PersistentVector.cs
您可以检查ClojureCLR实现。它是CLR/DLR执行引擎之上的Clojure语言的实现。我猜您不能简单地将代码复制并粘贴到您的项目中,但是您可以用很少的工作来提取特定的持久数据结构。查看Clojure\Clojure\Lib中的实现,如PersistentVector.cs。
Ido.
被罩。
#2
1
There's a .NET implementation (callable from a C# library) of persistent vectors in the FSharpX.Collections package, also available on NuGet.
FSharpX中有一个持久向量的。net实现(可从c#库调用)。集合包,也可在NuGet上获得。
Here's the usage example from the project's front page:
以下是该项目首页的使用示例:
// 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
#1
2
You can check out ClojureCLR implementation. It is an implementation of Clojure language on top of CLR/DLR execution engine. I guess you can't simply copy&paste the code to your project but with little work you can extract specific persistent data structures. Look inside Clojure\Clojure\Lib for implementation such as PersistentVector.cs
您可以检查ClojureCLR实现。它是CLR/DLR执行引擎之上的Clojure语言的实现。我猜您不能简单地将代码复制并粘贴到您的项目中,但是您可以用很少的工作来提取特定的持久数据结构。查看Clojure\Clojure\Lib中的实现,如PersistentVector.cs。
Ido.
被罩。
#2
1
There's a .NET implementation (callable from a C# library) of persistent vectors in the FSharpX.Collections package, also available on NuGet.
FSharpX中有一个持久向量的。net实现(可从c#库调用)。集合包,也可在NuGet上获得。
Here's the usage example from the project's front page:
以下是该项目首页的使用示例:
// 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