3.3.1 Predicates for testing equality

Dylan provides two predicates for testing equality: = and ==. The = predicate determines whether two objects are similar. Similarity is defined differently for different kinds of objects. When you define new classes, you can define how similarity is tested for those classes by defining a method for =.

The == predicate determines whether the operands are identical — that is, whether the operands are the same object. The == predicate (identity) is a stronger test: two values may be similar but not identical, and two identical values are always similar.

If two numbers are mathematically equal, then they are similar:

? 100 = 100;
#t
? 100 = 100.0;
#t

Two numbers that are similar, and have the same type, are the same object:

? 100 == 100;
#t

Two numbers that are similar, but have different types, are not the same object:

? 100 == 100.0;
#f

Characters are enclosed in single quotation marks. If two characters look the same, they are similar and identical:

? 'z' = 'z';
#t
? 'z' == 'z';
#t

Strings are enclosed in double quotation marks. Strings that have identical elements are similar, but may or may not be identical. That is, strings can have identical elements, but not be the same string. For example, these strings are similar:

? "apple" = "apple";
#t

Just by looking at two strings, you cannot know whether or not they are the identical string. The only way to determine identity is to use the == predicate. The following expression could return #t or #f:

? "apple" == "apple";

A string is always identical to itself:

? begin
    let yours = "apple";
    let mine = yours;
    mine == yours;
  end; 
#t