Logical AND in PB vs && in C++

Everything else that doesn't fall into one of the other PB categories.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

SFSxOI wrote:

Code: Select all

enabled = #False ; a 0
If CallFunction(Lib, "SomeFunction) Not enabled
   Debug "OK"
EndIf
I would of thought

Code: Select all

If Not CallFunction(Lib, "SomeFunction) = enabled
or

Code: Select all

If CallFunction(Lib, "SomeFunction) = Not enabled
But I could be wrong.
Last edited by Derek on Mon Jan 29, 2007 3:26 pm, edited 1 time in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

hm... hard to say... to lazy to calculate it through right now..

there is an easier way:

Code: Select all

If CallFunction(Lib, "SomeFunction")
  Debug "True"
EndIf

; or use

If Not CallFunction(Lib, "SomeFunction")
  Debug "False"
EndIf

; or use

WindowNumber = OpenWindow( #PB_Any, .....)

If Not WindowNumber 
  Debug "Window not opened"
EndIf
oh... and have a nice day.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

so sad really. Oh well, in C++ (in which I am not an expert by any means, just a novice) (and I am by no means an expert with PureBasic either - and I ask a lot of stupid questions sometimes) being able to do a boolean is a standard thing. In other languages its a standard thing.

I read a thread at: http://www.purebasic.fr/english/viewtopic.php?t=20594

where it was said it wasn't considered important as it doesn't add any functionality.

Not being critical, just an observation; Well it doesn't add any functionality in terms of adding a new whiz bang function, but it seems it would add functionality in terms of improving the language. In my way of thinking a product should appeal to the widest base of customers and include things that are competitive with other products that are of the same genre. I think boolean's should be added, but oh well, if they aren't its not the end of the world, but i hate to think that a fast compiled basic language needs to add code to replace or do something thats done with a simple operator everywhere else.

In C++ it's easy to do this:

Code: Select all

if (enable && 0 != ref) ; where enable can be 1 or 0 - and ref can be 1 or 0 or not 1 or 0 but some other value like 2 for example.
In PB this would take a work around with up to several lines of code that might not work with future versions of PB, where as the ability to do this has and will continue to be a standard in C++ (I believe - who knows, all things change eventually). I'd just like to see it in PB. Oh well...maybe one day.

Thanks for the responses folks, i'm gonna give it a whirl :)
Last edited by SFSxOI on Mon Jan 29, 2007 4:24 pm, edited 2 times in total.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

mind the way you post links..... I can't get this one

ok got it http://www.purebasic.fr/english/viewtopic.php?t=20594
oh... and have a nice day.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Whoops....sorry
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Anyway...

Is what we are really simply saying then for the ' &&' in C++ for boolean expressions is, for this C++ expression:

Code: Select all

if (enable && 0 != region)
the equation is true (1) if each side is NOT 0?

so for PureBasic:

Code: Select all

; break it down a little (enable && 0) != region
; the equation = (enable && 0)
;!= in C++ is not equal to - in PureBasic this is <>

enable = 1 ; can be 1 or 0 - the left side of &&
xyz = 0; will only be 0 in the equation - the right side &&

; is a Not 0 valid?

if enable Not 0
enable = 1
EndIf

If xyz Not 0
xyz = 1
EndIf

If (enable And xyz) <> region ; is it (enable Or xyz) or (enable Not xyz)?
; or is it: If (enable = 1) And (xyz = 1) 
; do something here
EndIf
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

sorry, it's some years passed that i worked with C.

Code: Select all

if (enable && 0 != region) 
doesn't look practicable for me.

Code: Select all

enable && 0
means

Code: Select all

enable && #False
so it should always equal false, shouldn't it?
oh... and have a nice day.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Code: Select all

if (enable && 0 != region) 
I think this is supposed to mean:

enable AND (0 <> region)

so not always false, depending on region.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

but is it correct then?

is "!=" really higher evaluation priority than "&&"?


but if it's meant that way....

would just this work in PB:

Code: Select all

If enable And region
whilst this means both <>0
oh... and have a nice day.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Yes that should work.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Kaeru Gaman wrote:sorry, it's some years passed that i worked with C.

Code: Select all

if (enable && 0 != region) 
doesn't look practicable for me.

Code: Select all

enable && 0
means

Code: Select all

enable && #False
so it should always equal false, shouldn't it?
well, thats one of the questions I have too. If both sides of the equation must be NOT 0 for the whole equation to be true, we already know that enable can be either true or false (1 or 0), and the other side will always be 0, the question arises if - if both sides are 0, will a NOT 0 in PB render a true for the equation? How to test that for the PB NOT operator?
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Derek wrote:

Code: Select all

if (enable && 0 != region) 
I think this is supposed to mean:

enable AND (0 <> region)

so not always false, depending on region.
Ahhhh..HA! I see something that looks like light at the end of the PureBasic tunnel now - could just be an approaching train :) - but i'll have to look to see.
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

@SFSxOI

please use your EDIT-button...
there's no need for three-in-a-row.... ;)

@topic
if it's meant

Code: Select all

enable AND (0 <> region) 
the easiest PB-construct is

Code: Select all

If enable And region
;)
oh... and have a nice day.
Post Reply