Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Naive question: how hard are namespaces for functions



On 18 maja 2017 at 00:43:39, Bart Schaefer (schaefer@xxxxxxxxxxxxxxxx) wrote:
> On May 17, 4:20pm, Sebastian Gniazdowski wrote:
> }
> } Maybe namespaces are easy?
>  
> This depends entirely on what you mean by "namespaces".
>  
> Voluntarily naming functions with an identifiable prefix string is easy.
>  
> Calling those functions by a name other than the full name with the
> prefix string is probably of middling difficulty, but would require
> some sort of collision resolution if the same suffix appeared with two
> or more prefixes.

I might be too simple on this, but thought that calling would be with full prefix, only display of $functions (also output of builtin `functions`) would be changed. That might be not too much, but it lead me to an idea:

- prefix is always separated with ":" or "::"
- when defining, one sets ZSH_NSPACE="name"
- then he has functions name::load, name::exit, etc.
- such definition, confronted with ZSH_NSPACE, results in:
  - internal change of name of the functions to ^Aname^Aload, ^Aname^Aexit,
  - when any call is made, "::" is detected, and first the ^A... fields in functions hash table are checked,
  - then normal string e.g. "name::exit" is searched
- displaying of $functions skips elements starting with ^A unless ZSH_NSPACE is set

Just free thinking. Double-searching functions tab is an obvious slowdown, but it would happen only to "::" functions. Legacy software would rarely suffer because "::" function names are rare (and would suffer not much except when performance-hungry), maintained software would utilize ZSH_NSPACE and single search would happen.

But what namespace should completion functions have, not breaking too much similarity to current version.

> Dividing $functions (or any hash parameter value) up into named sections
> that the shell somehow understands natively, is very difficult.
>  
> I'm not following what this would have to do with how long it takes to
> load function definitions.

I've did a run on this (in other mail), it was an connected issue "many functions feel hard" with "many functions might require optimization", and also the division you mentioned, introducing namespaces might be through some division, which might open way to optimization.

--
Sebastian Gniazdowski
psprint /at/ zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author