(There was some discussion about the below on the
AOLserver mailing list in June 2004.)
I would like to add some new subcommands to ns_set:
ns_set keys $setId
ns_set values $setId
These would return a list of the keys or values in the
ns_set respectively. While you can get these lists by
looping with ns_set key / value / array, it is
convenient to have them as primitives. The attach
patch implements this feature request.
As an example of how ns_set keys and values might be
used in practice, in some of my code I need to generate
a <SELECT> using ns_htmlselect from the keys and values
in an ns_set, which means we need separate lists of the
values and labels to pass to that proc.
There is a chance this patch could break existing code
as ns_set uses Tcl_GetIndexFromObj without the
TCL_EXACT flag, so any code relying on the uniqueness
of a key/value abbreviation would now get an error like:
% ns_set k $setid
ambiguous option "k": must be array, cleanup, copy,
cput, create, delete, delkey, find, free, get, icput,
idelete, idelkey, find, iget, isnull, iunique, key,
keys, list, merge, move, name, new, print, purge, put,
size, split, truncate, unique, update, value, or values
As suggested by various people on the mailing list,
ns_set could use some other cleanup. It currently has
ns_set
idelete and ns_set purge subcommands, both of which are
noops. ns_set idelete doesn't really make sense since
ns_set delete takes a field number and so case is
irrelevant. I'm not sure what ns_set purge did / was
supposed to do. These subcommands could probably be
removed. Another suggestion was to make ns_set use
Tcl_Obj's for performance and to support binary values
(see also RFE #458929). Neither of these items is
addressed in the attached patch.
Add keys and values subcommands to ns_set