scope

cmake variable scope, add_subdirectory

时光怂恿深爱的人放手 提交于 2019-12-28 04:52:05
问题 I have a CMakeLists.txt in my project root and one in my /src folder. The one in the /src folder only contains a variable with the .cpp files ( set (SOURCEFILES main.cpp foo.cpp) ) and in the root CMakeLists.txt I do add_subdirectory(src) and later I do add_executable(MyApp ${SOURCEFILES}) . But cmake gives me the error add_executable called with incorrect number of arguments, no sources provided How do I get cmake to see the variable? I read that cmake only knows global variables, but that's

Why is the type not accessible?

柔情痞子 提交于 2019-12-28 04:26:39
问题 I'm trying to return a type from a fortran function. This is the code. module somemodule implicit none ! define a simple type type sometype integer :: someint end type sometype ! define an interface interface ! define a function that returns the previously defined type type(sometype) function somefunction() end function somefunction end interface contains end module somemodule In gfortran (4.4 & 4.5) I get the following error: Error: The type for function 'somefunction' at (1) is not

How to avoid accidentally implicitly referring to properties on the global object?

∥☆過路亽.° 提交于 2019-12-28 04:08:11
问题 Is it possible to execute a block of code without the implicit with(global) context that all scripts seem to have by default? For example, in a browser, would there be any way to set up a script so that a line such as const foo = location; throws Uncaught ReferenceError: location is not defined instead of accessing window.location , when location has not been declared first? Lacking that, is there a way that such an implicit reference could result in a warning of some sort? It can be a source

Javascript eval on global scope?

不羁的心 提交于 2019-12-28 04:01:40
问题 Is it possible to use the eval command to execute something with a global scope? For example, this will cause an error: <script> function execute(x){ eval(x); } function start(){ execute("var ary = new Array()"); execute("ary.push('test');"); // This will cause exception: ary is not defined } </script> <html><body onLoad="start()"></body></html> I know the 'with' keyword will set a specific scope, but is there a keyword for the global scope? Or is it possible to define a custom scope that

Javascript eval on global scope?

僤鯓⒐⒋嵵緔 提交于 2019-12-28 04:01:10
问题 Is it possible to use the eval command to execute something with a global scope? For example, this will cause an error: <script> function execute(x){ eval(x); } function start(){ execute("var ary = new Array()"); execute("ary.push('test');"); // This will cause exception: ary is not defined } </script> <html><body onLoad="start()"></body></html> I know the 'with' keyword will set a specific scope, but is there a keyword for the global scope? Or is it possible to define a custom scope that

Is there a generic way to memoize in Scala?

寵の児 提交于 2019-12-28 02:29:29
问题 I wanted to memoize this: def fib(n: Int) = if(n <= 1) 1 else fib(n-1) + fib(n-2) println(fib(100)) // times out So I wrote this and this surprisingly compiles and works (I am surprised because fib references itself in its declaration): case class Memo[A,B](f: A => B) extends (A => B) { private val cache = mutable.Map.empty[A, B] def apply(x: A) = cache getOrElseUpdate (x, f(x)) } val fib: Memo[Int, BigInt] = Memo { case 0 => 0 case 1 => 1 case n => fib(n-1) + fib(n-2) } println(fib(100)) //

Static (Lexical) Scoping vs Dynamic Scoping (Pseudocode)

巧了我就是萌 提交于 2019-12-28 02:22:19
问题 Program A() { x, y, z: integer; procedure B() { y: integer; y=0; x=z+1; z=y+2; } procedure C() { z: integer; procedure D() { x: integer; x = z + 1; y = x + 1; call B(); } z = 5; call D(); } x = 10; y = 11; z = 12; call C(); print x, y, z; } From my understanding, the result of this program when run using static scoping is: x=13, y=7, and z=2. However, when it is run using dynamic scoping , the result is: x=10, y=7, and z=12. These results are the ones that our professor gave us. However, I

Nested list comprehension scope

℡╲_俬逩灬. 提交于 2019-12-28 01:02:29
问题 The best way to explain my question is with an example: example.py: class A(object): integers = [1, 2, 3] singles = [i for i in integers] class B(object): integers = [1, 2, 3] pairs = [(i, j) for i in integers for j in integers] When I run this under python 2 it works fine, but under python 3 I get a NameError for class B (but not class A ): $ python example.py Traceback (most recent call last): File "example.py", line 6, in <module> class B(object): File "example.py", line 8, in B pairs = [

JavaScript scope and closure

拈花ヽ惹草 提交于 2019-12-27 17:35:14
问题 I'm trying to wrap my head around closures (there's a joke in there somewhere) and I ran across this: (function () { /* do cool stuff */ })(); How does this work? What's the purpose of putting the function in parens? Why the empty parens afterwards? 回答1: The point of this is that any variables declared in the cool stuff will not be created in global namespace. Any function in javascript will create such a scope. Suppose you have some javascript you want to run. If you do this: var b = 1; //

JavaScript scope and closure

时间秒杀一切 提交于 2019-12-27 17:34:58
问题 I'm trying to wrap my head around closures (there's a joke in there somewhere) and I ran across this: (function () { /* do cool stuff */ })(); How does this work? What's the purpose of putting the function in parens? Why the empty parens afterwards? 回答1: The point of this is that any variables declared in the cool stuff will not be created in global namespace. Any function in javascript will create such a scope. Suppose you have some javascript you want to run. If you do this: var b = 1; //