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)
- X-seq: zsh-workers 37965
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: min() max() math functions (was: Re: Feature request (@M):# with context matches)
- Date: Sun, 14 Feb 2016 14:33:48 +0000
- In-reply-to: <160210094134.ZM2246@torch.brasslantern.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVDCOPzbU25+vTAXMQjonS1sznDX_SBq4-8rUZPQewa5Tg@mail.gmail.com> <CAKc7PVAe0N2bp2XS5U4mOKnTgxQRsj4UGy7NQpHput9VsbnAJw@mail.gmail.com> <160130085456.ZM9730__49922.0612728552$1454172936$gmane$org@torch.brasslantern.com> <20160207002212.GC24068@tarsus.local2> <160206170040.ZM1927__13399.3204137825$1454806909$gmane$org@torch.brasslantern.com> <20160209032308.GA20947@tarsus.local2> <160208212222.ZM27970@torch.brasslantern.com> <20160210092324.GA6339@tarsus.local2> <160210094134.ZM2246@torch.brasslantern.com>
Bart Schaefer wrote on Wed, Feb 10, 2016 at 09:41:34 -0800:
> On Feb 10, 9:23am, Daniel Shahaf wrote:
> } > 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.
> }
> } Why is it a problem for zshmodules to reference zshcontrib? Should
> } zmathfunc's documentation be located elsewhere?
>
> It's not exactly a problem, more like a bad precedent. E.g. I was careful
> to have zshcontrib for the *-word-match functions refer to the vim text
> objects, but I would not reference in the other direction. It should IMO
> be possible to throw away the zshcontrib manual and still have a complete
> reference to the "bare" shell.
>
> The most obvious counter-argument is that the entire completion system
> depends on mutually cooperating options, builtins, and shell functions.
> And the complist module already references the colors autoload, so I
> should probably just shrug and ignore my sense of propriety.
I don't think it's a problem for other manuals to provide pointers to
functionality in zshcontrib. It might be a problem if some core
functionality _depended_ on zshcontrib functionality, but that's not the
case here.
In the interest of going forward, I'll commit what I have so far, but we
can tweak the docs in further commits if needed.
Cheers,
Daniel
Interdiff relative to users/21256:
diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index 11678e5..f8754fb 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -3804,7 +3804,7 @@ xitem(tt(min+LPAR())var(arg)tt(, ...+RPAR()))
xitem(tt(max+LPAR())var(arg)tt(, ...+RPAR()))
xitem(tt(sum+LPAR())var(arg)tt(, ...+RPAR()))
item(tt(zmathfunc))(
-Autoloading tt(zmathfunc) defines the three mathematical functions
+The function tt(zmathfunc) defines the three mathematical functions
tt(min), tt(max), and tt(sum). The functions tt(min) and tt(max) take
one or more arguments. The function tt(sum) takes zero or more arguments.
Arguments can be of different types (ints and floats).
diff --git a/Functions/Math/zmathfunc b/Functions/Math/zmathfunc
index 17d3336..4ff4070 100644
--- a/Functions/Math/zmathfunc
+++ b/Functions/Math/zmathfunc
@@ -1,21 +1,26 @@
#autoload
-setopt localoptions multifuncdef
+zsh_math_func_min() {
+ local result=$1
+ shift
+ local arg
+ for arg ; do
+ (( $arg < result )) && result=$arg
+ done
+ (( result )) # return
+}
+functions -M min 1 -1 zsh_math_func_min # at least one argument
-zsh_math_func_min zsh_math_func_max() {
+zsh_math_func_max() {
local result=$1
shift
local arg
for arg ; do
- case $0 in
- (*max) (( $arg > result )) && result=$arg;;
- (*min) (( $arg < result )) && result=$arg;;
- esac
+ (( $arg > result )) && result=$arg
done
(( result )) # return
}
functions -M max 1 -1 zsh_math_func_max # at least one argument
-functions -M min 1 -1 zsh_math_func_min # at least one argument
zsh_math_func_sum() {
local sum
Messages sorted by:
Reverse Date,
Date,
Thread,
Author