From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id D2A99292B1 for ; Fri, 16 Feb 2024 06:46:52 +0100 (CET) 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: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=+ppMRP9bCoDGxsdTkH4YzWEj4lksUH6nBoqQNrU3iiI=; b=OL+G9fSuRgDuJWqArVeK5zLGVa 6Oo4Klbuobnn60F8BpqCRSjKA5DkS8XYakit6DQNDLYlSS/Ld6+2dDdZvqaGDShIOofhneTI7fg67 +G9nspEIiKzaOz257um+Eq/nMbAxxmQeuaEc3bB0BANRCkRimMwZSco93DgVZstBuJpKXPbuWuX1m s50smI7tiR/tTNgEycie0guniBIZjeXEvwWVJq0tZYcHeJkX58y/OLHHYYoQrdxndkPvi1VdqO/A9 6BsnZw2mEfOEbDf/QTWquFzA+8GkwmeKmsR3nxeqCxZOmAjQP/j3XbpyUvcd4WNdareW6eq8bieAz bFnivZUQ==; Received: by zero.zsh.org with local id 1rar3k-000LoW-6x; Fri, 16 Feb 2024 05:46:52 +0000 Received: by zero.zsh.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rar39-000LUN-Qx; Fri, 16 Feb 2024 05:46:16 +0000 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id 1F5F427C005B; Fri, 16 Feb 2024 00:46:14 -0500 (EST) Received: from imap48 ([10.202.2.98]) by compute2.internal (MEProxy); Fri, 16 Feb 2024 00:46:14 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddugdeklecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvvefutgfgsehtqhertderreejnecuhfhrohhmpefnrgif rhgvnhgtvgcugggvlhojiihquhgviicuoehlrghrrhihvhesiihshhdrohhrgheqnecugg ftrfgrthhtvghrnhepheegieduieegvddvffdvgeefuddugfetvdettddtfedutdejvefg jefgveethedunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheplhgrrhhrhihvodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudeh udekjeejtdegqdduudelvdejfeekhedqlhgrrhhrhihvpeepiihshhdrohhrghesfhgrsh htmhgrihhlrdgtohhm X-ME-Proxy: Feedback-ID: iaa214773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id CE6F031A0065; Fri, 16 Feb 2024 00:46:13 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-144-ge5821d614e-fm-20240125.002-ge5821d61 MIME-Version: 1.0 Message-Id: In-Reply-To: References: <4c14e191-0605-4492-9f67-9a5b35ef132b@eastlink.ca> <4da0eeb4-4589-4c5d-9b89-a1a22209e18e@eastlink.ca> <7ccf5b82-a37d-47b5-a700-fb1096ab495c@eastlink.ca> <0875ffd7-e3a4-4ddc-9c4b-47e2c593ea4c@eastlink.ca> <1745fff9-822c-499f-b60e-7248e95438c5@app.fastmail.com> Date: Fri, 16 Feb 2024 00:45:53 -0500 From: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= To: "Mikael Magnusson" , "Bart Schaefer" Cc: zsh-workers@zsh.org Subject: Documenting $(( foo )) as similar to $(( ($foo) )) Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Seq: 52545 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: On Sun, Feb 4, 2024, at 9:43 PM, Mikael Magnusson wrote: > On 2/5/24, Bart Schaefer wrote: >> On Sun, Feb 4, 2024 at 12:49=E2=80=AFPM Lawrence Vel=C3=A1zquez wrote: >>> >>> I'm not sure if the zsh manual spells this behavior out explicitly, >>> but bash and ksh share it. >> >> "Arithmetic Evaluation" says (pretty far down after the discussion of >> operators): >> =3D=3D=3D >> Named parameters and subscripted arrays can be referenced by name wit= hin >> an arithmetic expression without using the parameter expansion syntax. >> For example, >> ((val2 =3D val1 * 2)) >> assigns twice the value of $val1 to the parameter named val2. >> >> =3D(and later)=3D >> >> Scalar variables can hold integer or floating point values at differe= nt >> times; there is no memory of the numeric type in this case. >> >> If a variable is first assigned in a numeric context without previous= ly >> being declared, it will be implicitly typed as integer or float and >> retain that type either until the type is explicitly changed or until >> the end of the scope. This can have unforeseen consequences. >> =3D=3D=3D >> >> It doesn't explicitly say how "the value of $val1" is determined, but >> if it were expanded with $val1 you'd get the whole text string which >> would then be interpreted as arithmetic, so expanding without the $ >> works the same. > > This last bit is not 100% true, a parameter will combine into its > context with $ but not without: > % a=3D3+2 > % echo $(( 5 / a )) # 5/5 > 1 > % echo $(( 5 / $a )) # 5/3 + 2 > 3 > > I think effectively you can think of foo as ($foo), at least in all > cases I can think of to try. I just noticed that Bart added the following text to zshmisc(1): If the expansion of $val1 is text rather than a number, then when val1 is referenced that text is itself evaluated as a math expression as if surrounded by parentheses `($val1)'. I assumed that Mikael's comparison of foo with ($foo) was meant to be an analogy, so I didn't nitpick it at the time, but I worry that this addition to the documentation could be misconstrued as implying that code like this ought to be valid: % foo=3D'1) + (2' % print $((foo)) zsh: bad math expression: unexpected ')' ...just because this is valid (if ill-advised): % print $((($foo))) 3 --=20 vq