Sign in to follow this  
Followers 0

AutoIt in a different perspective

36 posts in this topic

Posted

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!

Share this post


Link to post
Share on other sites



Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted (edited)

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

Share this post


Link to post
Share on other sites

Posted

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?

Share this post


Link to post
Share on other sites

Posted (edited)

How long was you in the shower?

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

Share this post


Link to post
Share on other sites

Posted

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:

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

Ternary would also be nice.

Seems like your wish finally came true.
James likes this

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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.

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted

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

Share this post


Link to post
Share on other sites

Posted (edited)

Ternary is too. This reminds me, I recently discovered some mistakes in the (my own) documentation, I need to update it. It's a job for later on today.

Edited by czardas

Share this post


Link to post
Share on other sites

Posted (edited)

I recently discovered some mistakes in the documentation, I need to update it. It's a job for later on this today.

Great. Just post in the help file thread I would look at it in due course.

Edit: Whoops! I re-read it and realised it was your documentation.

Edited by guinness
czardas likes this

Share this post


Link to post
Share on other sites

Posted

High order functions, objects, threads etc are great when writing larger programs with AutoIt. In practice most of the time I just needed a simple code snippet (which is mostly available on the wiki if not in the help file).

Another perspective is not from a language construct, but from a first time programmer (where nothing is implied). For example I had some moments where I was confused on its Basic-like syntax. Some examples:

1) Equality

When you compare something it must be of the same type, for example

; If int = int then true

If 1 = 1 then ConsoleWrite("true")

; Ok, that works as expected. However the following valid statement returns always false

If 1 = not(2) then ConsoleWrite("true")

; So I compared an int with the boolean false, so I have to write something like this:

If 1 <> 2 then ConsoleWrite("true")

or

If StringCompare ( "1", "2", 1) <> 0 then ConsoleWrite("true")

To get equality between int, string. Such syntax would be clearer to me

If 1 not = 2 then ConsoleWrite("true")

or

If 1 != 2 then ConsoleWrite("true")

2) arrays

To work with arrays you can typically use Basic statements like Ubound, Dim, Redim

With the current use function naming conventions I would opt for

Ubound - 1 --> ArraySize

ReDim --> ArrayResize

Which new programmer would search for Ubound or ReDim? I also got confused that most of the time you can use array[0] to get the array size, while on other occasions you need Ubound.

Side note: I would like to work with (i.e. Vector) collections, instead of just arrays. Needs less low level work.

3) The following seems to me some historic usage of the Basic syntax.

For example the conditional statement have the following syntax

If --> EndIf

Select --> EndSelect

Switch --> EndSwitch

With --> EndWith

But loops

While --> WEnd

For --> Next

Do --> Until

When just looking at logic of the loop this seems logical, but when looking to the whole language why not do the following:

While --> EndWhile

For...To --> EndFor

Foreach ... in .. EndForeach

Do --> EndDo

If the logic on loops needs to be kept then I would suggest to use While --> Done, instead of While --> WEnd

3) Besides includes it would be nice to define a package/project, so when working with multiple file the init (main) file will always be started.

4) Template expression

This would make codes with multiple lines easier to work with. Like I posted on example script: ression

New JVM languages like Kotlin, Xtend and Ceylon have good support for this.

5) RunDos

When I first started to use _RunDos I would expect that it equals to Run(@ComSpec & " /c " & 'commandName', "", @SW_HIDE). Then there is ConsoleWrite/ConsoleRead which only works in a CUI. Found it all a bit confusion when working with the console. Couldn't this be reworked (like Mat's UDF for this)?

Ok, in my examples I still wrote about some language constructs like packages, collections and template expressions, but I hope the examples on a different perspective from a newbie point-of-view adds also something to this discussion.

Share this post


Link to post
Share on other sites

Posted

3) 'End' keyword to close all control structures. Preprocessor does an automatic conversion to correct keyword to match last used control structure. For example, input:

While True
Sleep(500)
End

Preprocesses into:

While True
Sleep(500)
WEnd

It's a trivial thing, but can be convenient.

4) Multi-line strings. Why didn't I think of that? Pick any syntax (up for debate on this), I would prefer:

$a = [[This is
a multi
line string.]]

Preprocesses into:

$a = "This is" & @CRLF & _
"a multi" & @CRLF & _
"line string."

@CRLF, @LF or @CR can be determined by what characters you use in your source file.

Share this post


Link to post
Share on other sites

Posted

4) Multi-line strings. Why didn't I think of that? Pick any syntax (up for debate on this), I would prefer:

$a = [[This is
a multi
line string.]]

Preprocesses into:

$a = "This is" & @CRLF & _
"a multi" & @CRLF & _
"line string."

Like HereDoc strings. Yea that would be a very nice addition, got my vote. As far as syntax goes, [[Lua or the more unofficial standard <<HEREDOC style, well, I'd go for the <<HEREDOC style, Lua is somewhat ambiguous imho as it looks like an array assignment.

$a = <<HEREDOC_END
This is
a multi
line string.
HEREDOC_END

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
Sign in to follow this  
Followers 0




  • Recently Browsing   0 members

    No registered users viewing this page.