From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19793 invoked from network); 7 Mar 2021 21:57:36 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Mar 2021 21:57:36 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1615154256; b=0PQ1IPAj7OfiHryNwz3xcCez9kDkMmJaC2D/WyTQ6bLGPW8YkT/71XinrjmwfHaG/n4jXS/5HF HbHXyy8PmpgIGpQNmMPEGiDIoCfEvugInqYJcSa5KQ8QEf7r6STU2oN0umCaPynNCg5px066Pg cwRrgD2MXi9aSFcxGrAkV+1Wgyfw+87+q07K6/E1V+8/4628AnUQEl34f930N8yYCMYvCXmU5q P3EqkqclfNnJM9V1QuszJGDQGRhToTzX92U+06nC06gKuvR1jq5e2cWwWZKlwEkrbj/Bj6imvx dhyfWtGmSJ7sd9HVKHMOJeGRVu9cNwfp9JfrTifiyBuncA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1615154256; bh=Z20rv6OrkVCJt5hJlrHjASkxSYzAu3SUIjWPxZqAZn8=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Subject:Cc:To:From: Date:References:In-Reply-To:Message-ID:MIME-Version:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=eNyWMHRqn8cq6qcKAJ96aIH96A3y9U13FVVLOax6cWkTj8i4lqFyCZt1QcLu45XezZmCyKGTHW UW/wP5sOpQ6QC0LB3ciRrdP4xcK3+sBfVJWRNoWUV8EO4KdmoerBrIS0hCxqVgWeeM8ce9GeS/ gs7LquyNSOPC0kbhgPqehVpOsV5UIivNTKw+E2qhAMNvD00Vpp6Zzzb6U/Mg2617cY/zbkjt/C FyUCDCgVsmzmlcXCYU7A28FjdG6w9eq2tD+zzwOumdd2ymyBtxKpiqACgQ90n3kN1M6DA+waQB bEgx8FizY7ZC5U64rWC3OQtXay+9380uZ2UXRUcGxGmQqQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Subject:Cc:To:From:Date:References:In-Reply-To:Message-Id: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=GeC3DA8NHvK2U+plvEaghzuBJIuwOd8boztc75k8KDw=; b=DectfoIt0TEpzQU7DMOZEsJXHT 9U8GFlI55NoO5g6lSxWJnVds+oqaAJC88furSkRorunS+36p1ihbEyCyQEq84leWSdldJvNWk9VaO HwTDsNfgyJagqONf89teBncA92T/mdBB/LOanJmfkqTrDgeLCOIe51SrPajn8JoxpWtx37JBy7akU oN+pdzmX/3/uFi7VzXQR1ft1I2LXJYpZt6URH1c/unHpdyqkg23rTIhI+x0FnxDrkIVlOwSQgSofI YLJT1Qx7i+uk56AwCV1Df78lYARr5lMl//ObBFx28Pq3B/PXCiubEJqFwpjrwUV+5afil5hZYdOF+ OTM2STlw==; Received: from authenticated user by zero.zsh.org with local id 1lJ1P3-00010o-0e; Sun, 07 Mar 2021 21:57:33 +0000 Authentication-Results: zsh.org; iprev=pass (out5-smtp.messagingengine.com) smtp.remote-ip=66.111.4.29; dkim=pass header.d=daniel.shahaf.name header.s=fm2 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm2 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from out5-smtp.messagingengine.com ([66.111.4.29]:55255) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1lJ1Ok-0000qm-Kz; Sun, 07 Mar 2021 21:57:16 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id CC74D5C009B; Sun, 7 Mar 2021 16:57:13 -0500 (EST) Received: from imap37 ([10.202.2.87]) by compute3.internal (MEProxy); Sun, 07 Mar 2021 16:57:13 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=mime-version:message-id:in-reply-to :references:date:from:to:cc:subject:content-type :content-transfer-encoding; s=fm2; bh=GeC3DA8NHvK2U+plvEaghzuBJI uwOd8boztc75k8KDw=; b=L+HtvtB4/GYc/z8UaD+QSfCqa0zDOpQqr3mbPn7YMD fIM6ak2me9lXY1SyhfxMRio/FZhgyHXm96uZd0ijyXaz5IntzCa4nS8eMzSD98gg f6S4LOWcOarLgkBORc7DFfB4RNftINVfLc4KXJ38pa3QeuKIg5d2+kujpSYrRRMf Zif/EWRIaaPePjsPiIcHiWojFfONsaDbIW+pBFnl9oykOz5RhrgSW28FNzUgakAp egSg/viye0cfI7sgeG0ef3l7ID9KTulkxwURSftvPK8aIqSTdm18o++ky3DCWzrM 49K+Af+uQQqHTZfT6tzwSL99wJxy9VbsQJMD7BdhSYaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=GeC3DA8NHvK2U+plvEaghzuBJIuwOd8boztc75k8K Dw=; b=Odczohui5SFHLtB7ZaJ8jbG7c8a8PLTya/SUUB6pFMbYbFGASlJpL2e71 mQEiSVqGz3p3SU8xeVsPT+oB8NQtpw5+uCr46m+HpNBoN0aghG5b7vX2iZJteOqt Vf1j/ELfLGtg+Ln5a24kqGRoarX7WSuYS/s0RlpzSvQdy4SsojOrQzQqmLEHweLx ENKSiSute0PCtYdqjTEk7E/8SDYWfQqX+H+C0NA2q2cy/tqJQXltCUkizYOWAkoC NkipTFgE7I+sIS/OreuYfYsytHZ7Olkgj+p7e98yFGH5/RjPq0smwgZtOilqFFCO QPX1VHwFZa8FMaFFNUW8X0+6/McaQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledruddutddgudegudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdff rghnihgvlhcuufhhrghhrghffdcuoegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrg hmvgeqnecuggftrfgrthhtvghrnhepfefhkeefveeileelheeiffdtkedujeelvdfhtdej tdeggedvuefffeelhefhvdfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 101586B4005F; Sun, 7 Mar 2021 16:57:12 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-206-g078a48fda5-fm-20210226.001-g078a48fd Mime-Version: 1.0 Message-Id: In-Reply-To: References: <20210307171712.GA9936@tarpaulin.shahaf.local2> Date: Sun, 07 Mar 2021 21:56:51 +0000 From: "Daniel Shahaf" To: "Bart Schaefer" Cc: "Nikolaus Thiel" , "zsh-workers@zsh.org" Subject: Re: zmathfunc: min, max, sum throw error if result equals 0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 48153 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: Bart Schaefer wrote on Sun, 07 Mar 2021 21:39 +00:00: > On Sun, Mar 7, 2021 at 9:17 AM Daniel Shahaf = wrote: > > > > Nikolaus Thiel wrote on Sun, Mar 07, 2021 at 17:37:09 +0100: > > > > > > When the result of min, max or sum equals 0, the functions throw a= n error. >=20 > I would not equate "return nozero" with "throw an error", FWIW. >=20 > > Ouch. Patch series attached. >=20 > I think your regression tests cover this, but use of "true" avoids > changing the result in "functions -M" context, correct? Yeah. =C2=ABreturn 0=C2=BB causes the arithmetic expression to evaluate= to 0, because the argument to =C2=ABreturn=C2=BB is math-evaluated. > Is it worth testing invalid cases? Such as uses outside math context > where the arguments are not syntax checked? I'd say this specific example of an invalid case is lower priority, since there's no promise of any particular failure mode. We could add a test to ensure it doesn't format C:, of course. A test for min() and max() with zero arguments would make sense, since those cases actually do promise a specific failure mode. Could also add tests with three arguments in various permutations. If you have ideas, feel free to write them and post them; I'll transplant them into Z02 once I have committed it. > As long as we're on the subject: >=20 > zsh_math_func_min() { > local result=3D$1 > shift > local arg > for arg ; do > (( $arg < result )) && result=3D$arg > done > (( result )) > true # Careful here: `return 0` evaluates an arithmetic expression > } >=20 > Because of the way math context works, if any of $@ is a string that > can be interpreted as a math expression, the above will evaluate it at= > least twice (and up to $# times in the case of $1). This could have > side-effects. Could you post a regression test for this? Related to code as it is in master, are =C2=AB(( $arg < result ))=C2=BB = and =C2=AB(( arg < result ))=C2=BB equivalent? > zsh_math_func_min() { > local result=3D$(( $1 )) Doesn't this still do multiple string-to-number conversions? > shift > local arg n > for arg ; do > (( n =3D arg )) # evaluate arg exactly once > (( n < result && (result =3D n) )) > done > (( result )) > true # Careful here: `return 0` evaluates an arithmetic expression > } Hmm. I'll go ahead and push the series now, then, so it'll be easier for you to work on revisions. If anyone has commit reviews, don't let the fact that I've pushed things affect you. Cheers, Daniel