[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Using '-1' in a method named '*'
From: |
Andy Wingo |
Subject: |
Re: Using '-1' in a method named '*' |
Date: |
Tue, 28 Feb 2017 09:54:15 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) |
On Mon 27 Feb 2017 20:21, Andy Wingo <address@hidden> writes:
> Hi,
>
> On Mon 27 Feb 2017 11:06, Alejandro Sanchez <address@hidden> writes:
>
>> (define v (make <vector3> #:x 1))
>>
>> (* -1 v) ; Does not work
>> (* -2 v) ; Works fine
>
> I believe that Guile is doing strength reduction, transforming (* -1 v)
> to (- 0 v).
I spoke too soon. Guile 2.1.x does indeed do this at compile-time, but
only if "v" is an instance of a built-in number type. Guile 2.0.x
doesn't do this strength reduction at all at compile-time.
It turns out there is an easier way to reproduce this bug without GOOPS:
(* -1 "")
scm_product was handling this case specially because of weird
implementation reasons (making sure that negating the most negative
fixnum was a bignum; see b5c40589).
In summary I think Guile's strength reduction is fine as it relies on
type inference to prove when it is safe. This is "just" a bug, albeit
an annoying one that we need to fix!
Andy