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 19336 invoked from network); 8 Mar 2021 02:25:36 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Mar 2021 02:25:36 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1615170336; b=aFAfbCWQBeEhhv5DzPKmoXv6ElEZFO5hCqwKyxVy5Ggr5REif4VGNq3GMBcelo5SNbddjg7WcY ZhHDsOnVsDQaOnuBvzOPzGrHMxumBaQGFIOcI/GB/WZAfAqDxF8DJE7epi8UrlNEb4Yic5MvG5 h52d0ZImi/zSqlmctQJo1zQ2zHFIGvjSYaOTbQx/ovbzd6PMf/fA6NNlcsupX1RTONN+qWK/tc 71w35JT+ukUJDGYt/+yTAjOEqUhUN9tVNop+aoxvIdVhDQGLTq6bbhPzDcN6QS+T1QvyemO1QW BpRij9uN3eO1FTGroRoJhpLwrXXJR7jclnpYgbMY0VIwfw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f179.google.com) smtp.remote-ip=209.85.167.179; 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=1615170336; bh=iCKWz0u710td4GhnbfBM/nplLd9GVsBWaXowlrAcvAU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=R67QzOIINfvaWw5UxHkY5xIqW0wcKCWYd4XBgPpUc8h9eRGciyQDvix/udRerF4izOmnJmLx/+ crupaxMdNh+RRcdnAnIeHTo/EhcwrFCTxKzBW+SD9qiBpZoCttHzKIKl7ZZ6yPzawR/J8qEeYw vvH2tU6u5f+VNG32a/20FofYqBdXFAP+RU6A7QU5yGflmdCkc+LozSmD/Tqiyg6I0U3bJIRxna aeR+xhgyFDnPQTDdZtqVk8Csel7cHAxX1a7BznK9jdSZg3Lop7vX+2WKoOAJxCFSOtskxt2j+d qssqgIc2xV0KBcx2DYu++8JZ6xotlJh/2ScwOEshsk2Y0g==; 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:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=wMJn9EOf8pUXUxsSDaiTqKU4Ls3fkl8PrYm1Fa5EdYI=; b=kvfMnlnfo0dROoQgDlErRwnysi WnbrywTOUbCwWlXu6wTgHvLqTw8SBeN4W09ilQKkRfr7YDlTLBLWJkWCPB0IAycjghY6fVHDWn8WM xUX4ZbNKz9PoqM+yW6/ODLt4FNxPsE3qaUGIItZkF89WasjhoUHf4yVvJ32Aqy/y5mQb7X2bHpF7f GuZgW7OOQdlwjMl2zB3fecEpkN/DDJfbjRO1mn1xUUfL1+ihnpY+8Tji3oaolEmvTKttXzoqsDz9D QIVnZumG8mAtN9dNSbHssWfbHaNPZxmQ9BEcXfnHyUcJMc3ev35w9gI0mHOHXzS6Lm5WicsOahQiA qUg7wyUQ==; Received: from authenticated user by zero.zsh.org with local id 1lJ5aQ-00086p-VP; Mon, 08 Mar 2021 02:25:34 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f179.google.com) smtp.remote-ip=209.85.167.179; 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-f179.google.com ([209.85.167.179]:35303) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lJ5aB-0007x0-Ih; Mon, 08 Mar 2021 02:25:20 +0000 Received: by mail-oi1-f179.google.com with SMTP id u6so2114282oic.2 for ; Sun, 07 Mar 2021 18:25:19 -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 :content-transfer-encoding; bh=wMJn9EOf8pUXUxsSDaiTqKU4Ls3fkl8PrYm1Fa5EdYI=; b=xdqsI/C5N5dwuzIO0JNDy6/Bp6NJ6sThEDqkcZoaxHONyscCG59jhIKosqnFTKdB+F FTYdyaWrKkJQbGU/Gm1pnu4NTnOfzU1HJLZZBOjLr1noQCPre7cd0NFJQX3F4Czi8FMo FqM9vsgGy38rpEOMwcngwvqluaJznVM8IRjlj8t5JSpu8L56cUD7zKwdkLy4194BEWju scf7l/Rrl3n8P0QOfPL+LlO0oRK5Jio20vjJDngvJE4OO49Tjcsl8yEfMMg7yEIJKA9J LHAsE9JPFaBubH4giGttZ0d9p0j3iq+aG4i3cOE4VBYyTddfTTz10Lo9IGR35w90aqt0 oqZQ== 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:content-transfer-encoding; bh=wMJn9EOf8pUXUxsSDaiTqKU4Ls3fkl8PrYm1Fa5EdYI=; b=HwgOimjk96/FUxz70qbghpDWjKC4PgjABJryyJyVoeO5pAj8hEOUpduYTev3MLYA89 vQ0GFjLTXYOx4ijuOzQ4oG+2qtnnq964GiNzXzCQxwOanpbOLeypuTg+wZBRdCCgQqKS IJatYElhMChI4o7Uf8e3XkHNJDW7C5nVylfeYuEG+m8z5qN0h20G1zgWD7zimUnpfMa8 6srNlC6bAT0yYx7LvaFGml2ZJddInvuldZjDIOivfsNH7k5aMsYTe3+gteFF3LKUhoFU Kpvcuj0IV6f2vHfEzTMkpi1gcoJVlZGfWVV5S8uXHa5sT6FWEwQQGzPcJgGTx9MHj4LT w+lw== X-Gm-Message-State: AOAM532FclvU2Itsg++mGfjic/RMISodxu0djpATcA5Ei5AzEls1EaZa 1lwJMuf4gg94XiQapUTpfxQMudkvyfO4H1GxSiM9s16hv88eZA== X-Google-Smtp-Source: ABdhPJzj/kBRHJEQa3c685XsKZYOD/VZsJoc1C9u/WUPvkWWKeLzDKhiQ86JAR1jLqmy2xIpcFULC9anY3iDw+FVmTo= X-Received: by 2002:aca:aa41:: with SMTP id t62mr13731501oie.84.1615170314037; Sun, 07 Mar 2021 18:25:14 -0800 (PST) MIME-Version: 1.0 References: <20210307171712.GA9936@tarpaulin.shahaf.local2> In-Reply-To: From: Bart Schaefer Date: Sun, 7 Mar 2021 18:25:00 -0800 Message-ID: Subject: Re: zmathfunc: min, max, sum throw error if result equals 0 To: "zsh-workers@zsh.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 48156 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 1:57 PM Daniel Shahaf wrote= : > > Bart Schaefer wrote on Sun, 07 Mar 2021 21:39 +00:00: > > > Is it worth testing invalid cases? Such as uses outside math context > > where the arguments are not syntax checked? > > If you have ideas, feel free to write them and post them; I'll > transplant them into Z02 once I have committed it. One possibility below; I'll follow up if I think of more. With your patch adding "true" at the end, we get this: % zsh_math_func_min "foo bar" x y z zsh_math_func_min:7: bad math expression: operator expected at `bar' zsh_math_func_min:7: bad math expression: operator expected at `bar' zsh_math_func_min:7: bad math expression: operator expected at `bar' zsh_math_func_min:9: bad math expression: operator expected at `bar' toltec-ubuntu% echo $? 0 Doesn't seem as though anything that prints that many error messages should return zero. > > 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? In thinking more about it, I believe this only matters when the function is called outside of math context. In math context, the arguments are all going to be evaluated down to numbers before they are passed to the function. % (( x =3D 0 )); zsh_math_func_min "x +=3D 2" 4 5 6 % print $x 8 % (( (x =3D 0), min("x +=3D 2", 4, 5, 6) )) % print $x 2 > Related to code as it is in master, are =C2=AB(( $arg < result ))=C2=BB a= nd > =C2=AB(( arg < result ))=C2=BB equivalent? No, but again math context matters. % arg=3D"x +=3D 2" x=3D0 result=3D0 % (( $arg > result )) && result=3D$arg % print $result $x $(( result )) $x x +=3D 2 1 3 3 % x=3D0 result=3D0 % (( arg > result )) && (( result=3Darg )) % print $result $x $(( result )) $x 4 4 4 4 > > zsh_math_func_min() { > > local result=3D$(( $1 )) > > Doesn't this still do multiple string-to-number conversions? I don't think so ... the $(( ... )) should turn $1 into a single number assigned to result. What are you thinking about?