将 comp 别名为 º和部分为 ¬在 Clojure 中
我错过了一个简短的语法来表达 Clojure 中函数的基本操作。因此,我开始使用 º
作为 comp
的简写(因为它更接近数学运算符,但易于访问),并使用 Ø
作为partial
(因为让我想起缺少参数)。
您对此有何看法?它有用还是有使代码混乱的风险?
I missed a short syntax to express fundamental operations over functions in Clojure. Because of that, I started to use º
as a shorthand for comp
(cause it's closer to the math operator but easily accessible) and ¬
for partial
(because reminds me of missing parameters).
What are your thoughts about this? is it useful or does it have the risk of making code confusing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据经验,我会非常犹豫是否为已经命名的既定概念发明新名称。
As a rule of thumb, I would be very hesitant to invent new names for already-named established concepts.
我不喜欢在代码中使用非 ASCII 字符(在字符串/字符文字和注释之外)。让您的编辑器在显示代码时为您美化代码,而不是在保存代码时美化代码怎么样?例如,以下函数将导致 Emacs 将
comp
显示为∘
(实际的函数组合符号):显然它并不完美 - 它似乎破坏了
的显示compfoo
等——但您也许可以调整它以适合您。I prefer not to use non-ASCII characters in code (outside of string / character literals and comments). How about having your editor prettify the code for you when it's displayed, but not when saving it? E.g. the following function will cause Emacs to display
comp
as∘
(the actual function composition symbol):Apparently it's not perfect -- it seems to mangle the display of
compfoo
etc. -- but you might be able to tweak it to work for you.对于不了解该符号的人来说,这会让人感到困惑。我想打字可能也很困难。我只是坚持使用标准名称。
It's confusing for people who don't know the notation. I imagine it's probably quite difficult to type, too. I'd just stick with the standard names.