From: Robert Klemme Date: 2013-04-16T00:41:47+09:00 Subject: Re: Wondering why no "increment" or "decrement" operator in ruby --20cf3074d2e81c091f04da6817da Content-Type: text/plain; charset=ISO-8859-1 On Mon, Apr 15, 2013 at 4:01 PM, Rob Biedenharn wrote: > Why wouldn't the syntactic sugar for ++a be a=a.succ (for "successor") > since that is defined on more types? > Yes, that's even better. But, as you discovered > for --a you could use a=a.pred (for "predecessor"), but that's only > defined on Integer (and had no built-in use like #succ does). > #succ and #pred are not that symmetric in terms of availability. Maybe Matz also wanted to avoid hiding an assignment inside an operator which does not contain an equals sign. And then there are of course the postfix variants of these operators which need a temp variable or #tap: a++ -> a.tap { a = a.succ } Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ --20cf3074d2e81c091f04da6817da Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable



On Mon, Apr 15, 2013 at 4:01 PM, Rob Biedenharn &= lt;rob@agil= econsultingllc.com> wrote:
=A0
Why wouldn't the syntactic sugar for ++a be a=3Da.succ (for = "successor") since that is defined on more types?

Yes, that's even better. = =A0But, as you discovered
=A0
for --a you could use a=3Da.pred (for "predecessor"), but th= at's only defined on Integer (and had no built-in use like #succ does).=

#succ and #pred are not that symmetric i= n terms of availability. =A0Maybe Matz also wanted to avoid hiding an assig= nment inside an operator which does not contain an equals sign.

And then th= ere are of course the postfix variants of these operators which need a temp= variable or #tap:

a++ -> a.tap { a =3D a.succ }

=
Kind regards
robert

--=
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractice= s.com/
--20cf3074d2e81c091f04da6817da--