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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17633 invoked from network); 7 Mar 2021 21:40:26 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Mar 2021 21:40:26 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1615153226; b=Mbcu190b0dLr3d6rpgSnrGWDrdU8DfK2WRM9wOCeLw/qpCDFHY7GBejhPDaA5p0Gh+7uwVpHth OiSj9a+yvMz8nH1LOVhKFsc03Ndq6zb2kvs6DHokXpWSzak2p9yD03DL4vebw0KrlA8gfPIce1 QEOy/VDqVs8gjnDAOuTRnpjnA/zqxOfQJZvICpWEqv8wUQq5AZNUL4m1n1IyhcIO4sn+9LVnpm Tw4EowrUZ8xDCemal2P6SfflkEBI4G3/Kf6dTRgPVl0TfYjaff9MGqbDFAxmHGJ5ocuuHJOHpK cKCZaXUicfU/JJKwgA75XEdrubVg2kvgx33bRg1C3v0NIw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1615153226; bh=uYsRp1zCMRhr6xN2Ky8UWwHiQEgn3VtcN9EeSJN9aEg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=AOytz76ITx9t4QCvy72VVD1q5mog92/zzn+T6cNzuaF8/S3NSFcV0/d07rj9xXucg7th6APwCe hPAufy2phsfQOK4A+slYI7c/pSnHeDlR/Eh3/bjBKchDJQm3GTUQ2yxS2XIWGZbVsmCJ9hJHgk EHmayA17q1arOXFBL3QfSl0xRu08nWcqmkAb6sxtHcq+zF4uMXak+bGpZ9dFCXtNrJkVSouvAH FJ9FIwyP58O9Tg+kgFRTzDh6+KaelRmspCCg4o1nLj0eYF5OvFe+UzLw0hVuSl7ToMX1bchqvS s3St4liVJD8nqDVo99BczYtamwUmIg9DplNVmwG2WLnJjQ==; 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-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=MRECPimPbVCfOvgpDfPugyrfXDQY+jssz9QsHXSusMQ=; b=0fT9I/u7+jtrehNsLHK+RGXLHz UryjPZz6ynMBZR4q84ir8zf+2PlBsz0w5e94oTxV1SzxG8WviV/X2XeUu4Ev6EQqYy8MyrvNrpnbb 4tRHUSWAhwgzxJahDn2KksGbzmJCchltmFsaD0X6Z8uEFiCsHFzlz8IxPHSk/iPmAeQNQXcn3Ap86 qXK4RCo/3/n+9j2zHhBrHAHPSOcNvZlDHfoAQTTo+Pa4/zF2nPnJICdaeeSuNRlIYUJDedfpS6ykE +5z4a11nh3dxOulUkaVbYQup4wnGFfMyZ8YMUD548IOgbMyFtdJtDdE8KLpy1VEByvmfDqtF8hmxf Z2bFYW5Q==; Received: from authenticated user by zero.zsh.org with local id 1lJ18R-000065-9H; Sun, 07 Mar 2021 21:40:23 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f180.google.com ([209.85.167.180]:33174) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lJ188-000PvW-ES; Sun, 07 Mar 2021 21:40:05 +0000 Received: by mail-oi1-f180.google.com with SMTP id a13so9033060oid.0 for ; Sun, 07 Mar 2021 13:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MRECPimPbVCfOvgpDfPugyrfXDQY+jssz9QsHXSusMQ=; b=ISGvSeKIPNmx9OrhBeEHHalbSAiJ+M3t7udfiVRtXwGIdmkm5/63mA7Ror7YL1+98+ te8wciV6BJKYQIxzX72kj+6dR+SELrtwkwm/AI7zRFQGR5C6qsAW4GLL/NugO8DxW9qk v8uR2Z27bKEClCZueCDuevrLezGXb8hVFp+tKwO3DTTdVZg3XgkmYHKRtNlH1QGw2MdN lJI0nNiydGAmsNqkiaIQoPYh3WIIAL5wy7o9Pdbz6D/YTJIiI4pKflCKNCIwe+VUXhGJ 44HtDrqsvGBS8+o90ssbu4a/LlpkoxMWsKMbofW4n7IT0ug2XfcqhOW4mWgiN+KLFEyN xRRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MRECPimPbVCfOvgpDfPugyrfXDQY+jssz9QsHXSusMQ=; b=SVxpepky03M9g9cpAfcqKzGTiDLvxT84q9BHJ7dgHNNBOt+OeoLdW+PCB/CnPpbEUi yCgix4Cj+oGP8TUisSsYmkR8yXdk815b1obF7TLxz+6sSoiwt7E1kYiheF1SNwZv2ZlN QLTv0sYQSODjAAKoEHr7K0PMelDo0TQOB4XUplhJNXtuSQa1C9zIpJkUB7xio4E+4R6A QgO0X/RBcb1tu8ic2IkvBFeWsRjzKw8kIW+j2Cyb7WDy0V5/LNBQ/wPvFMWTqndrCiHe pDIbxJ5ktaxYpO90q6iES1fpev1127HyS3gJImPtve3clQNVntpzkob4u6OTZiwU15ko 4CEA== X-Gm-Message-State: AOAM531YHzfFRZkwQPMyl6MT6VDE6zh0ZrSJ0xJ95+91jv8TxggoOu37 O386hWvvTnUvTGuBggGmzVox+HxxhNx8gkeYy0/6WhqMs6HLdA== X-Google-Smtp-Source: ABdhPJzNmHQ+R8uuK5QNNtSlR8Szh9ZVObV+XGcAKjaTwIX9uHETm+Z3KrhYusTFl1jUuWxsuEIuHZ9/LxSDCLVC2FQ= X-Received: by 2002:aca:aa41:: with SMTP id t62mr13122808oie.84.1615153203030; Sun, 07 Mar 2021 13:40:03 -0800 (PST) MIME-Version: 1.0 References: <20210307171712.GA9936@tarpaulin.shahaf.local2> In-Reply-To: <20210307171712.GA9936@tarpaulin.shahaf.local2> From: Bart Schaefer Date: Sun, 7 Mar 2021 13:39:52 -0800 Message-ID: Subject: Re: zmathfunc: min, max, sum throw error if result equals 0 To: Daniel Shahaf Cc: Nikolaus Thiel , "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" X-Seq: 48151 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: 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 an error. I would not equate "return nozero" with "throw an error", FWIW. > Ouch. Patch series attached. I think your regression tests cover this, but use of "true" avoids changing the result in "functions -M" context, correct? Is it worth testing invalid cases? Such as uses outside math context where the arguments are not syntax checked? As long as we're on the subject: zsh_math_func_min() { local result=$1 shift local arg for arg ; do (( $arg < result )) && result=$arg done (( result )) true # Careful here: `return 0` evaluates an arithmetic expression } 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. zsh_math_func_min() { local result=$(( $1 )) shift local arg n for arg ; do (( n = arg )) # evaluate arg exactly once (( n < result && (result = n) )) done (( result )) true # Careful here: `return 0` evaluates an arithmetic expression }