What does “^:static” do in Clojure?

一个人想着一个人 提交于 2019-12-03 22:05:01
Arthur Ulfeldt

In the development of Clojure 1.3 Rich wanted to add the ability for functions to return types other than Object. This would allow native math operators to be used without having to cram everything into one function.

The original implementation required functions that supported this to be marked :static. this meta data caused the compiler to produce two versions to the function, one that returned Object and one that returned that specific type. in cases where the compiler determined that the types would always match the more specific version would be used.

This was later made fully automatic so you don't need to add this anymore.

bmillare

According to the Google Groups thread “Type hinting inconsistencies in 1.3.0”, it’s a no-op.

^:static has been a no-op for a while AFAIK, made unnecessary after changes to vars a while back.

a May 2011 post by Chas Emerick

Seems it's a new metadata attribute in clojure 1.3. And you can compare the source between 1.3 and 1.2:

So I think it has something to do with ^:dynamic which indicates whether the var is allowed for dynamic binding. Just my guess. Not sure until I see document about this attribute.

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