tags:

views:

46

answers:

1

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 ?

+2  A: 

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!

Hostile Fork