本文介绍了为什么设计师在clojure中做向量,映射和集合函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

丰富的向量,映射和设置函数,而列表和序列不是函数。
为什么所有这些集合都不能使函数一致?

Rich made vector, map, and set functions, while list, and sequence are not functions. Why cannot all these collections be function to make it consistent?

此外,为什么我们不将所有这些组合数据作为函数映射位置它的内部数据?

Further, why don't we make all these compose data as a function which maps position to it's internal data?

如果我们将所有这些组合数据作为函数,那么clojure中只会有函数和原子数据。这将最小化该语言的基本要素?

If we make all these compose data as function then there will be only function and atom data in clojure. This will minimize the fundamental elements in that language right?

我相信一个最小,最好只有2,一组基本要素将使语言更简单,更具表现力和更灵活。这是否正确?

I believe a minimal, best only 2, set of fundamental elements would make the language simpler, more expressive and more flexible. Is this correct?

推荐答案

向量,地图和集合都是关联数据结构。地图是最明显的;它们只是将任意键与任意值相关联。向量可以被认为是一个映射,其关键集必须是小于向量大小的所有非负整数的集合。最后,集合可以被认为是将密钥映射到自己的映射。

Vectors, maps, and sets are all associative data structures. Maps are the most obvious; they simply associate arbitrary keys with arbitrary values. A vector can be thought of as a map whose key set must be the set of all nonnegative integers less than the vector's size. Finally, sets can be thought of as maps that map keys to themselves.

重要的是要理解向量的顺序性质和向量的关联性质是两个正交的东西。这是一个数据结构,它设计得很好地支持两个抽象(在某种程度上,例如,你不能有效地插入向量的开头)。

It's important to understand that the sequential nature of a vector and the associative nature of a vector are two orthogonal things. It's a data structure that's designed to be good at supporting both abstractions (to some extent; for instance, you can't efficiently insert at the beginning of a vector).

列表比向量更简单;它们是有限顺序数据结构,没有更多。列表不能有效地返回特定索引处的元素,因此它不会将该功能作为其核心接口的一部分。当然,您可以使用 nth 按索引来获取列表的元素,但在这种情况下,您明确将其视为序列

Lists are simpler than vectors; they are finite sequential data structures, nothing more. A list can't efficiently return the element at a particular index, so it doesn't expose that functionality as part of its core interface. Of course, you can get an element of a list by index using nth, but in that case, you're explicitly treating it as a sequence, not as an associative structure.

因此,为了回答您的问题, IFn 向量,映射和集合的实现存在,因为关联数据结构的想法和纯函数的想法之间极其密切的关系。列表和其他序列不是固有关联的,因此为了一致性,它们不实现 IFn

So to answer your question, the IFn implementations for vectors, maps, and sets are there because of the extremely close relationship between the idea of an associative data structure and the idea of a pure function. Lists and other sequences are not inherently associative, so for consistency, they do not implement IFn.

这篇关于为什么设计师在clojure中做向量,映射和集合函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 18:05