在 clojure 中应用 str 时保留空格

发布于 2025-01-05 22:24:24 字数 409 浏览 1 评论 0原文

我正在尝试将 [\space \space \space \a \space] 之类的 vec 减少到

"   a "

但是,我得到:

Clojure> (apply str [\space \space \space \a])
         " a "

看来 str 正在剥离多个 \space 字符。有办法解决这个问题吗?

(顺便说一下,我只是使用 尝试 Clojure 来尝试并完成 4clojure)

I'm trying to reduce a vec like [\space \space \space \a \space] to

"   a "

However, I'm getting:

Clojure> (apply str [\space \space \space \a])
         " a "

It seems str is stripping multiple \space chars. Is there a way to get around this?

(By the way, I'm just using Try Clojure to try and work through 4clojure)

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

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

发布评论

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

评论(2

冷…雨湿花 2025-01-12 22:24:24

我认为这是 tryclj 问题,而不是 clojure 问题。
刚刚在 clojure 1.2 上测试

(apply str [\space \space \space \a]) => "   a"

UPD:
我几乎可以肯定这是 tryclj 标记问题。刚刚在tryclj上测试过

(= (apply str [\space \space \a]) " a") => false
(= (apply str [\space \space \a]) "  a") => true

I think its tryclj issue, not clojure.
Just tested on clojure 1.2

(apply str [\space \space \space \a]) => "   a"

UPD:
I'm almost sure that is tryclj markup issue. Just tested on tryclj

(= (apply str [\space \space \a]) " a") => false
(= (apply str [\space \space \a]) "  a") => true
孤寂小茶 2025-01-12 22:24:24

这不是 clojure 问题,只是 HTML 问题: 如果我写:

a      b       c

这会呈现为 abc,因为 HTML 会折叠空格(请随意检查这个问题的来源 - 我确实在两个实例中都写了很多空格)。您的 repl 位于 HTML 环境中,因此如果得知在一两个地方它对于转义 块不够小心,我不会感到太惊讶。

It's not a clojure issue, just an HTML issue: If I write:

a      b       c

That renders as just a b c because HTML collapses whitespace (feel free to check the source of this question - I really wrote lots of spaces in both instances). Your repl is in an HTML environment, so I wouldn't be too surprised to learn that in one or two places it isn't careful enough about escaping <code> blocks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文