develooper Front page | perl.perl5.porters | Postings from January 2001

Re: Multiple post(inc|dec)rement

Thread Previous | Thread Next
From:
abigail
Date:
January 17, 2001 11:52
Subject:
Re: Multiple post(inc|dec)rement
Message ID:
20010117195346.6084.qmail@foad.org
On Wed, Jan 17, 2001 at 02:56:04PM +0000, Nicholas Clark wrote:
> On Wed, Jan 17, 2001 at 02:39:52PM +0000, Simon Cozens wrote:
> > On Wed, Jan 17, 2001 at 02:21:34PM +0100, Johan Vromans wrote:
> > > Stephen McCamant <smcc@CSUA.Berkeley.EDU> writes:
> > > 
> > > > IMHO, pp_pre(inc|dec) were written the way they are now for a reason
> > > > (namely efficiency), and it isn't worth slowing them down just to make 
> > > > some pathological examples more intuitive.
> > > 
> > > And, my dear Stephen, how much is the slowdown for an average Perl
> > > program?
> > 
> > I'm of the opinion that if people think that writing
> > 
> >     (++$a, ++$a)
> > 
> > is a good idea, then they're fundamentally confused anyway. Slowing
> > Perl down isn't going to unconfuse them.
> 
> I don't agree that they are confused.
> C has a documented concept of "undefined" (and a spec)
> 
> perl only has implementation defined behaviour, and no comprehensive spec.
> 
> for $a=2
> (++$a, ++$a) could easily mean 2 things
> 
> (3, 4)
> 
> if I assume that arguments get evaluated left to right (not an unreasonable
> assumption, but if people should not make this we need to document it)

In fact, it should be documented even if multiple pre-increments aren't
allowed. After all, ($a, $b) is valid, but they can have side effects
if $a and $b are tied.

> (4, 3) or (3, 4)
> 
> if I assume that argument get evaluated in some order. I'm not worried what
> that order is, but I am assuming that one is fully evaluated before the
> other's evaluation starts.
> However, (4, 4) isn't intuitive, unless you are a *good* C programmer.
> [bad C programmers will assume one of the above]

I'm hardly a C programmer, let alone a good one, but I'd find (4, 4) quite
intuitive. Assuming ties and operator overload don't play a role, I would
not find it unreasonable when (++$a, ++$a) is equivalent with

    do {$a += 1; $a += 1; ($a, $a)}


Abigail

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About