scope

Accessing private variables from within a closure.

I'm trying to reference a private variable of an object from within a closure. The code below would seem to work, but it complains Fatal error: Cannot access self:: when no class scope is active in test.php on line 12 and Fatal error: Using $this when not in object context in test.php on line 20. Any ideas how to accomplish the same res...

What is the scope of a char*[] in C?

I have some code that does the following: while(some condition) { char *line[WORDLEN]; //do stuff to line, including strcat(line, "words") printf("%s", line); line[0] = '\0'; } However, it seems like line[0] = '\0' is not doing what I am hoping it will do. I want to go back through the loop, and use line as though ...

Best way to override named_scope for has_many associations in Rails?

Note: I'm using Rails 2.3.8, not 3. I have a Photo model with a default_scope: default_scope :conditions => ["published = ?", true], :order => :position Calling photo_album.photos returns all published photos ordered by position as it should. However, when looping through these photo albums in an admin panel to display the number of ...

How to return a char array created in function?

Hello, I've been programming badly for quite a while and I only really just realised. I have previously created many functions that return character strings as char arrays (or at least pointers to them). The other day someone pointed out that when my functions return the char arrays pointed to by my functions have gone out of scope and...

Ruby Instance Variable Scope Question

I come from C++ and JAVA, which with Scope there is either global or local. I'm now learning ruby-on-rails and with ruby there is local, instance and global. I've never really heard of instance till now. With or without rails, what is the understanding and usage of the instance variable? Global = Variable across all objects share I...

Javascript variable scope question

Hi, I'm having trouble resolving a scope issue with my javascript. I have an array, dog[] that is defined from JSON, that I need access to from inside a nested function. function blah(json) { for (var u = 0; u < json[0][1][u].length; u ++ ) { var dog = 'k' + json[0][1][u].doggies; console.log(dog); // prints array of doggie str...

Member access in Inheritance Hierarchy - C++

struct A { protected: int y; public: int z; }; struct F : A { public: using A::y; private: using A::z; }; int main() { F obj_F; obj_F.y = 9; obj_F.z = 10; } Source: http://publib.boulder.ibm.com/infocenter/comphelp/v7v91/index.jsp?topic=/com.ibm.vacpp7a.doc/language/ref/clrc14cplr135.htm In the above code obj_F.z = 10;...

form_for and scopes, rails 3

Hi I have a problem due to scopes and the form_for helper in rails 3. The routes - file looks like this: scope "(/:tab)" do resources :article end The form looks something like this: <%= form_for(@article) %> <%= f.label :title %> <%= f.text_field :title %> etc. <%end%> The tab - attribute is stored in params[:tab], as ...

Anything wrong with a really large __init__?

I'm writing a Python program with a GUI built with the Tkinter module. I'm using a class to define the GUI because it makes it easier to pass commands to buttons and makes the whole thing a bit easier to understand. The actual initialization of my GUI takes about 150 lines of code. To make this easier to understand, I've written the __i...

Does licensing matter for Maven artifacts that are runtime or test scoped?

My company is very concerned about entaglements that could result from the use of copy-left (e.g. GPL) code in our product. Because of this we have no compile scope Maven artifacts with copy-left licenses. However, with runtime or test scoped artifacts, does the same requirement apply? I wouldn't think so, but am very interested in he...

Should I encapsulate blocks of functionality in anonymous JavaScript functions?

My intuition is that it's a good idea to encapsulate blocks of code in anonymous functions like this: (function() { var aVar; aVar.func = function() { alert('ronk'); }; aVar.mem = 5; })(); Because I'm not going to need aVar again, so I assume that the garbage collector will then delete aVar when it goes out of scope. Is this rig...

javascript scope question

I've written a little Ajax-y page, that displays data rows from an ajax request. Each row has a "delete link" to allow the user to delete the row quickly, also via ajax. My problem is one with the scope of the function-- The "main" page has a function that looks like this: <script language="javascript" type="text/javascript"> window.a...

How to set object property in prototype function (scope problem)?

This is something trivial, which I've forgotten. There are possibly duplicates - I searched a little, found similar, but couldn't find as concise. String.prototype.test = function(){this.bar = this.length + 2;} var str = "foo"; str.test(); console.log(str); // foo console.log(str.bar); ...

Python: Advanced Nested List Comprehension Syntax

I was playing around with list comprehensions to get a better understanding of them and I ran into some unexpected output that I am not able to explain. I haven't found this question asked before, but if it /is/ a repeat question, I apologize. I was essentially trying to write a generator which generated generators. A simple generator t...

Access local variable from outside the function

I'm using TopUp to make a simple slideshow. Unfortunately they don't expose the image index. Is there a way I can access the local variable "index" without having to modify the original script? TopUp = (function() { var index = null; ... } ...

Javascript and JQuery "this" scope errors

A sample bit of code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt; <div id="myinfo">info</div> <input id="clickme" type="button" value="click here to display info"/> <script type="text/javascript"> function Fighter() { this.name = "Kenny"; // fight...

Tomcat 5.5 Axis2 application scope problem - Unable to create single instance

I have deployed an axis2 web service on Tomcat 5.5. The web service functions as expected. But I noticed I was getting duplicated log entries. After researching it became clear that multiple instances of the class were being created - ie the first time it ran, one log entry; second time, two entries and so on. I added the scope="appl...

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-...

Variable scope in JavaScript (Dojo)

I've started playing with Dojo a bit and I'm curious about variable scope issue that I've experienced. I have the following code: <div dojoType="dijit.form.Button"> <script type="dojo/method" event="onClick" args="evt"> console.dir(lastSelectedItem); </script> Rename </div> <div dojoType="dojo.data.ItemFileReadStor...

CD - Writing Custom Contexts & Scopes

Hi all, I would like to have my own contexts for some CDI-based projects. I need (want) custom scopes so that I can isolate the how long a component lives and where. To implement your own context, you need to implement the Context interface which is pretty self-explanatory, but how or where to you really define when it is created? Th...