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 4967 invoked from network); 7 Oct 2022 20:01:50 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 7 Oct 2022 20:01:50 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1665172910; b=AEP8Iz/z0WcyodQiV8rq8g7m7PdFOyB00bf5Ljl8ecTgEV4l3K6PPsdJJ1meEF3K5oKi4INDdw AIzYHH07jPHcea1L/v82XBNr6xdPG0PsWHRkB1hJIUYPIdDN6PSYd65lrVN5bc7p7+5PM2pzat oT62/L2irLTk7LFakWcjc6HtRy4lLKoNGiXiYjC8uXEyHcO01c6c0yUjTZcL9BM+gi8Omhcm/L 9F6uW8rbSE8s2s6/6vZukqucoWhn6egmlxkZNBNM0uQjfY6qt6er5rNiAcHBLMlUEWTFl8iuVX vM9dH16qXUkytWEKsiyJWdtvin6TC+0CLL8DyrX+QbEcGA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 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-20210803; t=1665172910; bh=EJLeKrHLbzwu1ugUA+6k4757LXdxQMg+ITEWcSh2DE4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=Z3TgBvSB2RfxXXqqa8afH0bplJwTBDi5GoBhXjMvztAoako1MeX+lYPo5v892QlLOtqACD0qJY yvxiaA+I924sOEx6MW4HgHDcKauQ69hM7o38rN5nqpnxEeDFp/8E2mi4AR5xy6Ex3eHxi5u0ib CLTST/gPawCra2Ml41+gI9zSdd5MOboLXfZW+MP2yiID3YFQXPbKmJleGNAcWqXlnV0lVhuFHX 7+IREyIlB712x+S4KqELRf/PCTsD6iSzuEc/UcI+tK97+llYJr3arqWQFl6aF8TRVlGmJngSNN bU/YTZBss7tlLuOoBh1HH/ygNHJ9uKdrIV8rKgouFXLJjw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=9CqEVt1NlUbX/JWVuw+Gew+156PQk2mukwbJA4WZvx8=; b=grmq6AgMCIOHoV8YDu/R24JGhy ipTaJvy6glxT6jZ+vej61chsJyNlxph5da9yyZVSOnyPuRiIkbJHjB86KI05Hx9k7XRN63Eokv2NM 1vZZurFrJdrVqSWin54eYaQ5Q9wqEjwr3bd7NaLMBzsvCbz73htMcMD5tF2VUWFRt3DkRdF8Yck/l BIqAu6OpcLAMP2/wEb+dYt1+c2xryAW0mqUsX6tAhd7VBOSomHaGZYMINnDMNVvFIikdNLEwrdVJp W5MQG98t1oGhRLN+hGdx8kNqYAOKcIFAtGS5RaS9VHJJ3RSW2NvAJdiNRjSdAlTT+rLqf9vf2sEzs M8huwePQ==; Received: from authenticated user by zero.zsh.org with local id 1ogtXY-000GFu-Mg; Fri, 07 Oct 2022 20:01:48 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f50.google.com) smtp.remote-ip=209.85.218.50; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f50.google.com ([209.85.218.50]:39759) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ogtWl-000FW4-Q8; Fri, 07 Oct 2022 20:01:00 +0000 Received: by mail-ej1-f50.google.com with SMTP id b2so13547827eja.6 for ; Fri, 07 Oct 2022 13:00:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9CqEVt1NlUbX/JWVuw+Gew+156PQk2mukwbJA4WZvx8=; b=A0MzmwnKDWxH0PExrEL2yMc5dVMLVTT3KDFdMKykxbgQ/ED1olszcJrkVdLdFvOYqP modtvgjQd7lLkx4TWYJILhydpbLzFJQ5TeMsDpGJVa7fTLlEgKmb5JRpkm1caUH5mXTS eu6LvQ3G4mYTjuCQj38gDi1ML7xPlM8GTgJjs10gD9g3hC8/IPMlyrnGzjFcCTFucc1b P2VAI3DbQYxdhykq2MG1kqT/ujfKarJviua6vpobgKvxR9g6XwiCd+bkh3+jlYiEfzsV JJR6fRquLe2lH1u50hmlQjn93vfDZEZjuumE8hI26k5CdF4VR2jM4XHjfLS7qkBYq43g x74w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9CqEVt1NlUbX/JWVuw+Gew+156PQk2mukwbJA4WZvx8=; b=EPKXotpwTpYyIZYOv6/51yrt1T2VZPWRCJof+Pz428byqH/2TE4HpfGVZXBt7U5CNS wgWYK5fe6EI2xFCRxLqQorkMI+8SPZ+EN9p9kK16sEKEAU0rZVAZLbdysS81WUJJ51iM 4ZKiQbCg7o3+smmBk1x0FYb/6+V/Dx21G3Gj2f3iD2Cj2mA+qcb7AmxEbulEPgVEjhBr AI/yeNCuNHZkwsbS4TPcgdLhgVGEntEknfyq/OfJ5TnmQFGaR+SdB4o6z9xqf3f4R0Ki p0kT15x9cVSm0WT1czb+8tuU3x35AUznpXmnozWEacUSAB6Wl3hMF34GjKoqWInIub5R S8jA== X-Gm-Message-State: ACrzQf2RKhkSv1eLNLtosQz66KOL4oJO71qaEBg4D5LjIalm1DcjqGhB 0v2z4nR2zFOANYs/RdZ/i6M3iMIgnZpfXioQO5VAlg== X-Google-Smtp-Source: AMsMyM5vokKcqf+xpzPw/th0WVx9Eq8bBy1UGsExjBptJ9EWQ/fidV1WPyagC6z5PV9AGscYhCPrU3girbFD3CdtXLw= X-Received: by 2002:a17:906:58c7:b0:722:f4bf:cb75 with SMTP id e7-20020a17090658c700b00722f4bfcb75mr5356945ejs.450.1665172859034; Fri, 07 Oct 2022 13:00:59 -0700 (PDT) MIME-Version: 1.0 References: <1774a1bc-c353-4e16-80a2-0082457de6e0@eastlink.ca> <3bf17a2cc56cbc65fc0ba855fe9c7d2d2f63befb.camel@ntlworld.com> <8b1497ca-5d26-3e23-47c7-1c85b7c4fa73@eastlink.ca> <0bc658a2-3941-82f5-2433-d105f31db09a@eastlink.ca> <24710fd4-bf5f-889d-4cca-8b922823cb86@eastlink.ca> In-Reply-To: <24710fd4-bf5f-889d-4cca-8b922823cb86@eastlink.ca> From: Bart Schaefer Date: Fri, 7 Oct 2022 13:00:47 -0700 Message-ID: Subject: Re: unexpected unmodified variable To: Ray Andrews Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 28199 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Fri, Oct 7, 2022 at 8:28 AM Ray Andrews wrote: > > By default the function is implemented by a shell function of the same na= me; if > shellfn is specified it gives the name of the corresponding shell functi= on > while mathfn remains the name used in arithmetical expressions. As with widgets, you can have a math function named X that's implemented by a shell function named Y. The default is that if the shell function is Y, then the math function is also Y. > The name > of the function in $0 is mathfn (not shellfn as would usually be the ca= se), > provided the option FUNCTION_ARGZERO is in effect. This is just explaining how $0 works in case you're trying to have a function that references itself by name. > The positional > parameters in the shell function correspond to the arguments of the mat= he=E2=80=90 > matical function call. If you write $(( func2(a,b,c) )) then inside func2, $1 =3D=3D a, $2 =3D=3D = b, $3 =3D=3D c "Positional parameters" always means $1, $2, etc., that's not math-function-specific, it's just shell terminology. > The result of the last arithmetical expression eval=E2=80=90 > uated inside the shell function (even if it is a form that normally only = re=E2=80=90 > turns a status) gives the result of the mathematical function. The parenthetical refers to the fact that some math operations are true/false, e.g. (( x > 12)) "is a form that only returns a status". Omitting that, the rest of the sentence should be clear. > ... which might just be the most impenetrable bit of computer bafflegab I= 've ever read, I can't get past the first sentence. Seriously? This is all using phrases that refer to concepts appearing elsewhere throughout the zsh manual. > You have to be Peter to understand that. Well, he did write it. > No typo, everything is copied and pasted without edit: Oh. Given the way you wrote func2, if you remove the return statement there are NO math expressions in func2 at all, so $(( func2() )) is [except for side-effects] a no-op, and the assignment in var=3D$(( func2() )) is just skipped, leaving the previous value of $var unchanged. If you turn the count=3D2 assignment into a math expression, either by your "integer count=3D2" test or by using (( count=3D2 )), then $(( func2() )) returns the value from that. It is a bit weird that var=3D$((...)) does nothing at all in that circumstance, I would have expected it either to assign empty string to $var or to have a nonzero $? as a result. Unanticipated edge case, possible bug. > Tho I do wonder why '$(( ))' is 'local' and '$( )' spawns a subshell $(...) spawns a subshell because stdin/stdout text is passed from one process to another using pipes, and if a process has a pipe to itself it can deadlock trying to read something it hasn't written yet (or write something there isn't room for because not enough has been read yet). $((...)) looks that way by analogy to ((...)), not by analogy to $(...). > one might wish for some method of asking '$( )' to run 'local' too "Local" text substitution is what ordinary $param references are for ... $(...) specifically means to use processes and pipes. That said, a still-missing feature in zsh is the ability to tie a function to a variable so that referencing the variable as $foo invokes the function that's tied to it, to produce the effect you're asking for. Ksh has a syntax for that.