variable-scope

Scope of form variables in Grails

Hi, I am creating a Grails application which has an input page with text fields. Here the user can type in the data and on submit, the control goes to the action in controller. Here I get the value of the form data using params.empName etc. But the scope of this data is very small and doesnt get carried on if I do a redirect from the c...

How to live with Emacs Lisp dynamic scoping?

I've learned Clojure previously and really like the language. I also love Emacs and have hacked some simple stuff with Emacs Lisp. There is one thing which prevents me mentally from doing anything more substantial with Elisp though. It's the concept of dynamic scoping. I'm just scared of it since it's so alien to me and smells like semi-...

Logger Object - Variable Scope - access to Class/Function/etc..

So I want to find the best method of allowing my Logger class to access any part of the script either another class/function/etc... How would I do this? How do I make it global. Could I do something like this: Logger::info('Add message like this?'); Calling script: calling.php require_once('Logger.class.php'); // Just adding the cl...

A javascript Object ambiguous problem

this is a very very strange problem... see this code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN"> <head> <title>TEST</title> <script src="http://misc.fandongxi.com/js/jquery.1.4.js" type="text/javasc...

What is the difference between Dim, Global, Public, and Private as Modular Field Access Modifiers?

In VB6/VBA, you can declare module-level variables outside of a specific Sub or Function method. I've used Private and Public before inside modules and understand them like so: Public - visible to all code inside the module and all code outside the module, essentially making it global. Private - visible only to code inside the module....

variable scope with inner classes

I am creating a Splash screen(Activity) in my Android app. I have an inner class which extends AsyncTask. The constructor for this inner class accepts a Context object, which is being sent inside the Splash activity's onCreate method. There is also reference to a constant String field. public class Splash extends Activity { private...

Variable scope in VBScript functions

I have a question about variable scope in VBScript. I know there's the following keywords (from autoitscript.com): Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!) Global = Forces creation of the variable in the Global scope Local = Forces creation of the variable in ...

Variable scope in PHP

I have an issue with php. The following code generates the error "PHP Warning: mysqli_close() expects parameter 1 to be mysqli, null given[...]" on the line containing the mysqli_query <html> <head> <?php $table = "prjsuggestions"; /$mysqli = NULL; if(!empty($_POST['posttext'])){ $pnameempty = empty($_POST['postnam...

python string is default global

I have a question about global variable in Python. The code is following. If I do not use global M in function test, It would issue error. But Why it does not show error for string s. I do not declare it as global. global M M = [] s = "abc" def test(): ### global M print M M.append(s) print M UnboundLocalError: local v...

javascript passing variables from a method with a loop to a click function

Hi, basically I'm trying to pass a variable that is defined in a JSON array that is parsed through in a for loop to be accessible in a click statement. $(document).ready(function() { getJSON(); var usedID; }); function readJSON() { for (var i = 0; i < json.array.length; i ++) { usedID = json.array[i].id; var template = $('re...

Delegates and variables scope

Hello all, I have the following code: public void SetMove(Position3D pos, float time, float linearity, bool relative) { ExecuteOnActiveClients(delegate(NeuroClient client) { client.Engine.GetProcAnimation(name).SetMove(pos, time, linearity, relative); ...

Variables scope

I have two javascript files included at the header of my website. Both files contains almost same variables. If I have header like this <head> <script src="http://127.0.0.1/js/file1.js" type="text/javascript"></script> <script src="http://127.0.0.1/js/file2.js" type="text/javascript"></script> </head> Is it possible to ...

Allow for loop initialization in GCC and Clang when std={c,gnu}89?

How can I enable for loop initialization when compiling in c89 or gnu89 mode using GCC and Clang? ...

How does Perl variable scope work in while loop under strict mode?

I'm very new to Perl and I'm confused with exactly how its variable scope works. I'm trying to create an array of Hashes from the result of a MySQL query. The following code works, as intended, without use strict my %hash = (); while (my %hash = %{$qhand->fetchrow_hashref()} ) { push(@results, {%hash}); } but when strict ...

Question on C# local variables scope

Hi, I am just wondering, I thought I cannot have variables with the same name: int Test; public void A(int Test) { } Why this does compile? I know I can use this keyword but seems to me strange that as the method is in the scope of the class it allows me to declare the variable with the same name. ...

Python function local name binding from an outer scope

I need a way to "inject" names into a function from an outer code block, so they are accessible locally and they don't need to be specifically handled by the function's code (defined as function parameters, loaded from *args etc.) The simplified scenario: providing a framework within which the users are able to define (with as little sy...

[Django] Get parameters of object in metaclass of this object

My problem is a python/django mix. I have a form model that will display some fields. Basing on some parameter of this model, the data sent to metaclass creating this object should differ. But how can I reach this parameter when inside the body of Meta ? Should I use some global var instead of object parameter (as it is introduced only t...

Ruby variable scoping is killing me

I have a parser that reads files. Inside a file, you can declare a filename and the parser will go and read that one, then when it is done, pick up right where it left off and continue. This can happen as many levels deep as you want. Sounds pretty easy so far. All I want to do is print out the file names and line numbers. I have a cl...

variable scope in python nested functions

As I am studying decorators, I noticed something strange : def f(): ... msg='aa' ... def a(): ... print msg ... msg='bb' ... def b(): ... print msg ... return a,b ... >>> a,b = f() >>> a() bb >>> b() bb >>> Why a() returns 'bb' and not 'aa' ?? ...

How should I avoid unintentionally capturing the local scope in function literals?

I'll ask this with a Scala example, but it may well be that this affects other languages which allow hybrid imperative and functional styles. Here's a short example (UPDATED, see below): def method: Iterator[Int] { // construct some large intermediate value val huge = (1 to 1000000).toList val small = List.fill(5)(s...