Let's assume that there is a function that expects another function as an argument.
One way to use that:
Another way:
The desired way with the hypothetical function "BindFunction":
(The example code should highlight specific aspects of these approaches. That's the reason for the different signatures of the sort function.)
Is something like that possible? Do you think that it would be useful?
Func GetSortedListOfVillains (ByRef $hero, Const ByRef $sortingAlgorithmOfEvil) ; That will take a while, so fight with swords while riding on chairs (xkcd.com/303/). Local $villains = [$evilOverlord] ; should be global _ArrayConcatenate ($villains, VisitGhibliHills ($hero)) _ArrayConcatenate ($villains, VisitForestOfInconvenience ($hero)) _ArrayConcatenate ($villains, VisitHillsOfModerateEvil ($hero)) _ArrayConcatenate ($villains, VisitMountDoom ($hero)) $sortingAlgorithmOfEvil ($villains) Return $villains EndFunc
Global $Sort_Arguments ; ... $Sort_Arguments = ["evilsort", $SORT_IGNORECASE] ; Let's assume that you're using a compiler which translates this into valid AutoIt. GetSortedListOfVillains ($theHero, Sort) ; ... Func Sort (ByRef $array) If Not IsArray ($Sort_Arguments) Then Return SetError (...) ; I changed this function yesterday. Use the specified sorting algorithm and silently ignore any other arguments. ; Bonus points for silently changing the meaning of an argument. EndFunc
GetSortedListOfVillains ($theHero, SpecialEvilSortUsingAUniqueVillainIdList) ; ... Func SpecialEvilSortUsingAUniqueVillainListId (ByRef $array) ; this is the id of the list v Return Sort ("evilsort", 16372, $array) ; That's a magical number, but I can't pass it as an argument. ; And I need to create a separate function for every used combination of id and sorting algorithm. EndFunc
Is something like that possible? Do you think that it would be useful?