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

Re: min() max() math functions (was: Re: Feature request (@M):# with context matches)



Bart Schaefer wrote on Mon, Feb 08, 2016 at 21:22:22 -0800:
> On Feb 9,  3:23am, Daniel Shahaf wrote:
> } How do I shield zmathfunc against callers that unsetopt functionargzero?
> 
> Sticky emulation would do it for you.  E.g.
> 
>     emulate zsh -c 'autoload -U zmathfunc'
> 

Good to know.

If I'm not mistaken, using this form would also fix the cshjunkiequotes
problems Sebastian has been running into.  

Shouldn't this form be used more often?  As in, wouldn't using this form
be correct for the majority of autoloadable functions?

> Or examine $funcstack[1] instead of $0 (with localoptions noksharrays),
> although that introduces a dependence on zsh/parameter.
> 
> } I guess I'll have to drop the the multifuncdef usage altogether?
> 
> See for example zmv, zcp, zln.
> 

I think the path of least resistance is to drop the multifuncdef usage,
and not require the user to create symlinks or to have zsh/parameter
[although that module is probably ubiquitous?] or to do the autoload
specially.

> Although it seems an oversight that you can't combine -u and -M for the
> functions command.
> 

Would this be easy to add?  (Just another flag in the stub function
structure, maybe?)  I can check later but don't have time to right now.

> } +Autoloading tt(zmathfunc) defines the three mathematical functions
> 
> You do have to both autoload it and run it, like e.g. "colors".

Indeed.  How about:

    The function tt(zmathfunc) defines the three mathematical functions...

> Given that, why not have zmathfunc perform "zmodload zsh/mathfunc"
> too?
> 

I don't see a good reason to force users of the autoload to use the
module.  It's a non-obvious side effect (consider somebody who does
'autoload zmathfunc && zmathfunc && zmodload -F ... zsh/mathfunc')
that's not easy for the caller to disable.  (But see below)

> } +++ b/Doc/Zsh/mod_mathfunc.yo
> } +The functions tt(min), tt(max), and tt(sum) are defined not in this module
> } +but in the tt(zmathfunc) autoloadable function
> 
> Ehh, I'm not sure it's the job of any module's doc to explain what it
> does NOT define, much less to cross-reference zshcontrib.

The functionality of zmathfunc is related to that of zsh/mathfunc.  The
reason they aren't the same thing is due to implementation considerations
(we separated functions that can be implemented satisfactorily in shell
code from those that must be implemented in C), not due to interface
considerations.  In fact, that's an argument in favour of making
zsh/mathfunc autoload zmathfunc (sic, in this order).

Why is it a problem for zshmodules to reference zshcontrib?  Should
zmathfunc's documentation be located elsewhere?

Cheers,

Daniel



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