scope

Referencing environment and scope

倾然丶 夕夏残阳落幕 提交于 2019-12-11 00:35:21
问题 In any programming language, is the type of referencing environment dependent on the scoping? i.e. a static scoped language would necessarily have static referencing environment? 回答1: Yes. The referencing environment is the collection of variables which can be used. In a static scoped language, you can only reference the variables in the static reference environment. A function in a static scoped language does have dynamic ancestors (i.e. its callers), but it can not reference any variables

Why let at function scope in JavaScript?

别等时光非礼了梦想. 提交于 2019-12-11 00:21:27
问题 I understand the block vs. function scoping of let & var (or I thought I did). Recently I ran across some JavaScript that used let in function scope where I thought it would be equivalent to using var , like: function xyz ( abc ) { let mno = abc - 1; /* or whatever */ ... } Is there any functional difference between that and using var there? Or is it just a stylistic thing? 回答1: No difference whatsoever. It's either a stylistic thing or a misunderstanding of how var and let work. Perhaps the

Friend method “not declared in this scope” in C++

瘦欲@ 提交于 2019-12-10 23:17:39
问题 First to provide some context, this is for an assignment involving semaphores. We are to find code for the dining philosophers problem, get it working, and then perform some analysis and manipulation. However, I am stuck with an error. The original code is taken from http://www.math-cs.gordon.edu/courses/cs322/projects/p2/dp/ using the C++ solution. The error I am receiving in Code::Blocks is philosopher.cpp|206|error: 'Philosopher_run' was not declared in this scope| and this error occurs in

Change variable scope of function in Javascript

拟墨画扇 提交于 2019-12-10 23:16:48
问题 I'm not interested in call or apply to change the this reference. Just for my own interest, I'm playing with an idea for another require technique for javascript that would make for some cleaner definitions, and the goal was to not have to pass arrays or doubly reference module names for my definitions. I have a sample solution (just a proof of concept) using toString and eval on a function but I'm wondering if there is a safer or more efficient way to do this. // Sample module libraries

Declare symbols that remain valid outside their scope

只谈情不闲聊 提交于 2019-12-10 22:25:35
问题 Z3 2.x had the feature (well, probably rather the bug) that symbol declarations were not popped away, e.g. the following code is accepted by Z3 2.x: (push) (declare-fun x () Int) ; Assumptions made in this scope will be popped correctly (pop) (assert (= x x)) Z3 3.x no longer accepts this code ("unknown constant"). Is there a way to restore the old behaviour? Or another way how one could declare symbols inside scopes such that the declaration (and only the declaration, not the assumptions) is

Scope ambiguity in nested if

半世苍凉 提交于 2019-12-10 22:14:32
问题 Let's say one has a class Foo such as class Foo { public: void bar(); operator bool() const { return true; } }; then one can do if(Foo foo = Foo()) { if(Foo foo = Foo()) { foo.bar(); } } Now I'm having trouble grasping the scope resolution going on here (I would've expected a compiler error for redeclaring foo). I expect foo.bar() to execute on the second foo (its scope is "closer") but am I garanteed that it's actually a different object than the first foo? Furthermore, are they each

sharing dictionary contents between class instances

丶灬走出姿态 提交于 2019-12-10 21:56:26
问题 let's say I have a Dictionary structure like var stocks = new Dictionary<string, double>(); stocks.Add("APPL", 1234.56); While retaining the ability to Add and Remove from the Dictionary, is there a way the contents can be 'shared' between instances of it's containing class? (By the way, I am forced to inherit from a containing class that cannot be static.) Or is there another way to represent the data that would allow this type of sharing? 回答1: A class does not need to be static to have

Are model beans singleton in spring?

纵饮孤独 提交于 2019-12-10 21:38:37
问题 In spring the classes annotated with @Controller , @Service , @Repository , @Component act as Spring beans and will be instantiated by Spring container in singleton (Default scope). Here the model beans are not annotated with any stereo type annotations. My question here is whether the model beans are singleton or not i.e., if they come under Spring container. If it is true then, how has the concurrency issue been handled? 回答1: Model attributes, ex. from @ModelAttribute annotated parameters,

Javascript: when does the scope chain created?

£可爱£侵袭症+ 提交于 2019-12-10 21:32:21
问题 I heard two kinds of saying: When function is defined: In book Professional Javascript for Web Developers, 3rd Edition , in the Chapter 7: Function Expressions Closures parts: When compare() is defined, its scope chain is created , preloaded with the global variable object, and saved to the internal [[Scope]] property. When the function is called, an execution context is created and its scope chain is built up by copying the objects in the function’s [[Scope]] property. it's said the scope

JavaScript variable scope return “undefined” [duplicate]

自作多情 提交于 2019-12-10 21:24:48
问题 This question already has answers here : Surprised that global variable has undefined value in JavaScript (6 answers) Closed 5 years ago . There is one sentence in JavaScript Guide about variable scope:"Variables in JavaScript are in a sense "hoisted" or lifted to the top of the function or statement. However, variables that aren't initialized yet will return a value of undefined." /** * Example 2 */ // will return a value of undefined var myvar = "my value"; (function() { console.log(myvar);