Is clojure.lang really just implementation details?

陌路散爱 提交于 2019-12-23 12:56:06

问题


In Clojure, some tasks (such as instantiating a PersistentQueue or using deftype to implement a custom data type that is compatible with the clojure.core functions) require knowledge of the classes and/or interfaces in clojure.lang.

However, according to clojure.lang/package.html:

The only class considered part of the public API is clojure.lang.IFn. All other classes should be considered implementation details.

Are these statements incorrect or outdated? If so, are there plans to correct them in the future? If not, is there a more preferred way to perform the tasks mentioned above, or should they simply not be done at all in idiomatic Clojure code?


回答1:


Alex Miller has commented on this in the past (the whole thread is worth reading though):

I'd say there is a range of "public"-ness to the internals of Clojure.

  • The new Clojure API (clojure.java.api.Clojure) is an official public API for external callers of Clojure. This API basically consists of ways to resolve vars and invoke functions.
  • For Clojure users in Clojure, pretty much any var that's public and has a docstring, and shows up in the api docs can be considered public API.
  • Clojure vars that are private or have no docstring (such that the var is omitted from public api docs) are likely places to tread very carefully.
  • The Clojure internal Java interfaces [clojure.lang] are certainly intended to allow library builders to create useful stuff that plays in the Clojure world. I do not know that anyone has ever said that they are "public", but I certainly think that any change to a core interface likely to break external users would be considered very carefully.
  • The Clojure internal Java classes [clojure.lang] should in most cases be considered private and subject to change without notice. There are grey areas even there.

In general, we do not place a high value on encapsulation or hiding internals. In most cases, the internals are left available if they might be useful to an advanced user doing interesting things, with the caveat that the weirder things you do, the more likely you are to be accidentally broken in a future release.



来源:https://stackoverflow.com/questions/33845364/is-clojure-lang-really-just-implementation-details

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!