Why does clojure convert dashes in names to underscores in the filesystem?

被刻印的时光 ゝ 提交于 2019-12-17 20:42:53

问题


I have been using clojure for a couple of months now and one thing I really don't understand is why dashes in namespace names must be represented as underscores in the filesystem. Can anyone explain this to me, and is it possible to be able to use dashes in the filenames too?


回答1:


It's a necessary workaround for Java interoperability.

When a Clojure namespace is AOT (ahead-of-time) compiled into a Java .class file, it has to have a name that is a valid Java identifier. Dashes aren't valid in Java class names, so Clojure converts them to underscores. It also converts characters like * into words like _STAR_.




回答2:


Do you mean that the .class files on disk have underscores where the functions in Clojure had dashes? I'm sure I read that it's something to do with the JVM not supporting dashes in those file names. (Or at least it not being a guarantee that it supports them.)

This is only a limitation of the class file names, and Clojure silently deals with this problem anyway. Your own code can still handle files with dashes in the filename.

I'm sorry that I don't have a reference for this right now.



来源:https://stackoverflow.com/questions/4420944/why-does-clojure-convert-dashes-in-names-to-underscores-in-the-filesystem

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