From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15534 invoked by alias); 19 Oct 2015 19:34:59 -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: 20795 Received: (qmail 8683 invoked from network); 19 Oct 2015 19:34:58 -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=X+5rdgje c=1 sm=1 tr=0 a=vsFYQC4/11PqlKifmEOq9w==:117 a=vsFYQC4/11PqlKifmEOq9w==:17 a=N659UExz7-8A:10 a=wThWasOynSqZf5fpTKwA:9 a=pILNOxqGKmIA:10 Message-id: <562545DD.5020008@eastlink.ca> Date: Mon, 19 Oct 2015 12:34:53 -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> In-reply-to: <151019113517.ZM32739@torch.brasslantern.com> Content-type: text/plain; charset=windows-1252; format=flowed Content-transfer-encoding: 7bit On 10/19/2015 11:35 AM, Bart Schaefer wrote: > On Oct 18, 10:46pm, Ray Andrews wrote: > } > } That's a bit of a surprise, why is zsh fussier with '-=' than with '+='? > > Outside of the (( )), -= is not an assignment operator at all, because > the default is to do either array or string assignment, and there is > no sensible way to "subtract" one array or string from another. > > Conversely += is defined to mean "append", so it is a valid operator. > > I'd almost call it a bug that [outside of (( )) context] first+=second > does arithmetic when $first is an integer. It ought to be either an > error or forcibly convert $first to string and append "second". I've managed to suppress my gag reflex with all that arithmetic stuff--goes back to the need to 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. I see what you mean tho--we can append strings but we can't un-append them (tho one might consider that as " first=${first%$second} " (not sure if I wrote that right, but you get me) ). For now I feel comforted to always use the (( )) because it's explicit and you can mercifully space things: (( first -= second )). Just to comment, 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. We don't have warnings do we? In C, of course, if one is doing something strange the compiler doesn't stop you, but it will warn you. I once had great fun writing an encrypt function that performed arithmetic on strings--the compiler didn't like it, but it did what it was told. Na ... can't have warnings in interpreted stuff, tho there could be a proofreader ...