AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug in parsing Local declaration

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
Hardeep



Joined: 02 Jul 2006
Posts: 87

PostPosted: Thu Jul 19, 2007 1:04 pm    Post subject: Bug in parsing Local declaration Reply with quote

AHK Version : 1.0.47.01
When a variable is initialized to a numeric value inside a multiple Local declaration, the spaces/tabs added to the right of the numeric value but before a comma, get appended to the variable.
Code:
Myfunc()
{   Local x=1  , y=2, z=3
   MsgBox,% x y z   ;Shows "1 23"
}
Myfunc()
This only happens when setting variables to numeric values
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6551
Location: Pacific Northwest, US

PostPosted: Thu Jul 19, 2007 3:06 pm    Post subject: Reply with quote

variables are local by default, why are you declaring them so? does it work if you leave out the local? (I suppose that forces you to use multiple lines then?)
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Jul 19, 2007 3:11 pm    Post subject: Reply with quote

This has been fixed in today's v1.0.47.02: "Fixed declaration initializers not to retain whitespace at the end of literal numbers. Also, they now allow spaces between a closing quote and the next comma."

Thanks for reporting it.
Back to top
View user's profile Send private message Send e-mail
Helpy
Guest





PostPosted: Thu Jul 19, 2007 3:35 pm    Post subject: Reply with quote

engunneer wrote:
variables are local by default, why are you declaring them so?
Because it is a good programming habit to declare local variables, and it allows global variables to be visible, which is a more familiar paradigm for lot of programmers...
Back to top
engunneer



Joined: 30 Aug 2005
Posts: 6551
Location: Pacific Northwest, US

PostPosted: Thu Jul 19, 2007 3:39 pm    Post subject: Reply with quote

an even better answer is that it allows you to keep some variables local when the variables in the function are changed to global-by-default. - in fact, using Local in this way sets all the others to global by default.

Quote:

If a function needs to reference or create a large number of global variables, it can be defined to assume that all its variables are global (except its parameters) by making its first line either the word "global" or the declaration of a local variable. For example:

Code:

SetDefaults()
{
    global  ; This word can be omitted if the first line of this function will be something like "local MyVar".
    Var := 33  ; Assigns 33 to a global variable, first creating the variable if necessary.
    local x, y:=0, z  ; Local variables must be declared in this mode, otherwise they would be assumed global.
    ; ...and so on.
}


_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
Hardeep



Joined: 02 Jul 2006
Posts: 87

PostPosted: Thu Jul 19, 2007 3:58 pm    Post subject: Reply with quote

Quote:
in fact, using Local in this way sets all the others to global by default.

Thats exactly why I am using it. The code posted above was just an example.

That was fast Chris...Thanks Very Happy
Back to top
View user's profile Send private message
Helpy
Guest





PostPosted: Thu Jul 19, 2007 4:13 pm    Post subject: Reply with quote

engunneer wrote:
an even better answer is that it allows you to keep some variables local when the variables in the function are changed to global-by-default.
That's what I wrote, but probably in a non-explicit or confusing way.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group