What is the difference between eq?, eqv?, equal?, and = in Scheme?

I’ll answer this question incrementally. Let’s start with the = equivalence predicate. The = predicate is used to check whether two numbers are equal. If you supply it anything else but a number then it will raise an error: (= 2 3) => #f (= 2.5 2.5) => #t (= ‘() ‘()) => error The … Read more

How to test the equivalence of maps in Golang?

The Go library has already got you covered. Do this: import “reflect” // m1 and m2 are the maps we want to compare eq := reflect.DeepEqual(m1, m2) if eq { fmt.Println(“They’re equal.”) } else { fmt.Println(“They’re unequal.”) } If you look at the source code for reflect.DeepEqual‘s Map case, you’ll see that it first checks … Read more

Why does `if None.__eq__(“a”)` seem to evaluate to True (but not quite)?

This is a great example of why the __dunder__ methods should not be used directly as they are quite often not appropriate replacements for their equivalent operators; you should use the == operator instead for equality comparisons, or in this special case, when checking for None, use is (skip to the bottom of the answer … Read more

How to show loading spinner in jQuery?

There are a couple of ways. My preferred way is to attach a function to the ajaxStart/Stop events on the element itself. $(‘#loadingDiv’) .hide() // Hide it initially .ajaxStart(function() { $(this).show(); }) .ajaxStop(function() { $(this).hide(); }) ; The ajaxStart/Stop functions will fire whenever you do any Ajax calls. Update: As of jQuery 1.8, the documentation … Read more

Elegant ways to support equivalence (“equality”) in Python classes

Consider this simple problem: class Number: def __init__(self, number): self.number = number n1 = Number(1) n2 = Number(1) n1 == n2 # False — oops So, Python by default uses the object identifiers for comparison operations: id(n1) # 140400634555856 id(n2) # 140400634555920 Overriding the __eq__ function seems to solve the problem: def __eq__(self, other): “””Overrides … Read more