zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: suprise with -=
Date: Mon, 19 Oct 2015 12:34:53 -0700	[thread overview]
Message-ID: <562545DD.5020008@eastlink.ca> (raw)
In-Reply-To: <151019113517.ZM32739@torch.brasslantern.com>

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 ...



  reply	other threads:[~2015-10-19 19:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19  5:46 Ray Andrews
2015-10-19 18:35 ` Bart Schaefer
2015-10-19 19:34   ` Ray Andrews [this message]
2015-10-20  0:27     ` Bart Schaefer
2015-10-21  2:55       ` Ray Andrews
2015-10-21  3:52         ` Bart Schaefer
2015-10-21 18:01       ` Ray Andrews
2015-10-21 18:43         ` ZyX
2015-10-22 15:29           ` Ray Andrews
2015-10-22 15:43             ` ZyX
2015-10-22 16:02               ` Ray Andrews
2015-10-22 23:56               ` Bart Schaefer
2015-10-23  7:34                 ` Daniel Shahaf
2015-10-21 18:46         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=562545DD.5020008@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).