Clojure关键字中允许使用的字符是什么? [英] What are the allowed characters in a Clojure keyword?

查看:106
本文介绍了Clojure关键字中允许使用的字符是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在查找clojure关键字中允许的字符列表。具体来说,我有兴趣知道是否允许以下​​任何字符: - _



我不是一个java程序员,所以我不知道潜在的后果。我不知道clojure关键字是否映射到java关键字,如果有这样的事情。

解决方案

编辑



当我最初撰写这个答案时,我可能对你能逃脱什么?不过,为了公平起见,关键字可否受理问题似乎仍然悬而未决。所以:



首先,关于新读者的一些关键字:




  • 关键字有两种口味,合格和不合格。未限定的关键字,如:foo ,没有命名空间组件。合格关键字看起来像:foo / bar 其中斜杠之前的部分是名称空间,表面上。关键字不能被引用,并且可以被赋予不存在的命名空间,因此它们的命名空间行为不同于其他Clojure对象。

  • 关键字可以通过文字创建给读者,如:foo 或由关键字函数,即(关键字 -str (关键字 ns name li>
  • 关键字仅评估自己,与指向vars的符号不同。请注意关键字不是符号



什么是官方允许的? / p>

根据读者文档,允许使用单个斜杠, 。



实际允许什么?



或多或少任何东西,但空格似乎被允许在读者。例如,

  user> :-_./ asdfgse / aser / se 
:-_./ asdfgse / aser / se

似乎合法。上述关键字的命名空间为:

  user> (namespace:-_./ asdfgse / aser / se)
-_./asdfgse/aser

因此,命名空间似乎包含最后一个正斜杠之前的所有内容。



关键字函数更加宽容:

  user> (关键字//// +/////)
://// + //////
user> (命名空间(关键字//// +/////))
//// +

同样,如果使用关键字函数,空格也很好。我不确定对Unicode字符有什么限制,但是当我放入任意字符时,REPL看起来不会抱怨。



有什么可能



在关键字被实习时验证关键字时出现了一些错误。假设最长的开放 clojure ticket 涉及关键字的验证。因此,关键字功能在未来可能会停止这么宽容,虽然这似乎是在空气中。请参阅assembla ticket和 google小组讨论


I am looking for a list of the allowed characters in a clojure keyword. Specifically I am interested to know if any of the following characters are allowed: - _ /.

I am not a java programmer, so I would not know the underlying ramifications if any. I don't know if the clojure keyword is mapped to a java keyword if there is such a thing.

解决方案

Edit:

When I initially composed this answer, I was probably a little too heavily invested in the question of "what can you get away with?" In fairness to myself though, the keyword admissibility issue appears to be unsettled still. So:

First, a little about keywords, for new readers:

  • Keywords come in two flavours, qualified and unqualified. Unqualified keywords, like :foo, have no namespace component. Qualified keywords look like :foo/bar where the part prior to the slash is the namespace, ostensibly. Keywords can't be referred, and can be given a non-existent namespace, so their namespace behaviour is different from other Clojure objects.
  • Keywords can be created either by literals to the reader, like :foo, or by the keyword function, which is (keyword name-str) or (keyword ns name).
  • Keywords evaluate to themselves only, unlike symbols which point to vars. Note that keywords are not symbols.

What is officially permitted?

According to the reader documentation a single slash is permitted, a no periods in the name, and all rules to do with symbols.

What is actually permitted?

More or less anything but spaces seem to be permitted in the reader. For instance,

user> :-_./asdfgse/aser/se
:-_./asdfgse/aser/se

Appears to be legal. The namespace for the above keyword is:

user> (namespace :-_./asdfgse/aser/se)
"-_./asdfgse/aser"

So the namespace appears to consist of everything prior to the last forward slash.

The keyword function is even more permissive:

user> (keyword "////+" "/////")
:////+//////
user> (namespace (keyword "////+" "/////"))
"////+"

And similarly, spaces are fine too if you use the keyword function. I'm not sure exactly what limitations are placed on Unicode characters, but the REPL doesn't appear to complain when I put in arbitrary characters.

What's likely to happen in the future:

There have been some rumblings about validating keywords as they are interned. Supposedly one of the longest open clojure tickets is concerned with validation of keywords. So the keyword function may cease to be so permissive in the future, though that seems to be up in the air. See the assembla ticket and google group discussion.

这篇关于Clojure关键字中允许使用的字符是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆