Re: [Scheme-reports] Procedural equivalence: the last debate
John Cowan 06 Jun 2013 05:40 UTC
will@ccs.neu.edu scripsit:
> Although some people have suggested that implementations must
> actually allocate a fresh location every time the lambda is
> evaluated, they're wrong.
I don't see how this claim can be made consistent with the plain language
of R5RS 4.1.4: "Each procedure created as the result of evaluating a
lambda expression is (conceptually) tagged with a storage location",
unless we are to understand that these location tags need not be distinct.
> Furthermore, the R5RS semantics allows both eq? and eqv? to
> return #t when given procedures whose (conceptual) location
> tags are distinct, provided those procedures would behave the
> same under all circumstances.
Quite so: that is one of the #t-or-#f cases.
> In my opinion, the R5RS (and previous documents) erred when they
> referred to eq? as an equivalence predicate. eq? is not required
> to be reflexive when applied to numbers or characters, so it isn't
> really an equivalence predicate. Its restriction to the kinds of
> values on which it is required to be reflexive is an equivalence
> predicate, but it isn't an equivalence predicate on its entire
> domain.
This is clearly true, and there should probably be an editorial change
to note that `eq?` is not really an equivalence predicate.
> (define (cowan-test-eq n x y)
> (cond ((eq? x y) 'done)
> ((= n 0)
> (cowan-test-eq n 'a 'a))
> (else
> (cowan-test-eq (- n 1) x y))))
>
> (define (cowan-test-eqv n x y)
> (cond ((eqv? x y) 'done)
> ((= n 0)
> (cowan-test-eqv n 'a 'a))
> (else
> (cowan-test-eqv (- n 1) x y))))
>
> > (time (cowan-test-eq 100000000 'a 'b))
> Elapsed time...: 423 ms (User: 422 ms; System: 0 ms)
> done
>
> > (time (cowan-test-eqv 100000000 'a 'b))
> Elapsed time...: 2177 ms (User: 2177 ms; System: 1 ms)
> done
Well, I suppose this means that `eq?` is inlined and `eqv?` is not.
However, a system that breaks down `eqv?` into an inlined `eq?` test
followed, if the test fails, by an inlined type test and a fallback
to a non-inlined version of `eqv?` that handles the outside cases
would presumably show a much smaller difference.
--
I Hope, Sir, that we are not John Cowan
mutually Un-friended by this cowan@ccil.org
Difference which hath happened http://www.ccil.org/~cowan
betwixt us. --Thomas Fuller, Appeal of Injured Innocence (1659)
_______________________________________________
Scheme-reports mailing list
Scheme-reports@scheme-reports.org
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports