Hello, very nice feature .
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? (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.
Fat arrow =>
Re: Fat arrow =>
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:
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
function check(current,other){
if(typeof other !== 'object' && typeof current !== 'object') return current === other;
let equal = false;
for(let prop in other){
if(current[prop] === undefined) throw new Error("FAILED");
equal = equal || check(current[prop],other[prop]);
}
if(!equal) throw new Error("FAILED");
return equal;
}
function test(comment,callback){
let error;
try{
//execute the tests;
callback();
}catch(e){
// Get the result whether it passed or failed
error = e.message;
}
console.log(comment,error === "FAILED" ? "FAILED" : "PASSED");
}
function expect(value){
this.toBe = function(other){
if(value !== other) throw new Error("FAILED");
}
this.toEqual = function(something){
check(value,something);
}
return this;
}
// The tests start HERE
test('Is 2+2 be 4?',() => {
expect(2 + 2).toBe(4); // returns : Is 2+2 be 4? PASSED
});
test('Is 2+3 be 4?',() => {
expect(2 + 3).toBe(4); // returns : Is 2+3 be 4? FAILED
});
test('Is {value:3*3} equal {value:9}?',() => {
expect({value:3*3}).toEqual({value:9}); // returns : Is {value:3*3} equal {value:9}? PASSED
});
test('Is {value:2*3} equal {value:9}?',() => {
expect({value:2*3}).toEqual({value:9}); // returns : Is {value:2*3} equal {value:9}? FAILED
});
test('Is {value:{arr:[6]}} equal {value:9}?',() => {
expect({value:{arr:[6]}}).toEqual({value:9}); // Is {value:{arr:[6]}} equal {value:9}? FAILED
});
Re: Fat arrow =>
I like it too! It looks great
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.
btw, fat arrow sounds very strange for me
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.
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.
btw, fat arrow sounds very strange for me
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.
Re: Fat arrow =>
Did we really get lambda expressions?
Maybe it's time to move to AHK v2
Maybe it's time to move to AHK v2
Recommends AHK Studio
Re: Fat arrow =>
@ wolf_II, I do not know, but hi .
@ Flipeador, good point about automating it, cheers.
@ nnnik, v2
Cheers.
@ Flipeador, good point about automating it, cheers.
@ nnnik, v2
Cheers.
Re: Fat arrow =>
Code: Select all
EnumWindows(ParentID := 0, Visible := FALSE)
{
Local pEnumChildProc := CallbackCreate("EnumChildProc", "F&", 2) ; You can't do it Static. is it a bug?
, oWindows := []
Local R := DllCall("User32.dll\EnumChildWindows", "Ptr", ParentID, "UPtr", pEnumChildProc, "UPtr", 0)
CallbackFree(pEnumChildProc)
Return R ? oWindows : FALSE
; ==================================================================
; Nested Functions
; ==================================================================
EnumChildProc(params) ; EnumChildProc(HWND hwnd, LPARAM lParam)
{
; You must specify oWindows and Visible with lambda, or else, it will not work. is it a bug?
Return ((WindowId,oWindows,Visible) => !Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId) ? oWindows.Push(WindowId) : 1).call(NumGet(params, "Ptr"), oWindows, Visible)
;Local WindowId := NumGet(params, "Ptr")
;If (!Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId))
;oWindows.Push(WindowId)
;Return 1
} ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms633493(v=vs.85).aspx
} ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms633494(v=vs.85).aspx
For Each, WindowId in EnumWindows(0, TRUE)
List .= "[" . WindowId . "] " . WinGetClass("ahk_id" . WindowId) . "`n"
MsgBox List
Re: Fat arrow =>
Whoa! This is huge!
Re: Fat arrow =>
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?
Re: Fat arrow =>
i would think it would work with how you would normally split things into multiple lineskczx3 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?
https://lexikos.github.io/v2/docs/Scrip ... ntinuation
this works:
Code: Select all
EnumWindows(ParentID := 0, Visible := FALSE)
{
Local pEnumChildProc := CallbackCreate("EnumChildProc", "F&", 2) ; You can't do it Static. is it a bug?
, oWindows := []
Local R := DllCall("User32.dll\EnumChildWindows", "Ptr", ParentID, "UPtr", pEnumChildProc, "UPtr", 0)
CallbackFree(pEnumChildProc)
Return R ? oWindows : FALSE
; ==================================================================
; Nested Functions
; ==================================================================
EnumChildProc(params) ; EnumChildProc(HWND hwnd, LPARAM lParam)
{
Return ((WindowId
,oWindows
,Visible) => !Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId)
? oWindows.Push(WindowId)
: 1).call(NumGet(params, "Ptr")
, oWindows
, Visible)
}
}
For Each, WindowId in EnumWindows(0, TRUE)
List .= "[" . WindowId . "] " . WinGetClass("ahk_id" . WindowId) . "`n"
MsgBox List
Re: Fat arrow =>
Mulitiline seems to work as expected.
where (...) and expr can be multilined as expected. Any example which didn't work as you expected kczx3? Disregarding how javascript works.
Cheers.
Code: Select all
(...)
=> expr
Cheers.
Re: Fat arrow =>
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 . However, it seems you also cannot do a static initialisation to nested functions, that seems more bug like,Flipeador wrote:; You can't do it Static. is it a bug?
Code: Select all
f(){
static a := callbackcreate("g") ; error
g(){
}
}
Code: Select all
static n := "g"
static a := callbackcreate(func(n)) ; error
I'm not sure what you mean.; You must specify oWindows and Visible with lambda, or else, it will not work. is it a bug?
Cheers.
Re: Fat arrow =>
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.
I don't see how the current thing could be particulary useful.
Recommends AHK Studio
Re: Fat arrow =>
What do you mean nnnik? I saw no problems with multiline expressions. Do you have an example not working properly?
Re: Fat arrow =>
Seperate expressions. Using , at a new line is just a sucky method of combining it into a single expression.
Recommends AHK Studio
Re: Fat arrow =>
I see, yes that would be nice ofc.
Re: Fat arrow =>
I was talking about what nnnik references regarding multiple expressions
Re: Fat arrow =>
I mean, in the lambda scope, oWindows and Visible variables are not defined; so you must pass them through parameters.Helgef wrote:I'm not sure what you mean.Flipeador wrote:; You must specify oWindows and Visible with lambda, or else, it will not work. is it a bug?
You cannot do:
Code: Select all
Return (WindowId => !Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId) ? oWindows.Push(WindowId) : 1).call(NumGet(params, "Ptr"))
I must pay more attentionHelgef wrote:Since EnumChildProc is a closure
Re: Fat arrow =>
using the recent update with automatic continuation inside {} and [] allows for:
and
Still no If/Else throw Loops or break.
Code: Select all
() => [
DllCall( 1 )
DllCall( 2 )
DllCall( 2 )
]
Code: Select all
() => {
lambda:
DllCall( 1 )
DllCall( 2 )
}
Recommends AHK Studio
Re: Fat arrow =>
I cannot deduce from the documentation that that would be expected, reducing your example,You cannot do:
Code: Select all
f()
f(){
a := 1
g()
msgbox a ; blank - unexpected
g(){
() => a
}
}
Code: Select all
h(){
(a)
}
As a side note, @Flipeador, you could make your function like this instead,
Code: Select all
EnumWindows(ParentID := 0, Visible := FALSE)
{
static EnumChildProc := (oWindows, Visible, WindowId) => !Visible || DllCall('User32.dll\IsWindowVisible', 'Ptr', WindowId := NumGet(WindowId, "Ptr")) ? oWindows.Push(WindowId) : 1
Local oWindows := []
Local pEnumChildProc := CallbackCreate(EnumChildProc.bind(oWindows, Visible), "F&", 2)
Local R := DllCall("User32.dll\EnumChildWindows", "Ptr", ParentID, "UPtr", pEnumChildProc, "UPtr", 0)
CallbackFree(pEnumChildProc)
Return R ? oWindows : FALSE
} ; https://msdn.microsoft.com/en-us/library/windows/desktop/ms633494(v=vs.85).aspx
Return to “AutoHotkey Development”
Who is online
Users browsing this forum: No registered users and 12 guests