equality

In Objective-C, what is the equivalent of Java's “instanceof” keyword?

余生颓废 提交于 2019-11-28 15:21:37
I would like to check whether an object (e.g. someObject ) is assignable (cast-able) to a variable of another type (e.g. SpecifiedType ). In Java, I can write: someObject instanceof SpecifiedType A related question is finding whether the runtime type of an object is equal to a another type. In Java, I can write: someObject.getClass().equals(SpecifiedType.class) How can this be done in Objective-C? mouviciel Try [myObject class] for returning the class of an object. You can make exact comparisons with: if ([myObject class] == [MyClass class]) but not by using directly MyClass identifier.

Python if not == vs if !=

我们两清 提交于 2019-11-28 13:33:06
问题 What is the difference between these two lines of code: if not x == 'val': and if x != 'val': Is one more efficient than the other? Would it be better to use if x == 'val': pass else: 回答1: Using dis to look at the bytecode generated for the two versions: not == 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 2 (==) 9 UNARY_NOT 10 RETURN_VALUE != 4 0 LOAD_FAST 0 (foo) 3 LOAD_FAST 1 (bar) 6 COMPARE_OP 3 (!=) 9 RETURN_VALUE The latter has fewer operations, and is therefore likely to be

What happens when you call `if key in dict`

给你一囗甜甜゛ 提交于 2019-11-28 12:21:25
I have a class (let's call it myClass ) that implements both __hash__ and __eq__ . I also have a dict that maps myClass objects to some value, computing which takes some time. Over the course of my program, many (in the order of millions) myClass objects are instantiated. This is why I use the dict to keep track of those values. However, sometimes a new myClass object might be equivalent to an older one (as defined by the __eq__ method). So rather than compute the value for that object again, I'd rather just lookup the value of older myClass object in the dict . To accomplish this, I do if

Equality in Kotlin

一曲冷凌霜 提交于 2019-11-28 12:15:30
I'm learning Kotlin, with a C++ and Java background. I was expecting the following to print true , not false . I know that == maps to equals . Does the default implementation of equals not compare each member, i.e. firstName and lastName ? If so, wouldn't it see the string values as equal (since == maps to equal again)? Apparently there's something related to equality versus identity that I haven't got right in Kotlin yet. class MyPerson(val firstName: String, val lastName: String) fun main(args: Array<String>) { println(MyPerson("Charlie", "Parker") == MyPerson("Charlie", "Parker")) } JB

How or is that possible to prove or falsify `forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q.` in Coq?

最后都变了- 提交于 2019-11-28 11:18:32
I want to prove or falsify forall (P Q : Prop), (P -> Q) -> (Q -> P) -> P = Q. in Coq. Here is my approach. Inductive True2 : Prop := | One : True2 | Two : True2. Lemma True_has_one : forall (t0 t1 : True), t0 = t1. Proof. intros. destruct t0. destruct t1. reflexivity. Qed. Lemma not_True2_has_one : (forall (t0 t1 : True2), t0 = t1) -> False. Proof. intros. specialize (H One Two). inversion H. But, inversion H does nothing. I think maybe it's because the coq's proof independence (I'm not a native English speaker, and I don't know the exact words, please forgive my ignorance), and coq makes it

Is there any connection between `a :~: b` and `(a :== b) :~: True`?

浪子不回头ぞ 提交于 2019-11-28 11:14:44
Is there any connection implemented between propositional and promoted equality? Let's say I have prf :: x :~: y in scope for some Symbol s; by pattern matching on it being Refl , I can transform that into prf' :: (x :== y) :~: True like this: fromProp :: (KnownSymbol x, KnownSymbol y) => x :~: y -> (x :== y) :~: True fromProp Refl = Refl But what about the other direction? If I try toProp :: (KnownSymbol x, KnownSymbol y) => (x :== y) :~: True -> x :~: y toProp Refl = Refl then all I get is • Could not deduce: x ~ y from the context: 'True ~ (x :== y) Yes, going between the two

Reference equality performance difference? ((object)obj1 == (object)obj2) vs. object.ReferenceEquals( obj1, obj2 )

一笑奈何 提交于 2019-11-28 10:47:59
Is there extra overhead in using the object.ReferenceEquals method verses using ((object)obj1 == (object)obj2) ? In the first case, there would be a static method call involved, and in both cases some form of casting to an object would be involved. Even if the compiler balances out those methods, what about inequality? (object)obj != null as compared to... !object.ReferenceEquals(obj,null) I suppose that at some point, a logical negation would occur, either within the != operator, or as applied to the result of the ReferenceEquals method. What do you think? There's also the issue of

3 Equals or Case Equality operator

只谈情不闲聊 提交于 2019-11-28 10:46:48
In Ruby Integer === 5 returns true . Similarly String === "karthik" returns true . However, 5 === Integer returns false . And "karthik" === String . Why is the operator not commutative? The simple answer is: because it doesn't make sense. The relationship the operator describes is not commutative, why should the operator be? Just look at your own examples: 5 is an Integer . But is Integer a 5 ? What does that even mean ? === is the case subsumption operator , and subsumption doesn't commute. The fact that the case subsumption operator uses equals signs, and that it is usually called the triple

Pointer equality in Haskell?

拜拜、爱过 提交于 2019-11-28 09:56:53
Is there any notion of pointer quality in Haskell? == requires things to be deriving Eq, and I have something which contains a (Value -> IO Value), and neither -> nor IO derive Eq. EDIT: I'm creating an interpreter for another language which does have pointer equality, so I'm trying to model this behavior while still being able to use Haskell functions to model closures. EDIT: Example: I want a function special that would do this: > let x a = a * 2 > let y = x > special x y True > let z a = a * 2 > special x z False Apocalisp EDIT : Given your example, you could model this with the IO monad.

Object comparison for equality : JAVA

二次信任 提交于 2019-11-28 09:46:27
问题 public ClassA { private String firstId; private String secondId; public void setFirstId(String firstId) { this.firstId = firstId; } public String getFirstId() { return id; } public void setSecondId(String secondId) { this.secondId = secondId; } public String getSecondId() { return secondId; } } public ClassB { private String firstId; private String secondId; public void setFirstId(String firstId) { this.firstId = firstId; } public String getFirstId() { return id; } public void setSecondId