| View previous topic :: View next topic |
| Author |
Message |
infogulch
Joined: 27 Mar 2008 Posts: 184
|
Posted: Tue Jun 17, 2008 10:07 pm Post subject: Function Variable Declarations |
|
|
Some ideas:
Sorry if they've already been suggested.
1. Assume StaticFunctions 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 NamespacesBe 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 |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Sat Oct 25, 2008 10:37 pm Post subject: Re: Function Variable Declarations |
|
|
| 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 |
|
 |
infogulch
Joined: 27 Mar 2008 Posts: 184
|
Posted: Sun Oct 26, 2008 4:38 am Post subject: |
|
|
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.
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.
 _________________
A great Beginner's Tutorial |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5390 Location: /b/
|
Posted: Sun Oct 26, 2008 10:13 am Post subject: |
|
|
AutoHotkey is not OO it would be pointless to give functions scope, even less to think about inheritance and polymorphism. _________________
 |
|
| Back to top |
|
 |
|