John W. Krahn <[EMAIL PROTECTED]> wrote:
> Kevin Meltzer wrote:

[ back and forth ]

>> >>> > This is actually a bug. It just seems that nobody seems to 
>> >>> > care :) It would break too many JAPHs which use this.
>> >>> >
>> >>> > So, don't depend on it, in case it is ever fixed.
>> >>>
>> >>> Can you cite a reference to this behavior described as a bug?
>> >>
>> >> Does that behavior not seem like a bug to you?
>> >
>> > Not necessarily.  :-)
>> 
>> I'm curious as to why. When I mentioned it on channel, a few people
>> didn't see it as a bug either, at first. Being that it is using -- 
>> in a way which isn't consistent with -- (it increments as opposed to
>> decrement). In fact, it isn't just with --/++ but + and - will yield
>> the same results. Anyways, just curious why you think that subtracting
>> from 0 yields a 1 doesn't seem like a bug (and when adding 1 never
>> yields a 0).
> 
> Well, because Perl has lots of special cases like this.  Most people
> don't ever use $| let alone the special properties of $|--.  The average
> programmer just needs to know that setting $| to 1 turns on autoflush
> and setting $| to 0 turns off autoflush.  What about the fact that ++
> will increment a string but -- will not decrement it?

My 2p:

$| is a boolean.  It's an alias to a *bit*.

And I'm not sure what the best semantic for $bool-- 
would be, but two possibilities come to mind:

- make it falser

  This might be kind of nice, actually.  

  $|-- would always turn autoflushing off.

- treat it as zero and decrement it

  This is what it does now.

  "But that's not what it does now!"

Sure it is:

Any non-zero number is "true", so decrementing zero
has to yield a "true" value.

  $x = 0;  # false
  $x--;    # true

And just so with $|:

  $| = 0;  # false
  $|--;    # true  

If you ignore what the numeric value is afterward, 
this does exactly what it should.

Obviously, the fact that the numeric value is *one*
afterward is a little jarring.  But maybe it's best
if you don't think of $| as ever being zero or one.

Think of it as a "pure" boolean, which gets 
temporarily coerced to zero or one when you use 
it in a non-boolean context.  

And anyway...

$^W behaves the same way so it can't be a bug.  :)

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to