Composer is dependent on Plaster, which has been abandoned for reasons discussed on its page.
AutoHotkey's lack of tracing garbage collection (to handle, for example, closures) seems to preclude implementing a functional programming language atop it.
Composer is a library of common functional programming constructs that is intended to encourage writing composeable code in AutoHotkey. This is challenging because the built-in commands and functions make heavy use of mutable global variables and goto labels, commands cannot be composed, the call stack size is fixed, tail call elimination is not performed, and anonymous functions and closures are not supported. Code without observable side effects and unstructured control flow (i.e. composeable code) is easier to test and reuse.
Composer requires Plaster for error handling and polymorphism.
It is written in AutoHotkey L v1.
It is currently in a very early state of development. It is incomplete, lacks proper documentation, error handling, and testing. The API is unstable.
Only the constructs necessary to build functions at run time have been completed. Those are Compose, Curry, Delay, and FixArity.
Compose nests a pair of functions, combining them into a single function, like g(f(x)) in mathematics. Composed functions can be composed. It is often used when you want to build a function at run time and need to pass a function's return value to another function, as opposed to passing the function as a value.
Code: Select all
Add2(X) {
return X + 2
}
MulBy5(X) {
return X * 5
}
Add2ThenMulBy5 := Compose.(Func("MulBy5"), Func("Add2"))
MsgBox, % Add2ThenMulBy5.(3) ; Shows: 25
Code: Select all
MyAdd(X, Y) {
return X + Y
}
CurriedMyAdd := Curry.(Func("MyAdd"))
Add8 := CurriedMyAdd.(8)
MsgBox, % Add8.(6) ; Shows: 14
Code: Select all
MyDiv(X, Y) {
return X / Y
}
Delayed7 := Delay.(Func("MyDiv"), [21, 3])
MsgBox, % Delayed7.() ; Shows: 7.000000
Code: Select all
Array1to2 := FixArity.(Array, 1, 2)
MsgBox, % Repr.(Array1to2.()) ; throws Exception("type error",, "FixArity(Func(""Array""), 1, 2).() expected >= 1 argument")
MsgBox, % Repr.(Array1to2.("a", "b")) ; Shows: ["a", "b"]