scope

LINQ Query - Explanation needed of why these examples are different

淺唱寂寞╮ 提交于 2019-12-21 04:34:07
问题 I'm reading the book "LINQ Pocket Reference" and there is a particular example (slightly modified below) that I'm having difficulty getting my head around... The explanation in the book is a bit brief, so I was wondering if someone could break it down step-by-step for me so that it makes sense... IEnumerable<char> query2 = "Not what you might expect"; foreach (char vowel in "aeiou") { var t = vowel; query2 = query2.Where(c => c != t); // iterate through query and output (snipped for brevity)

What is the scope of the counter variable in a for loop?

断了今生、忘了曾经 提交于 2019-12-21 04:07:11
问题 I get the following error in Visual Studio 2008: Error 1 A local variable named 'i' cannot be declared in this scope because it would give a different meaning to 'i', which is already used in a 'child' scope to denote something else This is my code: for (int i = 0; i < 3; i++) { string str = ""; } int i = 0; // scope error string str = ""; // no scope error I understand that str ceases to exist once the loop terminates, but I also thought that the scope of i was confined to the for loop as

Variable scope in VBScript functions

久未见 提交于 2019-12-21 04:00:10
问题 I have a question about variable scope in VBScript. I know there's the following keywords (from autoitscript.com): Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!) Global = Forces creation of the variable in the Global scope Local = Forces creation of the variable in the Local/Function scope Imagine that I have the following .vbs file: Dim strPath strPath = "C:\folder" DisplayPath strPath Sub DisplayPath(strPath) 'Does this

Building a class hierarchy in Coq?

回眸只為那壹抹淺笑 提交于 2019-12-21 03:56:19
问题 I can naively construct a hierarchy of algebraic structures in Coq using type classes. I'm having some trouble finding resources on Coq's syntax and semantics for type classes. However, I believe the following is a correct implementation of semigroups, monoids and commutative monoids: Class Semigroup {A : Type} (op : A -> A -> A) : Type := { op_associative : forall x y z : A, op x (op y z) = op (op x y) z }. Class Monoid `(M : Semigroup) (id : A) : Type := { id_ident_left : forall x : A, op

Rails validates_uniqueness_of across multiple columns with case insensitivity

谁都会走 提交于 2019-12-21 03:33:11
问题 I have a model that has two fields, which I will call first_name and last_name, and I want to make sure that the combination of the two are case-insensitively unique. I've gotten halfway there by using this: validates_uniqueness_of :first_name, :scope => :last_name The problem is that the uniqueness check seems to be case sensitive, even though the documentation says it should be case insensitive by default. So given an existing record: { :first_name => 'John', :last_name => 'Smith' } This

PHP: $_SESSION - What are the pros and cons of storing temporarily used data in the $_SESSION variable

半城伤御伤魂 提交于 2019-12-21 03:10:32
问题 One thing I've started doing more often recently is retrieving some data at the beginning of a task and storing it in a $_SESSION['myDataForTheTask'] . Now it seems very convenient to do so but I don't know anything about performance, security risks or similar, using this approach. Is it something which is regularly done by programmers with more expertise or is it more of an amateur thing to do? For example: if (!isset($_SESSION['dataentry'])) { $query_taskinfo = "SELECT participationcode,

How to make block local variables the default in ruby 1.9?

久未见 提交于 2019-12-21 02:50:09
问题 Ruby 1.9 gives the ability to define variables that are just local to a block and do not close over variables of the same name in an outer scope: x = 10 proc { |;x| x = 20 }.call x #=> 10 I would like to have this behaviour as default for some blocks I define - without having to use the |;x, y, z| syntax (note the semicolon). I do not think Ruby allows this natively but is it possible to hack this functionality? I have one solution currently but it's quite ugly as it requires checking to see

Variable scope outside of classes

空扰寡人 提交于 2019-12-20 23:33:04
问题 My text editor of choice is extensible through python plugins. It requires me to extend classes and override its methods. The general structure looks similar the snippet below. Note that the function signature is fixed. ftp_client is supposed to be shared by instances of both classes. ftp_client = None class FtpFileCommand(sublime_plugin.TextCommand): def run(self, args): global ftp_client # does it reference the variable of the outer scope? self.ftp_client = ftplib.FTP('foo') # login and

C++ method call and type scope resolution ambiguity

余生长醉 提交于 2019-12-20 18:16:44
问题 I hope the title actually describes what I wanted to ask... I wrote a piece of code that compiles with gcc and works as I intended. However, it does not compile with llvm and the code executes differently when compiled with icc! Here is an example of the problem: #include <iostream> using std::cout; using std::endl; class A { public: virtual void foo() { cout << "A::foo()" << endl; } }; class B : public A { public: typedef A base; virtual void foo() { cout << "B::foo()" << endl; } }; int main

Rails includes with scope

时光总嘲笑我的痴心妄想 提交于 2019-12-20 17:37:48
问题 I have a model called Author. An author has many Articles. Articles have a scope called .published that does: where(published: true). I want to load the author, with the published articles. I tried: Author.includes(:articles.published).find(params[:author_id]) But that throws an error: undefined method 'published'. Any idea? 回答1: I think the best solution would be: Author.includes(:articles).where(:articles=>{published: true}).find(params[:author_id]) Or you can create scope: class Author <