functional-programmingmit-schemestructural-equality

What defines structural equality?


In terms of structural equality,

Why would (equal? (list 'a 'b)) evaluate to true but (equal? (list 2 'b) '(2 'b)) evaulates to false?


Solution

  • '(2 'b) is equivalent to (list 2 (list 'quote 'b)) - a list whose first element is a number and whose second element is another list.

    It does not compare equal to (list 2 'b) because (list 2 'b)'s second element is a symbol and symbols are not considered equal to lists.