From: Alejandro Sanchez <hiphish@openmailbox.org>
To: 26026@debbugs.gnu.org
Subject: bug#26026: Defining a method named zero? breaks primitive zero?
Date: Wed, 8 Mar 2017 12:07:56 +0100 [thread overview]
Message-ID: <AA1AF09F-8A00-4552-B030-70F829C3C93E@openmailbox.org> (raw)
If I define a ‘zero?’ predicate method for a custom class the primitive ‘zero?’ is lost. Here is a simple vector module:
;;; File vector2.scm
(define-module (vector2)
#:use-module (oop goops)
#:export (<vector2> get-x get-y zero?))
(define-class <vector2> ()
(x #:init-value 0 #:getter get-x #:init-keyword #:x)
(y #:init-value 0 #:getter get-y #:init-keyword #:y) )
(define-generic zero?)
(define-method (zero? (v <vector2>))
(and (zero? (get-x v))
(zero? (get-y v))))
In the Guile REPL try executing the following code:
scheme@(guile-user)> (use-modules (oop goops) (vector2))
scheme@(guile-user)> (zero? (make <vector2>))
This will display
WARNING: (guile-user): `zero?' imported from both (ice-9 r5rs) and (vector2)
ERROR: In procedure scm-error:
ERROR: No applicable method for #<<generic> zero? (1)> in call (zero? 0)
Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue.
scheme@(guile-user) [1]> ,bt
In vector2.scm:
11:7 2 (_ #<<vector2> 105e87e00>)
In oop/goops.scm:
1438:4 1 (cache-miss 0)
In unknown file:
0 (scm-error goops-error #f "No applicable method for ~S in call ~S" (#<<gen…> …) …)
Apparently the problem is that ‘zero?’ is defined in two modules and the vector2 definition overrides it. This isn’t the case with other primitives like ‘+’ or ‘*’, so this seems like a bug? I had built Guile from HEAD a few days ago, my package manager shows 6fff84d as the version number, so I guess that must be the hash of the commit HEAD was pointing to at that time.
next reply other threads:[~2017-03-08 11:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-08 11:07 Alejandro Sanchez [this message]
2017-04-19 15:12 ` bug#26026: Defining a method named zero? breaks primitive zero? Andy Wingo
[not found] ` <handler.26026.D26026.149261474410577.notifdone@debbugs.gnu.org>
2017-04-22 14:46 ` bug#26026: closed (Re: bug#26026: Defining a method named zero? breaks primitive zero?) Alejandro Sanchez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AA1AF09F-8A00-4552-B030-70F829C3C93E@openmailbox.org \
--to=hiphish@openmailbox.org \
--cc=26026@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).