zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Oliver Kiddle <okiddle@yahoo.co.uk>, zsh-workers@sunsite.dk
Subject: Re: PATCH: += parameter assignments
Date: Mon, 14 Jan 2002 18:47:15 +0000	[thread overview]
Message-ID: <1020114184715.ZM18893@candle.brasslantern.com> (raw)
In-Reply-To: <20020114124525.3912.qmail@web9301.mail.yahoo.com>

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   


  parent reply	other threads:[~2002-01-14 18:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-01-14 12:45 Oliver Kiddle
2002-01-14 13:04 ` Peter Stephenson
2002-01-14 18:47 ` Bart Schaefer [this message]
2002-01-15 16:16   ` Oliver Kiddle
2002-01-15 17:54     ` Bart Schaefer
2002-01-16 14:43   ` Oliver Kiddle
  -- strict thread matches above, loose matches on Subject: below --
2001-12-17 12:02 Oliver Kiddle
2001-12-17 12:11 ` Borsenkow Andrej
2001-12-17 12:28   ` Peter Stephenson
2001-12-17 12:28   ` Oliver Kiddle
2002-01-07 17:38     ` 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=1020114184715.ZM18893@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=okiddle@yahoo.co.uk \
    --cc=zsh-workers@sunsite.dk \
    /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).