Jump to content

AutoIt in a different perspective


Recommended Posts

Threads like always catch my eye. Primarily not because I really want object oriented AutoIt (I do btw - a lot), but because people are using AutoIt in fun and creative ways. That gives you, reader, a pretty good idea of what this thread is all about. It's a mind teaser, to provoke thought.

Look at what Kip has done with his preprocessor (and a history of others before him), the possibilities are seemingly endless. By creating a preprocessor for AutoIt (not the kind that simply improves execution speed), we can do more with the language than what is officially available to us. The question central to this thread is:

What cool and fun things can we do with AutoIt?

I'm always trying out new languages when I get an opportunity. With seeing more and more of other languages always comes envy of other language features. I am quite sure that anyone who reads this and knows another language will go "True, i've always wanted [...] in AutoIt". There are possible through a preprocessor which produces (even neatly looking) AutoIt code to reach this goal.

I've some simple ideas to get the thread started.

When keyword

inspired by await

$finished = False

When PixelGetColor(100, 100) == 0xFF00FF
  MouseClick("Left", 100, 100)
  $finished = True
EndWhen

While Not $finished
  Sleep(100)
WEnd

This can be compiled to:

$finished = False

AdlibRegister("__implDetail__When01", 100)

While Not $finished
  Sleep(100)
WEnd

Func __implDetail__When01()
  If PixelGetColor(100, 100) == 0xFF00FF Then
    MouseClick("Left", 100, 100)
    $finished = True
  EndIf
EndFunc

The trick is to determine the right amount of sleep it needs automagically (it's a private implementation detail after all). Perhaps 100ms is a good default choice, but some will need to define it themselves.

Inline functions (maybe even called delegates)

Inspired by Lua inline functions.

HotKeySet("a",  Func()
         Send("b")
    EndFunc)

Actual code:

HotKeySet("a", "__GenericFunctionName01")

Func __GenericFunctionName01()
  Send("b")
EndFunc

How this works is that any time you use Func() it is replaced with a function name (as string), and the function statements are preprocessed into a new function with that name.

Moar!

Link to comment
Share on other sites

I think the best way to implement this would be a generic preprocessor that then has community written plugins. Ideally it would be AutoIt, as we all know that well, but I doubt it's feasible as a plugin language. The plugins would install hooks for the different syntactical elements and could then have a series of methods they can call on the script to change the output.

Link to comment
Share on other sites

Man if we had closures and alike, I'd die a little.

Ternary would also be nice.

$aVal = true
$myVal = ($aVal ? "hello" : "world")

But I don't think that can be as easily processed as what you mentioned Manadar.

I can see this turning into a "I wish AutoIt had..." list. But hey..

That can be preprocessed into:

$aVal = true
$myVal = _Iif($aVal, "hello", "world")

Have a look in the help file for _Iif. We can include it if it's not already in the script.

It stands for "if and only if". I didn't know that for a long time. http://en.wikipedia.org/wiki/If_and_only_if

Also, let's make this an "I wish AutoIt had .. and let's add it right now" thread.

Edited by Manadar
Link to comment
Share on other sites

  • 1 year later...

I was taking a shower and came up with this:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)

Func a($b = c())
  Return $b
EndFunc

Func c()
  Return 5
EndFunc

For the uninitiated, the above yields: Badly formatted "Func" statement.: Func a($b = c())

Preprocesses into:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)

Func a($b = Default)
   If $b = Default Then $b = c()
   Return $b
EndFunc

Func c()
   Return 5
EndFunc

Abusing (or misusing) Default for this purpose yields a leaky abstraction. Perhaps it is better to use @NUMPARAMS for this purpose.

Link to comment
Share on other sites

I was taking a shower and came up with this:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)

Func a($b = c())
Return $b
EndFunc

Func c()
Return 5
EndFunc

For the uninitiated, the above yields: Badly formatted "Func" statement.: Func a($b = c())

Preprocesses into:

Func a($b = Default)
If $b = Default Then $b = c()
Return $b
EndFunc

Abusing (or misusing) Default for this purpose yields a leaky abstraction. Perhaps it is better to use @NUMPARAMS for this purpose.

Why do you concider using Default in this manner to by a misuse of Default. I often use it like this.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Why do you concider using Default in this manner to by a misuse of Default. I often use it like this.

I dug up an old thread, so it's possible you didn't read the first post. I'm looking at ways to use a preprocessor to transparently add functionality to AutoIt.

If you look at this bit of code:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)
ConsoleWrite(a(Default) & @CRLF)

Func a($b = c())
    Return $b
EndFunc

Func c()
    Return 5
 EndFunc

It's the functional equivalent of:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)
ConsoleWrite(a(Default) & @CRLF)

Func a($b = 5)
    Return $b
 EndFunc

Which has the following output:

3
5 (The result of calling c, since $b was not passed)
Default

Where as if you preprocess it into what I described above:

ConsoleWrite(a(3) & @CRLF)
ConsoleWrite(a() & @CRLF)
ConsoleWrite(a(Default) & @CRLF)

Func a($b = Default)
    If $b = Default Then $b = c()
    Return $b
EndFunc

Func c()
    Return 5
EndFunc

The result is:

3
5
5

This is how an implementation detail in a preprocessor breaks user code unexpectedly because of the leaky abstraction. You can (I think) fix it by using @numparams.

Edited by Manadar
Link to comment
Share on other sites

Anything that improves on speed of execution and/or coding time, and that eases the programming process, I'm down for it... as long as the additions don't take away from the ease of use of AutoIt and become a complex programming language.

The idea of adding features are great, as long as it doesn't increase the time it takes to get from idea to deployment.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Ternary would also be nice.

Seems like your wish finally came true.

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

When I wrote my first UDF I declared all variables as Local, assuming that just as in perl packages, these variables would only be visible to the functions in the UDF but otherwise hidden for the rest of the script.

Unfortunately this wasn't the case. I think this would be a good feature (data encapsulation), although being somewhat like a closure I can imagine it's very hard to actually implement.

Just my two cents.

Seems like your wish finally came true.

Cool, I was wishing for ternary as well although _Iif() works just fine.

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

_Iif is ugly yea, but I personally haven't run into problems with it sofar. Now I got to find me a piece of wood to knock on...

I agree with your humble opinion though. Ever since I first learned about ternary (PHP) I've used it left and right where I could. It's a great shorthand for simple If...Else statements.

[center]Spiderskank Spiderskank[/center]GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

Link to comment
Share on other sites

as long as the additions don't take away from the ease of use of AutoIt and become a complex programming language.

Also could be stated: "as long as the additions don't take away from the ease of use of AutoIt and become a complex programming language because I don't like change and I don't want to learn."
Link to comment
Share on other sites

_Iif is ugly yea, but I personally haven't run into problems with it sofar. Now I got to find me a piece of wood to knock on...

I agree with your humble opinion though. Ever since I first learned about ternary (PHP) I've used it left and right where I could. It's a great shorthand for simple If...Else statements.

There are times when it's best not to use it though... :)
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...