[Implemented] Boolean Expressions

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

[Implemented] Boolean Expressions

Post 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.
oh... and have a nice day.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post by akj »

Another working possibility is:

Code: Select all

a = 7 
b = 5 
Debug (Not (Not a>b))
Anthony Jordan
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post 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:
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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.
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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:
oh... and have a nice day.
akj
Enthusiast
Enthusiast
Posts: 668
Joined: Mon Jun 09, 2003 10:08 pm
Location: Nottingham

Post 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
Anthony Jordan
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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
Last edited by blueznl on Mon Mar 20, 2006 11:56 am, edited 1 time in total.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

perfectly readable!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

all a matter of taste! :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post 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 ))
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post 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!
oh... and have a nice day.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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.
@}--`--,-- A rose by any other name ..
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Hey Dare - u gettin awfully personal now :evil: :P
Post Reply