
Bool() use?
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Bool() use?
I just tried PureBasic 5.10 and this snippet no longer works: result = num1 And num2. It says I have to use Bool(), but there's no Help file yet. (I can guess and assume how it works, but I'd like to know for sure, so I don't write incorrect code). 

Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
- Arctic Fox
- Enthusiast
- Posts: 609
- Joined: Sun Dec 21, 2008 5:02 pm
- Location: Aarhus, Denmark
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
Thanks for showing me how to do it. I don't have a Help file that has Bool() in Compiler Functions (I don't have the latest beta yet).Arctic Fox wrote:The help entry for Bool() is in 'Compiler Functions'.
Why would it go under Compiler Functions anyway? Seems odd. It's an everyday function, rather that something that tells the compiler how to act.
Also, I take it that "result = a Or B" would now also become "result = Bool(a Or b)" ?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
Re: Bool() use?
Because it's not a runtime function, it's interpreted by the compiler at compilation time. It generates different code.MachineCode wrote:Why would it go under Compiler Functions anyway?
Yep.MachineCode wrote:Also, I take it that "result = a Or B" would now also become "result = Bool(a Or b)" ?
"Have you tried turning it off and on again ?"
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
Thanks, Luis. 

Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
- flaith
- Enthusiast
- Posts: 704
- Joined: Mon Apr 25, 2005 9:28 pm
- Location: $300:20 58 FC 60 - Rennes
- Contact:
Re: Bool() use?
Right, for example, if you want to try if a char is a digit or not :MachineCode wrote:Also, I take it that "result = a Or B" would now also become "result = Bool(a Or b)" ?
Code: Select all
Procedure.i isDigit(__char.c)
ProcedureReturn Bool(__char >= '0' And __char <= '9')
EndProcedure
“Fear is a reaction. Courage is a decision.” - WC
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Bool() use?
That has to be the silliest thing I've every read. My entire program is interpreted by the compiler at compile time and converted into machine code.luis wrote:Because it's not a runtime function, it's interpreted by the compiler at compilation time. It generates different code.MachineCode wrote:Why would it go under Compiler Functions anyway?
The internal workings of the compiler should not dictate the placement of material in the help file.
For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
-
- Addict
- Posts: 4791
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Bool() use?
That is not silly at all.BorisTheOld wrote:That has to be the silliest thing I've every read.luis wrote:Because it's not a runtime function, it's interpreted by the compiler at compilation time. It generates different code.MachineCode wrote:Why would it go under Compiler Functions anyway?
So what? I estimate that more than 99% of all programs written in PB additionally do some computations at runtime.BorisTheOld wrote:My entire program is interpreted by the compiler at compile time and converted into machine code.
Regards, Little John
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Bool() use?
But that's my point. When I write code in a high level language I don't care how the underlying code performs the actual function - at compile time or at run time. So when I code x=SizeOf(y) and x=Len(y), all I care about is the result not how it was obtained.Little John wrote:Maybe. However, I estimate that more than 99% of all programs written in PB additionally do some computations at runtime.
Which all begs the question, why are Bool, InitializeStructure, CopyStructure, and ClearStructure classified as Compiler Functions, when they do their work at run time?
Silly, isn't it?

For ten years Caesar ruled with an iron hand, then with a wooden foot, and finally with a piece of string.
~ Spike Milligan
~ Spike Milligan
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Bool() use?
Because they are worker functions that cause the compiler to generate code for you that you would otherwise have to write. Bool() allows you to write one line instead of an If-Else-Endif block, CopyStructure allows for the one-line 'a.point = b.point' whereas without it you would have had to set each member individually, same for ClearStructure which would have you setting each element to zero, which gets quite involved with the recent addition of dynamic objects in structures. These are compiler functions all right, and I don't find them silly.why are Bool, InitializeStructure, CopyStructure, and ClearStructure classified as Compiler Functions
BERESHEIT
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
I don't know about silly, but to me, Bool() should go in the Math lib, since it's performing a math calculation. Anyway, not trying to cause further argument about it. Just saying how it looks.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
-
- Addict
- Posts: 4791
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Bool() use?
Yes, for a similar reason I don't understand why there are all those discussions on nuclear power stations and whatnot. My power just comes out of the electric socket.BorisTheOld wrote:When I write code in a high level language I don't care how the underlying code performs the actual function - at compile time or at run time. So when I code x=SizeOf(y) and x=Len(y), all I care about is the result not how it was obtained.

Seriously:
It can matter, whether a function or command has an effect at compile time or at runtime. I'll demonstrate it by some simple examples.
Code: Select all
DataSection
MapLabel:
IncludeBinary "map.data" ; file size: 50 MB
EndDataSection
If IncludeBinary has an effect at runtime, then my EXE file will not increase by 50 MB, but I have to ship the file "map.data" to the customers of my program.
Code: Select all
DataSection
CompilerIf Date() > 1000
MapALabel:
IncludeBinary "mapA.data"
CompilerElse
MapBLabel:
IncludeBinary "mapB.data"
CompilerEndIf
EndDataSection
Since CompilerIf / CompilerElse has an effect at compile time, the last code can only work if Date() is also evaluated at compile time. If you know that Date() is a runtime function, then you immediately understand why this code can't work.
I hope you see now, why asking whether something happens at compile time or at runtime is a "natural" consideration when talking about compiled computer programs -- and why it can serve a purpose. Actually, I expect a good documentation to tell me whether a given function or command has an effect at compile time or at runtime. If you personally are not interested in this information, you are free to ignore it.

The original problem here in this thread was, that the help for Bool() could not be found. The reason for this was not any principle problem related to compile time or runtime, but just a small bug in the help file. It has been fixed, and all is fine now, I think.

Regards, Little John
Re: Bool() use?
Or.....flaith wrote:Right, for example, if you want to try if a char is a digit or not :MachineCode wrote:Also, I take it that "result = a Or B" would now also become "result = Bool(a Or b)" ?Code: Select all
Procedure.i isDigit(__char.c) ProcedureReturn Bool(__char >= '0' And __char <= '9') EndProcedure
Code: Select all
Macro isDigit(__char)
(__char >= '0' And __char <= '9')
EndMacro
Debug isDigit('0')
Debug isDigit('9')

Anyway... just curious, but what exactly does 'Bool' do that can't already be done with a macro or a 'If - EndIf' statement arangement or a reqular expression or some other comparison type of arangement and the results return true or false?
Last edited by SFSxOI on Thu Jan 24, 2013 8:57 am, edited 1 time in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Re: Bool() use?
It can be chained in an expression
Re: Bool() use?
I absolutely agree with BorisTheOld. Long time ago I had the same discussion on the German forum.
There are some really compiler functions like SizeOf() or OffsetOf(), this functions can be completely replaced at compiletime. On the other hand, we have functions like ClearStructure() and I would be interested to know, how the storage can be cleared at compiletime.
There are some really compiler functions like SizeOf() or OffsetOf(), this functions can be completely replaced at compiletime. On the other hand, we have functions like ClearStructure() and I would be interested to know, how the storage can be cleared at compiletime.
sorry for my bad english