如何在字符集中选择一个字母?

发布于 2024-08-31 06:45:41 字数 159 浏览 2 评论 0原文

想要这样做:

letters: charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pick letters 2

但是 pick 不适用于 charset 那么我应该使用 charset 来获取位置 2 处的字母?

Would like to do this:

letters: charset "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pick letters 2

but pick doesn't work with charset so what should I use with charset to get the letter at position 2 ?

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

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

发布评论

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

评论(1

你好,陌生人 2024-09-07 06:45:41

字符集是“集合”,因此实际上没有“位置”的概念。使用它们,您可以测试成员资格、进行差分、求反等。但它们只是一种优化。

如果您关心“枚举顺序”,那么强制执行顺序的是您的枚举器,而不是集合。

请注意此代码来自
http://www.mail-archive.com/[email protected]/msg16432.html

bitset: charset "aaaaybcx"
chars: copy {}
for i 0 (subtract length? bitset 1) 1 [
    if find bitset i [append chars to-char i]
]
?? chars

如果您确实关心顺序,请考虑保留一个系列(例如字符串!)。例如,在上面的示例中,没有什么可以阻止您:

 letter-string: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 letter-set: charset letter-string
 pick letter-string 2

那么您将获得两全其美!

Charsets are "sets" and thus don't really have the concept of a "position". With them you can test for membership, do differencing, negation, etc. But they're just an optimization.

If you care about an "enumeration order" then it is your enumerator which enforces the order, not the set.

Note this code from
http://www.mail-archive.com/[email protected]/msg16432.html

bitset: charset "aaaaybcx"
chars: copy {}
for i 0 (subtract length? bitset 1) 1 [
    if find bitset i [append chars to-char i]
]
?? chars

If you actually care about the order, consider keeping a series (e.g. string!) around. e.g. in your example above, nothing is stopping you from making:

 letter-string: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 letter-set: charset letter-string
 pick letter-string 2

Then you get the best of both worlds!

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