AutoHotkey Community

It is currently May 26th, 2012, 9:23 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject:
PostPosted: March 19th, 2007, 3:53 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
jonny wrote:
The only issue here (and it's already documented, even if it isn't ideal behavior) is that if temp0 is already a variable in global scope, StringSplit inside a function will create the array globally. This means any reference in global scope will cause it to function that way. So, how is MsgBox concerned with this?
The point here is that StringSplit should not reference the global variable at all but should create a local array. Why should the StringSplit command be treated differently?

The relevance to MsgBox is that if MsgBox references a variable in a function it creates it as local in this case. This is opposite to StringSplit. You don't see an issue with this?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 4:15 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
Documentation wrote:
Note: any non-dynamic reference to a variable creates that variable the moment the script launches. For example, a reference to Array1 outside a function creates Array1 as a global the moment the script launches. Conversely, a reference to Array1 inside a function immediately creates it as a local.

Documentation wrote:
For commands that create arrays (such as StringSplit), the resulting array is local if the assume-global mode is not in effect or if the array's first element has been declared as a local variable (this is also true if one of the function's parameters is passed -- even if that parameter is ByRef -- because parameters are similar to local variables). Conversely, if the first element has been declared global, a global array is created.


It's not accessing the value like MsgBox does, it's just checking to see whether it's local or global.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 5:28 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
jonny wrote:
It's not accessing the value like MsgBox does, it's just checking to see whether it's local or global.
...but it should access the value like MsgBox does... ...or MsgBox should access the value like StringSplit does...

Never mind... I feel like I'm talking to a wall...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 6:49 am 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
The feeling is mutual. I think that, either way, the issue has been beat out enough for Chris to discern whether there's a problem or not, and if so, what it is. Let's just leave it be for now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 19th, 2007, 11:33 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Hopefully, when (if?) true arrays will be implemented, this issue will go away. Management of automatically generated (pseudo-)arrays in functions has always been a delicate issue, I have been bitten several times...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2007, 2:41 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Thanks for the report. If I understand correctly, the crux of the problem is in bold below:

Fixed StringSplit when used inside a function so that it always creates a local array when OutputArray0 is local, even if OutputArray0 also exists as a global.

Corrupt: I think this issue is specific to StringSplit; it doesn't seem related to anything else involving globals/locals or that other topic you mentioned.

Thanks.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2007, 4:40 pm 
Offline

Joined: February 6th, 2007, 12:20 pm
Posts: 4
Chris wrote:
Fixed StringSplit when used inside a function so that it always creates a local array when OutputArray0 is local, even if OutputArray0 also exists as a global.


Chris, does "Fixed" here mean that you have changed this function now?
I posted this trying to learn AHK (my very first post!) and it turns out that I found an inconsistency... I love AHK, but it's so awkward, compared to dozens of other languages I must have used in the past. But its power makes it worth all the effort!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 20th, 2007, 6:25 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Yes, it should be fixed in the next update. Thanks again for reporting it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2007, 6:35 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
Chris wrote:
Thanks for the report. If I understand correctly, the crux of the problem is in bold below:

Fixed StringSplit when used inside a function so that it always creates a local array when OutputArray0 is local, even if OutputArray0 also exists as a global.

Corrupt: I think this issue is specific to StringSplit; it doesn't seem related to anything else involving globals/locals or that other topic you mentioned.

Thanks.
Hi Chris. I might be misunderstanding the logic behind the design (and possibly your post) but what I was trying to point out is that it seems logical that using a non-dynamic variable name in the SplingSplit line should create a local array unless the array was specified as global at the beginning of the function. In other words... instead of "always creates a local array when OutputArray0 is local" it would be more consistent if it was "always creates a local array unless OutputArray0 has been declared as global". This seems to be how the MsgBox line is interpreted. Here's another example. Temp1 and Temp2 get created as local in the function since they were referenced by name but Temp0 was not created as local when referenced by name. None of the variables were declared as local or global so it seems to be inconsistent (unless I'm misunderstanding the issue).
Code:
temp0=1
f()
MsgBox main`ntemp0 = %temp0%`ntemp1 = %temp1%`ntemp2 = %temp2%
return

f()
{
   x = ab
   t = temp
   out = f()`n
   StringSplit,temp,x
   MsgBox % out . "`ntemp0 = " . %t%0 . "`ntemp1 = " . temp1 . "`ntemp2 = " . temp2
   return
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 22nd, 2007, 5:21 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
I see what you mean: the wording is imprecise because there are two ways for OutputArray0 to be global: declaration and assume-global. So it's probably better to write the following in the changelog:

Fixed StringSplit inside assume-local functions so that it creates a local array even when OutputArray0 exists as a global but not a local.

The above still doesn't mention "except when declared as global", but that seems okay because it's explicitly documented.

The bug has been fixed in today's v1.0.46.10. If anyone has any more problems with it, please let me know.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 25th, 2007, 4:07 am 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2542
Thanks :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 1:36 am 
Offline

Joined: October 5th, 2004, 5:03 pm
Posts: 121
Location: Brasília, Brazil
I thought it had been debugged, but it is back again... StringSplit is not working inside my functions in compiled scripts (only in compiled scripts)... Does anyone know what the problem is?

I'm trying to change all "StringSplit" with "Loop, parse", but it has taken long.

AHK Version 1.0.47.06

Lingoist


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 2:00 am 
Offline

Joined: November 2nd, 2004, 2:43 pm
Posts: 1019
Location: London, UK
Is your autohotkey.bin the same version. The file can be found in the compiler directory.

_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 23rd, 2008, 2:34 am 
Offline

Joined: October 5th, 2004, 5:03 pm
Posts: 121
Location: Brasília, Brazil
Superfraggle wrote:
Is your autohotkey.bin the same version. The file can be found in the compiler directory.


All programs were installed last June (every program is in its latest version, including AutoHotKey).

I'd like to post a good example here, but my script has more than 30.000 lines... All small examples I've tried to write to post here worked very well...

Lingoist


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2008, 4:26 am 
Offline

Joined: October 5th, 2004, 5:03 pm
Posts: 121
Location: Brasília, Brazil
I give up... No scripts of mine work properly anymore when compiled... I've made a function in order to replace all "StringSplit" with "Loop parse" automatically.

YOU WILL HAVE TO SELECT THE ENTIRE LINE WITH StringSplit (INCLUDING LINE CARRIAGE) AND PRESS "CONTROL+ALT+SHIFT+R".

Code:
   script updated on the next message


I Hope it will be fixed soon...


Last edited by lingoist on October 15th, 2008, 3:50 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 31 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group