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) : ...
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?
...
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...
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...
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...
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...
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 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?
...
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...
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...
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
...
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 ...
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 ...
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...
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...
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? 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? ...
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;
...
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...
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><...