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.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,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 BFB862BD6A for ; Mon, 5 Feb 2024 16:22:40 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1707146560; b=o3RYSvS2wHXPl3mjU6MdHFLYWzG1Ct6SUy0UC07bIXJPDmhWBoEtErPLhY5T8w2ZqFFj1QrW2g uN5EvXhbnx/t12mxZe+pHHMM5CggdReg6jOS5dfiRuTi6IvY16V3ILrSuR0nfUOoJF8JLY82WK 6QDyv5QUObC+6LrZ0PtaFeBpQ2fTs3OSY+L97SmKeXT79MK7uegmH4mFc8e1H2Y+mKxbxdZLoq 9mXC84UPOnybT/QrAwUBXBow04IsdPLeDnHJPkTXA+brHYFmSw6n7MR1GmmTCj4sSI5TMOPS3X dXBqbvS6F+gzqvh8kmb8OeytpMCuE8jW0soOiGtSR2dnJw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1707146560; bh=edms3KLnTIMQhwEuUdZyMkFyC7pAHxCkNRBRyfhN0ZQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:In-Reply-To:From: References:To:Subject:MIME-Version:Date:Message-ID:DKIM-Signature; b=PQLfCxWT1WQNgZYiUQRa8ja9U+5tXpl74lSlD57oV3A2UYoBZy9F8rIvnBgTomgHqjtZi6+C9J zOzyglI2dnTnblBGDYjXtebVdGFLHATlO0lHh005SyJdaauMJCrcduLBOCDvJAPSHLwC/CtOLF poYXI6uRkUXZsIKLHZATS7oUkzYF9DW9ztHWpcfwAES/hBoWyTBaxRzMBgkhNHVXyV7gMe+UQB 7HfDY7bc/RL1YNsOY+waa6yVRiKIErnlYo32KbziLm7igPQvRpSgQqGT3gBV3tNw9aXhFO0cFC 5PcBTKt3IWwUN5qwR0EZATRrH/u1wOAJrHnaFnUVk/YSzA==; 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:In-reply-to:From:References:To:Subject:MIME-version:Date: Message-id:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=UhbjBCiVW92HCoD2qDxJVoghSEfLZHy93BQu3QYr5p0=; b=UPah5lYPIYeg36JQ2I/WURhwCr mLqe3sjpI81vzAstWJ68i8/uZp5fJVyUSwz5f+2UGyNaFeajxKRS5yluQOMCkygdMdg/iA70JOGUR zvLJriB6fYb7mXfAYVSRUdFAHqXswT+aUFoGVvb79jGbmQSqNmdEjsjGvoejMaFmnlIYx5duF9w7X RqhyZp16fwkPfkOL0Chqzko/M2Ljni+li69Ipp+sPtg84ClNisQJlCtZWZ/Tf5xqflR7EWI6iycCX 0DahqBilh1OfmI8hVO1b8lcVCmLU5l8qCFmpvrGe3ETj0+rssckoU6abkWFOEJ/WVwUrc5x8fasuL xaqCy5rw==; Received: by zero.zsh.org with local id 1rX0nu-000Eyt-7W; Mon, 05 Feb 2024 15:22:38 +0000 Authentication-Results: zsh.org; iprev=pass (mta04.eastlink.ca) smtp.remote-ip=24.224.136.10; dmarc=none header.from=eastlink.ca; arc=none Received: from mta04.eastlink.ca ([24.224.136.10]:47863) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rX0mu-000EJN-UK; Mon, 05 Feb 2024 15:21:38 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta04.eastlink.ca ([24.224.136.10]) with ESMTPS id <0S8E0B0602GZX550@mta04.eastlink.ca> for zsh-users@zsh.org; Mon, 05 Feb 2024 11:21:35 -0400 (AST) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id X0msrPkKbmZzJX0mtrhVc3 (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Mon, 05 Feb 2024 11:21:35 -0400 X-Authority-Analysis: v=2.4 cv=Ie8kWnqa c=1 sm=1 tr=0 ts=65c0fcff a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=IkcTkHD0fZMA:10 a=TeKVZIJUOLLQKD3WG1EA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedvtddgjeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepteffhffgvdeffeelveelhfegudevkeduhfehheevhfekhfevieehjeejheefvefgnecukfhppedvgedrvddtjedrudelrddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrudelrddufedphhgvlhhopegludelvddrudeikedrtddruddungdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdpnhgspghrtghpthhtohepvddprhgtphhtthhopeerredprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Message-id: <279c61c4-ef0b-4eb7-8a6c-619fbf70502d@eastlink.ca> Date: Mon, 5 Feb 2024 07:21:34 -0800 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: for loop 'bad math expression' Content-language: en-US To: zsh-users@zsh.org 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> From: Ray Andrews In-reply-to: Content-type: text/plain; charset=UTF-8; format=flowed Content-transfer-encoding: 8bit X-Seq: 29637 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: Gentlemen: I'm a bit behind here. I hadn't expected this to thread to get so involved.  We may have a bit of a mishmash here, thanks for your patience as I try to sort it out: > Did you see my followup? The variable does not get "promoted"; it's still a string,  as you can tell by the fact that += appends to it instead of adding. Right, 'var' isn't fiddled with.  It just seem that taking the value of var and using it as the name of a brand new variable seems a bit strange to me.  Who cares?  Even I don't care, all that matters is that I'm aware of the situation.  I don't like German grammar either but the Germans don't care.  At this point all that remains 'open' is that I think 'abc' should 'typedef -p' as an integer.  And it seems, as I said, that any direct assignment to 'var' breaks the relationship with 'abc'. > When I wrote "x+=d", it was not inside arithmetic context, so the shell did not interpret either x or d as a number; it just appended the literal value "d" onto the end of the string held in x. Right.  My own post included a demonstration of that.  I get it. Dunno, maybe the shell's internal machinery requires the creation of 'abc' as a new variable in order to perform the arithmetic.  ... Come to think of it, that makes sense.  I'd just not expect the new variable to be visible but that's a trivial matter.     % var="abc+def"     % abc=2     % def=3     % echo $(( var ))     5 ... that stretches my mind yet again.  Interesting that 'var' is completely passive as to what "abc+def" might possibly mean until such times as an answer is demanded by the echo.     % var="abc+def"; echo $var     abc+def ... what must be a simple string when written becomes an addition of two variables retroactively.  Ok ... if that's the way it is then that's the way it is.  Yeah ... within the $(()) the string 'abc+def' NOW becomes an addition of two variables.  Sure ... interpreted ... not C ... not retroactive either. more like indeterminate. > and this interpretation came about quite naturally from some incremental improvements in the shell's ability to do arithmetic. Right, as I said, arithmetic would have accreted onto the shell at some point, so had to be merged in with existing data types.  Sorta like an associative array is 'really' just a normal array under the hood, but given a different interpretation. Thus the way an A array is easy to break if you aren't careful. > See, the shell has never really had data types like other programming languages. Exactly.  But it takes deep surgery to cut the C-think out of the brain.  "abc+def" looks like a string is a string is a string. > ... BASIC got the name from the way you introduce names for things in a math proof or paper. The depth of your historical knowledge astonishes me Mark. >Ok, not quite shut up yet.  One note:     % z=`expr $x + $y` ... actually it's these tortures that are exactly the sort of therapy I need.  Too bad there wasn't some document: "Shell programing for folks who are used to strongly typed languages." > No.  It "increments like one" because you ran "abc=1; let abc+=3", and the arguments to "let" are interpreted as arithmetic expressions. If you'd run "abc=1; abc+=3" you would have gotten string concatenation. RIGHT!  Got it. > Using >  % let var=value > always applies math context, just as ((...)) and  $((...)) and $[...] do. ... it's another gotcha ... I know and expect that $((()) has its internal grammar.  But 'let' seems ... naked ... for lack of a better word and it's a strain on grammatical rigor that it gets special, invisible favors.  Don't like it.  But it's one of those ancient traditions that's written in stone, I take it. > All your examples have been broken, and your conjectures confused. Yes.  One tries to form an inner model of what's going on.  Seems there's no Phlogiston after all ;-) > ... This can have unforeseen consequences. HA! Yes, that's a little bit of comfort for poor wretches like myself.  Like trying to get somewhere in Mexico City traffic, one simply needs to be very careful.  I expect if we had history to do over again, shells would have proper typing and all of this would be 10X simpler. Thanks guys.