Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

Propose new features and changes
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

23 Jan 2019, 10:20

i might have already suggested this, i dont remember

Code: Select all

greet := name => 'hello, ' name
msgbox greet.Call('world') ; too long
msgbox %greet%('world') ; too percenty
msgbox greet('world') ; non-existent function
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

23 Jan 2019, 10:40

; too percenty
:lol: I agree, it stings in my eyes, but I can not give any other reason why we need a change.

Cheers.
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

04 Feb 2019, 15:33

Lambda functions (or "fat arrow functions") are available in v2
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

04 Feb 2019, 19:28

Nothing, really. I wanted to add this to the discussion and make you aware of it. Maybe you'll consider using v2 from now on if you aren't already.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

05 Feb 2019, 05:37

the example is v2. the first line even is a lambda! how is any of this relevant?
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

05 Feb 2019, 07:55

you posted this on the wish list... wouldn't it be cool to know a way to use some of the features you wish were there already..?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

05 Feb 2019, 10:28

ure not making any sense man. the wish is to make callables callable without having to resort to %%-sign deref or .Call(). not implement callables
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

05 Feb 2019, 11:14

Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)
You wish for lambdas. Lambdas exist in v2. How am I not making sense?

the wish is to make callables callable without having to resort to %%-sign deref or .Call().
If that's your wish, you should have put that in the title... Instead you chose to put "callable funcs", which already exist; "callable BoundFuncs", which already exist; "lambdas" which already exist in v2, and "callable custom user objs"...
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

05 Feb 2019, 11:16

Clearly there was a misunderstanding, please do not discuss this more, I don't want any more off topic notifications.

Cheer.
SALZKARTOFFEEEL wrote:
06 Feb 2019, 01:24
You know, you can always just unsubscribe from the topic.
I'm not going to unsubscribe from a topic which interests, just me because there is an off topic discussion which doesn't interest me, you know...
Last edited by Helgef on 06 Feb 2019, 03:23, edited 1 time in total.
User avatar
SALZKARTOFFEEEL
Posts: 89
Joined: 10 May 2017, 11:14
Location: Germany
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

06 Feb 2019, 01:24

You know, you can always just unsubscribe from the topic.
But I agree, there was a misunderstanding and I have no intent in discussing further as I don't think we'll find a conclusion any time soon.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

06 May 2019, 11:25

we're getting there. reminds me of ahk_h

Code: Select all

class PercentlessCallable
{
	Call(greeting, name) {
		MsgBox greeting ', ' name '!'
	}

	__Item[greeting, name] {
		get {
			return this.Call(greeting, name)
		}
	}
}

fn := new PercentlessCallable()

fn['Hello', 'world']
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

06 May 2019, 12:00

Your call syntax was already possible before (also in v1), with __get, although is doesn't distinguish between [] and . (unless you demand multiple params I guess)
we're getting there
Nope, we're getting more of it, obj[expr](params) is being replaced by obj.%expr%(params). obj[prop_name_expr] is being replaced with obj.%prop_name_expr%.

Cheers.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 03:17

I might consider allowing () as an operator applied to any expression which is not otherwise recognized as a function call; however, it would have to be (var)(), not var(), otherwise valuable error checking is lost, and the function and variable namespaces become mixed. I'm pretty sure this was already brought up.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 09:17

while (var)() certainly is more pleasant to look at, compared to %var%(), im not sure whether it is the right direction to be taking it to. ideally, var() would be best. though, barring an extensive parser overhaul, this is likely unfeasible.
as an alternative i was thinking about different patterns for designating callables, eg <var>() but this doesnt look particularly good either

how about marking callables with a keyword?

Code: Select all

/*
'fn' reserved keyword takes the resolved name of the variable that follows
and assigns that name to the lambda that follows, effectively declaring a function with that name

fn greet := name => 'hello, ' name
becomes internally
greet := greet(name) => 'hello, ' name
*/

greet := greet(name) => 'hello, ' name ; for demo purposes only, in the actual script this line would read: fn greet := name => 'hello, ' name
msgbox greet('world') ; calls the named lambda
msgbox lambdaCaller(greet, 'world') ; passing the lambda, stored in the variable, as a variable still supported

lambdaCaller(fn, Args*) { ; to simulate a function accepting a lambda and doing something with it
	return fn.Call(Args*)
}
although i have no idea how scoping and runtime declarations will be managed in this case, and also name clashes with existing functions
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 09:20

So you are biased against %% because you don't like how it looks?
Whats the reason for that?
Or is it just that you associate %% with the command syntax which you have a bias against?
Recommends AHK Studio
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 09:49

not only am i biased against requiring %var%() to call callables, im also biased against any other propositions diverging from var(). that includes var.Call(), (var)(), <var>() and whatever else i or anyone else may come up with. ideally there should be no syntactical difference when it comes to calling functions versus calling callables. if someone was designing AHK from scratch, i doubt they would, on purpose, design it in a way such that calling functions will be done by applying the () operator to the function name but calling callables would require that u surround the callable's var name with % signs before applying the parens operator
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 10:22

I might consider allowing () as an operator applied to any expression which is not otherwise recognized as a function call; however, it would have to be (var)(), not var(),
var () :?:.

% look like blobs, they doesn't naturally enclose / delimit as does (/) and </> (or x/y where x!=y for that matter.)
biased against any other propositions diverging from var()
I suppose it would work if a local var took precedence over a global function, eg

Code: Select all

f(){
	local var := func('a')
	var() ; calls func('a')
}
var(){
}
You would get duplicate error if you also define var() {} in f, and likewise, in the global namespace,

Code: Select all

var := ... ; anything
var() ; error
var(){
}
Having something denote that the function call is dynamic generally makes writing and understanding the code easier though, I prefer that, even if it is %%.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

07 May 2019, 18:46

(),{} and [] already have a meaning which shouldnt be mixed - and I feel that it is counterintuitive to allow a special case for () when a local variable is explicitly defined inside a function.
Especially considering that this doesnt solve the problem - There has to be an alternative for all other cases, where this method isn't viable.

Using <> as braces seems possible but could be problematic with the normal AHK logic when it comes to operators.
I dont think there is another brace type character in the normal ascii plane.
Therefore we have no choice but to take a single character.

% represents dynamic code in AHK for historical reasons.
The choice here seems pretty obvious and intuitive.
Recommends AHK Studio
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Callable Func, BoundFunc, lambdas, custom user objs(ie no %%)

22 May 2019, 05:32

Helgef wrote:
07 May 2019, 10:22
% look like blobs, they doesn't naturally enclose / delimit as does (/) and </> (or x/y where x!=y for that matter.)
thats exactly it. reminds me of these few posts
https://www.autohotkey.com/boards/viewtopic.php?p=256095#p256095
[Shambles] wrote:One example is the use of % (note: non-directional, unlike [], {}, and <>) brackets for substitution.
https://www.autohotkey.com/boards/viewtopic.php?p=41939#p41939
[Shambles] wrote:% is particularly problematic, because it is used both as brackets, and alone. The bracketed form is especially hard to read, because unlike ‘normal’ brackets, % is not directional.

Helgef wrote:
07 May 2019, 10:22
Having something denote that the function call is dynamic generally makes writing and understanding the code easier though, I prefer that, even if it is %%.
why is it important to make this distinction? for example, C doesnt. neither does JS. why is it important to know whether the thing im calling is a callback or a hardcoded function
nnnik wrote:
07 May 2019, 18:46
% represents dynamic code in AHK for historical reasons.
The choice here seems pretty obvious and intuitive.
its only intuitive if uve spent most of ur time writing AHK Basic scripts
and just because thats how u used to do things back then, doesnt mean its the best way to do things going forward

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 40 guests