What makes it a compiler function is that even though it has parameters, they are not variable and can't be changed at runtime. The parameters depend on information that is only available at compiletime.Josh wrote: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.
Bool() use?
Re: Bool() use?
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Bool() use?
Run this a few times and you'll see that Bool is a run-time function. Check the Help file.Demivec wrote:What makes it a compiler function is that even though it has parameters, they are not variable and can't be changed at runtime. The parameters depend on information that is only available at compiletime.
The compiler has no way of predicting the outcome of the Random statements.
Code: Select all
A.i
B.i
X.i
For X = 1 To 20
A = Random(1, 0)
B = Random(1, 0)
Debug "A = " + Str(A) + ", B = " + Str(B) + ", A or B = " + Str(Bool(A Or B))
Next
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
Re: Bool() use?
InitializeStructure(), ClearStructure(), CopyStructure() are "compiler functions" (if you want to call it that way),
because you need to specify what structure you are clearing / modifying in order to get PB internals right
(strings, maps, lists, ...). It's impossible to get this information at runtime because PB does not store type information
and therefore does not allow reflection of code.
Bool() evaluates the given expression (in a way that is only allowed in this statement) and guarantees a boolean result.
Since PB doesn't allow the direct use of boolean expressions anymore (and they were never really supported anyway),
Fred provided us with a way to use them properly.
It's not about static functions which have deterministic results after the code has been generated,
it's about functions that require additional information or add additional functionality.
All those "functions" could be considered keywords:
This would be an alternative way of doing that.
Even though this would be more consistent and logical in my eyes,
it's not really that much of a difference, is it? The only difference is the parenthesis around the call.
And to go a little off topic here: look at PHP's echo keyword.
It's pretty much the same case. Echo could be just a regular function as it does nothing too "specific" language-wise.
But it is considered a keyword because it provides an addition to the syntax (no parenthesis, always known, ...).
because you need to specify what structure you are clearing / modifying in order to get PB internals right
(strings, maps, lists, ...). It's impossible to get this information at runtime because PB does not store type information
and therefore does not allow reflection of code.
Bool() evaluates the given expression (in a way that is only allowed in this statement) and guarantees a boolean result.
Since PB doesn't allow the direct use of boolean expressions anymore (and they were never really supported anyway),
Fred provided us with a way to use them properly.
It's not about static functions which have deterministic results after the code has been generated,
it's about functions that require additional information or add additional functionality.
All those "functions" could be considered keywords:
Code: Select all
InitializeStructure *a, MyStructure
ClearStructure *a, MyStructure
CopyStructure *a, *b, MyStructure
Even though this would be more consistent and logical in my eyes,
it's not really that much of a difference, is it? The only difference is the parenthesis around the call.
And to go a little off topic here: look at PHP's echo keyword.
It's pretty much the same case. Echo could be just a regular function as it does nothing too "specific" language-wise.
But it is considered a keyword because it provides an addition to the syntax (no parenthesis, always known, ...).
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: Bool() use?
I am not certain, but I think some people may be mistaking bool() tests for bitwise tests. Take the preceding code sample, for instance, and change the random numbers to be 0-5 instead of 0-1... you rarely get a zero (1 in 36 chance.) because to get the zero, both A and B must be =0.
The reason "bool" is "evaluated at compilation" and not at runtime is because the "bool" instruction does not generate any code. Rather, Fred uses it to help his parsing, and it specifies to the compiler that "A or B" should return a 0 or 1 for an assignment value rather than be used in a conditional test as previously it was. Previously, Fred allowed the "lazy" (a technical term, not a slight against Fred) boolean test within the compiler do it automatically, even though it was not a supported feature. However, because of the way he implemented it, it was not 100% foolproof within the assignment realm. Therefore, he added the bool() function to clarify it and make boolean tests solid and stable.
Where they belong in the help file... meh. Who cares.
The reason "bool" is "evaluated at compilation" and not at runtime is because the "bool" instruction does not generate any code. Rather, Fred uses it to help his parsing, and it specifies to the compiler that "A or B" should return a 0 or 1 for an assignment value rather than be used in a conditional test as previously it was. Previously, Fred allowed the "lazy" (a technical term, not a slight against Fred) boolean test within the compiler do it automatically, even though it was not a supported feature. However, because of the way he implemented it, it was not 100% foolproof within the assignment realm. Therefore, he added the bool() function to clarify it and make boolean tests solid and stable.
Where they belong in the help file... meh. Who cares.
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
Where it belongs will obviously aid in where people start searching. For me, it's logical to look under Math, because it's doing a calculation. Makes sense.Tenaja wrote:Where they belong in the help file... meh. Who cares.
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?
To me, the logical place would be on the "Variables and Types" page, because that is where the boolean operators (And, Or, XOr, Not) are described. It would make sense to put it immediately after Not.
Re: Bool() use?
@BorisTheOld: I was responding to the statement by Shield about what might determine when something would be considered a compiler function. I was not referring to whether Bool() was such a function or not.BorisTheOld wrote:Run this a few times and you'll see that Bool is a run-time function. Check the Help file.Demivec wrote:What makes it a compiler function is that even though it has parameters, they are not variable and can't be changed at runtime. The parameters depend on information that is only available at compiletime.
Even so, my opinion is that it would be a compile time function for the same reason I stated, because the value of it's parameters can't be changed at runtime. Its only parameter is a boolean expression, not a string, and not simply a variable or function value. You can't change the boolean expression to anything else at runtime. You also cannot specify boolean expressions for any runtime functions, whether for your own functions or any of the library functions.
The second question is: "Where it should be put in the Help Manual?"
I think it can be put in the 'Misc' topic. I agree with those that think the 'Misc' category in the help file should be done away with eventually. I think that wherever it is put it should be linked to the topics for keywords that include conditional expressions (i.e. 'If/Endif', 'While/Wend', Variables & Operators').
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
Tenaja wrote:To me, the logical place

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?
OMG
In another language you would not need Bool() for this kind of expressions.
a = (b or c) it's more than enough to understand what you want to accomplish here, but not a = (b = c).
Moreover PB didn't support even the first kind of expression, and since the language lack the differentiation between "=" as assignment versus "=" as comparator (=, == in c/c++) fred decided to introduce one thing whose action is actually more similar to a keyword than a function, and called it Bool().
Bool it's not a runtime function in the sense you would imagine a runtime function, like abs() or len().
It's actually a way to instruct the compiler to generate some code to make expressions like a = (b or c) to work as expected.
So put it where you like it, fred decided to put it under the "compiler functions" section. It's not a bad place in my opinion, but that's irrelevant in the scope of the original question.
The original question was why Bool() was there and not in company of some other runtime functions.
The answer, even if some elderly think was silly, it's true.
Because it's not a runtime function, it's an artifice to induce the compiler to generate slightly different code, since it wasn't from the start able to correctly cope with those kind of expressions. The fact its param can be a runtime random function does not have anything to do with it. And fred decided to put this class of "functions" together.
If you don't like it, that's another matter, certainly it's not a silly answer.
In another language you would not need Bool() for this kind of expressions.
a = (b or c) it's more than enough to understand what you want to accomplish here, but not a = (b = c).
Moreover PB didn't support even the first kind of expression, and since the language lack the differentiation between "=" as assignment versus "=" as comparator (=, == in c/c++) fred decided to introduce one thing whose action is actually more similar to a keyword than a function, and called it Bool().
Bool it's not a runtime function in the sense you would imagine a runtime function, like abs() or len().
It's actually a way to instruct the compiler to generate some code to make expressions like a = (b or c) to work as expected.
So put it where you like it, fred decided to put it under the "compiler functions" section. It's not a bad place in my opinion, but that's irrelevant in the scope of the original question.
The original question was why Bool() was there and not in company of some other runtime functions.
The answer, even if some elderly think was silly, it's true.
Because it's not a runtime function, it's an artifice to induce the compiler to generate slightly different code, since it wasn't from the start able to correctly cope with those kind of expressions. The fact its param can be a runtime random function does not have anything to do with it. And fred decided to put this class of "functions" together.
If you don't like it, that's another matter, certainly it's not a silly answer.
"Have you tried turning it off and on again ?"
Re: Bool() use?
MachineCode wrote:Tenaja wrote:To me, the logical placeNice.

Anyway, this is one of those features that may make sense to place in several locations--or at the least, link to it multiple places. I think Fred knows the help file quality is not quite keeping up with the compiler quality. I think that's a good thing, though...especially since the forum is helpful.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Bool() use?
Almost 100% of the time when I want doc help on a command, I just type it in the IDE, set the caret on it and push the help button. Wherever it is located in the doc it comes right up. So I never care where it is. Actually, I find it hard to believe that this discussion involving so many members is actually happening
<to no-one in particular>: Seriously, get a life!

BERESHEIT
Re: Bool() use?
I, for one, never accept these kind of unsolicited suggestions. I'm quite able to decide how to spend my time.netmaestro wrote:Seriously, get a life!
In fact, now I move over to other subjects

"Have you tried turning it off and on again ?"
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Bool() use?
netmaestro wrote:Seriously, get a life!

Where the sun don't shine!luis wrote:So put it where you like it

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?
Ergh, was not my intention but I see how can it be read that way 

"Have you tried turning it off and on again ?"
-
- Enthusiast
- Posts: 542
- Joined: Tue Apr 24, 2012 5:08 pm
- Location: Ontario, Canada
Re: Bool() use?
That only works if one knows what one is looking for. With so many keywords in PB, it's not always easy to find stuff if one doesn't already know about its existance.netmaestro wrote:Almost 100% of the time when I want doc help on a command, I just type it in the IDE, set the caret on it and push the help button. Wherever it is located in the doc it comes right up. So I never care where it is......
For example, there is a help topic on structures that gives lots of examples and links to other topics. However, there are no references or links in that topic to CopyStructure and InitializeStructure, which are actually in Compiler Functions with other structure-related topics.
What some of us are saying is that most of what is in Compiler Functions, including Bool, could more usefully be moved to other sections, where they would be more easy to find.
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