From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3720 invoked from network); 14 Jan 2002 18:47:28 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 14 Jan 2002 18:47:28 -0000 Received: (qmail 17594 invoked by alias); 14 Jan 2002 18:47:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16455 Received: (qmail 17580 invoked from network); 14 Jan 2002 18:47:21 -0000 From: "Bart Schaefer" Message-Id: <1020114184715.ZM18893@candle.brasslantern.com> Date: Mon, 14 Jan 2002 18:47:15 +0000 In-Reply-To: <20020114124525.3912.qmail@web9301.mail.yahoo.com> Comments: In reply to Oliver Kiddle "Re: PATCH: += parameter assignments" (Jan 14, 12:45pm) References: <20020114124525.3912.qmail@web9301.mail.yahoo.com> X-Mailer: Z-Mail (5.0.0 30July97) To: Oliver Kiddle , zsh-workers@sunsite.dk Subject: Re: PATCH: += parameter assignments MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jan 14, 12:45pm, Oliver Kiddle wrote: } Subject: Re: PATCH: += parameter assignments } } Bart Schaefer wrote: } } > integer i=4 } > typeset s=4 } > i+=5 } > s+=5 } > ((i+=5)) } > ((s+=5)) } > print $i $s } > } > yields } > } > 14 50 } } What would you have sooner expected - `14 14'? The point is that I can't think of -anything- reasonable to expect, except perhaps that in a saner world ((s+=5)) would be an error because you can't add an integer to a string. Unfortunately we're beyond hope of changing that (and I wouldn't really want to anyway). About the closest thing I can come up with is that all assignments in (( )) should force the parameter type to change to numeric (integer or float), but that has its own set of potential gotchas. Better might be if += outside of (( )) always converted numerics to strings and then did an append. } > However, what I consider to be worse is that: } > } > s=four } > ((s+=5)) } > s+=5 } > print $s } > } > yields } > } > 55 (Incidentally, while were on that subject: s=4four ((s+=5)) gives an error (bad math expression: operator expected at `four'), so why doesn't that same thing happen when the leading digit is absent?) } I'm not sure that I've entirely understood your argument here as your } example doesn't seem particularly confusing to me. The ((s+=5)) results } in 5 with s remaining a scalar - that was the case before. It remained } a scalar so the s+=5 results in 55. The argument is something like this: It's OK for += to mean "convert to number, do arithmetic, then convert back to the original type" as long as it *always* means that. It's confusing when it means one thing in (( )) and two or more things (depending on the parameter type) outside (( )). To have -= be additive for strings and "subtractive" for numeric types is just compounding the problem. } The results might not be imediately obvious after a mix of both the } math and non-math += for scalars but considered on their own I don't } find them "confusing". What I don't like is that I can't look at `s+=5' and know what it's going to do. At least I know `((s+=5))' will always add 5 numerically, even if it might convert s to 0 first. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net