[Implemented] NOT (or !) operator

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

[Implemented] NOT (or !) operator

Post by Amiga5k »

So we can do If Not OpenConsole() etc. instead of If OpenConsole() = #FALSE...

I know it's easy enough to do:

Code: Select all

Procedure Not(expression)
   If expression
      ProcedureReturn #FALSE
   Else
      ProcedureReturn #TRUE
   Endif
EndProcedure

If Not(OpenConsole())...
But it would be nice. Or possibly using '!' instead of Not (too C-Like?)

Just a tiny wish. :)

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: NOT (or !) operator

Post by tinman »

Amiga5k wrote:Or possibly using '!' instead of Not (too C-Like?)
We already have ! for XOR :)
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

PureBasic already has the bitwise NOT operator, it's just not the usual character '!' as in many other languages, in PB it's the '~' sign. It's in the manual under the section that says "Variables, Types and operators".

Edit: Sorry that wasn't what you were asking for, why not use this instead of logical NOT:

Code: Select all

if <expression> = 0 ; same as 'if NOT <expression>'
User avatar
geoff
Enthusiast
Enthusiast
Posts: 128
Joined: Sun Apr 27, 2003 12:01 am
Location: Cornwall UK
Contact:

Post by geoff »

Logical not makes code clearer.

Code: Select all

found=search_file_for_string(file$,a$)
If NOT found
  etc
  etc
EndIf
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

[quote]
Edit: Sorry that wasn't what you were asking for, why not use this instead of logical NOT:

Code: Select all

if <expression> = 0 ; same as 'if NOT <expression>' 
[\code]
[\quote]
I do already (although I prefer If <expression> = #FALSE), but I got used to 'Not' in other languages and kinda liked it. It's simple enough to write a Not procedure, but just thought I'd throw this idea out there, too.

And Tinman, you're right about the '!' operator :( No big deal. I just use the Not procedure to do it:
[code]
If Not(<expression>)
   ...
Else
   ...
EndIf
[\code]

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
Revolver
User
User
Posts: 22
Joined: Tue Apr 29, 2003 9:20 pm

Post by Revolver »

Personally I can't believe that a logical NOT was left out of PureBasic in the first place... What was Fred thinking!
Amiga5k
Enthusiast
Enthusiast
Posts: 329
Joined: Fri Apr 25, 2003 8:57 pm

Post by Amiga5k »

I forgive him. He's got other fish to fry :) I'm sure he will add it as soon as he can. In the mean time, it's easy to get around it. Talk about omissions, all three versions of Blitz are missing Val() :( and Int() works in a completely different way than all other basics' versions of Int(). So I can do without the Not statement for now, really. ;)

btw, I think Fred is supposed to have the new version of PB up June 1st!

Russell
*** Diapers and politicians need to be changed...for the same reason! ***
*** Make every vote equal: Abolish the Electoral College ***
*** www.au.org ***
flim
New User
New User
Posts: 5
Joined: Fri Jun 06, 2003 4:57 pm

Post by flim »

I would like to see logical Not and also "break" and "continue" keyword for loop.
Post Reply