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 

Function Variable Declarations

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
infogulch



Joined: 27 Mar 2008
Posts: 184

PostPosted: Tue Jun 17, 2008 10:07 pm    Post subject: Function Variable Declarations Reply with quote

Some ideas:
Sorry if they've already been suggested.

1. Assume Static
    Functions can be declared Assume Global or Local currently. Assume Static would be a useful addition. This would make all variables created by the function static, accessible between calls, as well as making variable declarations shorter if you want all variables in the function static. E.g.:
      FuncFoo(x) {
      Static
      ... code ...
      }
2. Declare Namespaces
    Be able to declare an entire namespace global/local/static. This would simplify many scripts that declare lots of variables. It could work similar to the way StringSplit etc creates variables if the OutputArray variable is declared.

    Syntax Ideas: To specify a namespace, put an asterisk directly after the variable. E.g. : Global Var_* would make any variables starting with Var_ globally accessible. An Asterisk because it's not an allowed character in variables, and is commonly known as a Wildcard. For simplicity and readability, you might want to limit declared namespaces to ones that end with an underscore: _ .


Thanks for looking.
_________________
A great Beginner's Tutorial
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sat Oct 25, 2008 10:37 pm    Post subject: Re: Function Variable Declarations Reply with quote

infogulch wrote:
Assume Static
I like this idea.

infogulch wrote:
Declare Namespaces
I prefer nested functions (ecmascript/c# style) where child functions are assumed global and accessible via dot notation like myfunc.sub(params)
_________________

Back to top
View user's profile Send private message Visit poster's website
infogulch



Joined: 27 Mar 2008
Posts: 184

PostPosted: Sun Oct 26, 2008 4:38 am    Post subject: Reply with quote

ah, nested functions would work really well. Basically that's the format people use when they make a library where this might be useful.

E.g. IE.Init() instead of IE_Init().

Actually, now that I'm thinking about it, I originally wanted declaring variable namsepaces as an easy way to declare a bunch of similar variables. E.g. Lets say I have a function whose variables I want to be global, except for 20 variables that I want to be local and all start with myFunc_. So instead of doing: Global `n Local myFunc_1, myFunc_2, myFunc_3 ... for all 20 variables, it would just be: Global `n Local myFunc_* done. But I like the nested functions anyway. Smile

I was also going to suggest shared static variables. So several functions (a library) could share internal information and it still not be accessible to the rest of the script. But nested functions would work for this as well.

Here's something different: Inherited Namespaces. They would allow a function to "Inherit" the caller's variable accessibility. An easy to think of example would be my PG_*() array functions. They are currently limited to only adjust psuedo-arrays that are global. When we get real arrays, though, this won't be a big deal, but really any helper function where you don't want to be forced into putting a bunch of redundant variables into params, or being forced into using global variables, this would be useful.

Smile
_________________
A great Beginner's Tutorial
Back to top
View user's profile Send private message
Titan



Joined: 11 Aug 2004
Posts: 5390
Location: /b/

PostPosted: Sun Oct 26, 2008 10:13 am    Post subject: Reply with quote

AutoHotkey is not OO it would be pointless to give functions scope, even less to think about inheritance and polymorphism.
_________________

Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List 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