BoundFunc bound parameters can be accessed via __Item()

Share your ideas as to how the documentation can be improved.
iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

BoundFunc bound parameters can be accessed via __Item()

Post by iseahound » 09 Mar 2021, 00:32

It wasn't obvious to me that one could recover parameters in bound funcs.

Code: Select all

k := (x) => (y) => x  ; k(x, y) takes 2 arguments.
k5 := k(5)            ; k5 is a partially applied function.
MsgBox k5[1]          ; Recovers the bound argument.
https://lexikos.github.io/v2/docs/objects/Functor.htm#BoundFunc

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: BoundFunc bound parameters can be accessed via __Item()

Post by swagfag » 09 Mar 2021, 05:39

well, u cant actually. i found it kinda sus that @lexikos wouldnt document such a feature, so i went to check in the source and in fact there isnt such a feature
Func[] simply invokes the function(the same way Func() would, assuming __Item hasnt been defined)

Code: Select all

#Requires AutoHotkey v2.0-a128-f63b0eb4
MsgBox['helloworld']
so indexing into ur boundfunc doesnt recover anything, ure simply supplying the remaining parameter, calling it, yielding whatever u passed in as the first argument and discarding the second(which is a byproduct of the way uve designed the function)

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: BoundFunc bound parameters can be accessed via __Item()

Post by lexikos » 09 Mar 2021, 16:32

That's not intentional, and it only does it if there are no own properties defined.

Post Reply

Return to “Suggestions on Documentation Improvements”