scoping

How to refer to a global type from within a class that has a nested type with the same name?

对着背影说爱祢 提交于 2019-12-23 17:17:59
问题 I have a class declared at the global scope and another class with the same name that is nested within some class. class Address { var someProperty: String? } class ThirdPartyAPI { class Address { var someOtherProperty: String? init(fromAddress address: Address) { self.someOtherProperty = address.someProperty } } } The question is: how can I refer to a global class instead of the inner one from its initialiser? In the example given I've got an error Value of type 'ThirdPartyAPI.Address' has

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

谁都会走 提交于 2019-12-22 18:04:25
问题 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.

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

会有一股神秘感。 提交于 2019-12-22 10:00:09
问题 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

Environments in R Shiny

非 Y 不嫁゛ 提交于 2019-12-21 12:42:29
问题 At http://shiny.rstudio.com/articles/scoping.html the rules for scoping in shiny are well explained. There are 3 environments or levels nested inside each other: objects available within a function, within a session and within all sessions. Using <- will change the object within the environment you are in and <<- will change it globally i.e. for all sessions. What if I define a variable within the session but want to change it from within a function? <- will just change it within the function

Environments in R Shiny

China☆狼群 提交于 2019-12-21 12:41:26
问题 At http://shiny.rstudio.com/articles/scoping.html the rules for scoping in shiny are well explained. There are 3 environments or levels nested inside each other: objects available within a function, within a session and within all sessions. Using <- will change the object within the environment you are in and <<- will change it globally i.e. for all sessions. What if I define a variable within the session but want to change it from within a function? <- will just change it within the function

What methods are there to modularize C code?

孤人 提交于 2019-12-20 12:15:56
问题 What methods, practices and conventions do you know of to modularize C code as a project grows in size? 回答1: Create header files which contain ONLY what is necessary to use a module. In the corresponding .c file(s), make anything not meant to be visible outside (e.g. helper functions) static. Use prefixes on the names of everything externally visible to help avoid namespace collisions. (If a module spans multiple files, things become harder., as you may need to expose internal things and not

Python variable assigned by an outside module is accessible for printing but not for assignment in the target module

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:21:01
问题 I have two files, one is in the webroot, and another is a bootstrap located one folder above the web root (this is CGI programming by the way). The index file in the web root imports the bootstrap and assigns a variable to it, then calls a a function to initialize the application. Everything up to here works as expected. Now, in the bootstrap file I can print the variable, but when I try to assign a value to the variable an error is thrown. If you take away the assignment statement no errors

Are variables statically or dynamically “scoped” in javascript?

故事扮演 提交于 2019-12-18 11:08:24
问题 Or more specific to what I need: If I call a function from within another function, is it going to pull the variable from within the calling function, or from the level above? Ex: myVar=0; function runMe(){ myVar = 10; callMe(); } function callMe(){ addMe = myVar+10; } What does myVar end up being if callMe() is called through runMe()? 回答1: Jeff is right. Note that this is not actually a good test of static scoping (which JS does have). A better one would be: myVar=0; function runMe(){ var

Set a functions environment to that of the calling environment (parent.frame) from within function

送分小仙女□ 提交于 2019-12-17 18:41:15
问题 I am still struggling with R scoping and environments. I would like to be able to construct simple helper functions that get called from my 'main' functions that can directly reference all the variables within those main functions - but I don't want to have to define the helper functions within each of my main functions. helpFunction<-function(){ #can I add a line here to alter the environment of this helper function to that of the calling function? return(importantVar1+1) } mainFunction<

While without global

坚强是说给别人听的谎言 提交于 2019-12-17 10:09:29
问题 This snippet of code is from JuliaBoxTutorials myfriends = ["Ted", "Robyn", "Barney", "Lily", "Marshall"] i = 1; while i <= length(myfriends) friend = myfriends[i] println("Hi $friend, it's great to see you!") i += 1 end giving this error when run with Julia v1.0 UndefVarError: i not defined Stacktrace: [1] top-level scope at ./In[12]:5 [inlined] [2] top-level scope at ./none:0 But when i += 1 is replaced with global i += 1 it works. I guess this was still working in v0.6 and the tutorial