equality

How do the SQL “IS” and “=” operators differ?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 11:12:35
问题 I am building some prepared statements that use parametrized values. As an example: SELECT * FROM "Foo" WHERE "Bar"=@param Sometimes @param might be NULL . In such cases, I want the query to return records where Bar is NULL , but the above query will not do that. I have learned that I can use the IS operator for this. In other words: SELECT * FROM "Foo" WHERE "Bar" IS @param Aside from the differing treatment of NULL , are there any other ways in which the above two statements will behave

In Scala, is there a neat and simple way to compare one value with multiple values

試著忘記壹切 提交于 2019-12-05 11:00:06
问题 Say I have a variable x, and I want to check if it's equal to any one of multiple values a, b, c, d, e (I mean the == equality, not identity). In an SQL query the same concept is handled with WHERE x IN (a, b, c, d, e). Is there something equivalent in Scala that's as straightforward as that? I know it's otherwise possible to do it in one line with a complex expression such as building a HashSet and checking for existence in the set, but I'd prefer to use a simple construct if it's available.

Clojure equality of collections with sequences

自古美人都是妖i 提交于 2019-12-05 09:00:37
I noticed that Clojure (1.4) seems to be happy to consider vectors equal to the seq of the same vector, but that the same does not apply for maps: (= [1 2] (seq [1 2])) => true (= {1 2} (seq {1 2})) => false Why should the behaviour of = be different in this way? Clojure's = can be thought of as performing its comparisons in two steps: Check if the types of the things being compared belong to the same "equality partition", that is a class of types whose members might potentially be equal (depending on things like the exact members of a given data structure, but not the particular type in the

Minimization with R nloptr package - multiple equality constraints

不羁的心 提交于 2019-12-05 08:41:30
Is it possible to specify more than one equality constraint in nloptr function in R? The code that I am trying to run is the following: eval_f <- function( x ) { return( list( "objective" = x[3]^2+x[4]^2, "gradient" = c( 0, 0, 2*x[3], 2*x[4] ) ) ) } # constraint functions # equalities eval_g_eq <- function( x ) { constr <- c( x[1] + x[2] + x[3] - 4, x[1]^2 + x[2]^2 + x[4] - 15 ) grad <- c( c(1, 1, 1, 0), c(2*x[1], 2*x[2], 0, 1) ) return( list( "constraints"=constr, "jacobian"=grad ) ) } # initial values x0 <- c( 1, 5, 5, 1 ) local_opts <- list( "algorithm" = "NLOPT_LD_MMA", "xtol_rel" = 1.0e-7

C# string equality operator returns false, but I'm pretty sure it should be true… What?

偶尔善良 提交于 2019-12-05 08:36:28
I'm trying to write a unit test for a piece of code that generates a large amount of text. I've run into an issue where the "expected" and "actual" strings appear to be equal, but Assert.AreEqual throws, and both the equality operator and Equals() return false. The result of GetHashCode() is different for both values as well. However, putting both strings into text files and comparing with DiffMerge tells me they're the same. Additionally, using Encoding.ASCII.GetBytes() on both values and then using SequenceEquals to compare the resulting byte arrays returns true. The values are 34KB each, so

Using CLOS class instances as hash-table keys?

放肆的年华 提交于 2019-12-05 07:11:42
I have the following class: (defclass category () ((cat-channel-name :accessor cat-channel-name :initarg :cat-channel-name :initform "" :type string :documentation "Name of the channel of this category") (cat-min :accessor cat-min :initarg :min :initform 0 :type number :documentation "Mininum value of category") (cat-max :accessor cat-max :initarg :max :initform 1 :type number :documentation "Maximum value of category")) (:documentation "A category")) Now, I would like to use this class as a key for a hash-table. The addresses of instances can be easily compared with eq . The problem is

Equality for anonymous types [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-05 05:59:15
This question already has answers here : Why does the Equals implementation for anonymous types compare fields? (4 answers) Closed 5 years ago . Why does the semantics of Equals() and == differs when used to compare anonymous types? Why does one compare values and the other compare references? What is the reason behind it? == doesn't call Equals , it looks for == overloaded operator. Since anonymous types doesn't have overloaded == operator, so C# uses reference comparison for it. But with Equals it compares field values. That is why the result between == and Equals differ. Anonymous Types (C#

In Groovy, why does the behaviour of '==' change for interfaces extending Comparable?

≡放荡痞女 提交于 2019-12-05 04:47:05
I'm trying to develop a project in Groovy and I've found some of my tests failing in an odd way: I have an interface Version extends Comparable<Version> with two concrete subclasses. Both override equals(Object) and compareTo(Version) - however, if I try to compare two instances of Version that are of different concrete types using == , the equality check fails even though explicit equals and compareTo checks pass. If I remove the extends Comparable<Version> part of Version , I get the expected behaviour - == gives the same result as equals would. I've read elsewhere that Groovy delegates ==

Scala: Does == default to equals?

流过昼夜 提交于 2019-12-05 04:39:14
I'm reading through Programming in Scala. It says: You can redefine the behavior of == for new types by overriding the equals method, which is always inherited from class Any . The inherited equals , which takes effect unless overridden, is object identity, as is the case in Java. So equals (and with it, == ) is by default the same as eq , but you can change its behavior by overriding the equals method in the classes you define. It is not possible to override == directly, as it is defined as a final method in class Any . That is, Scala treats == as if was defined as follows in class Any :

Actionscript Date Comparison

こ雲淡風輕ζ 提交于 2019-12-05 03:58:50
In my Actionscript code I have two dates: var date1:Date = new Date(2011,1,1); var date2:Date = new Date(2011,1,1); This doesn't work: var equal:Boolean = date1 == date2; From reading I've found that this is a working alternative since it just gets the number of milliseconds from a standard point in time. var equal:Boolean = date1.getTime() == date2.getTime(); So my questions are: Why doesn't the normal equality operator work on Dates in actionscript? ">" as well as "<" operators seem to work fine, but can they be trusted? Why would they work but not the equality operator? Is there a standard