Jump to content

perplexed about some boolean expressions


Recommended Posts

 Shouldn't the last 2 lines give as result false instead of True?

$value = 1
ConsoleWrite( $value = Null)
ConsoleWrite(@CRLF)
ConsoleWrite( $value > Null)
ConsoleWrite(@CRLF)
ConsoleWrite( $value < Null)
ConsoleWrite(@CRLF)
ConsoleWrite( $value >= Null)
ConsoleWrite(@CRLF)
ConsoleWrite( $value <= Null)
ConsoleWrite(@CRLF)

 

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites

Null evaluates to 0 in mathematical operations (according to the help file). I can't test at the moment but I would expect:

$value = 1
ConsoleWrite( $value = Null)  ; False
ConsoleWrite(@CRLF)
ConsoleWrite( $value > Null)  ; True
ConsoleWrite(@CRLF)
ConsoleWrite( $value < Null)  ; False
ConsoleWrite(@CRLF)
ConsoleWrite( $value >= Null) ; True
ConsoleWrite(@CRLF)
ConsoleWrite( $value <= Null) ; False
ConsoleWrite(@CRLF)

What do you get?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

I think the problem is caused by the Statement ($value operator Null) not being a mathematical operation. It is a comparison.
Null is not a value (but a keyword) so you can't compare it this way and assume it is evaluated to 0.
I tested:

$value = 1
$Null = Null
;                                                 $Null = ""      $Null = 0       $Null = Null    $Null = Int(Null)
ConsoleWrite($value = $Null)  ; Expected: False   Result: False   Result: False   Result: False   Result: False
ConsoleWrite(@CRLF)
ConsoleWrite($value > $Null)  ; Expected: True    Result: True    Result: True    Result: False   Result: True
ConsoleWrite(@CRLF)
ConsoleWrite($value < $Null)  ; Expected: False   Result: False   Result: False   Result: False   Result: False
ConsoleWrite(@CRLF)
ConsoleWrite($value >= $Null) ; Expected: True    Result: True    Result: True    Result: True    Result: True
ConsoleWrite(@CRLF)
ConsoleWrite($value <= $Null) ; Expected: False   Result: False   Result: False   Result: True    Result: False
ConsoleWrite(@CRLF & @CRLF)


 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

I was hoping to be able to use it in comparisons too, but as also your tests show, it's better to avoid ...
however I would have expected an error in response to that use rather than these "strange" results.
Thank you @water for your reply.

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites

You can. Use function IsKeyword. 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites

Granted, Null has been introduced in AutoIt only lately, yet it's kinda half-backed, maybe due to the variant nature under AutoIt variables.

Idealy, Null literally means "I don't know the value", something completely distinct from zero, empty string, False, an empty array, etc.  So the correct way to handle any operation involving Null is to consistantly return Null.  That's how it behaves in SQL for instance, since SQL explicitely uses ternary logic (True, False, Null).

Anyway, in light of the intended meaning of Null, it doesn't make sense to try to compare this keyword to anything. You should get 5 times Null as result of your code.  Indeed, not returning Null is wrong, else one would have to devise a logical way to compare any datatype to Null and return something sensible.  That's impossible:
Null vs some object ???
Null vs Default ???
Null vs 3.1415926 ???
Null vs False ???

Some may consider debatable whether not returning Null when it's part of an operation is an actual bug, but from my window it clearly is, because Null is currently inconsistent:

ConsoleWrite(Null < 0)
ConsoleWrite(@CRLF)
ConsoleWrite(Null = 0)
ConsoleWrite(@CRLF)
ConsoleWrite(Null > 0)
ConsoleWrite(@CRLF)

ConsoleWrite(Null < "")
ConsoleWrite(@CRLF)
ConsoleWrite(Null = "")
ConsoleWrite(@CRLF)
ConsoleWrite(Null > "")
ConsoleWrite(@CRLF)

ConsoleWrite(Null < False)
ConsoleWrite(@CRLF)
ConsoleWrite(Null = False)
ConsoleWrite(@CRLF)
ConsoleWrite(Null > False)
ConsoleWrite(@CRLF)

ConsoleWrite(Null < True)
ConsoleWrite(@CRLF)
ConsoleWrite(Null = True)
ConsoleWrite(@CRLF)
ConsoleWrite(Null > True)
ConsoleWrite(@CRLF)

ConsoleWrite(Null < Default)
ConsoleWrite(@CRLF)
ConsoleWrite(Null = Default)
ConsoleWrite(@CRLF)
ConsoleWrite(Null > Default)
ConsoleWrite(@CRLF)

If Null Then ConsoleWrite("Null is True" & @LF)
If Not Null Then ConsoleWrite("Here Null behaves like False" & @LF)

Also Null = Null should return Null as well.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...