Quote:
* I don't think you should allow empty keys.
You haven't commented now on whether the keys should be trimmed of leading/trailing spaces.
I know I put in the restriction about keys not being empty, and then took it out, but what is the great harm? A value can be empty, eg.
ArraySet "myarray", "mykey", ""
Now you wouldn't want a restriction that you can't have empty values (because a 'message' or something might be empty). So what is the problem with a blank key? eg.
ArraySet "myarray", "", "some un-named value"
This is being done in a script, if you don't want to use un-named keys (or un-named arrays), don't.
As for the spaces issue, I thought I may as well remove the space trimming, after all, again you can do it if you want to, eg. now these are all different keys:
ArraySet "myarray", "mykey", "foo"
ArraySet "myarray", " mykey", "foo"
ArraySet "myarray", "mykey ", "foo"
ArraySet "myarray", " mykey ", "foo"
Again, this is done in a program (script), if you add an extra space when writing keys, it is no real difference to mistyping the key altogether.
Quote:
* You should guarantee that keys are unique, so it can be used to uniquify a list of things. (do this in perl a lot)
I may not have clarified that. Keys are indeed unique, so if you use any key (including the "empty" key) it will always only refer to a single entry in the array.
The ArraySet function replaces an existing value if necessary, however it returns a different return code if you are keen to know whether that actually happened.
Quote:
* You should provide a way to get the list of values.
You can get an array of the key names, just "for each" through that to extract the values.
However to keep my script-writers happy, I have added a new function ArrayGetValues that simply returns an array of all the values, in case you want them and don't particularly care what the keys are.
Quote:
... or a different command, so you can create 'more or less' keyless arrays.
I don't really see why you would use a keyed array system and then want to make keyless arrays, but in case you do, my earlier suggestion of numeric keys would work. Either keep track of the highest key and just keep adding 1 to it, or use ArrayGetLastKey to find the value of the last key, and add 1 to that, as in my earlier example.
|