scope

Using functions and environments

Following the recent discussions here (e.g. 1, 2 ) I am now using environments in some of my code. My question is, how do I create functions that modify environments according to its arguments? For example: y <- new.env() with(y, x <- 1) f <- function(env,z) { with(env, x+z) } f(y,z=1) throws Error in eval(expr, envir, enclos) : ...

#Define's scope throughout library?

Say I have a constant: #define PI 3.14 Say I have a static library with multiple header and source files. If I declare this in the header file, will its scope apply to all of the source files? Or do the source files need to include the header with the declaration of PI? ...

C++ stack memory still valid?

Hi all, If I create an object on the stack and push it into a list, then the object loses scope (outside of the for loop in the example below) will the object still exist in the list? If the list still holds the object, is that data now invalid/possibly corrupt? Please let me know, and please explain the reasoning.. Thanks, jbu cl...

How to define a macro that retains its scope after it's been called

I'm trying to make a macro to make it easier to define properties. Simplified example but at the moment I have this to provide a property with a public get and private set: #define propertyRO(xxType, xxName)\ property xxType xxName\ {\ xxType get() {return m___##xxName;}\ void set(xxType value) {m___##xxName = v...

My Oracle 9i package won't compile, says that a user-defined function is out of scope... but it isn't...

I have an Oracle package which contains user-defined functions and procedures, including two user-defined functions which are called from SELECT and UPDATE statements. The functions in question are defined before the procedures that call them. This piece of code compiles and works fine on Oracle 10g but won't compile on 9i. The code s...

What is the scope of require_once in PHP?

Simple question: Is the scope of require_once global? For example: <?PHP require_once('baz.php'); // do some stuff foo ($bar); function foo($bar) { require_once('baz.php'); // do different stuff } ?> When foo is called, does it re-parse baz.php? Or does it rely on the already required file from the main php file (analagou...

How to access a (shadowed) global function in ruby.

Hi, I was wondering how to access a global function fn in ruby from a class which also defined a method fn. I have made a workaround by aliasing the function like so: def fn end class Bar alias global_fn fn def fn # how to access the global fn here without the alias global_fn end end I'm looking for some...

Is it possible to declare two variables of different types in a for loop?

Is it possible to declare two variables of different types in the initialization body of a for loop in C++? For example: for(int i=0,j=0 ... defines two integers. Can I define an int and a char in the initialization body? How would this be done? ...

variable scope in statement blocks

for (int i = 0; i < 10; i++) { Foo(); } int i = 10; // error, 'i' already exists ---------------------------------------- for (int i = 0; i < 10; i++) { Foo(); } i = 10; // error, 'i' doesn't exist By my understanding of scope, the first example should be fine. The fact neither of them are allowed seems even more odd. Sur...

Ruby IRB - Requires and Scope

Trying to understand this problem I'm running into. I create file welcome.rb. The contents of this file: welcome_message = "hi there" I then launch an irb session. And type require 'welcome'. That works fine. Then I type: puts welcome_message I get the error message undefined local variable or method `welcome_message' for main:Obj...

Question on overview of C# OOP in business WinForms application - scope of Object

I may have all this OO completely wrong, but here goes: Ok, the scenario is a classic order entry. Customer places an Order which has OrderLineItems of StockItems. Order is entered by Employee. Application starts and asks for login/password Employee selects 'Orders' from Mainmenu form Orders forms opens.... Employee selects Customer ...

Objective-C iPhone - NSMutableArray addobject becomes immediately out of scope.

ok. I have a really odd and mind boggling problem. I have two class files, both of which are NSObject inheritors. The series of code is as follows CustomClass *obj; obj = [[CustomClass alloc] init]; [myArray addObject:obj]; <--------Immediately after this line if I hover over the array it shows it as having 1 object that is out of ...

What is the difference between an object's scope and it's context in javascript?

In the vernacular, scope and context have a lot in common. Which is why I get confused when I read references to both, such as in the quote below from an article on closures: Scope refers to where variables and functions are accessible, and in what context it is being executed. (@robertnyman) As far as I can tell, context is just ...

python decorator to modify variable in current scope

Goal: Make a decorator which can modify the scope that it is used in. If it worked: class Blah(): # or perhaps class Blah(ParentClassWhichMakesThisPossible) def one(self): pass @decorated def two(self): pass >>> Blah.decorated ["two"] Why? I essentially want to write classes which can maintain specifi...

Creating many new instances vs reusing them?

I have multiple business entities in VB.NET Windows Forms application. Right now they are instanced on application startup and used when needed. They hold descriptions of business entities and methods for storing and retrieving data. To cut the long story short, they are somewhat heavy objects to construct (they have some internal dictio...

Why does it matter that in Javascript, scope is function-level, not block-level?

In the question http://stackoverflow.com/questions/1451009/javascript-infamous-loop-problem the accepted answer from Christoph's says JavaScript's scopes are function-level, not block-level What if Javascript's scopes are block-level, then would the Infamous Loop problem still occur? Or will there be a different (and easier) ...

In Javascript, when is a new scope created? (with a new function and in a "with" statement) Are these the only 2 situations?

In Javascript, when is a new scope created? The 2 situations I know of are: with a new function in a "with" statement as a note, any new block (in if-then-else, loops, or just beginning a block for no other reason) won't create a new scope. Is there a third situation where a new scope is created besides the two situations above? ...

Scoping inside Javascript anonymous functions

I am trying to make a function return data from an ajax call that I can then use. The issue is the function itself is called by many objects, e.g.: function ajax_submit (obj) { var id = $(obj).attr('id'); var message = escape ($("#"+id+" .s_post").val ()); var submit_string = "action=post_message&message="+message; ...

Lexical and dynamic scoping in Mathematica: Local variables with Module, With, and Block

The following code returns 14 as you'd expect: Block[{expr}, expr = 2 z; f[z_] = expr; f[7]] But if you change that Block to a Module then it returns 2*z. It seems to not matter what other variables besides expr you localize. I thought I understood Module, Block, and With in Mathematica but I can't explain the difference in beha...

What's the scope of a Javascript variable declared in a for() loop?

Check out the following snippet of HTML/Javascript code: <html> <head> <script type="text/javascript"> var alerts = []; for(var i = 0; i < 3; i++) { alerts.push(function() { document.write(i + ', '); }); } for (var j = 0; j < 3; j++) { (alerts[j])(); } for (var i = 0; i < 3; i++) { (alerts[i])(); } </script> </head><body><...