scope

What is the relation between compile time execution of import/use and its scope and dynamics?

拜拜、爱过 提交于 2021-01-29 09:00:31
问题 This question originates from my previous question Why do fully qualified names have to be used when dynamically assessing namespaced elements? and another question Use php namespace inside function. Both of these questions boil down to the following explanation by php.net: Importing is performed at compile-time, and so does not affect dynamic class, function or constant names.... ....The use keyword must be declared in the outermost scope of a file (the global scope) or inside namespace

Im having promlen with button functions in gui powershell

允我心安 提交于 2021-01-29 05:58:50
问题 I am struggling here. i cannot figure out how to make the button functions read the $listbox1.selectedItems and $listbox2.selectedItem whats wrong here? if i try to look at the $listbox items after the OK button been pressed it will show me but not if i call the function button, ive deleted some unneccesery code parts. $form = New-Object System.Windows.Forms.Form $form.StartPosition = 'CenterScreen' $button1 = New-Object System.Windows.Forms.Button $button1.Text = 'Link' $button2 = New-Object

Local variables in global scope Lua

妖精的绣舞 提交于 2021-01-28 20:24:06
问题 So let's say I have a lua file, and at the top, I define a variable outside of any function, but I call it local local x = 1 Is there any difference between that local x, and a global x? 回答1: Yes, as it is local to the chunk that it is created in. Lua handles a chunk as the body of an anonymous function with a variable number of arguments (see §3.4.11). As such, chunks can define local variables, receive arguments, and return values. Moreover, such anonymous function is compiled as in the

Rationale for declaring variables at the top of each block in C? [closed]

久未见 提交于 2021-01-28 11:23:22
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 10 days ago . Improve this question I am teaching C programming and I am quite strict regarding variable declaration. As we use the C11 standard and knowing that the students would later use other programming language, I teach this rule: Any declared symbol should have its scope as narrow

Pointer valid out of scope? [duplicate]

爷,独闯天下 提交于 2021-01-28 08:35:03
问题 This question already has answers here : Can a local variable's memory be accessed outside its scope? (20 answers) Closed 5 years ago . There's a PDF I'm reading which says that a pointer is invalid after it passes out of scope. See slide #14 in the file below: http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-087-practical-programming-in-c-january-iap-2010/lecture-notes/MIT6_087IAP10_lec05.pdf Now I wrote almost the exact same code below in C++ with Dev-C++ compiler:

Understanding variable scope in nested functions in Python

ε祈祈猫儿з 提交于 2021-01-28 03:14:59
问题 I have the following functions in Python3.7 def output_report(): sheet_dict = {1: 'All', 2: 'Wind', 3: 'Soalr'} sheet_name = sheet_dict[sheet_num] file_name = f'{file_name}_{sheet_name}_row_{row_num}.csv' if row_num else f'{file_name}_{sheet_name}.csv' return file_name def test_file(x): file_name = output_report(sheet_num) return f'{x}_{file_name}' def good_func(): sheet_num = 2 row_num = 2 a = test_file('new file') return a when I call: good_func() It raises an error that: NameError: name

Issue with appending to DataFrame if empty

半世苍凉 提交于 2021-01-28 01:51:02
问题 I have a data frame that I initialize out of scope of a local method. I would like to do as follows: def outer_method(): ... do outer scope stuff here df = pd.DataFrame(columns=['A','B','C','D']) def recursive_method(arg): ... do local stuff here # func returns a data frame to be appended to empty data frame results_df = func(args) df.append(results_df, ignore_index=True) return results recursive_method(arg) return df However, this does NOT work. The df is always empty if I append to it this

Why do already popped scopes affect the check-sat time in subsequent scopes?

不想你离开。 提交于 2021-01-28 00:09:58
问题 General problem I've noticed several times that push-pop scopes that have already been popped appear to affect the time that a check-sat in a subsequent scope needs. That is, assume a program with multiple (potentially arbitrarily nested) push-pop scopes, each of which contain a check-sat command. Furthermore, assume that the second check-sat takes 10s, whereas the first one takes only 0.1s. ... (push) (assert (not P)) (check-sat) ; Could be sat, unsat or unknown (pop) ... (push) (assert (not

JS: Default function parameter values and scope

感情迁移 提交于 2021-01-27 21:33:56
问题 I'm a bit confused about how scope & variable assignment within a function seems to change when assigning a default parameter value for that function. For example, when this function has a default value assigned to parameter i , the output array variable appears to be block-scoped when inspected with Chrome Dev Console,: function steps(n, i = 40) { var output = [n]; } steps(10, 20); However, by removing the default parameter value for i , the output array variable is scoped locally: function

node - this.func() is not a function

佐手、 提交于 2021-01-27 19:31:32
问题 function Job(name, cronString, task) { "use strict"; this.name = name; this.cronString = cronString; this.isReady = false; this.task = task; } Job.prototype.performTask = (db, winston) => { "use strict"; const Promise = require("bluebird"); let that = this; return new Promise((resolve, reject) => { let output = ""; let success = true; try { output = that.task(); } catch(error) { success = false; reject(error); } if(success) { resolve(output); } }); }; module.exports = Job; Javascript newbie