[Gambas-user] strange problem with NOT

Jean-Francois Perreault cmcpero at ...142...
Mon Mar 21 21:10:32 CET 2005


Benoit Minisini wrote:

>The Not operator has a priority greater than comparison operators in Gambas.
>
>You can see the priority of each operator in the 'gb_reserved_temp.h' file in 
>the 'share' directory.
>
>Should Gambas operators have exactly the same priority than in VB ? Anyway, 
>you can use parenthesis to force the priority without fear - it does not slow 
>the interpreter.
>
>We can decide all together to change priorities if there are good reasons for 
>that. The development version is done for that - breaking everything :-)
>
>Regards,
>  
>

the reason why I mentionned trying to avoid parenthesis was in case 
gambas implemented "short-circuiting"

in the case of a AND if you have

IF b <> 0 AND c > d THEN

the interpreter might test b <> 0 and if it returns false , skip 
evaluation of c > d

if you had

IF NOT (b <> 0) AND NOT (c > d) THEN
or just
IF (b <> 0) AND (c > d) THEN

then both expression are evaluated before the AND , causing a 
performance penalty
like that it doesn't seem much but in the case of more complex 
expression the performance gain could be significant

but this is only for convenience because you could just do

IF NOT (b <> 0) THEN
    IF NOT (c > d) THEN

also short circuiting can be used for flow control

IF a <> 0 AND (c + d)/a THEN

if expression are evaluated left to right (not usually garanteed with MS 
BASIC languages) then you would be sure that (c + d)/a does not get 
evaluated if it would raise a division by zero error

I found those tricks in the previously linked page , there are way 
around this to make it work just as fast with gambas anyway so it's not a
problem if it doesn't get implemented , it's just the NOT behavior that 
was strange since there's been some talk about visual basic and gambas
on the devel list , I though pointing out that difference could be 
useful since it's contradict that goal

---
Jean-Francois Perreault




More information about the User mailing list