From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Wingo Newsgroups: gmane.lisp.guile.bugs Subject: bug#26106: Defining a method named '-' with one parameter Date: Wed, 19 Apr 2017 17:00:25 +0200 Message-ID: <87vaq0l9x2.fsf@igalia.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1492614082 5787 195.159.176.226 (19 Apr 2017 15:01:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 19 Apr 2017 15:01:22 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux) Cc: 26106@debbugs.gnu.org To: Alejandro Sanchez Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Apr 19 17:01:14 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0r6V-00019H-Ck for guile-bugs@m.gmane.org; Wed, 19 Apr 2017 17:01:11 +0200 Original-Received: from localhost ([::1]:48653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0r6X-0007Qq-Vb for guile-bugs@m.gmane.org; Wed, 19 Apr 2017 11:01:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42058) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0r6Q-0007QD-VN for bug-guile@gnu.org; Wed, 19 Apr 2017 11:01:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0r6N-00017j-22 for bug-guile@gnu.org; Wed, 19 Apr 2017 11:01:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58842) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d0r6M-000175-N6 for bug-guile@gnu.org; Wed, 19 Apr 2017 11:01:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d0r6M-0002Tn-9h for bug-guile@gnu.org; Wed, 19 Apr 2017 11:01:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Andy Wingo Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 19 Apr 2017 15:01:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 26106 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 26106-submit@debbugs.gnu.org id=B26106.14926140369488 (code B ref 26106); Wed, 19 Apr 2017 15:01:02 +0000 Original-Received: (at 26106) by debbugs.gnu.org; 19 Apr 2017 15:00:36 +0000 Original-Received: from localhost ([127.0.0.1]:57041 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d0r5v-0002Sy-H2 for submit@debbugs.gnu.org; Wed, 19 Apr 2017 11:00:35 -0400 Original-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 ) id 1d0r5u-0002Sr-Gg for 26106@debbugs.gnu.org; Wed, 19 Apr 2017 11:00:34 -0400 Original-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= Original-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) Original-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) In-Reply-To: (Alejandro Sanchez's message of "Wed, 15 Mar 2017 14:35:18 +0100") X-Pobox-Relay-ID: EF708538-2510-11E7-B362-07D2064AB293-02397024!pb-sasl1.pobox.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: "bug-guile" Xref: news.gmane.org gmane.lisp.guile.bugs:8753 Archived-At: On Wed 15 Mar 2017 14:35, Alejandro Sanchez 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 () > (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 ) (v )) > (make #:x (* n (get-x v)) #:y (* n (get-y v)))) >=20=09 > (define-method (- (v )) > (* -1 v)) >=20=09 > (define v (make #: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 #< - (2)> in call (- 0 #< 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 #< 10a8e4020>) > In unknown file: > 0 (scm-error goops-error #f "No applicable method for ~S in c= all ~S" (#< - (2)> (- 0 #<)) #) 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