scoping

Any way to access function installed by makeActiveBinding?

 ̄綄美尐妖づ 提交于 2019-12-06 18:51:57
问题 The title basically says it all. If I do this ... makeActiveBinding("x", function() runif(2), .GlobalEnv) x # [1] 0.7332872 0.4707796 x # [1] 0.5500310 0.5013099 ... is there then any way for me to examine x to learn what function it is linked to (and if not, why not)? (In this case, I'd like to be able to learn that x was defined to be function() runif(2) .) 回答1: With a bit of noodling around in envir.c , I can get this to work: #include <Rcpp.h> using namespace Rcpp ; #define HASHSIZE(x)

scope of the object literal methods

余生长醉 提交于 2019-12-06 17:28:19
I am currently doing some experiment about scoping and hoisting in JS.Here i have two example which confusing me in a different way.First i have assigned a anonymous function to a variable named parent.Obviously returned child function has access to its outer function scope so it can access text variable.It is clear and easy.Here is the code.. var parent = function() { var text = 'i can access the container'; return function() { alert(text); } }(); parent(); Later i wanted returned an object instead of a function which have a method.This method is not directly in the body of the immediately

Xtext cross referencing and scoping

血红的双手。 提交于 2019-12-06 09:34:57
I have some problems with xtext cross referencing Here is a very simple grammer: grammar org.xtext.example.mydsl1.Test with org.eclipse.xtext.common.Terminals generate test "http://www.xtext.org/example/mydsl1/Test" Model: block=Block? cs+=Company* ; Block: '{' g=[Employee] '}'; Company: 'Company' name=ID '{' es+= Employee* '}'; Employee: 'Employee' name=ID ';' ; and it is my dsl : { Pooyan } Company Sony{ Employee Pooyan; Employee John; } It always shown that "Couldn't resolve reference to Employee 'Pooyan'." Could anyone please help me? I have no idea... The fully qualified name of Pooyan is

parallel::clusterExport how to pass nested functions from global environment?

笑着哭i 提交于 2019-12-06 08:39:29
I'm making a function (myFUN) that calls parallel::parApply at one point, with a function yourFUN that is supplied as an argument. In many situations, yourFUN will contain custom functions from the global environment. So, while I can pass "yourFUN" to parallel::clusterExport, I cannot know the names of functions inside it beforehand, and clusterExport returns me an error because it cannot find them. I don't want to export the whole enclosing environment of yourFUN, since it might be very big. Is there a way for me to export only the variables necessary for running yourFUN? The actual function

Python scoping problem

╄→гoц情女王★ 提交于 2019-12-06 03:52:31
I have a trivial example: def func1(): local_var = None def func(args): print args, print "local_var:", local_var local_var = "local" func("first") func("second") func1() I expect the output to be: first local_var: None second local_var: local However, my actual output is: first local_var: Traceback (most recent call last): File "test.py", line 13, in func1() File "test.py", line 10, in func1 func("first") File "test.py", line 6, in func print "local_var:", local_var UnboundLocalError: local variable 'local_var' referenced before assignment My understanding of python scoping rules dictate that

Scoping rules for variables initialized in a for loop [duplicate]

旧巷老猫 提交于 2019-12-06 02:03:59
This question already has answers here : Closed 6 years ago . Possible Duplicate: Javascript closure inside loops - simple practical example I'm playing around with setTimeout in a project of mine in order to throttle the adding of elements to the DOM (so UI won't freeze during page loading). However, I've encountered something a bit puzzling to me. Given this code: for(var i = 0; i < 5; i++) { var j = i + 10; console.log("i is: " + i + " j is: " + j); setTimeout(function() { console.log("in timeout i is: " + i + " j is: " + j); }, i * 1000); } I get the following output: i is: 0 j is: 10 i is

Issue with child scoping of this in Typescript

被刻印的时光 ゝ 提交于 2019-12-05 19:25:16
This is ALMOST the same as every other this scoping question I have read so far other than one slight difference which makes it relevant (imo) to ask this question. Now originally my problem was scoping of this with Knockout and Typescript, so given the following: class ViewModel { public SomeObservableArray = new ko.observableArray(); public AddToTheObservableArray(someJsonData: any) { this.SomeObservableArray.push(new SomePojo(someJsonData)); } } So the this bit in the above code would blow up because Typescript makes you think that this is the class instance, but in reality it is some other

Rails: default scoping being cached by query cache?

时光毁灭记忆、已成空白 提交于 2019-12-05 19:25:01
I got a default scoping like this which is dynamic: default_scope :conditions => ["departure_date >= ?", DateTime.current.beginning_of_day] When I use this code the first day is ok. Lets say first day is 28-03-2011 But the next day seems like it's still using "departure_date >= 28-03-2011" Is my default scoping being cached? The problem is that that code is only being executed once , when your app is loaded, and thus the actual date isn't changing. You need to change it to load lazily: default_scope lambda { { :conditions => ["departure_date >= ?", DateTime.current.beginning_of_day] } } This

Scoping issue in Javascript

怎甘沉沦 提交于 2019-12-05 02:50:59
问题 I need to have some information about the Scoping issue in Javascript. I know that it spports lexical(static) scoping, but, does not it support dynamic scoping as well? If you know anything about the scoping in Javascript, would you please share them with me ? Thanks 回答1: I think you're confused because Javascript uses static scoping but at function-level, not at block level like usual structured languages. var foo = "old"; if (true) {var foo = "new";} alert (foo == "new") So be careful,

Any way to access function installed by makeActiveBinding?

梦想与她 提交于 2019-12-05 00:15:21
The title basically says it all. If I do this ... makeActiveBinding("x", function() runif(2), .GlobalEnv) x # [1] 0.7332872 0.4707796 x # [1] 0.5500310 0.5013099 ... is there then any way for me to examine x to learn what function it is linked to (and if not, why not)? (In this case, I'd like to be able to learn that x was defined to be function() runif(2) .) With a bit of noodling around in envir.c , I can get this to work: #include <Rcpp.h> using namespace Rcpp ; #define HASHSIZE(x) LENGTH(x) #define HASHVALUE(x) TRUELENGTH(x) // [[Rcpp::export]] SEXP get_binding_fun( std::string name,