in reply to $a++ allowed by $a-- is not ! why?
I'm going to register what I consider to be the most serious reason why -- isnt implemented this way. Reversability. Consider that the rules say any string matching /\A[A-Za-z]*[0-9]*\z/. So this means that 'Zz9' incremented becomes 'AAz0'. Now, what happens when we decrement? Presumbly we should go from 'AAz0' back to 'Zz9'. So we need decrement to remove the leading character. All fine and good. So we decrement a bunch more and eventually get to 'z9'. Now we increment one, and get 'aa0'. So we then end up in the odd situation where -- and ++ are not reversable (++(--'Aa0')!='Aa0') (what the correct name for this? commutable?). It gets even odder, because if we contine down this path we get to '9' which again if we reverse course and increment leaves us at "10" and in the same problem as before but with different colors. And if we contine to decrement we go to -1 and etc as per normal numbers. But what happens if we decrement "A"? If we go to undef as one poster suggested we get a contradiction (in that --0 produces -1 but --'a' produces undef), and after we decrement undef again we get -1 (with a warning thrown in) so now its all a big mess.
++ Zz9 => AAa0 -- AAa0 => Zz9 -- aa0 => z9 -- Aa0 => z9 ++ z9 => aa0 -- a0 => 9 -- 10 => 9 ++ 9 => 10 -- 0 => -1 -- a => undef -- undef => -1
Given all this I can totally understand why -- isnt implemented. I don't think I would have a problem if this behaviour did occur, but I think its strange enough that I can see why it doesn't.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: $a++ allowed by $a-- is not ! why?
by kabel (Chaplain) on Sep 01, 2003 at 08:43 UTC | |
by jonadab (Parson) on Sep 01, 2003 at 15:19 UTC | |
by kabel (Chaplain) on Sep 01, 2003 at 16:35 UTC | |
by jonadab (Parson) on Sep 01, 2003 at 18:33 UTC | |
by tilly (Archbishop) on Sep 01, 2003 at 21:58 UTC | |
| |
by demerphq (Chancellor) on Sep 01, 2003 at 09:48 UTC | |
by kabel (Chaplain) on Sep 01, 2003 at 10:12 UTC | |
by demerphq (Chancellor) on Sep 01, 2003 at 11:02 UTC |