Jump to content
Robinson1

AutoIT Language: Why BitAND is not an infix statement

Recommended Posts

Posted (edited)

Okay it's about the style of the AutoIT Language. Concerning: 
BitAND, BitOR, BitXOR, BitXOR, 
BitShift, BitRotate

That's a very simple but fundamental question:
 Why BitAND is not  infix?

In most other common programming languages it is.
Let's take JavaScript. Here I write:

Result = Value & Mask


But on AutoIT it's

$Result = BitAND ( $Value , $Mask )

That's more the Lisp / prefix way.
While the logical and is indeed infix
 

$bIsEnable = $bIsGUI_chkEnabled and $bIsGUI_chkChecked


So I wonder why it is like this.
What is the Idea behind this language design decision?  

Okay Autoit is a matured Language but yeah -  It's never to late for a change.
Wasn't there ideas to unify it any way?
So we also make the 'Bit' operations infix as well?
... while Just keeping the 'old' prefix version -for backwards compatibility - as well.


UPDATE #1: Now I created a ticket for this:
https://autoitscript.com/trac/autoit/ticket/3752

Well to generalise/modulate It more I may bring it down to the Subject Verb Object  thing you have with language.
"I go swimming" that's S-V-O or some infix.
"Swimming I go". is O-S-V - postfix and sound much like yoda-style. While
"go I swimming" is V-S-O - prefix and 'feels' more like kinda question.

There is no right or wrong here - however personally I find infix is most appropriate here.

Edited by Robinson1

Share this post


Link to post
Share on other sites

Each language has its idiosyncrasies.  The form is less important than the result.  As long as we have the method to perform the task, I don't care how it is done.  I have learned so many programming languages over the years, that it is not bothering to use one way or the other.  What you are asking is kind of puerile.  In my opinion, you are implying that everybody should speak english, because it would be nice to be all identical.  It doesn't work that way.

Share this post


Link to post
Share on other sites

Cool thanks for your reply.

6 minutes ago, Nine said:

The form is less important than the result.  As long as we have the method to perform the task, I don't care how it is done. 

Fully go ya point. The pragmatic programmer. No matter how it's done - as long as it is done.

However I see coding and code as kinda of art.
So it that context such puerile questions matters. :)

Share this post


Link to post
Share on other sites

It's because AutoIt results from an incremental (spiral-type) development for interactive automation, not as a full-fledged language.

Your remark applies to Mod() as well, something we all can live with quietly.

I see you feel it matters, so you'd be more than happy with a complete functional language like Wolfram Mathematica.


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)

Share this post


Link to post
Share on other sites
Posted (edited)
10 hours ago, jchd said:

Your remark applies to Mod() as well

Good point. Mod() is good candidate for a mod and a POC. :) 
Nice to have some challenges. Doing MATE gave me some good inside and idea how AutoIt works - I guess just for fun I may create some MODed AutoIT that'll accept

 

$result = mod(3,2) 

as well as 

$result = 3 mod 2

Token opcodes  0x40 .. 0x58 are in used for operators.
0x59 .. 0x7E are still *free* to use.
So I may use 0x60 for the new  infix mod operator

Edited by Robinson1

Share this post


Link to post
Share on other sites

Stay home but don't hold your breath.


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)

Share this post


Link to post
Share on other sites

Im not privy to the specifics but it just has to do with the way autoit was written as been said before.  The best guess would be how autoit handles various variables and how it guesses what exactly the expected outcome is supposed to be.

The & symbol is used when combining strings so the language assumes that the variables in question are strings. Doing simple tests will help you understand this better.

$a=1+2

MsgBox('','',$a & VarGetType($a))   ;this results in a 3 and type int32

$a=$a & 3

MsgBox('','',$a & VarGetType($a)) ;this results in a 33 and type string

the point is if you use some type of operation that results in binary if you try to bitand() said binary  using & it will just be a string and not be interpreted correctly further on down the line if its being fed into a function thats expecting raw bytes but gets a string instead.  That string will be converted into the binary representation of the ascii characters that were sent or the function will fail entirely either way the result is not going to be the expected outcome.

you also have to think of these keywords and operators as functions.  Using the keyword "and" really is the equivalent to

$x= $y and $z

;gets interpreted in my imagination as something like

$x=and($y,$z)

;which is defined somewhere else probably lala land...

bool and(auto arg1,auto arg2)
{
    if ((arg1 == true) && (arg2 == true))
        {return true
        }
    else
        {return false
        }

}

you start to understand why this all becomes necessary.  I guess its possible to have multiple functions named and() but they'd have to be in separate namespaces and then the issue becomes short of specifying variable types or return types how does the interpreter decide what to do with what is being sent to it? If that becomes necessary then its starting to flush the simplicity aspect of the language down the drain.  

don't ask me why mod() exists vs % symbol. apparently % doesn't exist. 

That all being said using bitand() = & once it goes through the compiler.  If you really want to start asking some serious questions you should probably be asking why we arn't just coding in machine code.  bc afterall we could just eliminate all this business and just type it out in 1s an 0s.  


Spoiler

 

 

Share this post


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.

  • Similar Content

    • By j0kky
      Hi guys,
      Bitwise operations in Autoit is possible only till 32 bit integers, but sometimes WinAPI requires to process 64 bit vectors... so?
      So you can use this little UDF to handle properly those integers!
      Func _BitAND64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitAND($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueANDed[64], $i For $i = 0 To 63 $aValueANDed[$i] = ($iValue1[$i] And $iValue2[$i]) ? 1 : 0 Next Return __BinToDec64($aValueANDed) EndFunc ;==>_BitAND64 Func _BitOR64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitOR($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueORed[64], $i For $i = 0 To 63 $aValueORed[$i] = ($iValue1[$i] Or $iValue2[$i]) ? 1 : 0 Next Return __BinToDec64($aValueORed) EndFunc ;==>_BitOR64 Func _BitXOR64($iValue1, $iValue2) If Not ((VarGetType($iValue1) = "Int64") Or (VarGetType($iValue2) = "Int64")) Then Return BitXOR($iValue1, $iValue2) $iValue1 = __DecToBin64($iValue1) $iValue2 = __DecToBin64($iValue2) Local $aValueXORed[64], $i For $i = 0 To 63 $aValueXORed[$i] = (($iValue1[$i] And (Not $iValue2[$i])) Or ((Not $iValue1[$i]) And $iValue2)) ? 1 : 0 Next Return __BinToDec64($aValueXORed) EndFunc ;==>_BitXOR64 Func _BitNOT64($iValue) If Not (VarGetType($iValue) = "Int64") Then Return BitNOT($iValue) $iValue = __DecToBin64($iValue) For $i = 0 To 63 $iValue[$i] = Not $iValue[$i] Next Return __BinToDec64($iValue) EndFunc ;==>_BitNOT64 Func __DecToBin64($iDec) Local $tDec = DllStructCreate("int64 num"), $aBin[64], $bBit, $i $tDec.num = $iDec For $i = 0 To 63 $bBit = (Mod($tDec.num, 2) ? 1 : 0) $aBin[63 - $i] = $bBit $tDec.num = Floor($tDec.num / 2) Next Return $aBin EndFunc ;==>__DecToBin64 Func __BinToDec64($aBin) Local $tDec = DllStructCreate("int64 num"), $i If $aBin[0] Then $tDec.num += 0x8000000000000000 ;2^63 = 9223372036854775808, but for Autoit the world ends at 9223372036854775807 (2^63 - 1) For $i = 1 To 63 If $aBin[$i] Then $tDec.num += 2 ^ (63 - $i) Next Return $tDec.num EndFunc ;==>__BinToDec64 If you are working with unsigned 64 bit integers and these functions return a negative value, don't worry, bitwise operations come out well, but Autoit manages all numbers as signed integers.
    • By 232showtime
      good day,
      Please I need a little help ive been trying to find where I got this magic number and I remember it was for Minimize, but I really dont remember where I got this. Last thing I remember i was reading the help file and saw this minize magic numbers, but I cant find it anymore, I dnt wnt to use this magic number anymore OMG! please help...
      here it is.
      Local $hAaSf = "C:\Main.xlsx" ;Main excel Local $iStateAsf = WinGetState($hAaSf) BitAND($iStateAsf, 16)  
    • By Ruigerock
      Goodmorning people,
      I've been busy with a usefull script for work but one part is not working as I thought it would.
      I took the known _IsEnabled function, change 3 words to have it check an disabled checkbox status
      The code below is not the actual script but it demonstrates the error.
      If you select "Check all but disabled" it will select all 3 checkboxes which is not my intention, ehh help?
      #include <MsgBoxConstants.au3> #include <GuiConstants.au3> #include <GuiConstantsEx.au3> Local $box[03] GuiCreate("Test", 300, 300, -1, -1) $box[00] = GUICtrlCreateCheckbox("Unchecked", 20, 40, 240, 20) $box[01] = GUICtrlCreateCheckbox("Disabled", 20, 60, 240, 20) $box[02] = GUICtrlCreateCheckbox("Checked", 20, 80, 240, 20) GUICtrlSetState($box[00], $GUI_UNCHECKED) GUICtrlSetState($box[01], $GUI_DISABLE) GUICtrlSetState($box[02], $GUI_CHECKED) $Button_Ok = GUICtrlCreateButton("Check all but Disabled", 20 , 110, 180, 45) $Button_KO = GUICtrlCreateButton("UnCheck all", 20 , 155, 180, 45) GuiSetState() Func _IsDisable($control) Return BitAND(GUICtrlRead($control), $GUI_DISABLE) = $GUI_DISABLE EndFunc While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $Button_Ok For $i = 0 to 2 If _IsDisable($box[$i]) Then GUICtrlSetState($box[$i], $GUI_UNCHECKED) Else GUICtrlSetState($box[$i], $GUI_CHECKED) EndIf Next Case $msg = $Button_KO For $i = 0 to 2 GUICtrlSetState($box[$i], $GUI_UNCHECKED) Next EndSelect WEnd
    • By PhoenixXL
      Rich-Edit Predict Text UDF

      Working
      It sub classes the rich-edit control and matches the current word through the Database
      & sets selection in accordance.

      For Edit Controls look

      Functions
      Predicts Text from an User-Defined Database. Sets the Predicted Text when Enter is pressed. Pressing Backspace deletes the previously typed character. Support Editing, Overwriting, Updating, Deleting the Database. Has the Feature to add New words the user types in the control, to the Database. Supports Sensitive and In-Sensitive Prediction. Currently Supports Auto-completion only. Rich Edit Controls only supported Future Updates​Support Auto-suggestion. Note That if you set a Password Char for the Edit Box the Prediction will automatically get Unregistered.This UDF requires Beta Release 3.3.9.4++ [beta-Oct-2012]

      Index

      ; #CURRENT# ===================================================================================================================== ;_RegisterPrediction ;_UpdatePredictList ;_UnRegisterPrediction ;_RegisterListingSpaceWords ;_RegisterListingNewWords ;_GetSelectedText ;_GetListCount ;_GetCurrentWord ;_GetCaretOffset ; =============================================================================================================================== ; #INTERNAL_USE_ONLY# =========================================================================================================== ;_New_WndProc ; AddToArray ; MakeArray ;_RichEdit_SubClass ;_AutoExit ;_PredictText ;_PredictSpaceText ;_SetSelection ;_MatchString ;_CtrlSetStyle ;_CtrlGetStyle ;_RemoveBit ; ===============================================================================================================================
      Please Notify for any other Updates and Bugs.

      Change-log
      v1.0 - First Release
      v1.1 - Fixed a bug.

      RichEditPredictText [uDF] v1.1
      v1.1 RichEditPredictText UDF.7z
      Previous Downloads : 80

      Regards
      Phoenix XL
×
×
  • Create New...