[racket] clarification for beginners please

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Apr 25 17:35:10 EDT 2013

On Apr 25, 2013, at 4:57 PM, David Vanderson <david.vanderson at gmail.com> wrote:

> 
> On 04/25/2013 02:57 PM, Matthias Felleisen wrote:
>>> (eqv? (factorial 1000) (factorial 1000)) ;; ... but they point to observably equal numbers, so eqv? uses = to compare them
>> #t
>>> (eqv? (cons 1 2) (cons 1 2)) ;; distinct pointers point to allocated structures, on the other hand, and eqv? compares pointers with pointer equality
>> #f
>> 
> I understand the rationale for eq? and equal? - What is the rationale for eqv?


As I mentioned, eq? is intensional equality -- meaning it equates two pieces of data if they are constructed in exactly the same way. For all 'compound data' (that includes closures), this means -- in current language implementation technology -- that these pieces of data are represented by the same machine pointer. Most people therefore crudely call this 'pointer equality'. 

equal? is extensional equality, meaning it equates two pieces of atomic data (e.g. numbers) if they are mathematically equal (that is, we rely on mathematics to define equality on numbers in an extensional manner) and it equates two pieces of compound if they consist of equal? pieces of data. 

eqv? is Scheme's attempt at incorporating an approximation to the so-called notion of observational equivalence. Two values are observationally equivalent if they are interchangeable in all contexts -- wherever you see one value, you can replace it with another value in an expression position. (If these values could show up inside of strings it would be trivial to distinguish all values.) You can easily show that this mathematically defined function is not computable. Therefore eqv? must be an approximation. And the rationale must be that it is useful in some programs. From a microscopic perspective, eqv? is mostly like equal? but when its recursive traversal reaches compound data it falls back on pointer equality. From a program perspective, I will admit that I fail to have an example handy. 



Posted on the users mailing list.