Jump to content

Concatenation and test evaluation badly prioritised ?


sksbir
 Share

Recommended Posts

Try this littre script:

msgbox(0,"test0","1=0 --> " & 1=0)  
msgbox(0,"test1","1=0 --> " & (1=0) )   

; EXPECTED : 1=0 --> 0 ....

Test 0 fail : Shouldn't contatenation be evaluated after comparison tests ?

Today, I have to use parenthesis to get it working like : see test 1

Using Autoit 3.1.1.0

[edit] I now understand what is happening :

first, autoit evaluates "1=0 --> " & 1

then compare "1=0 --> 1" = 0

so result is 0

Edited by sksbir
Link to comment
Share on other sites

  • 9 years later...

Nobody answered this and yes after 9years I am confused by this strange behavior as well...

$str="something"
if not $str="somethingelse" then dosomething()

does nothing. What is the reason for such strange behavior in autoit? This leads to unnecessary errors and prolongs development time when you have to debug it. Or is there any reason one would want to negate string with not $str?

Edited by LoWang
Link to comment
Share on other sites

By default autoit evaluation return bool type. it you want number just use int.

 

Please Don't revive old topic. Saludos

Link to comment
Share on other sites

What is the reason for such strange behavior in autoit?

This results from the priority of operators. See help file under "Operators".

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 comment
Share on other sites

  • Moderators

$str="something"

if not $str="somethingelse" then dosomething()

Would be more correctly written

$str="something"
If $str <> "somethingelse" then dosomething()

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Guys thank you for poingint me to the help pages and manuals, but I understand how to do it right and how it works already.

What I was asking is why is this behavior coded into AutoIt and if there is any specific reason or some advantage in certain situations or type of code which justifies this unusual "feature" of AutoIt programming language. So far I find only a lot of questions around the web with people being confused by this operators priority.

Edited by LoWang
Link to comment
Share on other sites

So you understand how it works, therefore what is the problem? Also jchd linked to the help file because it explains why it happens and yes it's "behaviour coded into AutoIt"!

Edited by guinness
Typo

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Do I need to have a problem to ask a question like that? Or is my curiosity too impolite if I question developers? ;) But if there was no special reason for this default operator priority or the origin of this decision it is no longer known then OK...

Edited by LoWang
Link to comment
Share on other sites

LoWang,

How exactly the AutoIt operators' priority differs from the languages you know and use and why it's so surprising to you?

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 comment
Share on other sites

if (!'string' === false) { // !'string' is equal to false and then false is compared with false hence true
    console.log('Internet is NOT broken!');
}

This is JavaScript. Therefore if AutoIt is broken, so is the entire web. Maybe contact ECMAScript and W3C and explain to them that they're wrong. Let us know what they respond with so we can change AutoIt. Thanks

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

OK OK, thank you for the effort, but your example unfortunately does not show anything, because I don't think strings are usually compared to false and if you add parenthesis

if (!('string' === false)) { // 'string' is not equal to false thus negating it with ! makes true
    console.log('Internet is NOT broken!');
}


it produces the same result...

However when I rewrote my example with comparing string to string to JavaScript I gotta say you are right. I did not know JavaScript's ! had higher priority then comparison 

var str="something"
if (! str=="somethingelse"){
    console.log('something');
}else{
    console.log('! has precedence in Javascript over ==');
}


The same seems to apply to PHP (again it uses exclamation mark instead of not) 

However if you try that in Python:
In [1]: str="abc"                                                                                
                                                                                                 
In [2]: not str=="abcd"                                                                          
Out[2]: True            
    

Or Perl:

$str="abc";
if (not $str eq "abcd"){
    print "eq has higher priority then not \n";
}else{
    print "false \n";
}

And here we see something quite interesting. You can use either ! or not as an operator but their behavior is different!

$str="abc";
if (! $str eq "abcd"){
    print "true \n";
}else{
    print "! has higher priority then eq \n";
}

This leads me to a conclusion: 
It looks like languages using "not" instead of ! have it's precedence lower. Unlike those using only ! The main thing which makes higher precedence of exclamation mark obvious is that you can (and usually everyone do) write it without space right after it. On the other hand you cannot usually ommit space after "not" operator (you can in Perl though…). So it seems AutoIt indeed is a bit special because there is no ! as a logical operator and the behavior of not operator is different then in other languages I know of. So thank you for an interesting discussion guys :)

Edited by LoWang
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...