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!
精彩评论