We could avoid breaking older script if we make boundfuncs completely consistent with func objects in every aspect. Also this is a reaction towards all your arguments Lexikos.By your own admittance, that isn't the only use of IsFunc. It is not acceptable to break scripts that rely on previously documented behaviour just because they're in the minority.
Make bound funcs consistent with func objects
Re: Make bound funcs consistent with func objects
Recommends AHK Studio
Re: Make isFunc return 1 for bound funcs
just me wrote:Topic: Make isFunc return 1 for bound funcs
My questions: So why should IsFunc() return True? How would you use such a return value?
Your answer:
Code: Select all
mc1 := new MyClass(Func("Foo"))
mc2 := new MyClass(Func("Foo").Bind(1))
Foo(optional := 0){
[...]
}
Class MyClass {
__New(callback){
if (IsFunc(callback)){
this.callback := callback
} else {
msgbox Callback is not a Func object or BoundFunc
ExitApp
}
}
}
If writing a library that accepts callbacks, a simple, consistent check that a valid callback was passed would be nice IMHO.
Re: Make bound funcs consistent with func objects
@evilC. I agree that identifying callables is desirable in many cases, but I disagree with using isFunc for it. Here is a perfectly valid use of isFunc, which would break if boundFuncs returns anything but 0 (or "").
Imo, it would be safer to have abs(callable) return -1, any script that risk passing a callable to abs is already broken anyways. To me, isCallable() returning true if a variable is callable would be the most logical.
Cheers
Code: Select all
mc1 := new MyClass("Foo")
mc2 := new MyClass(Func("Foo"))
Foo(ref){
; [...]
}
Class MyClass {
__New(callback){
; A reference to the caller is bound to the callback function.
if (IsObject(callback) && IsFunc(callback))
this.callback := callback.bind(this)
else if isFunc(callback)
this.callback := func(callback).bind(this)
else
throw
}
}
Cheers
Spoiler
Re: Make bound funcs consistent with func objects
Why would that cause an issue if boundFuncs were completely consistent with func Objects?Helgef wrote:@evilC. I agree that identifying callables is desirable in many cases, but I disagree with using isFunc for it. Here is a perfectly valid use of isFunc, which would break if boundFuncs returns anything but 0 (or "").Code: Select all
mc1 := new MyClass("Foo") mc2 := new MyClass(Func("Foo")) Foo(ref){ ; [...] } Class MyClass { __New(callback){ ; A reference to the caller is bound to the callback function. if (IsObject(callback) && IsFunc(callback)) this.callback := callback.bind(this) else if isFunc(callback) this.callback := func(callback).bind(this) else throw } }
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
So you think that BoundFuncObject.Bind(Value) should be valid?nnnik wrote:Why would that cause an issue if boundFuncs were completely consistent with func Objects?
Re: Make bound funcs consistent with func objects
Yeah it should be valid for consistency. It will return another bound func with an additionaly parameter in it's array.just me wrote:So you think that BoundFuncObject.Bind(Value) should be valid?nnnik wrote:Why would that cause an issue if boundFuncs were completely consistent with func Objects?
Thats what complete consistency means just me.
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
So you want to bind additional parameters to a function object whitout knowing if and how many parameters are already bound? Good luck, nnnik!
Re: Make bound funcs consistent with func objects
I don't need to know how many parameters are bound. I just need to know that the next parameters I bind can be bound ( .minParameters/.maxParameters ).just me wrote:So you want to bind additional parameters to a function object whitout knowing if and how many parameters are already bound? Good luck, nnnik!
Why would it make a difference if parameters are already bound. If you program properly it shouldn't matter.
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
No let me correct that in all cases it shouldn't matter
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
I'd say it should matter in every case. If you create a BoundFunc object with bound parameters, you can rely on the fact that these parameters are passed to the function as the first parameters. This order will be changed if you add additional parameters afterwards.
MinParams() and MaxParams() don't take account of pre-bound parameters.nnnik wrote:I don't need to know how many parameters are bound. I just need to know that the next parameters I bind can be bound ( .minParameters/.maxParameters ).
Re: Make bound funcs consistent with func objects
You misunderstand. I'm saying that in my implementation it should respect this exactly:just me wrote:MinParams() and MaxParams() don't take account of pre-bound parameters.nnnik wrote:I don't need to know how many parameters are bound. I just need to know that the next parameters I bind can be bound ( .minParameters/.maxParameters ).
Let me reexplin how I see bound funcs. Towards me bound funcs are just like functions.
Code: Select all
Message( title, msg, exitApp = 0 )
{
Msgbox % "title: " . title . "`nmsg: " . msg
if ( exitApp )
ExitApp, % exitApp
}
func( "Message" ).bind( "Test Script" )
Code: Select all
Message( title, msg, exitApp = 0 )
{
Msgbox % "title: " . title . "`nmsg: " . msg
if ( exitApp )
ExitApp, % exitApp
}
Message.bind( "Test Script" )( msg, exitApp = 0 )
{
title := "Test Script"
Msgbox % "title: " . title . "`nmsg: " . msg
}
I don't understand how the new parameters that will be added are not added as the first parameters, though the function that was explicitly passed towards the .bind function?
Could you give an example that shows what you mean?
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
Honestly, I don't understand what you mean.
Re: Make bound funcs consistent with func objects
Since you ask I assume your definition of consistency implies there wouldn't be a problemnnnik wrote:Why would that cause an issue if boundFuncs were completely consistent with func Objects?
Re: Make bound funcs consistent with func objects
To help me understand your concept, would you please answer the following questions?
Code: Select all
; --------------------------------------------------------------------------------------------------------------------------------
; Func object
FO := Func("Function")
MsgBox, 0, Func Object, % "MinParams: " . FO.MinParams . " - MaxParams: " . FO.MaxParams ; 2 - 2
FO.Call("FO Title", "FO Text") ; -> FO Title - FO Text
; --------------------------------------------------------------------------------------------------------------------------------
; BoundFunc object 1
BFO1 := FO.Bind("BFO1 Title")
; The following doesn't work currently, what should be returned?
MsgBox, 0, BoundFunc Object 1, % "MinParams: " . BFO1.MinParams . " - MaxParams: " . BFO1.MaxParams
BFO1.Call("BF01 Text") ; -> BFO1 Title - BFO1 Text
; --------------------------------------------------------------------------------------------------------------------------------
; BoundFunc object 2 (doesn't work currently)
BFO2 := BFO1.Bind("BFO2 Title")
; What should be returned?
MsgBox, 0, BoundFunc Object 2, % "MinParams: " . BFO2.MinParams . " - MaxParams: " . BFO2.MaxParams
; How should BFO2 be called?
BFO2.Call("???")
; Which parameters in which order would be passed to the function?
ExitApp
Function(Title, Text) {
MsgBox, 0, %A_ThisFunc%, Title: %Title% - Text: %Text%
}
Re: Make bound funcs consistent with func objects
Yeah I will edit the answers into your code:just me wrote:To help me understand your concept, would you please answer the following questions?
Code: Select all
[code]; --------------------------------------------------------------------------------------------------------------------------------
; Func object
FO := Func("Function")
MsgBox, 0, Func Object, % "MinParams: " . FO.MinParams . " - MaxParams: " . FO.MaxParams ; 2 - 2
FO.Call("FO Title", "FO Text") ; -> FO Title - FO Text
; --------------------------------------------------------------------------------------------------------------------------------
; BoundFunc object 1
BFO1 := FO.Bind("BFO1 Title")
; The following doesn't work currently, what should be returned?
MsgBox, 0, BoundFunc Object 1, % "MinParams: " . BFO1.MinParams . " - MaxParams: " . BFO1.MaxParams ; 1 - 1
BFO1.Call("BF01 Text") ; -> BFO1 Title - BFO1 Text
; --------------------------------------------------------------------------------------------------------------------------------
; BoundFunc object 2 (doesn't work currently)
BFO2 := BFO1.Bind("BFO2 Text")
; What should be returned?
MsgBox, 0, BoundFunc Object 2, % "MinParams: " . BFO2.MinParams . " - MaxParams: " . BFO2.MaxParams ; 0 - 0
; How should BFO2 be called?
BFO2.Call()
; Which parameters in which order would be passed to the function?
;BFO1 Title - BFO2 Text
ExitApp
Function(Title, Text) {
MsgBox, 0, %A_ThisFunc%, Title: %Title% - Text: %Text%
}
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
Code: Select all
BFO2 := BFO1.Bind("BFO2 Text")
; What should be returned?
MsgBox, 0, BoundFunc Object 2, % "MinParams: " . BFO2.MinParams . " - MaxParams: " . BFO2.MaxParams ; 0 - 0
; How should BFO2 be called?
BFO2.Call()
; Which parameters in which order would be passed to the function?
;BFO1 Title - BFO2 Text
How do you know whether pre-bound parameters exist when you create BFO2?
Re: Make bound funcs consistent with func objects
Yes, BFO2 is the result of binding parameters to the BFO1 bound func. That bound func accepts exactly 1 parameter and that's message. It would be strange if binding would not result in binding this parameter. Just like you can't set your own title when calling BFO1 you can't set your own title when binding it.So BFO2 wouldn't be able to specify an own Title parameter?
I don't understand why that would matter, but I guess it doesn't hurt to disclose the array of bound parameters someway ( e. g. boundFunc.boundParams )How do you know whether pre-bound parameters exist when you create BFO2?
Also it seems towards me that you want to bind parameters to the base func ( FO ). Why would you pass a BFO1 object towards .bind when you want to do that?
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
Following your concept
will pass "BFO2 Text" as the first parameter (Title) if BFO1 is a Func object. If it is a BoundFunc object, it will be added to the end of the list of pre-bound parameters.
It makes no sense without knowing the correct type of BFO1. Also, boundFunc.boundParams would not be consistent with the current Func objects and require to change your scipts.
Code: Select all
BFO2 := BFO1.Bind("BFO2 Text")
It makes no sense without knowing the correct type of BFO1. Also, boundFunc.boundParams would not be consistent with the current Func objects and require to change your scipts.
Re: Make bound funcs consistent with func objects
We are currently at an interface layer that is completely abstract from the final implementation. We need to stay on this layer. In the final implementation we could just store the new parameters that were bound but instead keep a reference towards the func object or bound func object that was used to create this bound func.just me wrote:Following your conceptwill pass "BFO2 Text" as the first parameter (Title) if BFO1 is a Func object. If it is a BoundFunc object, it will be added to the end of the list of pre-bound parameters.Code: Select all
BFO2 := BFO1.Bind("BFO2 Text")
Over the most recent posts I have asked you several times to find a reason for this.It makes no sense without knowing the correct type of BFO1.
Why?Also, boundFunc.boundParams would not be consistent with the current Func objects and require to change your scipts.
Recommends AHK Studio
Re: Make bound funcs consistent with func objects
After you changed the topic we are talking about "Make bound funcs consistent with func objects". I read this as "Let the BoundFunc object support the methods/properties of the current Func object". But now it seems that you want to change the implementation of Func objects to include the functions of BoundFunc objects, do you? I still don't get what you want to achieve with the changes and why you think it wouldn't require changes in existing scripts.
Who is online
Users browsing this forum: No registered users and 105 guests