GNU bug report logs - #26106
Defining a method named '-' with one parameter

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guile; Reported by: Alejandro Sanchez <hiphish@HIDDEN>; dated Wed, 15 Mar 2017 13:36:01 UTC; Maintainer for guile is bug-guile@HIDDEN.

Message received at 26106 <at> debbugs.gnu.org:


Received: (at 26106) by debbugs.gnu.org; 19 Apr 2017 15:00:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Apr 19 11:00:35 2017
Received: from localhost ([127.0.0.1]:57041 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1d0r5v-0002Sy-H2
	for submit <at> debbugs.gnu.org; Wed, 19 Apr 2017 11:00:35 -0400
Received: from pb-sasl1.pobox.com ([64.147.108.66]:59204
 helo=sasl.smtp.pobox.com) by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <wingo@HIDDEN>) id 1d0r5u-0002Sr-Gg
 for 26106 <at> debbugs.gnu.org; Wed, 19 Apr 2017 11:00:34 -0400
Received: from sasl.smtp.pobox.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 2DF1381BCA;
 Wed, 19 Apr 2017 11:00:33 -0400 (EDT)
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=pobox.com; h=from:to:cc
 :subject:references:date:in-reply-to:message-id:mime-version
 :content-type:content-transfer-encoding; s=sasl; bh=kWhDKxxiyflh
 LDkKfbWd0mKOWyM=; b=pMM4Eyi9ALliR+BUQvjXpALmvzyOW9ZEUBOBIQP6lCM9
 DkHck4+yhK2CG//SDnXa5Xrb/iuX9AbTID7OeCTw82bnGQjpJfj2o3YQyJ+gWsFc
 0YOMm8PLWqKATQnbPllpSh/HRULl1OUUBC7AORlTv51CDyRBYb8Oe/zEFxmTguY=
Received: from pb-sasl1.nyi.icgroup.com (unknown [127.0.0.1])
 by pb-sasl1.pobox.com (Postfix) with ESMTP id 2619A81BC9;
 Wed, 19 Apr 2017 11:00:33 -0400 (EDT)
Received: from rusty (unknown [88.160.190.192])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (No client certificate requested)
 by pb-sasl1.pobox.com (Postfix) with ESMTPSA id 598C881BC8;
 Wed, 19 Apr 2017 11:00:32 -0400 (EDT)
From: Andy Wingo <wingo@HIDDEN>
To: Alejandro Sanchez <hiphish@HIDDEN>
Subject: Re: bug#26106: Defining a method named '-' with one parameter
References: <F7542921-8F39-4B4E-B8ED-B6E8F53DAD10@HIDDEN>
Date: Wed, 19 Apr 2017 17:00:25 +0200
In-Reply-To: <F7542921-8F39-4B4E-B8ED-B6E8F53DAD10@HIDDEN> (Alejandro
 Sanchez's message of "Wed, 15 Mar 2017 14:35:18 +0100")
Message-ID: <87vaq0l9x2.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Pobox-Relay-ID: EF708538-2510-11E7-B362-07D2064AB293-02397024!pb-sasl1.pobox.com
X-Spam-Score: 0.7 (/)
X-Debbugs-Envelope-To: 26106
Cc: 26106 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.7 (/)

On Wed 15 Mar 2017 14:35, Alejandro Sanchez <hiphish@HIDDEN> write=
s:

> If I define a method named =E2=80=98-=E2=80=98 which only takes in one pa=
rameter, the expression =E2=80=98(- v)=E2=80=99 gets rewritten to =E2=80=98=
(- 0 v)=E2=80=99. Here is a minimal example:
>
> 	(use-modules (oop goops))
>=20=09
> 	(define-class <vector2> ()
> 	  (x #:init-value 0 #:getter get-x #:init-keyword #:x)
> 	  (y #:init-value 0 #:getter get-y #:init-keyword #:y))
>=20=09
> 	(define-method (* (n <number>) (v <vector2>))
> 	  (make <vector2> #:x (* n (get-x v)) #:y (* n (get-y v))))
>=20=09
> 	(define-method (- (v <vector2>))
> 	  (* -1 v))
>=20=09
> 	(define v (make <vector2> #:x 1 #:y 2))
> 	(* -1 v)  ; Works fine
> 	(- v)  ; Throws error
>
> Here is the error message:
>
> 	scheme@(guile-user)> (- v)
> 	ERROR: In procedure scm-error:
> 	ERROR: No applicable method for #<<generic> - (2)> in call (- 0 #<<vecto=
r2> 10a8e4020>)
>=20=09
> 	Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
> 	scheme@(guile-user) [1]> ,bt
> 	In current input:
> 	     23:0  2 (_)
> 	In oop/goops.scm:
> 	   1438:4  1 (cache-miss 0 #<<vector2> 10a8e4020>)
> 	In unknown file:
> 	           0 (scm-error goops-error #f "No applicable method for ~S in c=
all ~S" (#<<generic> - (2)> (- 0 #<<vec=E2=80=A6>)) #)

Is (- x) equivalent to (* x -1) ?

Right now there are a few things happening.  The "primitive expansion"
phase in an early part of the compiler turns (- x) to (- 0 x), where
obviously it should not be doing that.  But can it turn it into (* x -1)
?  Note that somewhat confusingly, a later part of the compiler that can
detect when X is a real number will undo that transformation, turning it
to (- 0 x) when X is real.  So that sounds OK from an optimization point
of view but is the (* x -1) tranformation correct from the math point of
view?

Andy




Information forwarded to bug-guile@HIDDEN:
bug#26106; Package guile. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 15 Mar 2017 13:35:41 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Mar 15 09:35:41 2017
Received: from localhost ([127.0.0.1]:56418 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1co95Z-0003na-Fn
	for submit <at> debbugs.gnu.org; Wed, 15 Mar 2017 09:35:41 -0400
Received: from eggs.gnu.org ([208.118.235.92]:57807)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <hiphish@HIDDEN>) id 1co95W-0003nI-O9
 for submit <at> debbugs.gnu.org; Wed, 15 Mar 2017 09:35:39 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <hiphish@HIDDEN>) id 1co95L-0005Bk-Up
 for submit <at> debbugs.gnu.org; Wed, 15 Mar 2017 09:35:33 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,T_DKIM_INVALID
 autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:50010)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <hiphish@HIDDEN>)
 id 1co95L-0005Bg-SN
 for submit <at> debbugs.gnu.org; Wed, 15 Mar 2017 09:35:27 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:48755)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <hiphish@HIDDEN>) id 1co95K-0000PE-QB
 for bug-guile@HIDDEN; Wed, 15 Mar 2017 09:35:27 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <hiphish@HIDDEN>) id 1co95H-0005Ai-O1
 for bug-guile@HIDDEN; Wed, 15 Mar 2017 09:35:26 -0400
Received: from lb1.openmailbox.org ([5.79.108.160]:39390
 helo=mail.openmailbox.org)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <hiphish@HIDDEN>)
 id 1co95H-00059g-G9
 for bug-guile@HIDDEN; Wed, 15 Mar 2017 09:35:23 -0400
Received: by mail.openmailbox.org (Postfix, from userid 20002)
 id 9E1C2501F91; Wed, 15 Mar 2017 14:35:20 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=openmailbox.org;
 s=openmailbox; t=1489584920;
 bh=kciHN1U75kjh7/uxXa4uZ1rzOM+MU8JAsXE4SQwzfa4=;
 h=From:Subject:Date:To:From;
 b=ZBeqhOJsEGieyEWNNbvIUIdbU1U8sdb4AcCoYA1kaYlRTY291E2bBqc2lbpTfyn9G
 dfZnLCyCpae0uHKYMQNzmQUr7LUAe4UVbTC13yLdTbO+ZHTPescmCSmdBfbT53fY/T
 NQP2IcBwzZTJTvr9ZxhfMhM5TClkgVrCWFqaJG9c=
From: Alejandro Sanchez <hiphish@HIDDEN>
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=openmailbox.org;
 s=openmailbox; t=1489584920;
 bh=kciHN1U75kjh7/uxXa4uZ1rzOM+MU8JAsXE4SQwzfa4=;
 h=From:Subject:Date:To:From;
 b=ZBeqhOJsEGieyEWNNbvIUIdbU1U8sdb4AcCoYA1kaYlRTY291E2bBqc2lbpTfyn9G
 dfZnLCyCpae0uHKYMQNzmQUr7LUAe4UVbTC13yLdTbO+ZHTPescmCSmdBfbT53fY/T
 NQP2IcBwzZTJTvr9ZxhfMhM5TClkgVrCWFqaJG9c=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Subject: Defining a method named '-' with one parameter
Message-Id: <F7542921-8F39-4B4E-B8ED-B6E8F53DAD10@HIDDEN>
Date: Wed, 15 Mar 2017 14:35:18 +0100
To: bug-guile@HIDDEN
Mime-Version: 1.0 (Mac OS X Mail 9.3 \(3124\))
X-Mailer: Apple Mail (2.3124)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
 [fuzzy]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -4.0 (----)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -4.0 (----)

If I define a method named =E2=80=98-=E2=80=98 which only takes in one =
parameter, the expression =E2=80=98(- v)=E2=80=99 gets rewritten to =
=E2=80=98(- 0 v)=E2=80=99. Here is a minimal example:

	(use-modules (oop goops))
=09
	(define-class <vector2> ()
	  (x #:init-value 0 #:getter get-x #:init-keyword #:x)
	  (y #:init-value 0 #:getter get-y #:init-keyword #:y))
=09
	(define-method (* (n <number>) (v <vector2>))
	  (make <vector2> #:x (* n (get-x v)) #:y (* n (get-y v))))
=09
	(define-method (- (v <vector2>))
	  (* -1 v))
=09
	(define v (make <vector2> #:x 1 #:y 2))
	(* -1 v)  ; Works fine
	(- v)  ; Throws error

Here is the error message:

	scheme@(guile-user)> (- v)
	ERROR: In procedure scm-error:
	ERROR: No applicable method for #<<generic> - (2)> in call (- 0 =
#<<vector2> 10a8e4020>)
=09
	Entering a new prompt.  Type `,bt' for a backtrace or `,q' to =
continue.
	scheme@(guile-user) [1]> ,bt
	In current input:
	     23:0  2 (_)
	In oop/goops.scm:
	   1438:4  1 (cache-miss 0 #<<vector2> 10a8e4020>)
	In unknown file:
	           0 (scm-error goops-error #f "No applicable method for =
~S in call ~S" (#<<generic> - (2)> (- 0 #<<vec=E2=80=A6>)) #)





Acknowledgement sent to Alejandro Sanchez <hiphish@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-guile@HIDDEN. Full text available.
Report forwarded to bug-guile@HIDDEN:
bug#26106; Package guile. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Mon, 25 Nov 2019 12:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.