POV-Ray : Newsgroups : povray.general : feature request (regarding &,|) Server Time
8 Aug 2024 18:20:17 EDT (-0400)
  feature request (regarding &,|) (Message 1 to 10 of 33)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Pabs
Subject: feature request (regarding &,|)
Date: 16 Nov 2000 21:44:56
Message: <3A149BF8.C688E185@hotmail.com>
Any one think they (logical operators &,|) shoud be short-circuit logic
operators (like &&, || in C/++) so that the following would be possible
#if( defined(somevar) & somevar)
    <some stuff>
#end
currently this is done like so
#ifdef(somevar)
    #if(somevar)
        <some stuff>
    #end
#end
--
Bye
Pabs


Post a reply to this message

From: Chris Huff
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 06:27:22
Message: <chrishuff-BD81EA.06273817112000@news.povray.org>
In article <3A149BF8.C688E185@hotmail.com>, Pabs <pab### [at] hotmailcom> 
wrote:

> Any one think they (logical operators &,|) shoud be short-circuit logic
> operators (like &&, || in C/++) so that the following would be possible

POV already has & and | operators that behave as boolean logic 
operators. What exactly do you want? Bit-level operators?
A "defined()" function would be useful though...I don't think it can be 
done as a macro.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Jérôme Grimbert
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 06:50:10
Message: <3A151B82.F3F5DD14@atos-group.com>
Chris Huff wrote:
> 
> In article <3A149BF8.C688E185@hotmail.com>, Pabs <pab### [at] hotmailcom>
> wrote:
> 
> > Any one think they (logical operators &,|) shoud be short-circuit logic
> > operators (like &&, || in C/++) so that the following would be possible
> 
> POV already has & and | operators that behave as boolean logic
> operators. What exactly do you want? Bit-level operators?
> A "defined()" function would be useful though...I don't think it can be
> done as a macro.
> 

No, he wants the behavior the C compiler has when evaluating:

 if ((divisor !=0)&&(amount/divisor ...

That is: if the divisor is 0, the division is not even performed
because the left part of the '&&' is false.

Sincerely, I'm against this idea for POV.
(it's ok in C).


Post a reply to this message

From: Geoff Wedig
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 08:13:06
Message: <3a152ee2@news.povray.org>


> No, he wants the behavior the C compiler has when evaluating:

>  if ((divisor !=0)&&(amount/divisor ...

> That is: if the divisor is 0, the division is not even performed
> because the left part of the '&&' is false.

> Sincerely, I'm against this idea for POV.
> (it's ok in C).


Oh, why?  Why should POV do extra work when the result is going to be false
already?  The reason it's done in C is to avoid that extra work.  Why would
this be a bad thing?  The only case I can think of is if there are side
effects to the second half of the equation (it calls a macro that creates an
object and returns a value), but that's so rarely necessary, plus needlessly
confusing (try figuring out code that has such side effects six months later
or which you didn't write) that it's not something that we really need.

Geoff


Post a reply to this message

From: Jérôme Grimbert
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 08:28:05
Message: <3A153271.A96486F8@atos-group.com>
Geoff Wedig wrote:
> 

> 
> > No, he wants the behavior the C compiler has when evaluating:
> 
> >  if ((divisor !=0)&&(amount/divisor ...
> 
> > That is: if the divisor is 0, the division is not even performed
> > because the left part of the '&&' is false.
> 
> > Sincerely, I'm against this idea for POV.
> > (it's ok in C).
> 
> Oh, why?  Why should POV do extra work when the result is going to be false
> already? The reason it's done in C is to avoid that extra work.  Why would
> this be a bad thing?  The only case I can think of is if there are side
> effects to the second half of the equation (it calls a macro that creates an
> object and returns a value), but that's so rarely necessary, plus needlessly
> confusing (try figuring out code that has such side effects six months later
> or which you didn't write) that it's not something that we really need.

You said it: it would open the door to needlessly confusing code.

The right way to write it is the current way:

#if (divisor <> 0.0)
#if (amount/divisor ...

There is no need to add confusion for the writer/reader of pov-script
with 'smart' browsing/evaluation of conditional expression.


Post a reply to this message

From: Geoff Wedig
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 09:42:37
Message: <3a1543dd@news.povray.org>


> Geoff Wedig wrote:
>> 
>> J?r?me Grimbert <jgr### [at] atos-groupcom> wrote:
>> 
>> > No, he wants the behavior the C compiler has when evaluating:
>> 
>> >  if ((divisor !=0)&&(amount/divisor ...
>> 
>> > That is: if the divisor is 0, the division is not even performed
>> > because the left part of the '&&' is false.
>> 
>> > Sincerely, I'm against this idea for POV.
>> > (it's ok in C).
>> 
>> Oh, why?  Why should POV do extra work when the result is going to be false
>> already? The reason it's done in C is to avoid that extra work.  Why would
>> this be a bad thing?  The only case I can think of is if there are side
>> effects to the second half of the equation (it calls a macro that creates an
>> object and returns a value), but that's so rarely necessary, plus needlessly
>> confusing (try figuring out code that has such side effects six months later
>> or which you didn't write) that it's not something that we really need.

> You said it: it would open the door to needlessly confusing code.

No, my *counterexample* (ie, the only reason you want anything else) is
needlessly confusing, because of side effects.  Having a pair of boolean
expressions that terminates if the first expression determines the whole
sequence is quite sensible.

I don't see why using two ifs is any clearer, it's just verbose, which is
its own kind of obtusification.

Geoff


Post a reply to this message

From: Warp
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 10:01:13
Message: <3a154839@news.povray.org>

: You said it: it would open the door to needlessly confusing code.

  Why it would be confusing code?

  If I write: #if(a>0 & b>0)
does it matter whether the part "b>0" is evaluated or not as long as the
result is correct?

  Actually, doing it C-like can produce faster parsing:

  #if(a>0 & extremely_long_calculation(a)) ...

  If a<=0 then the extremely_long_calculation() macro is not called, saving
potentially a lot of time.
  Of course you can do it in the long way:

#if(a>0)
  #if(extremely_long_calculation(a))
    ...
  #end
#end

but why should you do it yourself when the povray parser can do it
automatically for you?

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/

  "The derivative of sin(2x) is cos(2x)"  - Matt Giwer


Post a reply to this message

From: Jamie Davison
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 15:17:05
Message: <MPG.147f9db69ed5d68f98984d@news.povray.org>
On 17 Nov 2000 10:01:13 -0500, Warp wrote...
> : You said it: it would open the door to needlessly confusing code.
> 
>   Why it would be confusing code?

Because not everybody on these groups, or indeed everybody who uses POV, 
is experienced in, or capable of reading C style code.

I have enough trouble reading POV code as it is, and adding (more) 
abstract symbols to the scene description language would kill my ability 
to understand roughly what is happening in a scene file.

Sorry if I'm ranting, but I get a little fed up of seeing people trying 
to turn POV into a programming language, when, in my opinion, it isn't 
and shouldn't be.

Bye for now,
     Jamie.


Post a reply to this message

From: Chris Huff
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 18:34:29
Message: <chrishuff-5D818F.18344617112000@news.povray.org>
In article <3a154839@news.povray.org>, Warp <war### [at] tagpovrayorg> 
wrote:

>   Actually, doing it C-like can produce faster parsing:
> 
>   #if(a>0 & extremely_long_calculation(a)) ...
> 
>   If a<=0 then the extremely_long_calculation() macro is not called, 
> saving potentially a lot of time.

If that extremely_long_calculation sets up some variables for later use, 
not evaluating it could lead to obscure bugs in scene files. Having side 
effects like this may be bad style, but having them be ignored sometimes 
would lead to problems that are very difficult to track down when they 
are done.

In other words, it is a minor optimization that can be done within the 
scene language and produces the possibility for bugs that are extremely 
difficult to track down(or code that is very vague because it relies on 
this optimization). Not worth adding in my opinion.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: David Fontaine
Subject: Re: feature request (regarding &,|)
Date: 17 Nov 2000 18:57:54
Message: <3A15C595.691BF4BC@faricy.net>
Warp wrote:


> : You said it: it would open the door to needlessly confusing code.
>
>   Why it would be confusing code?
>
>   If I write: #if(a>0 & b>0)
> does it matter whether the part "b>0" is evaluated or not as long as the
> result is correct?

Yes, and besides, this is much clearer to me than
  #if(a>0)
    #if(b>0)
It's especially more clear when limiting to a set:
  #if(a>0 & a<10)
because you don't need to read ahead or look at indentation to see that you're
limiting a to an interval (0,10) (or is that [0,10]?). Same goes for a
non-contigous set:
  #if((a>0 & a<10) | a>20 | a=15)
Imagine that coded as individual tests!

--
David Fontaine  <dav### [at] faricynet>  ICQ 55354965
My raytracing gallery:  http://davidf.faricy.net/


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.