Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

AutoIt in a different perspective


  • Please log in to reply
35 replies to this topic

#1 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 23 May 2011 - 02:35 PM

Threads like AutoIt object oriented preprocessor 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!







#2 Mat

Mat

    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,066 posts

Posted 23 May 2011 - 03:23 PM

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.

#3 James

James

    Universalist

  • MVPs
  • 10,336 posts

Posted 23 May 2011 - 04:35 PM

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..

#4 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 23 May 2011 - 05:49 PM

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, 23 May 2011 - 05:51 PM.


#5 James

James

    Universalist

  • MVPs
  • 10,336 posts

Posted 23 May 2011 - 06:23 PM

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


I wish AutoIt had....
  • Closures
  • Ternary
  • Was object orientated, optionally like PHP say....
All I can think of for now. I quite like the limitations in place, except for those mentioned above.

#6 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 23 May 2011 - 06:41 PM

I wish AutoIt had....

  • Closures
  • Ternary
  • Was object orientated, optionally like PHP say....
All I can think of for now. I quite like the limitations in place, except for those mentioned above.

And how would you implement them? That's key.

#7 Richard Robertson

Richard Robertson

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 10,324 posts

Posted 23 May 2011 - 06:57 PM

New syntax is always fun to write. That's one of the things that always hung me on AutoIt.Net. There are features that .Net would require (or would be required for the AutoIter to target .Net) that are just weird to design while still remaining inside the AutoIt style.

#8 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 17 September 2012 - 10:00 AM

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.

#9 Bowmore

Bowmore

    Feinschmecker

  • Active Members
  • PipPipPipPipPipPip
  • 833 posts

Posted 17 September 2012 - 01:07 PM

I was taking a shower and came up with this:



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

#10 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 17 September 2012 - 01:17 PM

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, 17 September 2012 - 01:23 PM.


#11 czardas

czardas

  • MVPs
  • 7,049 posts

Posted 17 September 2012 - 01:28 PM

Interesting thread Manadar. Been looking at this wiki article, though I imagine you are familiar with the complete history of this subject: Law of Leaky Abstractions states:

All non-trivial abstractions, to some degree, are leaky.


How long was you in the shower?

#12 Manadar

Manadar

         

  • MVPs
  • 10,866 posts

Posted 17 September 2012 - 01:39 PM

How long was you in the shower?

10 minutes, I'm a huge fan of Joel Spolsky. His blog is great.

Edited by Manadar, 17 September 2012 - 01:40 PM.


#13 czardas

czardas

  • MVPs
  • 7,049 posts

Posted 17 September 2012 - 01:50 PM

The theory of programming is very interesting indeed. I sometimes wish I had discovered this much sooner, but that's how the cookie crumbles. I hope the shower didn't leak as much as the code. :rolleyes:

#14 Mechaflash

Mechaflash

    Sons of Anarchy

  • Active Members
  • PipPipPipPipPipPip
  • 1,377 posts

Posted 17 September 2012 - 02:11 PM

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.
“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.”

#15 guinness

guinness

    all-consuming swarm in inconspicuous disguise

  • Developers
  • 17,503 posts

Posted 17 September 2012 - 04:10 PM

Ternary would also be nice.

Seems like your wish finally came true.
  • James likes this

Example List: _AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_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()CodingDirToHTML5FileInstallrGeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()LockFile()Mapping CtrlIDsParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...
Updated: 26/09/2014


#16 dany

dany

    Polymath

  • Active Members
  • PipPipPipPip
  • 229 posts

Posted 17 September 2012 - 04:46 PM

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.

Spiderskank Spiderskank

GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

#17 James

James

    Universalist

  • MVPs
  • 10,336 posts

Posted 17 September 2012 - 04:51 PM

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

It's a feature that IMHO should always have been in the language :) _Iif is ugly and limited.

#18 dany

dany

    Polymath

  • Active Members
  • PipPipPipPip
  • 229 posts

Posted 17 September 2012 - 05:16 PM

_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.

Spiderskank Spiderskank

GetOpt Parse command line options UDF | AU3Text Program internationalization UDF | Identicon visual hash UDF

#19 jaberwacky

jaberwacky

    RegExp("\m/")

  • Active Members
  • PipPipPipPipPipPip
  • 3,205 posts

Posted 17 September 2012 - 07:58 PM

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."

#20 James

James

    Universalist

  • MVPs
  • 10,336 posts

Posted 17 September 2012 - 08:08 PM

_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... :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users