GNU bug report logs -
#13741
guile-2.0: optimize, and eq-ness of literals (test-suite)
Previous Next
Reported by: Daniel Hartwig <mandyke <at> gmail.com>
Date: Mon, 18 Feb 2013 03:29:01 UTC
Severity: normal
Found in version 2.0.7
Done: Andy Wingo <wingo <at> pobox.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#13741: guile-2.0: optimize, and eq-ness of literals (test-suite)
which was filed against the guile package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 13741 <at> debbugs.gnu.org.
--
13741: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=13741
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
On Mon 18 Feb 2013 10:16, ludo <at> gnu.org (Ludovic Courtès) writes:
> Daniel Hartwig <mandyke <at> gmail.com> skribis:
>
>> scheme@(guile-user)> (define x 1/2)
>> scheme@(guile-user)> (eq? x 2/4)
>> $7 = #f
>> scheme@(guile-user)> ,optimize (eq? x 2/4)
>> $8 = (eq? x 1/2)
>> scheme@(guile-user)> (define y 2/4)
>> scheme@(guile-user)> (eq? x y)
>> $9 = #f
>> scheme@(guile-user)> ,optimize (define y 2/4)
>> $10 = (define y 1/2)
>
> Quoth R5RS:
>
> `Eq?''s behavior on numbers and characters is
> implementation-dependent, but it will always return either true or
> false, and will return true only when `eqv?' would also return
> true. `Eq?' may also behave differently from `eqv?' on empty
> vectors and empty strings.
>
> What we may get wrong is that it looks as if it doesn’t always return
> either true or false, because the behavior depends on whether one of the
> operands is a literal.
>
> However, it’s fundamentally wrong to rely on eq? to compare numbers. So
> the test case you mention seems buggy, to start with.
Agreed, FWIW. Fractions are allocated on the heap, and eq? picks out
the difference between heap objects. Sometimes two values are the same
object, and sometimes not.
Closing the bug, but please follow up with any questions.
Cheers,
Andy
--
http://wingolog.org/
[Message part 3 (message/rfc822, inline)]
Version: 2.0.7
# stable-2.0, around commit: 3d2b267
# ./configure (no arguments)
hash.test has a failing case:
FAIL: tests/hash.test: hash-set and hash-ref:
;; 1/2 and 2/4 are equal? and eqv? but not eq?
(pass-if (equal? #f
(let ((table (make-hash-table)))
(hashq-set! table 1/2 (quote foo))
(hashq-ref table 1/2))))
which may be due to the optimizer or other component working on
literals:
scheme@(guile-user)> (eqv? 1/2 2/4)
$1 = #t
scheme@(guile-user)> (eq? 1/2 2/4)
$2 = #f
scheme@(guile-user)> ,optimize (eq? 1/2 2/4)
$3 = #f
scheme@(guile-user)> (hashq 1/2 31)
$4 = 6
scheme@(guile-user)> (hashq 2/4 31)
$5 = 20
scheme@(guile-user)> ,optimize (hashq 2/4 31)
$6 = (hashq 1/2 31)
scheme@(guile-user)> ;; uh oh
The ramifications reach beyond hash functions:
scheme@(guile-user)> (define x 1/2)
scheme@(guile-user)> (eq? x 2/4)
$7 = #f
scheme@(guile-user)> ,optimize (eq? x 2/4)
$8 = (eq? x 1/2)
scheme@(guile-user)> (define y 2/4)
scheme@(guile-user)> (eq? x y)
$9 = #f
scheme@(guile-user)> ,optimize (define y 2/4)
$10 = (define y 1/2)
I recall some discussion where it was made clear that literals can not
be assumed eq?, and that *at least* eqv? should be used to compare
numeric values unless they are known to be the same value (i.e. ‘(define
y x) (eq? x y)’).
Is that right? This particular test and some others properly should
fade away then, or at least drop the eq-case.
This bug report was last modified 12 years and 86 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.