开发者

How to pick a letter in a charset?

开发者 https://www.devze.com 2022-12-28 22:41 出处:网络
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 lette开发者_JS百科r at positio

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 lette开发者_JS百科r at position 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/rebol-list@rebol.com/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!

0

精彩评论

暂无评论...
验证码 换一张
取 消