Jump to content

Functions are now first class objects


Go to solution Solved by Mat,

Recommended Posts

Hello there,

Sorry for my lack of understanding, could anyone please show me the benefits or technical example of calling function through the variables ?

I read the example posted by Melba23, but not understanding that how should I use this feature in my future scripts.

Thanks in Advance.

 

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

  • Solution

Functions are not first class objects, as they cannot be created at runtime (yet). This is the first step towards possibly implementing that in the future. The correct term would be second class, in a similar way to C's function pointers.

A very common design pattern in other languages is a callback system like so: 

Local $a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

_EnumArray($a, MyCallback)

Func MyCallback($v)
    ConsoleWrite($v & @LF)

    Return True
EndFunc   ;==>MyCallback



; Calls $Callback for each element in the array.
; If the callback returns FALSE then enumeration is stopped.
; Returns TRUE if the callback returned TRUE for all elements.
Func _EnumArray($a, $Callback)
    For $i = 0 To UBound($a) - 1
        If Not $Callback($a[$i]) Then Return False
    Next

    Return True
EndFunc   ;==>_EnumArray

This is actually how the Enum* winapi functions work (though autoit handles this for you in WinAPI.au3 to return an array).

This functionality was available previously with Call() and passing string function names. Advantages of this system are:

  • AutoIt can check the functions for you, and fails with the correct error message if these are incorrect (e.g. incorrect number of parameters).
  • AutoIt will also report an undeclared function name when you pass it to the function, rather than when you try and call it which could be somewhere further down the line making it difficult to trace the real problem.
  • Works with obfuscator even if you use a variable rather than string literal.
  • This is doing it properly.

The main advantage you will see in every day use is that functions like HotkeySet can now take a function name as the second argument, rather than a string. This will report errors correctly as per point 2 above, though it appears that is not working correctly at the moment. I will report the bug now (assuming it is a bug as it means typos in keywords won't be reported as errors).

If I'm honest, the main reason I like this change is the last point above: This is doing it properly and using string function names was not a good design choice in the first place (though was probably a lot easier to implement).

Edited by Mat
Link to comment
Share on other sites

@Mat - In your example how does MyCallback return FALSE?

kylomas

 

MyCallback is just an example of any user supplied function, and _EnumArray would probably be in a library.

The user might want MyCallback to only process elements until it finds a certain element, so it would return true until it reached the element and then return false.

Since arrays are easy to pass around in AutoIt there isn't really a case where this provides new functionality and something you couldn't do before. It's just something you can use if you want to.

Link to comment
Share on other sites

Functions in AutoIt I left were first class entities. They were first class functions. This isn't arguable, not a bit.

After I left Jon did what's called cherry picking (and later fine tuning through beta testing, something I wasn't allowed to do unfortunately). Appereance of some new func related built-in functions suggest that Jon doesn't understand the concept fully, or maybe doesn't use AutoIt much to see what's he doing wrong. He managed to reduce the feature to a level when it's valid to ask why it was added at all.

This feature was meant to add new power to AutoIt as programming language and right now it's way not to use "string". My heart breaks when I see this.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Moderators

trancexx,

Then you should have stayed and helped develop AutoIt rather than resigning as a developer and continually bitching from the sidelines. :naughty:

We have all had more than enough of this never-ending carping from you - Jos has asked and now I am telling you to stop it. AutoIt is advancing in the direction that the original author wishes and if you do not like it then you know what you can do. :mad:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

trancexx,

Then you should have stayed and helped develop AutoIt rather than resigning as a developer and continually bitching from the sidelines. :naughty:

What I should have or have not is not up to you to say.

We have all had more than enough of this never-ending carping from you - Jos has asked and now I am telling you to stop it. AutoIt is advancing in the direction that the original author wishes and if you do not like it then you know what you can do. :mad:

M23

I don't care about what "you" had enough of. I don't care about what Jos said and I don't care about what you say. You know what you two can do.

To paraphrase you... All clear? :)

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Moderators

trancexx,

 

All clear?

Quite - I was expecting a response like that from you but I am disappointed to see my expectations confirmed. :(

And I hope that it is equally clear to you that you have now had your final warning. So please no more complaining about the way AutoIt is developing - you had your chance to influence it, but that time has now gone. Let it drop. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Functions in AutoIt I left were first class entities. They were first class functions. This isn't arguable, not a bit.

After I left Jon did what's called cherry picking (and later fine tuning through beta testing, something I wasn't allowed to do unfortunately). Appereance of some new func related built-in functions suggest that Jon doesn't understand the concept fully, or maybe doesn't use AutoIt much to see what's he doing wrong. He managed to reduce the feature to a level when it's valid to ask why it was added at all.

This feature was meant to add new power to AutoIt as programming language and right now it's way not to use "string". My heart breaks when I see this.

Give Jon a chance, he's taken a big step back since when you left, so he can start moving forward on his own terms. So far he seems to be putting the time and effort in and I think he'll make progress.

New features/functions have been almost entirely from MVP requests. Adding FuncName() is probably going to cause problems (or just return blank for anonymous functions) when/if functions do become first class, that's not a reflection on how much Jon understands what you were trying to do.

You were ahead of your time, but refused to compromise, so everyone loses out unfortunately. And I think you are going to continue to see features you started implementing being "cherry picked" in a similar way to this I'm afraid.

Link to comment
Share on other sites

  • Developers

I don't care about what "you" had enough of. I don't care about what Jos said and I don't care about what you say. You know what you two can do.

 

We knew already for a while that you don't care about anything else than yourself, but what really puzzles me is why you stick around moaning about it all like a little kid.

Why this urge to prove whatever it is you want to prove or is it just that you take pleasure from all of this?

Either way... grow up or simply go a play somewhere else.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Give Jon a chance, he's taken a big step back since when you left, so he can start moving forward on his own terms. So far he seems to be putting the time and effort in and I think he'll make progress.

 

New features/functions have been almost entirely from MVP requests. Adding FuncName() is probably going to cause problems (or just return blank for anonymous functions) when/if functions do become first class, that's not a reflection on how much Jon understands what you were trying to do.

 

You were ahead of your time, but refused to compromise, so everyone loses out unfortunately. And I think you are going to continue to see features you started implementing being "cherry picked" in a similar way to this I'm afraid.

It's not true I refused to compromise. Who told you that? If that's what you were told then you were being lied to.

I trust Jon almost completely. He's extraordinary figure. I can understand reasons for all of his actions because there is much logic involved, even though our logic sometimes differentiates particularly when human relations are involved. It's only his dogs that scare me to death.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Administrators

It's not true I refused to compromise. Who told you that? If that's what you were told then you were being lied to.

 

 

I did.  You were asking me to de-MVP de-Dev you because I wasn't able to be around.  I tried to talk you out of it by saying that I'd make time and as part of that I wanted to get a stable release out ASAP. I went though the changes, decided which ones I wanted to keep and which to cut - some permanently.  Pages of text later I gave up after this comment:

 

 I may accept it for some things, but for thing that's really important to me I won't.

 

Then I did as you asked an de-Deved you. And then I've since spent 6 hours a day for the last 4 weeks trying to make the extact feature set I asked of you to start with a reality.  I was hoping that when you saw I was willing to get things moving and a release was actually going to happen that you'd help but I think it's a lost cause and I'm better off relying on myself - shit programmer that I am or not.

Thread closed. Take it to PM if you wish but I'm sick this place today and I'm off out.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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