scope

Why is a local function not always hidden in C#7?

て烟熏妆下的殇ゞ 提交于 2020-05-07 21:42:30
问题 What I am showing below, is rather a theoretical question. But I am interested in how the new C#7 compiler works and resolves local functions. In C#7 I can use local functions. For example (you can try these examples in LinqPad beta): Example 1: Nested Main() void Main() { void Main() { Console.WriteLine("Hello!"); } Main(); } DotNetFiddle for Example 1 Rather than calling Main() in a recursive way, the local function Main() is being called once, so the output of this is: Hello! The compiler

NSIS脚本学习:预定义宏(Predefines)

流过昼夜 提交于 2020-04-18 04:34:22
预定义宏(Predefine)即无需用户赋值就可直接使用的宏 NSIS脚本中的预定义宏有如下六种: 1、${__FILE__}:Current script name. 输出当前脚本的名称(如Galatea.nsi) 2、${__LINE__}:Current line number. 输出当前代码在NSIS脚本中的行数 3、${__DATE__}:Date when the script started compiling according to the current locale. 输出当前日期(如2016/4/1) 4、${__TIME__}:Time when the script started compiling according to the current locale. 输出当前时间(如22:47:10) 5、${__TIMESTAMP__}:Date & time of the last modification to the script file according to the current locale. 输出当前日期和时间(如2016年4月1日 22:47:09),注意这里面有两个参数,因此如果直接使用 !echo ${__TIMESTAMP__} 在编译时就会报错: !echo expects 1 parameters, got 2.

Python global variable/scope confusion [duplicate]

南楼画角 提交于 2020-04-11 07:37:11
问题 This question already has answers here : Python scope: “UnboundLocalError: local variable 'c' referenced before assignment” [duplicate] (4 answers) Closed 4 years ago . I've started teaching myself python, and have noticed something strange to do with global variables and scope. When I run this: x = 2 y = 3 z=17 def add_nums(): y = 6 return z+y The result of 23 is printed... However, when I expand the return to be: x = 2 y = 3 z=17 def add_nums(): y = 6 z = z + y return z I get the following

Incrementing integer variable of global scope in Python [duplicate]

谁说我不能喝 提交于 2020-04-07 03:29:19
问题 This question already has answers here : How do I pass a variable by reference? (26 answers) Closed 4 years ago . I am trying to change global value x from within another functions scope as the following code shows, x = 1 def add_one(x): x += 1 then I execute the sequence of statements on Python's interactive terminal as follows. >>> x 1 >>> x += 1 >>> x 2 >>> add_one(x) >>> x 2 Why is x still 2 and not 3? 回答1: Because x is a local (all function arguments are), not a global, and integers are

Late destruction of function parameters

瘦欲@ 提交于 2020-04-05 15:53:54
问题 According to 5.2.2/4 "Function call" in n4640 (8.2.2/4 in n4659) function parameters are created and destroyed in the context of the caller. And implementations are allowed to delay the destruction of function parameters to the end of the enclosing full expression (as an implementation-defined feature). Note that the choice is not unspecified , but rather implementation-defined . ( It is not entirely clear how this agrees with 3.3.3 "Block scope" (6.3.3 in n4659), which seems to imply that

new Function scope

五迷三道 提交于 2020-03-26 07:59:14
问题 I've got a piece of code with a ReferenceError here or below: function foo() { function bar() { console.log('bar'); } var x = new Function('bar();'); x(); } foo(); // ReferenceError: bar is not defined Is it possible to make this happen? I mean the bar function to exist inside the new Function 回答1: Functions created with the Function constructor do not create closures to their creation contexts; they always are created in the global scope. When running them, they will only be able to access

What is the scope of variables in JavaScript?

亡梦爱人 提交于 2020-03-26 04:03:55
问题 What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? 回答1: TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking at the source code. The four scopes are: Global - visible by everything Function - visible within a function (and its sub-functions and blocks) Block -

Laravel - Using scope

99封情书 提交于 2020-03-25 18:47:27
问题 I am using scope to specify if i am not an admin, then return courses only by instructor. What I am trying to do is when an instructor signs into their account they can only view the course they have been assigned to teach.. I am unsure where i have gone wrong in my query.. it is throwing no errors so i know it has not broke it.. which is a good thing? But my query is not displaying the results I need. I appreciate any help. Thanks 回答1: Your instructor relation doesn't have user_id because it

Javascript OOP, Accessing methods from other nested methods

拈花ヽ惹草 提交于 2020-03-25 17:24:52
问题 Ok, folks, getting there with learning my JS. I have come across a singular one. Here's the code: hangar = function(game){ } hangar.prototype = { loadImages: function(graphicAssets){ ... }, writeTerminal: function(timer, str, destination){ }, writeStats: function(){ var writeTerminal = this.writeTerminal; console.log('wt', this.writeTerminal); console.log('wt2', writeTerminal); //ZOMG This does not work! }, handleHangarInput: function(layerShips, layerBg){ ... does some variable declarations

Clashing global and local variable name

佐手、 提交于 2020-03-24 00:39:18
问题 Here is the code snippet in question: package main import ( "fmt" ) var a string = "hello" func main() { b := "world" fmt.Println(a, b) a := "bye" fmt.Println(a, b) } Output: hello world bye world My question is, how do I resolve name clash between the "global" and "local" variables a ? More specifically, how do I tell Go which a to use? 回答1: I think your original example illustrates the situation well. Just like most in programming languages the scope matters. The scoping closest to the use