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

Re: Defining function based on alias



Bart Schaefer wrote on Sun, Jan 08, 2017 at 16:09:21 -0800:
> On Jan 8,  7:19pm, Peter Stephenson wrote:
> }
> } I am about to commit the following, which I hope will hope will stop
> } people coming to grief with this common confusion.  Please say if you
> } see any problems.
> 
> OK, here's an unusual case ...
> 
>     alias safely:foo='[[ -n $functions[foo] ]] || foo'
> 
>     safely:foo() { echo this is foo only if no other foo }
> 
> I hesitate to suggest further convolutions, but maybe an option to the
> alias command to "locally" switch on ALIAS_FUNC_DEF if it's actually
> *meant* to be used that way?

This case doesn't require a new option:

    alias safely:foo='[[ -n $functions[foo] ]] || function foo'

> Probably not very important.
> 

Another case:

% alias foo=''
% foo() echo hey  
hey

Or less minimally:

% setopt NO_multifuncdef 
% alias foo='' 
% foo bar () :        
% which -a foo bar  
foo: aliased to 
bar () {
        :
}

Should these two behave differently when the new option is set?  The
first case appeared to be a non-anonymous function definition and the
second a multifuncdef, but the alias changed the semantics.

As Bart said: probably not very important.



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