Fat arrow =>

Discuss the future of the AutoHotkey language
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Fat arrow =>

26 Mar 2018, 06:53

Hello, very nice feature :bravo:.

I get error: f := () => u := 1 (due to assignment), I can do u++ and (u := 1) though.

I make unspecfic title if others have general comments or questions, we do not need many threads.


Although I like the name. fat arrow, I'd prefer something easier to type, eg f := () :: expr, fat colon? :lol: (Sorry if I'm the kid complaining about getting a blue ferrari instead of a red)
I do not know how you type => on english keyboard, but on mine, I do shift+0 for =, then shift + < for >.


Cheers.
wolf_II
Posts: 1959
Joined: 08 Feb 2015, 20:55

Re: Fat arrow =>

26 Mar 2018, 09:26

Hi, I have come across a *.js file which looks promising for implementing a testing facility.
Unfortunately, it relies on a similar notation which is new to me. Can anybody please tell me if AHK's new FatArrow notation is similar enough to convert this JavaScript:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Flipeador
Posts: 883
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Fat arrow =>

26 Mar 2018, 10:53

I like it too! It looks great :D
I like the new operator. This is a lambda expression, right?
I write => just like you. I do not see anything bad in "not so simple to write", since it is not in common use, I would say.
Image

btw, fat arrow sounds very strange for me :lol:
offtopic: now, within the most significant, and as I mentioned in another topic, it would be nice to have VarSetLength (and the equivalent for objects) in the next update.
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fat arrow =>

26 Mar 2018, 11:41

Did we really get lambda expressions?
Maybe it's time to move to AHK v2
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

26 Mar 2018, 11:49

@ wolf_II, I do not know, but hi :wave:.
@ Flipeador, good point about automating it, cheers.
@ nnnik, :angel: :arrow: v2

Cheers.
User avatar
Flipeador
Posts: 883
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Fat arrow =>

26 Mar 2018, 15:22

Code: [Select all] [Expand] [Download] (Untitled.ahk)GeSHi © Codebox Plus

Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Fat arrow =>

27 Mar 2018, 16:02

Whoa! This is huge!
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Fat arrow =>

27 Mar 2018, 20:34

It doesn't seem like these can be multiline as in JavaScript. Anyone else able to get one to work on more than one line?
guest3456
Posts: 2332
Joined: 09 Oct 2013, 10:31

Re: Fat arrow =>

27 Mar 2018, 20:45

kczx3 wrote:It doesn't seem like these can be multiline as in JavaScript. Anyone else able to get one to work on more than one line?


i would think it would work with how you would normally split things into multiple lines
https://lexikos.github.io/v2/docs/Scrip ... ntinuation

this works:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

28 Mar 2018, 01:02

Mulitiline seems to work as expected.

Code: [Select all] [Download] GeSHi © Codebox Plus

(...) 
=> expr

where (...) and expr can be multilined as expected. Any example which didn't work as you expected kczx3? Disregarding how javascript works.

Cheers.
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

28 Mar 2018, 01:33

Flipeador wrote:; You can't do it Static. is it a bug?

Since EnumChildProc is a closure, I'm not sure there is a well defined scope when the static initialising takes place, even if it did work I'm not sure what to expect :think:. However, it seems you also cannot do a static initialisation to nested functions, that seems more bug like,

Code: [Select all] [Download] GeSHi © Codebox Plus

f(){
static a := callbackcreate("g") ; error
g(){
}
}

But passing func("g") above works as expected. But not

Code: [Select all] [Download] GeSHi © Codebox Plus

static n := "g"
static a := callbackcreate(func(n)) ; error

unless I define a function g outside of f.
; You must specify oWindows and Visible with lambda, or else, it will not work. is it a bug?

I'm not sure what you mean.

Cheers. :wave:
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fat arrow =>

28 Mar 2018, 02:12

Yeah I expected the fat arrow expression ( lambda expression ) to be able to handle multiple seperate expression lines.
I don't see how the current thing could be particulary useful.
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

28 Mar 2018, 02:16

What do you mean nnnik? I saw no problems with multiline expressions. Do you have an example not working properly?
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fat arrow =>

28 Mar 2018, 02:18

Seperate expressions. Using , at a new line is just a sucky method of combining it into a single expression.
Recommends AHK Studio
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fat arrow =>

28 Mar 2018, 02:20

e. g.
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

28 Mar 2018, 02:22

I see, yes that would be nice ofc.
User avatar
kczx3
Posts: 578
Joined: 06 Oct 2015, 21:39

Re: Fat arrow =>

28 Mar 2018, 04:07

I was talking about what nnnik references regarding multiple expressions
User avatar
Flipeador
Posts: 883
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: Fat arrow =>

28 Mar 2018, 04:28

Helgef wrote:
Flipeador wrote:; You must specify oWindows and Visible with lambda, or else, it will not work. is it a bug?

I'm not sure what you mean.

I mean, in the lambda scope, oWindows and Visible variables are not defined; so you must pass them through parameters.
You cannot do:

Code: [Select all] [Download] (Untitled.ahk)GeSHi © Codebox Plus

Return (WindowId => !Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId) ? oWindows.Push(WindowId) : 1).call(NumGet(params, "Ptr"))

Maybe I missed something in the documentation :lol:

Helgef wrote:Since EnumChildProc is a closure

I must pay more attention :wave:
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina SublimeText 3 & AHKv2
User avatar
nnnik
Posts: 2967
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Fat arrow =>

28 Mar 2018, 07:40

using the recent update with automatic continuation inside {} and [] allows for:

and

Code: [Select all] [Download] GeSHi © Codebox Plus

() => {
lambda:
DllCall( 1 )
DllCall( 2 )
}

Still no If/Else throw Loops or break.
Recommends AHK Studio
Helgef
Posts: 3033
Joined: 17 Jul 2016, 01:02
Contact:

Re: Fat arrow =>

28 Mar 2018, 07:42

You cannot do:

I cannot deduce from the documentation that that would be expected, reducing your example,

Code: [Select all] [Download] GeSHi © Codebox Plus

f()
f(){
a := 1
g()
msgbox a ; blank - unexpected
g(){
() => a
}
}

but it is not related to the fat arrow, you get the same result when replacing it with

in g.
As a side note, @Flipeador, you could make your function like this instead,

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 5 guests