在clojure中,以引导0s的速度传递数字会导致奇怪的行为。这是什么功能?

发布于 2025-01-29 00:19:30 字数 149 浏览 4 评论 0原文

因此,我在玩一些琴弦时不小心弄清楚了这一点。

(str 111) => "111"
(str 0111) => "73"

这是什么?

So, I accidentally figured this out while playing around with some strings.

(str 111) => "111"
(str 0111) => "73"

What is this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

病毒体 2025-02-05 00:19:30

0为前缀的数字为 Octal

0111
=> 73

数字 : 是 hexadecimal

0x111
=> 273

数字以xr前缀为xr ,其中x是2到36的数字,有一个radix:

2r111
=> 7

如果要与零一起使用零,请参见 格式 cl-format

(format "%04d" 111)
=> "0111"

(clojure.pprint/cl-format nil "~4,'0d" 111)
=> "0111"

Numbers prefixed with 0 are octal:

0111
=> 73

Numbers prefixed with 0x are hexadecimal:

0x111
=> 273

Numbers prefixed with Xr, where X is number from 2 to 36, have that radix:

2r111
=> 7

If you want to pad number with zeros, see format or cl-format:

(format "%04d" 111)
=> "0111"

(clojure.pprint/cl-format nil "~4,'0d" 111)
=> "0111"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文