From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27281 invoked by alias); 21 Oct 2015 02:55:32 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20800 Received: (qmail 12224 invoked from network); 21 Oct 2015 02:55:29 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Authority-Analysis: v=2.1 cv=T/C1EZ6Q c=1 sm=1 tr=0 a=vsFYQC4/11PqlKifmEOq9w==:117 a=vsFYQC4/11PqlKifmEOq9w==:17 a=N659UExz7-8A:10 a=SlrmfmdpmsKoxW1i5HEA:9 a=pILNOxqGKmIA:10 Message-id: <5626FE9D.9020003@eastlink.ca> Date: Tue, 20 Oct 2015 19:55:25 -0700 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: suprise with -= References: <562483C9.1060602@eastlink.ca> <151019113517.ZM32739@torch.brasslantern.com> <562545DD.5020008@eastlink.ca> <151019172744.ZM558@torch.brasslantern.com> In-reply-to: <151019172744.ZM558@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 10/19/2015 05:27 PM, Bart Schaefer wrote: > On Oct 19, 12:34pm, Ray Andrews wrote: > } > } [...] declare variable types, which is what I'm trying to do with > } 'integer' and after that I'd expect both increment and decrement to > } behave the same way. > > The parser doesn't know that "first" is an integer, or even that it's > a variable that was previously declared. This is perfectly legal: > > if (( RANDOM % 7 )) > then integer first > else declare first > fi > first+=second Then what does 'integer' or 'typset -i' do? > (Which is why I'm inclined to say it ought to always be string context > when not explicitly math context, but it's probably way to late for that.) Given all these little gotchas, I think you are right. (()) is math, otherwise you're on thin ice. Still tho, surely 'integer' should be a typecast and not changeable, tho of course it's too late to do anything about that. I can't help but wonder what was going on in the minds of the guys who coded the first shells and decided to permit this sort of anarchy, I'm sure they had their reasons but since the shells are written in C, I'd have expected normal C discipline to set the standard. > } I'd consider it very rude for any forcible conversions to occur. > } Better an error, tho again once one has declared an integer one might > } expect one's operators to behave consistently. > > Note: > > torch% integer first=1 second=2 > torch% first+=(second) > torch% echo $first > 1 second > > This has silently forced $first to change into an array because of > explicit array context; it did not interpret "(second)" as arithmetic > parens. Well I guess that's the universal reality of shells, so I just hafta get used to it. Actually I am already more or less used to it. > > Also just to mess things up a bit more: > > torch% integer first=1 second=2 > torch% third=first+second > torch% print $third > first+second > torch% integer third > torch% print $third > 3 > > If something has a string value and you re-declare it integer, it does > math on its string value. Doesn't happen for array to integer. > Thanks for the examples, these are so educational. I'll play with them for several days.