cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.95k stars 982 forks source link

TSPL4's description of eq?/eqv?/equal? for procedure comparison contradicts R6RS #670

Open symingz opened 1 year ago

symingz commented 1 year ago

TSPL4 asserts that (let ([f (lambda (x) x)]) (eq? f f)) => #t, but R6RS asserts that (let ([f (lambda (x) x)]) (eq? f f)) => unspecified. Similarly for eqv? and equal?.

When describing eq?, TSPL4 states on page 144 that "A procedure created by an evaluation of a lambda expression is identical to itself.", and shows on page 146 a corresponding example (let ([f (lambda (x) x)]) (eq? f f)) => #t. Similar examples are repeated for eqv? and equal? as they are expected to behave the same as eq? when used to compare procedures.

R6RS (including R6RS Errata), on the other hand, states in section 5.10 that:

An object fetched from a location ... is equivalent in the sense of eqv? (section 11.5) to the object last stored in the location before the fetch, except when that object is a procedure. When the object is a procedure, the object fetched from the location will also be a procedure that behaves identically to the procedure last stored in the location, but it is possible that it is not the same object.

The "except when that object is a procedure ..." part is added by R6RS Errata.

R6RS then has an example in section 11.5 which demonstrates this special treatment of procedures: (let ((p (lambda (x) x))) (eqv? p p)) => unspecified. According to R6RS's description of eq? and equal?, the same example would apply to them as well.

If Chez Scheme provides the stronger procedure comparison guarantee for eq?/eqv?/equal? that is currently stated in TSPL4, then it should be documented in CSUG instead of TSPL4.