%Expr% [BUG] or [_3D_ not understood]

Discuss the future of the AutoHotkey language
_3D_
Posts: 182
Joined: 29 Jan 2014, 14:40

%Expr% [BUG] or [_3D_ not understood]

20 May 2018, 15:01

Is next example Error or Bug?

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

AHKv2.0 use the future now.
_3D_
Posts: 182
Joined: 29 Jan 2014, 14:40

Re: %Expr% [BUG] or [_3D_ not understood]

20 May 2018, 15:40

I see - there need action with variable with the main function not just action.

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

df(s) {
__:= 1 ; some action but nothing
return %s% ; <<< a not visible
}
And ...

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

df(s) {
__:= a ; action with var from main function
return %s% ; <<< a visible
}
Thanks Helgef.

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

fun()
fun() {
a:= 1

df(s) {
return %s% ; <<< a not visible but A_Index visible
}

while a <= 5 {
msgBox(df("a") " | " df("A_Index")), a++
} }
AHKv2.0 use the future now.
Helgef
Posts: 3096
Joined: 17 Jul 2016, 01:02
Contact:

Re: %Expr% [BUG] or [_3D_ not understood]

20 May 2018, 16:02

Built in Variables are available everywhere, you can't declare them (eg local).
_3D_
Posts: 182
Joined: 29 Jan 2014, 14:40

Re: %Expr% [BUG] or [_3D_ not understood]

20 May 2018, 16:54

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

Actually there must be fake action for any variable that need to be visible.
AHKv2.0 use the future now.
_3D_
Posts: 182
Joined: 29 Jan 2014, 14:40

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 00:41

I do some tests and conclusion - AHK have main problem with %Expr%.
Test 1: global variables and functions

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

As we expected a, b, c not visible inside function deref.
Test 2: global variables and short functions

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

deref(__exp) => RegExMatch(__exp, "i)[%][a-z_]\w*[%]", __var)? __exp:= deref(RegExReplace(__exp, "i)" __var.Value, %subStr(__var.Value, 2, -1)% "")): __exp	

a:= 5
b:= 5
c:= 5

while A_Index <= 3 {
msgBox(deref("a= %a% | b= %b% | c= %c%"))
a+=1, b+=2, c+=3
}
In this case a, b, c visible inside short function deref.
Short function deref(__exp) work like MACROS when in global scope.
Test 3:We expected that short function will see variables in the same scope as in Test 2 (but)

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

fun()
fun() {
deref(__exp) => RegExMatch(__exp, "i)[%][a-z_]\w*[%]", __var)? __exp:= deref(RegExReplace(__exp, "i)" __var.Value, %subStr(__var.Value, 2, -1)% "")): __exp

a:= 1
b:= 1
c:= 1
while A_Index <= 3 {
msgBox(deref("a= %a% | b= %b% | c= %c%"))
a+=1, b+=2, c+=3
} }

Test 4:Nested function without "some action"

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


Test 5:Nested function with "some action"

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

Any variable that must be seen - must have "some action".
Test 6:BASIC programming style.

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

As we not expected there only 2 working sets: Test 2 and Test 6.
Conclusions:
1. AHK have 3 type of functions.
2. Short Functions and BASIC style worked in global scope like MACROSes.
3. Nested functions not work as we expected.
4. Probably it is main [BUG] how %Expr% work.
AHKv2.0 use the future now.
User avatar
nnnik
Posts: 3072
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 01:07

Can't we just remove %var%?
Recommends AHK Studio
Helgef
Posts: 3096
Joined: 17 Jul 2016, 01:02
Contact:

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 01:15

There are no bugs here.
fat arrow wrote:The function is assume-local if it is nested inside another function, otherwise it is assume-global.

Regarding Test 4), as pointed out in the link I provided above, you need to refer to the variables non-dynamically inside a nested function in order for them to be visible (free variables). Eg,

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



@ _3D_, your regex doesn't really cover all possible variable names.

@ nnnik, you could change the syntax, the feature should not be removed.
User avatar
nnnik
Posts: 3072
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 01:31

@ nnnik, you could change the syntax, the feature should not be removed.
why?
Recommends AHK Studio
Helgef
Posts: 3096
Joined: 17 Jul 2016, 01:02
Contact:

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 01:35

Because then you couldn't refer to a variable dynamically. Why do you want to remove it?
User avatar
nnnik
Posts: 3072
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 02:19

Because it causes inconsistencies with the several types of function definitions. It's also not a requirement for AHK v2 to refer to a variable dynamically. Why would you need this feature?
Recommends AHK Studio
Helgef
Posts: 3096
Joined: 17 Jul 2016, 01:02
Contact:

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 03:33

You should start a new topic motivating why it should be removed. An example of valid use is for performance when working with strings, variables are much faster than arrays.
guest3456
Posts: 2360
Joined: 09 Oct 2013, 10:31

Re: %Expr% [BUG] or [_3D_ not understood]

21 May 2018, 08:14

i vote: do NOT remove dynamic double de refs

lexikos
Posts: 6045
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: %Expr% [BUG] or [_3D_ not understood]

23 May 2018, 01:57

nnnik wrote:Because it causes inconsistencies with the several types of function definitions.
How so?

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 4 guests