Alan Grunwald
2024-11-29 21:03:25 UTC
I find I regularly want to know things like "what is first part of a
namespace name", "the first two parts" etc. I generally want to get the
same answer whether the name is a::b::c or ::a::b::c.
I can (and do) do this by getting a list of parts via something like
split [string map {"::" ":"} $name] ":"
but this is clunky - is there something like [namespace split] that
would return a list of parts?
For example, I'd like namespace split a::b::c to return {a b c}, and
namespace split ::d::e::f::g to return {d e f g}.
As a followup, if I write a proc namespaceSplit that does what I want,
is there a user-level way to modify the [namespace] command so that a
can execute namespaceSplit via [namespace split]?
Many thanks
namespace name", "the first two parts" etc. I generally want to get the
same answer whether the name is a::b::c or ::a::b::c.
I can (and do) do this by getting a list of parts via something like
split [string map {"::" ":"} $name] ":"
but this is clunky - is there something like [namespace split] that
would return a list of parts?
For example, I'd like namespace split a::b::c to return {a b c}, and
namespace split ::d::e::f::g to return {d e f g}.
As a followup, if I write a proc namespaceSplit that does what I want,
is there a user-level way to modify the [namespace] command so that a
can execute namespaceSplit via [namespace split]?
Many thanks