Page 1 of 3

[Implemented] Boolean Expressions

Posted: Sun Mar 19, 2006 2:06 pm
by Kaeru Gaman
As I recently was told, Boolean Expressions are still not implemented in Beta7...
is this correct?

Code: Select all

a = 7
b = 5
Debug (a>b)
should debug True resp. 1

in Ver 3.94 you have to Cast BOOL to the expression to make in work:

Code: Select all

a = 7
b = 5
Debug #False Or (a>b)
this is quite inconvenient for long expressions and tests..

Since Boolean Expressions are a very immanent Feature for programming, I wonder why it hasn't been solved yet.

Posted: Sun Mar 19, 2006 7:07 pm
by akj
Another working possibility is:

Code: Select all

a = 7 
b = 5 
Debug (Not (Not a>b))

Posted: Sun Mar 19, 2006 7:28 pm
by Polo
akj wrote:Another working possibility is:

Code: Select all

a = 7 
b = 5 
Debug (Not (Not a>b))
This is not supposed to be working :lol:

Posted: Sun Mar 19, 2006 8:53 pm
by Kaeru Gaman
the point is, it's not practicable to add an "Or 0" to every expression you want to use.

making use of Boolean Expressions is possible in almost every programming language.
(I don't know one that can't do it except PB)

Even the Commodore Basic V3.8 on the C64 25(!) years ago had it.

It should be a little change in the compiler with great advantage for users who are familiar to these operations.

Posted: Sun Mar 19, 2006 9:22 pm
by blueznl
please read here:

http://www.xs4all.nl/~bluez/datatalk/pu ... evaluation
PureBasic is NOT C(++) and does NOT allow things like:

a = a + 5*(b=c) + 6*(c=d)

Yes, I know. The compiler does not generate a syntax error, even though it should. But it's simply not supported and may cause hard to trace bugs. Just DON'T DO THIS. Sorry. You'll have to do it the long way...

If b = c
a = a+5
EndIf
If c = d
a = a+6
EndIf
note that boolean expressions in itself have nothing to do with conditions within expressions, which is what you're talking about

Posted: Sun Mar 19, 2006 11:25 pm
by Kaeru Gaman
well, i simply call a condition in brackets, wich is considered to return a boolen value, a "Boolean Expression".

maybe thats not absolutely correct, its just translated from the German "Boole'scher Ausdruck"

I been asking for this feature now since V3.92 (ok, in the German forum, maybe Fred din't notice it)
and I'm not pleased with "it's simply not supported".

Tons of minor Stuff such as 'named enums' and others are put into PB,
but some simple and fundamental (and very, very useful) feature is just ignored. :cry:

Posted: Mon Mar 20, 2006 2:16 am
by akj
In my experience blueznl's expression:
a = a + 5*(b=c) + 6*(c=d)
is acceptable in most dialects of Basic. So why not PureBasic?

Even the Locomotive Basic on my Amstrad CPC can handle expressions of this type and produce correct results.

Currently the assembler code generated by c=(a>b) is:
MOV ebx,dword [v_a]
CMP ebx,dword [v_b]
PUSH dword [v_b]
POP dword [v_c]
which to me seems wrong as the results of the CMP instruction are never used.

I think better code for c=(a>b) should be something like:
XOR eax,eax
MOV ebx,dword [v_a]
CMP ebx,dword [v_b]
JLE Ok0 ; Jump if a<=b
INC eax
Ok0:
MOV dword [v_c],eax

Posted: Mon Mar 20, 2006 11:14 am
by blueznl
i'm not saying it is a wanted feature or not, i'm just relaying fred's statement :-)

(although, personally, i think conditions inside expressions do not make the language a better one...

a = a = b
a = (a = b)
a = a = b * 120
a = (a = b) * 120

readable code? brrrrrr

Posted: Mon Mar 20, 2006 11:29 am
by dmoc
perfectly readable!

Posted: Mon Mar 20, 2006 11:56 am
by blueznl
all a matter of taste! :-)

Posted: Mon Mar 20, 2006 12:05 pm
by dmoc
Seriously though: as said already this sort of thing is do-able is most other languages, the rules of precedence are pretty clear and well known by almost every coder. This is actually one area that drives me nuts with any language/compiler creator (sometimes the users as well)... it's a feature that if implemented affects no one except those who want it, ie, a properly/thouroughly implemented expression parser would *NOT* stop anyone from coding as they currently do... but for those of us who hate IF-THEN's where the logic can be much better embedded in an expression it's much preferred and creates more concise code (and I think (imho) much more readable :P ))

Posted: Mon Mar 20, 2006 12:42 pm
by Kaeru Gaman
blueznl wrote:a = a = b
a = (a = b)
a = a = b * 120
a = (a = b) * 120

readable code? brrrrrr
I wonder why guys who are against* this feature always quote sensless code to prove their stand..

maybe its just because they have not the merest idea at all what do do with it...

take a look at this one:

Code: Select all

X - (X > 799)*801 +1
and tell me, what it does...

or how about this:

Code: Select all

C = Asc(In$) : Hex = ((C>47)&(C<58)*(C-48))+((C>64)&(C<71)*(C-55))
readable? ..for those who are able...
reliable? ..perfect!

..just two examples out of a million possible uses...

----------------------------
[edit]
*) by the way, why? is this a religious war?

> it's a feature that if implemented affects no one except those who want it

dmoc said it, thats the point!

so, everybody who don't need and want this feature, just sit down in silence!

Posted: Mon Mar 20, 2006 2:10 pm
by blueznl
I wonder why guys who are against* this feature always quote sensless code to prove their stand..

maybe its just because they have not the merest idea at all what do do with it...
thank you for your polite reply and the high esteem you have shown for some of us

perhaps some people may have some issues with readability, and may illustrate this by nonsense code, as perhaps readability is the thing they want to illustrate

perhaps they may understand what your brilliant and well thought out examples mean, and perhaps not

perhaps, just perhaps, they may be of a different opinion?

perhaps they have nothing against adding this feature, but perhaps they just mention a current limitation

perhaps they don't feel comfortable using a sledgehammer driving the point home?

perhaps i had a bad day...

perhaps that could be possible...

Posted: Mon Mar 20, 2006 2:22 pm
by Dare2
:)


Can look ugly - should be supported.


Actually, ugly things should get all the support we can offer. They don't have much going for them otherwise.

Posted: Mon Mar 20, 2006 2:37 pm
by dmoc
Hey Dare - u gettin awfully personal now :evil: :P